akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a - c) / (b + c) << endl;

	return 0;
}

Measured memory_bytes: 888
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>
//#include<unordered_set>

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;*/

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, sum = 0;
    cin >> n;
    vector<int> v(n);
    map<int,int> mp;
    for (int i = 0; i < n; i++){
        cin >> v[i];
        mp[v[i]]++;
        sum += v[i];
    }
    int q;
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        sum -= b * mp[b];
        sum += c * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 9496
from networkx import*
N = int(input())
G = MultiDiGraph()
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(i, demand = -c)
    G.add_weighted_edges_from([(i, -1, x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -2, x - y)], capacity = c)
    G.add_weighted_edges_from([(i, -3, -x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -4, -x - y)], capacity = c)
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(N + i, demand = c)
    G.add_weighted_edges_from([(-1, N + i, -x - y)], capacity = c)
    G.add_weighted_edges_from([(-2, N + i, -x + y)], capacity = c)
    G.add_weighted_edges_from([(-3, N + i, x - y)], capacity = c)
    G.add_weighted_edges_from([(-4, N + i, x + y)], capacity = c)

print(-min_cost_flow_cost(G))

Measured memory_bytes: 64036
#include <bits/stdc++.h>
using namespace std;

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
const ll MOD = 1'000'000'007;
const int MN = 200'000;
int DP[MN+1];

ll mod_add(ll a, ll b)
{
    return (((a % MOD) + (b % MOD)) % MOD);
}

ll mod_mul(ll a, ll b){
    return (((a % MOD) * (b % MOD)) % MOD);
}

/* Iterative Function to calculate (x^y)%p  
in O(log y) */
long long mod_exp(long long x, long long y) 
{ 
    long long res = 1; // Initialize result 
  
    x = x % MOD; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % MOD; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % MOD; 
    } 
    return res; 
} 

ll go(ll n){
    if(n < 3) return 0;
    if(DP[n] != -1) return DP[n];
    ll ans = 1;
    for(ll i = n-3; i >= 1; i--){
        ans = mod_add(ans, go(i));
    }
    DP[n] = ans;
    return ans;
}

int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    int S;
    cin >> S;
    memset(DP, -1, sizeof DP);
    if(S < 3){
        cout << 0 << endl;
    }else{
        ll ans;
        ans = go(S);
        cout << ans << endl;
    }
}

Measured memory_bytes: 4376
import numpy as np

n, m, x = map(int, input().split(' '))
a = np.zeros([n, m])
c = np.zeros(n)

for i in range(n):
  v = list(map(int, input().split(' ')))
  a[i, :] = np.array(v[1:])
  c[i] = v[0]

INF = 10000000000000000
ans = INF

for i in range(1<<n):
  skill = np.zeros(m)
  cost = 0
  for j in range(n):
    if i & (1<<j):
      cost += c[j]
      skill += a[j]
  if all(skill >= x):
    ans = min(ans, cost)

print(int(ans) if ans != INF else -1)
  


Measured memory_bytes: 27196
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1<<30)-(1<<15))

ll cost[20][20];
ll dddd[20][20];
void waasharuhuroido(ll n){
	rep(i,0,n)rep(j,0,n)dddd[i][j]=cost[i][j];
	rep(k,0,n)rep(i,0,n)rep(j,0,n)dddd[i][j]=min(dddd[i][j],dddd[i][k]+dddd[k][j]);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,0,10)rep(j,0,10)scanf("%lld",&cost[j][i]);
	waasharuhuroido(10);
	ll ans=0;
	rep(i,0,m)rep(j,0,n){
		int t;
		scanf("%d",&t);
		if(t!=-1)ans+=dddd[1][t];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(void){
    
   int K,X;
   cin >> K >> X;
   int l = X - K + 1;
   int r = X + K - 1;
  for(int i=l;i<=r;i++){
      if(i != r) cout << i << " ";
      if(i == r) cout << i << endl;
  } 
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;
const int MAX_V = 305;

struct road {
  int from;
  int to;
  long dist;

  bool operator>(road other) const {
    return dist > other.dist;
  }
};

long d[MAX_V][MAX_V];
long mind[MAX_V][MAX_V];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  priority_queue<road, vector<road>, greater<road>> que;

  rep(i, n) rep(j, n) {
    long dist;
    cin >> dist;

    d[i][j] = INF*INF;
    mind[i][j] = dist;
    que.push(road({i, j, dist}));
  }

  long res = 0;
  bool canDo = true;
  while (!que.empty()) {
    road v = que.top();
    que.pop();

    if (v.from >= v.to) continue;
    if (v.dist < d[v.from][v.to]) {
      res += v.dist;
      d[v.from][v.to] = v.dist;
      d[v.to][v.from] = v.dist;
      rep(i, n) {
        d[i][v.from] = min(d[i][v.from], d[i][v.to] + d[v.to][v.from]);
        d[i][v.to] = min(d[i][v.to], d[i][v.from] + d[v.to][v.from]);
        d[v.from][i] = d[i][v.from];
        d[v.to][i] = d[i][v.to];
      }
      rep(i, n) rep(j, n) {
        d[i][j] = min(d[i][j], d[i][v.from] + d[v.from][j]);
        d[i][j] = min(d[i][j], d[i][v.to] + d[v.to][j]);
      }
    } else if (v.dist > d[v.from][v.to]) {
      canDo = false;
      break;
    }
  }

  cout << (canDo?res:-1) << endl;
}


Measured memory_bytes: 4076
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;



int main(void){
    int n;
    cin >> n;
    vector<int> v;
    REP(i,n){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(RALL(v));
    ll ans=0;
    FOR(i,1,n){
        ans+=v[i/2];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4232
import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = ni()

    deka = 10 ** 9
    x1 = s // deka
    tmp = s % deka

    if tmp:
        y1 = deka - tmp
    else:
        x1 -= 1
        y1 = 0

    print(x1 + 1, y1, 1, deka, 0, 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5116
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int M;
  cin >> M;

  long long dsum = 0,nsum = 0;
  for(int i = 0;i < M;i++) {
    long long d,c;
    cin >> d >> c;
    dsum += c;
    nsum += d*c;
  }


  cout << dsum-1 + (nsum-1) / 9 << endl; 

}






Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function euc(a,m)
	b = m
	x = 1
	u = 0
	while b>0
		q = div(a,b)
		tmp = u
		u = x-q*u
		x = tmp
		tmp = b
		b = a-q*b
		a = tmp
	end
	x<0?x+abs(m):x
end

function abmp(a,b,p)
	if b == 0
		1
	elseif b%2 == 0
		k = abmp(a,div(b,2),p)
		(k*k)%p
	else
		(a*abmp(a,b-1,p))%p
	end
end

function binarr(n,p)
	z = 1
	for i in 1:n
		z = z*i%p
	end
	fac = Array{Int}(n+1)
	inv = Array{Int}(n+1)
	inv[n+1] = abmp(z,p-2,p)
	for i in 0:n-1
		inv[n-i] = (inv[n+1-i]*(n-i))%p
	end
	for i in 0:n
		fac[i+1] = (((z*inv[i+1])%p)*inv[n+1-i])%p
	end
	fac
end

function main()
	p = 10^9+7
	h,w,a,b = readline() |> split |> parseMap
	c = zeros(Int,w-b)
	d = zeros(Int,w-b)
	c[1] = binarr(h-a+b-1,p)[h-a]
	d[w-b] = 1
	for i in 1:w-b-1
		c[i+1] = (c[i]*euc(b+i,p)%p)*(h-a+b+i-1)%p
		d[w-b-i] = (d[w-b-i+1]*euc(i,p))%p*(a+i-1)%p
	end
	ans = 0
	for i in 1:w-b
		ans = (ans+c[i]*d[i])%p
	end
	println(ans)
end

main()

Measured memory_bytes: 117172
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int n, k;
bool has_enough(ll xmin, ll xmax, ll ymin, ll ymax, vector<P> &xy){
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    ll x = xy[i].first;
    ll y = xy[i].second;
    if (x >= xmin && x <= xmax && y >= ymin && y <= ymax)
      cnt++;
  }
  return cnt >= k;
}
int main() {
  cin >> n >> k;
  vector<P> xy(n);
  vector<ll> x(n);
  vector<ll> y(n);
  
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
    cin >> y[i];
    xy[i] = P(x[i], y[i]);
  }
  
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  ll ans = (x[n - 1] - x[0]) * (y[n - 1] - y[0]);
  for (int x1 = 0; x1 < n; ++x1) {
    for (int x2 = x1 + 1; x2 < n; x2++) {
      for (int y1 = 0; y1 < n; ++y1) {
        for (int y2 = y1 + 1; y2 < n; ++y2) {
          ll xmin = min(x[x1], x[x2]);
          ll xmax = max(x[x1], x[x2]);
          ll ymin = min(y[y1], y[y2]);
          ll ymax = max(y[y1], y[y2]);
          if (has_enough(xmin, xmax, ymin, ymax, xy))
            ans = min(ans, abs(xmax - xmin) * abs(ymax - ymin));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int x, num = 0, cnt = 0;
	int beki[999999] = { 0 };

	cin >> x;
	
	if (x == 1) {
		cout << 1 << endl;
		return 0;
	}
	/*
	for (i = 1; ; i++) {

		if(i*i > x) {
			num = i - 1;
			break;
		}
		else if (i*i == x) {
			num = i;
			break;
		}
	}

	*/

	for (i = 1; i <= x; i++) {
		for (j = 2; j <= x; j++) {
			if (pow(i,j) <= x) {
				beki[cnt] = pow(i, j);
				cnt++;
			}else if (pow(i,j) > x) {
				
				break;
			}
			

		}
	}

	int maxn = 0;
	for (i = 0; i < cnt; i++) {
		maxn = max(beki[i], maxn);
	}

	cout << maxn << endl;






	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long ll;

/////////////////////////////////DEBUG/////////////////////////////////
void printd(const char* format)
{
  #ifdef DEBUG
    std::cout << format;
  #endif
}
template<typename T, typename... Targs>
void printd(const char* format, T value, Targs... Fargs)
{
  #ifdef DEBUG
    for ( ; *format != '\0'; format++ ) {
        if ( *format == '%' ) {
           std::cout << value;
           printd(format+1, Fargs...);
           return;
        }
        std::cout << *format;

    }
  #endif
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

///////////////////////////////// YAY /////////////////////////////////
void solve()
{
  int n; cin>>n;
  int ac =0, wa =0, tle =0, re=0;
  for (int i = 0; i < n; i++) {
    string temp;std::cin >> temp;
    if(temp == "AC") ac++;
    else if (temp == "WA") wa++;
    else if(temp == "TLE") tle++;
    else if(temp ==  "RE") re++;
    /* code */
  }
  std::cout << "AC x "<<ac << '\n';


  std::cout << "WA x "<<wa << '\n';
  std::cout << "TLE x "<<tle << '\n';


  std::cout << "RE x "<<re << '\n';
}

int main(int argc, char const *argv[]) {
  int t;
  t=1;
  #ifdef DEBUG
    freopen("input.txt","r", stdin);
    clock_t start, end;
    start = clock();
    cin>>t;
  #endif


  for(int i = 1; i<=t; i++)
  {
    // std::cout << "Case "<<i<<": " << '\n';
    solve();
  }

  #ifdef DEBUG
    end = clock();
    double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
    time_taken *= 1000;
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " ms " << endl;
  #endif
}


Measured memory_bytes: 3628
a,b,c,x,y = map(int, input().split())
cost = {x:a, y:b}
s = min(x,y) * c * 2 + abs(x - y) * cost[max(x,y)]
t = max(x,y) * c * 2
u = a * x + b * y

print(min([s, t, u]))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
vector<long long int> hoge;
long long int query(long long int a,long long int b,long long int k,long long int l,long long int r){
  if(r<=a||b<=l) return 2147483647;
  if(a<=l&&b>=r){
    return hoge.at(k);
  }else{
    long long int c1=query(a,b,2*k+1,l,(l+r)/2);
    long long int c2=query(a,b,2*k+2,(l+r)/2,r);
    return min(c1,c2);
  }
}
void update(long long int n,long long int x,long long int y){
  long long int i=x+n-1;
  hoge.at(i)=y;
  while(i>0){
  i=(i-1)/2;
    hoge.at(i)=min(hoge.at(2*i+1),hoge.at(2*i+2));
  }
}
//hoge=vector<long long int>(2*n-1,INF)で初期化
int main(void){
  long long int n,q;
  cin>>n>>q;
  long long int N=1;
  while(N<n) N*=2;
  n=N;
  hoge=vector<long long int>(2*n-1,2147483647);
  for(long long int i=0; i<q; i++){
    long long int num,x,y;
    cin>>num>>x>>y;
    if(num==0){
      update(n,x,y);
    }else{
      long long int ans=query(x,y+1,0,0,n);
      cout<<ans<<endl;
    }
  }
}


Measured memory_bytes: 7068
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
priority_queue<int>q;
inline int read(){
	char ch=getchar();
	int o=0;
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		o=(o<<3)+(o<<1)+(ch^48);
		ch=getchar();
	}
	return o;
}
int n,m,ans,pos;
struct node{
	int time,money;
}w[100001];
inline bool cmp(node x,node y){
	return x.time<y.time;
}
int main(){
	n=read();
	m=read();
	for(register int i=1;i<=n;i++){
		w[i].time=read();
		w[i].money=read();	
	}
	sort(w+1,w+1+n,cmp);
	pos=1;
	for(register int i=1;i<=m;i++){
		while(w[pos].time<=i)q.push(w[pos++].money);
		if(!q.empty()){
			ans+=q.top();
			q.pop();
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

template <class T>
vector<T> prime_factorization(T n) {
    vector<T> ret;
    for (T i = 2; i * i <= n; i++) {
        T cnt = 0;
        while(n % i == 0) {
            n /= i;
            cnt++;
        }
        if(cnt != 0) ret.push_back(i);
    }
    if (n != 1) ret.push_back(n);
    return ret;
}

int main(){
    int64_t a, b;
    cin >> a >> b;

    auto a_div = prime_factorization(a);
    auto b_div = prime_factorization(b);

    int64_t ans = 1;
    for (auto & elm : a_div) {
        auto itr = find(b_div.begin(), b_div.end(), elm);
        // cout << *itr << endl;
        if(itr == b_div.end()) continue;
        ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main(){
    int n;
    double sum=0.0;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        // sum=sum+(1/a[i]);
    }
    for(int i=0; i<n; i++){
         sum=sum+(1.0/a[i]);
    }
    
    
    cout<<1.0/sum<<endl;



}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	//static boolean f;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		/* 入力の受け取り
		 * String s = sc.next();
		 * int a = sc.nextInt();
		 * long a = sc.nextLong();
		 */
		
		// 文字列(String)を文字(char)に分解
		// char[] s_char = s.toCharArray();
		
		int k = sc.nextInt();
		long sum = 0;
		
		for(int a=1;a<=k;a++) {
			for(int b=1;b<=k;b++) {
				for(int c=1;c<=k;c++) {
					sum += gcd(a,b,c);
				}
			}	
		}
		
		System.out.println(sum);
		
		/*
		 * if(f)
		 *	System.out.println("Yes");
		 * else
		 * 	System.out.println("No");
		 */
	}
	
	static long gcd(long a, long b, long c){
		return gcd(a,gcd(b,c));
	}
	
	// ユークリッドの互除法(最大公約数を求める)
	static long gcd(long x, long y) {
        return x%y==0? y : gcd(y,x%y);
    }
		
}


Measured memory_bytes: 35884
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBattle solver = new BBattle();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBattle {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();
            int sum1 = (a % d == 0 ? a / d : a / d + 1);
            int sum2 = (c % b == 0 ? c / b : c / b + 1);
            // out.println(sum1);
            if (sum1 >= sum2) out.println("Yes");
            else out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 32640
#include <bits/stdc++.h>
using namespace std;
int N;
int A[100000 + 100];
inline void chkmax(int &x, int y) {x = max(x, y); };
inline void chkmin(int &x, int y) {x = min(x, y); };
int main()
{
	scanf("%d", &N);
	int Max = 0, Min = 0x3f3f3f3f;
	for (int i = 1; i <= N; ++i)
	{
		int x;
		scanf("%d", &x);
		A[i] = x;
		chkmax(Max, x);
		chkmin(Min, x);
	}
	int Sum_Max = 0, Sum_Min = 0;
	if (Max > Min + 1) { puts("No"); return 0; }
	for (int i = 1; i <= N; ++i)
		if (A[i] == Max)Sum_Max ++;
		else Sum_Min ++;
	if (Max == Min)
	{
		if (N == Max + 1)puts("Yes");
		else if (N / 2 >= Max)puts("Yes");
		else puts("No");
	}
	else 
	{
		if (Sum_Max / 2 + Sum_Min >= Max && Max >= Sum_Min + 1)puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define sz(x) ll(x.size())
using namespace std;

int main() {
  ll n,m,ind;
  string s;
  vector<ll>a;
  cin >> n >> m >> s;
  ind=n;
  while(ind>0){
  	int flg=0;
  	for(ll j=m;j>=1;j--){
  		if(ind-j<0) continue;
  		if(s.at(ind-j)=='0'){
  			ind-=j;
  			a.push_back(j);
  			flg=1;
  			break;
  		}
  	}
  	if(flg==0) break;
  }
  if(ind==0){
  	reverse(a.begin(),a.end());
  	rep(i,sz(a)) cout << a.at(i) << " ";
  }
  else cout << -1 <<endl;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,m; cin >> n >> m;
  PQ pq;
  REP(i,n) {
    int a; cin >> a;
    pq.push(a);
  }
  REP(i,m) {
    int a = pq.top(); pq.pop();
    pq.push(a/2);
  }
  ll ans = 0;
  REP(i,n) { ans+=pq.top(); pq.pop(); }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 892
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

v = 0
li = [v]
set_ = {v}
while True:
    nxt_v = a[v]
    if nxt_v not in set_:
        li.append(nxt_v)
        set_.add(nxt_v)
        v = nxt_v
    else:
        start = nxt_v
        break

for i in range(len(li)):
    if li[i] == start:
        ratio = li[i:]
        syoko = li[0:i]

if k < len(syoko):
    print(syoko[k] + 1)

else:
    k -= len(syoko)
    print(ratio[k % len(ratio)] + 1)


Measured memory_bytes: 126720
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;

const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int N;
int p[21234], sum[21234];
int a[21234], b[21234];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", p + i);
	
	REP(i, N) sum[p[i] - 1] = i;
	
	int na = 0, nb = 800000000, d = 0;
	REP(i, N) {
		na++; nb--;
		
		if (d < sum[i]) na += sum[i] - d;
		else nb -= d - sum[i];
		
		d = sum[i];
		
		a[i] = na;
		b[i] = nb;
	}
	
	REP(i, N) printf("%d%c", a[i], i == N - 1 ? '\n' : ' ');
	REP(i, N) printf("%d%c", b[i], i == N - 1 ? '\n' : ' ');
	
	return 0;
}


Measured memory_bytes: 896
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())

    ans = 100
    for i in range(1, N+1):
        if N % i == 0:
            ans = min(ans, max(len(str(i)), len(str(N//i))))
        if i*i >= N:
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39152
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

template <class T> string toString(const T &t) { stringstream ss; ss << t; return ss.str(); }

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

void solve();
int main() { solve(); return 0; }

vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}

/// template end ///

void solve()
{
	while (true)
	{
		READ(int, a0, L);
		if (!(a0|L)) { break; }
		vector<int> list;
		list.push_back(a0);
		
		FOR(i, 1, 30)
		{
			string xx = toString(list.back());
			string x = string(L, '0');
			string y;
			copy(ALLOF(xx), x.begin()); 
			sort(ALLOF(x)); 
			reverse_copy(ALLOF(x), back_inserter(y));

			int n = atoi(y.c_str()) - atoi(x.c_str());
			auto j = find(ALLOF(list), n) - list.begin();
			if (j != list.size())
			{
				cout << j << ' ' << n << ' ' << i - j << endl;
				break;
			}
			list.push_back(n);
		}

	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<int> prime;
	bool a[50001]; for(int i=0;i<50001;i++) a[i]=true;
	a[0]=a[1]=false;
	for(int i=0;i<50000;i++)
	{
		if(!a[i]) continue;
		prime.push_back(i);
		for(int j=i*2;j<50000;j+=i) a[j]=false;
	}
	while(1)
	{
		int n ; cin >> n ;
		if(!n) return 0;
		int sum=0; int len=prime.size();
		for(int i=0;i<len;i++)
		{
			int tmp=n-prime[i];
			if(tmp>n/2) continue;
			if(0<=tmp && tmp<=50000 && a[tmp]==true)
			{
				sum++; 
		//		cout << tmp << ' ' << prime[i] << endl;
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	string str;
	cin>>str;
	if((str[2]==str[3])&&(str[4]==str[5]))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
    return 0;
}





Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

ll f(int x) {
  ll res = 0;
  while (x % 2 == 0) {
    x /= 2;
    ++res;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  for(int i = 0; i < n; ++i) {
    ans += f(a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  string s;
  cin >> s;
  bool ok = true;
  rep(i, s.size()) {
    if(i % 2 == 0 && s[i] == 'L') {
      ok = false;
      break;
    }
    if(i % 2 != 0 && s[i] == 'R') {
      ok= false;
      break;
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

void solve() {
	int n; cin >> n;
	ll sum = 0;
	vector<vector<ll>> ev(n), ev2(n);
	for (int i = 0; i < n; ++i) {
		int place; cin >> place;
		ll inPref, outPref;
		cin >> inPref >> outPref;
		if (inPref > outPref) {
			sum += outPref;
			ev[place-1].push_back(inPref-outPref);
		} else {
			sum += inPref;
			if (place < n)
				ev2[place].push_back(outPref-inPref);
		}
	}
	auto f = [&] (vector<vector<ll>> &evCh) {
		priority_queue<ll,vector<ll>,greater<ll>> cur;
		for (int iPlace = 0; iPlace < n; ++iPlace) {
			priority_queue<ll> disp;
			for (int x : evCh[iPlace]) {
				disp.push(x);
			}
			while (!disp.empty() && len(cur) <= iPlace) {
				cur.push(disp.top());
				disp.pop();
			}
			while (!disp.empty() && !cur.empty() && disp.top() > cur.top()) {
				cur.pop();
				cur.push(disp.top());
				disp.pop();
			}
		}
		while (!cur.empty()) {
			sum += cur.top();
			cur.pop();
		}
	};
	f(ev);
	reverse(all(ev2));
	f(ev2);
	cout << sum << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int nbTests;
	cin >> nbTests;
	for (int iTest = 0; iTest < nbTests; ++iTest) {
		solve();
	}
}


Measured memory_bytes: 19144
#include<stdio.h>

int main (void)

{

 int W,H,x,y,r;

 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0){

 printf("Yes\n");

}

else{

 printf("No\n");

}

return 0;

}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mod 1000000007
using namespace std;

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

int main(){
    fast();
    ll t=1;
//    cin>>t;
    while(t--){
    	string s;
    	ll val=0;
    	cin>>s;
    	for(ll i=0;s[i];i++){
    		val+=(s[i]-'0')%9;
		}
		if(val%9==0)cout<<"Yes";
		else
		cout<<"No";
	}
}

Measured memory_bytes: 3740
import sys
input = sys.stdin.readline
def main():
    N = list(input().rstrip())
    l = len(N)-1
    n = int(N[l])
    if n == 3:
        print('bon')
    elif n == 0 or n == 1 or n == 6 or n == 8:
        print('pon')
    else:
        print('hon')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

const int  mod = 1e9 + 7;
const int e = 2000 + 69;
const int base = 311;

ll a[4][4];
ll b[e];

int main()
{
   for(ll i=1; i<=3; i++)
   {
       for(ll j=1; j<=3; j++)
       {
           cin >> a[i][j];
       }
   }
   ll n;
   cin >> n;
   map<ll,ll>kt;
   for(int i=1; i<=n; i++)
   {
       ll x;
       cin >> x;
       kt[x]++;
   }
   for(int i=1; i<=3; i++)
   {
       ll dem = 0;
       for(int j=1; j<=3; j++)
       {
           if(kt[a[i][j]] > 0)
           {
               dem++;
           }
       }
       if(dem == 3)
       {
           cout << "Yes";
           return 0;
       }
   }
   for(ll j=1; j<=3; j++)
   {
       ll dem = 0;
       for(ll i=1; i<=3; i++)
       {
           if(kt[a[i][j]] > 0)
           {
               dem++;
           }
       }
       if(dem == 3)
       {
           cout <<"Yes";
           return 0;
       }
   }
   if(kt[a[1][1]] == 1 && kt[a[2][2]] == 1 && kt[a[3][3]] == 1 || kt[a[1][3]] == 1 && kt[a[2][2]] == 1 && kt[a[3][1]] == 1)
   {
       cout << "Yes";
       return 0;
   }
   cout <<"No";

}


Measured memory_bytes: 256
N = int(input())
S = input()


lList = []
rList = []
diffcount = 0
cacheS = ''
for x in S:
    cacheS = cacheS + x
for i, x in enumerate(cacheS):
    if x == '(':
        lList.append(i)
        diffcount += 1
    else:
        if diffcount > 0:
            rList.append(i)
            diffcount -= 1
        else:
            S = '(' + S

if 0 < diffcount:
    for i in range(diffcount):
        S = S + ')'
else:
    for i in range(diffcount):
        S = '(' + S

print(S)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    a = a + b;
    int x = std::stoi(a);
    rep(i, 1000) {
        if (x == i*i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    string x; cin >> x;

    int ans = x.length();
    int stack = 0;
    rep (i, x.length()) {
        if(x[i] == 'S') stack++;
        if(x[i] == 'T' and stack > 0) {
            stack--;
            ans -= 2;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
using namespace std;

int gcd(int x, int y)
{
  int r;
  if (x < y)
  {
    swap(x, y);
  }

  while (y > 0)
  {
    r = x % y;
    x = y;
    y = r;
  }

  return x;
}

int main()
{
  int a, b;
  cin >> a >> b;
  cout << gcd(a, b) << endl;

  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;

int main(){
    int n;
    cin >> n;
    int arr[n];
    int brr[n];
    int crr[n-1];
    for(int i=0; i<n; i++) cin >> arr[i];
    for(int i=0; i<n; i++) cin >> brr[i];
    for(int i=0; i<n-1; i++) cin >> crr[i];
    int cntr = 0;
    for(int i=0; i<n; i++){
        if(i>0){
            if((arr[i] - arr[i-1]) == 1){
                cntr += brr[arr[i]-1];
                cntr += crr[arr[i]-2];
            }else{
                cntr+= brr[arr[i]-1];
            }
        }else{
            cntr += brr[arr[i]-1];
        }
}
    cout << cntr;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] val_str = Console.ReadLine().Split(' ');
            int lengh = int.Parse(val_str[0]);
            int target_num = int.Parse(val_str[1]);

            string str = Console.ReadLine();

            char[] c = str.ToCharArray();

            c[target_num - 1] = char.Parse((c[target_num - 1].ToString()).ToLower());

            string result = new string(c);

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int main(void)
{
	float a,s,j;
	int d[5],f[5],i;
	for(i=1;i<=4;i++){
			d[i]=0;
			f[i]=0;
	}
	while(scanf("%f %f",&a,&s)!=EOF){
		if(a>=1.1){
			d[1]++;
		}
		else if(a>=0.6){
			d[2]++;
		}
		else if(a>=0.2){
			d[3]++;
		}
		else{
			d[4]++;
		}
		if(s>=1.1){
			f[1]++;
		}
		else if(s>=0.6){
			f[2]++;
		}
		else if(s>=0.2){
			f[3]++;
		}
		else{
			f[4]++;
		}
	}
	for(i=1;i<=4;i++){
		printf("%d %d\n",d[i],f[i]);
	}
	return 0;
}

Measured memory_bytes: 1052
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}

#define maxn 2005

ll n, a[maxn] = {0}, p[maxn] = {0}, dp[maxn][maxn] = {0};

int comp(int i, int j){
    return a[i]>a[j];
}

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
        
    cin>>n;
    for (int i = 0; i < n; i++){
        cin>>a[i];
        p[i] = i;
    }

    sort(p,p+n,comp);

    for (int size = 1; size <= n; size++){
        for (int i = 0; i < n; i++){
            int j = i + size-1;
            if (j>=n) break;
            if (i==j){
                dp[i][j] = a[p[n-size]]*abs(p[n-size]-i);
                continue;
            }
            dp[i][j] = max(a[p[n-size]]*abs(p[n-size]-i) + dp[i+1][j], a[p[n-size]]*abs(p[n-size]-j) + dp[i][j-1]);
        }
    }

    cout<<dp[0][n-1]<<"\n";

    return 0;
}
 

Measured memory_bytes: 25816
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 0){
        cout << (a + b) / 2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Vi vector<int>
#define Vll vector<long long>
#define Pii pair<int,int>
#define Pll pair<long long, long long>
#define VVi vector<vector<int>>
#define fori(i,a,b) for(int i=a;i<b; i++)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
typedef long long int ll;
typedef double dl;
using namespace std;
 
 
void soln(){
    ll n;cin>>n;
  	Vll v(n);
  	unordered_map<ll,ll> freq;
  	fori(i,0,n){
    	cin>>v[i];
      	freq[v[i]]++;
    }
  	ll count = 0;
  	for(auto i:freq){
     	if(i.first>i.second){
        	count+=i.second;
        }else if(i.first<i.second){
        	count+=(i.second-i.first);
        }
    }
    cout<<count<<"\n";
    
	return;
}
 
int main() {
	// your code goes here
	fastio;
	int t=1 ;//cin>>t;
	while(t--){
		soln();
	}
	return 0;
}


Measured memory_bytes: 8092
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef long long ll;
typedef vector<int> vi;

int main(){
	string s;
    cin >> s;

    for(int i = 0; i < s.size(); i = i+2){
        if(s[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = 1; i < s.size(); i=i+2){
        if(s[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX 100

void insertionSort(int a[], int n){
    int v, j;
    for(int i = 0; i < n; i++){
        cout << a[i];
        if(i != n - 1) cout << " ";
    }
    cout << endl;
    for(int i = 1; i < n; i++){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for(int i = 0; i < n; i++){
            cout << a[i];
            if(i != n - 1) cout << " ";
        }
        cout << endl;
    }
}

int main(){
    int n;
    int a[MAX];

    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];

    insertionSort(a, n);

    return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;

int main(){
  int h, m, s, t, q, w;
  cin>>h>>m>>s>>t>>q>>w;
  
  int g = ( t * 3600 + q * 60 + w  -  h * 3600 - m * 60 - s ) / 3600;
  int a = (( t * 3600 + q * 60 + w  -  h * 3600 - m * 60 - s ) / 60) % 60;
  int b = ( t * 3600 + q * 60 + w  -  h * 3600 - m * 60 - s ) % 60;
  
  
  int c, d, e, f, i, j;
  cin>>c>>d>>e>>f>>i>>j;
  
  int  k= ( f * 3600 + i * 60 + j  -  c * 3600 - d * 60 - e ) / 3600;
  int  l= (( f * 3600 + i * 60 + j  -  c * 3600 - d * 60 - e ) / 60) % 60;
  int  n= ( f * 3600 + i * 60 + j  -  c * 3600 - d * 60 - e ) % 60;
  
 
  int o, p, r, u, v, x;
  cin>>o>>p>>r>>u>>v>>x;
  
  int  y= ( u * 3600 + v * 60 + x  -  o * 3600 - p * 60 - r ) / 3600;
  int  z= (( u * 3600 + v * 60 + x  -  o * 3600 - p * 60 - r ) / 60) % 60;
  int  A= ( u * 3600 + v * 60 + x  -  o * 3600 - p * 60 - r ) % 60;
  
  cout<<g<<" "<<a<<" "<<b<<endl;
  cout<<k<<" "<<l<<" "<<n<<endl;
  cout<<y<<" "<<z<<" "<<A<<endl;


 return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
int main(void){
    int m, n, l;
    int A[110][110], B[110][110];
    long long C[110][110]={0};
    int i, j, k;
    
    scanf("%d %d %d\n", &m, &n, &l);
    
    for(i=1; i<=m; i++) {
        for(j=1; j<=n; j++) {
            scanf("%d", &A[i][j]);
        }
    }
    for(i=1; i<=n; i++) {
        for(j=1; j<=l; j++) {
            scanf("%d", &B[i][j]);
        }
    }
    
    for(i=1; i<=m; i++) {
        for(j=1; j<=l; j++) {
            for(k=1; k<=n; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
            if(j != 1) printf(" ");
            printf("%lld", C[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s; ll k;
    cin >> s >> k;
    ll n = s.size();
    vi chgCnt(n);
    rep(i, n){
        chgCnt[i] = (26-(ll)(s[i]-'a'))%26;
        if(chgCnt[i] <= k){
            k -=chgCnt[i];
            s[i] = 'a';
        }
    }
    k %= 26;
    s[s.size()-1] = (char)((ll)s[s.size()-1] + k);
    cout << s << endl;
}

Measured memory_bytes: 4240
#include <stdio.h>
#define bit(n,m)(((n)>>(m))&1)

int main(){
	int n,c;
	scanf("%d%d",&n,&c);
	int s=0;
	while(c--){
		int t;
		scanf("%d",&t);
		s|=1<<t;
	}
	for(int x=s;x<1<<n;x=(x+1)|s){
		printf("%d:",x);
		for(int k=0;k<n;k++)if(bit(x,k))printf(" %d",k);
		puts("");
	}
}


Measured memory_bytes: 2108