akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const long long INF = (long long) 1e18;

const int N = (int) 1.5e5;
vector <int> ch[N];
int dup[N];
int n;
long long gval;

vector <pair <long long, long long>> ans[N];

void up(int v)
{
    for (auto &p : ans[v])
    {
        p.first += dup[v];
        p.second += dup[v];
    }
}

void dfs(int v)
{
    ans[v].clear();

    if (ch[v].empty())
    {
        ans[v].emplace_back(0, 0);
    }
    else
    {
        int a = ch[v][0];
        int b = ch[v][1];

        dfs(a);
        dfs(b);

        if ((int) ans[a].size() < (int) ans[b].size())
            swap(a, b);

        int ptr = 0;
        for (auto &p : ans[b])
        {
            long long x = p.first;
            long long y = p.second;
            long long need = gval - x;
//            eprintf("need = %lld\n", need);
            while (ptr < (int) ans[a].size() && ans[a][ptr].second > need)
                ptr++;
            if (ptr < (int) ans[a].size())
            {
                ans[v].emplace_back(y, ans[a][ptr].first);
                ans[v].emplace_back(ans[a][ptr].first, y);
            }
        }

        sort(ans[v].begin(), ans[v].end());
        int sz = 0;
        for (int i = 0; i < (int) ans[v].size(); i++)
        {
            if (sz != 0 && ans[v][i].second >= ans[v][sz - 1].second)
                continue;
            ans[v][sz++] = ans[v][i];
        }
        ans[v].resize(sz);
    }

    up(v);

//    eprintf("return from %d:", v);
//    for (auto p : ans[v])
//        eprintf(" (%lld, %lld)", p.first, p.second);
//    eprintf("\n");
}


bool check(long long val)
{
    gval = val;
    dfs(0);
    return !ans[0].empty();
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    scanf("%d", &n);
    for (int i = 1; i < n; i++)
    {
        int p;
        scanf("%d%d", &p, &dup[i]);
        p--;
        ch[p].push_back(i);
    }

    long long bl = -1, br = INF;


    while (br - bl > 1)
    {
        long long bm = (bl + br) / 2;
        if (check(bm)) 
            br = bm;
        else
            bl = bm;
    }

    printf("%lld\n", br);


	return 0;
}




Measured memory_bytes: 32372
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int main() {
	int n = 0;
	int c[500] = {}, s[500] = {}, f[500] = {};
	int ans = 0; 
	double tmp = 0;

	cin >> n;
	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}

	rep(i,n) {

		ans = 0;

		for (int j = i; j < n - 1; j++) {

				if (ans < s[j]) {
					ans = s[j];
				}
				else if ((ans - s[j]) % f[j] == 0) {
				}else{
					tmp = (ans - s[j]) / f[j];
					ans = (tmp + 1) * f[j] + s[j];
					
				}
			
			ans += c[j];

		}

		cout << ans << endl;
	}

	return 0;

}

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

int main() {

	u32 a[3][3];
	
	for(u32 i=0; i<3; i++) {
		for(u32 j=0; j<3; j++) {
			cin >> a[i][j];
		}
	}
	
	u32 N;
	cin >> N;
	
	for(u32 k=0; k<N; k++) {
		u32 b;
		cin >> b;
		
		for(u32 i=0; i<3; i++) {
			for(u32 j=0; j<3; j++) {
				if(b == a[i][j]) {
					a[i][j] = 0;
					break;
				}
			}
		}
	}
	
	//yoko
	for(u32 i=0; i<3; i++) {
		bool jdg = true;
		for(u32 j=0; j<3; j++) {
			jdg = jdg & (0 == a[i][j]);
			if(!jdg) break; 
		}
		if(jdg) {
			cout << "Yes";
			return 0;
		}
	}

	// tate
	for(u32 i=0; i<3; i++) {
		bool jdg = true;
		for(u32 j=0; j<3; j++) {
			jdg = jdg & (0 == a[j][i]);
			if(!jdg) break; 
		}
		if(jdg) {
			cout << "Yes";
			return 0;
		}
	}
	
	// nane 1
	bool jdg = true;
	for(u32 i=0; i<3; i++) {
		jdg = jdg & (0 == a[i][i]);
		if(!jdg) break; 
	}
	
	if(jdg) {
		cout << "Yes";
		return 0;
	}
	
	// nane 2
	jdg = true;
	for(int i=0; i<3; i++) {
		jdg = jdg & (0 == a[i][2-i]);
		if(!jdg) break; 
	}
	if(jdg) {
		cout << "Yes";
		return 0;
	}
	
	cout << "No";
	return 0;
}


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

int x,jj=0;
bool a[100005]={false};
int price[10];

int main()
{
	cin>>x;
	for (int i=1;i<=6;i++)  price[i]=99+i;
	for (int i=1;i<=6;i++)  a[price[i]]=1;
	while (jj<=100000)
	{
		jj++;
		if (a[jj]==false)  continue;
		for (int i=1;i<=6;i++)
		{
			for (int j=jj;j<=100000;j+=price[i])
			{
				a[j]=1;
				if (j==x)
				{
					cout<<a[jj]<<endl;
					return 0;
				}
			} 
	    }
	    if (jj==x)
	    {
	        cout<<a[jj]<<endl;
			return 0;	
		}
		if (jj>x)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

#define N 100000

int serch(int a[], int b, int key){
  int i;
  for(i=0;i<=b-1;i++){
    if(a[i] == key){
      return 1;
    }
  }
  return 0;
}

int main(){
  int n, q, i, j, count = 0, discount = 0;
  int S[N],T[N];
  
   scanf("%d",&n);
  
  for(i=0; i<=n-1;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);

  for(i=0;i<=q-1;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<=q-1;i++){
    if(serch(S,n,T[i]) == 1){
      count += 1;
    }
  }

  printf("%d\n", count);
  
  
  return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<int> X(N); for (auto& x:X) cin >> x;

    float sum = 0;

    for (int i = 0; i < N; i++) {
        sum += X[i];
    }

    int ave = (int) sum / N;
    int ave2 = ave + 1;

    ll ans = 0;
    ll ans2 = 0;
    for (auto& x:X) ans += (x - ave) * (x - ave);
    for (auto& x:X) ans2 += (x - ave2) * (x - ave2);


    cout << min(ans, ans2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=998244353;
const int N=200005,E=524288;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
long long n,a,b,c,d;
map<long long,long long>dp;
int t;
long long dfs(long long n)
{
	if(n==0)
 		return 0;
 	if(n==1)
 		return d;
 	if(dp[n])
 		return dp[n];
 	long long y=n/5*5;
 	long long ans=1000000000000000000ll;
 	ans=min(ans,dfs(y/5)+c+(n-y)*d);
 	if(n%5!=0)
 		ans=min(ans,dfs(y/5+1)+c+(y+5-n)*d);
 	y=n/2*2;
 	ans=min(ans,dfs(y/2)+a+(n-y)*d);
 	if(n%2!=0)
 		ans=min(ans,dfs(y/2+1)+a+(y+2-n)*d);
 	y=n/3*3;
 	ans=min(ans,dfs(y/3)+b+(n-y)*d);
 	if(n%3!=0)
 		ans=min(ans,dfs(y/3+1)+b+(y+3-n)*d);
 	if((ull)n*d%M==n%M*d%M&&((ull)n*d)<=1000000000000000000ll)
 		ans=min(ans,n*d);
 	return dp[n]=ans;
} 	
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		cin>>n>>a>>b>>c>>d;
		dp.clear();
		cout<<dfs(n)<<endl;
	}
}

Measured memory_bytes: 4552
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if((H == 0) && (W == 0)) {
                break;
            }

            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    if(i%2 == 1) {
                        if(j%2 == 1) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    } else {
                        if(j%2 == 1) {
                            System.out.print(".");
                        } else {
                            System.out.print("#");
                        }
                    }
                }

                System.out.print("\n");
            }

            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 38072
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;

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

    ll a, b, n;
    cin >> a >> b >> n;

    ll x;
    if(n < b - 1) x = n;
    else x = b - 1;

    ll ans = floor(a * (x % b) / b);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<complex>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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--)
#define mp make_pair
#define fi first
#define sc second



int main(){
	int d,n;
	cin >> d >> n;

	if(d == 0) {
		if(n<100)cout << n << endl;
		else cout << 101 << endl;
	}
	else if(d == 1){
		if(n<100)
			cout << 100 * n << endl;
		else cout << 10100 << endl;
	}
	else if(d == 2) {
		if(n<100)cout << 10000 * n << endl;
		else cout << 1010000;
	}

	return 0;
}


Measured memory_bytes: 256
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int a, b, mx = -1000;
    cin >> a >> b;
    mx = max(mx, a + b);
    mx = max(mx, a - b);
    mx = max(mx, a * b);
    cout << mx << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P &a, const P &b) { return a.real() * b.imag() - a.imag() * b.real(); }
ld dot(const P &a, const P &b) { return a.real() * b.real() + a.imag() * b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps) {
    auto c3 = [](const P &a, const P &b, const P &c) {
        ld A = norm(b - c);
        ld B = norm(c - a);
        ld C = norm(a - b);
        ld S = abs(cross(b - a, c - a));
        P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
        ld r = abs(p - a);
        return make_pair(r, p);
    };

    auto c2 = [](const P &a, const P &b) {
        P c = (a + b) / (ld)2;
        ld r = abs(a - c);
        return make_pair(r, c);
    };

    auto in_circle = [](const P &a, const C &c) {
        return norm(a - c.pnt) <= c.rad * c.rad + eps;
    };

    int n = ps.size();
    random_shuffle(ps.begin(), ps.end());
    C c = c2(ps[0], ps[1]);
    for(int i = 2; i < n; ++i) {
        if(!in_circle(ps[i], c)) {
            c = c2(ps[0], ps[i]);
            for(int j = 1; j < i; ++j) {
                if(!in_circle(ps[j], c)) {
                    c = c2(ps[j], ps[i]);
                    for(int k = 0; k < j; ++k) {
                        if(!in_circle(ps[k], c)) {
                            c = c3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

// http://www.spoj.com/problems/QCJ4/
// http://www.spoj.com/status/ns=18116289

int main() {
    int n;
    cin >> n;
    vector<P> ps(n);
    for(int i = 0; i < n; ++i) {
        ld x, y;
        cin >> x >> y;
        ps[i] = P(x, y);
    }

    printf("%.18lf\n", (double)smallest_enclosing_disc(ps).rad);
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  int a,b;
  cin >> a >> b;
  int x = min(a,b);
  rep(i,max(a,b)){
    cout << x;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;

	int curr = 1, ans = 0;

	vector<int> arr(n + 2, 0);
	vector<int> suff(n + 2, 0);

	for(int i = 0; i <= n; i++){
		cin >> arr[i];
	}

	for(int i = n; i >= 0; i--) suff[i] = suff[i + 1] + arr[i];

	for(int i = 0; i <= n; i++){
		ans += curr;
		curr -= arr[i];
		if(curr < 0){
			cout << -1;
			return 0;
		}
		curr = min(curr * 2, suff[i + 1]);
	}
	cout << ans;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define maxn 128
using namespace std;

int n,m;
int a[maxn][maxn];

void read()
{
    cin>>n>>m;

    int i,j;

    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>a[i][j];
}

vector<int>v[maxn*maxn];
bool used[maxn*maxn];
bool tused[maxn*maxn];
int match[maxn*maxn];

void clearr()
{
    int i;
    for(i=0;i<maxn;i++)
        v[i].clear();
}

/*void build()
{
    int i,j;
    for(i=0;i<n;i++)
     {
        int sz=v[i].size();
        for(j=0;j<v[i].size();j++)
        {
            int nb=v[i][j];
            if(!match[nb])
            {
                match[nb]=i;
                break;
            }
        }
     }
}*/

bool khun(int i)
{
    //cout<<i<<" ";
    if(tused[i])return false;
    tused[i]=true;
    int j,sz=v[i].size();
    for(j=0;j<sz;j++)
    {
        int t=v[i][j];
        if(match[t]==-1||khun(match[t]))
        {
            match[t]=i;
            match[i]=t;
            return true;
        }
    }
    return false;
}

int ans[maxn][maxn];
void solve()
{
    int i,j,k;
    for(i=0;i<m;i++)
    {
        clearr();
        for(j=0;j<n;j++)
            for(k=0;k<m;k++)
                if(!used[a[j][k]])
                {
                    v[j].push_back((a[j][k]-1)/m+n);
                    v[(a[j][k]-1)/m+n].push_back(j);
                }
        memset(match,-1,sizeof(match));
        for (j=0;j<n;j++)
        {
            memset(tused,0,sizeof(tused));
            khun(j);
        }

        for(j=0;j<n;j++)
        {
            if(match[j]!=-1)
            {
                for(k=0;k<m;k++)
                {
                    if((a[j][k]-1)/m+n==match[j]&&!used[a[j][k]])
                    {
                        used[a[j][k]]=true;
                        ans[j][i]=a[j][k];
                        break;
                    }
                }
            }
        }
    }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
            cout<<ans[i][j]<<" ";
        cout<<endl;
    }
}

//bool ans[maxn][maxn];
int main()
{
    int i,j,k;
	read();
	solve();

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
            for(k=0;k<n;k++)
                if((ans[k][j]-1)/m==i)
                {cout<<ans[k][j]<<" ";break;}

        cout<<endl;
    }
	return 0;
}

/*
3 4
1 4 7 10
2 5 8 11
3 6 9 12
*/


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll X,K,D;
    cin >> X >> K >> D;
    ll ans;
    if(X==0){
        if(D%2==0) ans=0;
        else ans=D;
    }else{
        ll num = abs(X/D);
        if(K<num) ans = abs(X)-K*D;
        else{
            ll num2 = K-num; // 残りの移動数
            ll now = abs(X)-num*D;
            if(num2%2==0){
                ans = now;
            }else{
                ans = abs(now-D);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend();
#define sz  size()
#define forr(i,a,b) for(int i=a ;i <= b ; i++ )
#define inp ios_base::sync_with_stdio(false);cin.tie(NULL);
#define PQ_INC vector<int>, greater<int> ;
using namespace std ;

ll  lcm(ll a, ll  b){
 return a / __gcd(a,b) * b ;
}

const int N = 1e5+9 ,  mod = 1e7+9  , OO = 0x3f3f3f3f ;
int dX[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dY[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
pair < ll ,ll > p[N] ;
int n ;
ll m ;
ll ans ;
int main(){
  cin >> n >> m ;
  for (int i = 0 ; i < n ; i++ ) cin >> p[i].F >> p[i].S ;
  sort(p , p+n ) ;
  for (int i = 0 ; i < n ; i++) {
    if (m <= 0) break ;
    ans += min (m , p[i].S) * p[i].F ;
     m -= p[i].S ;
  }
  cout << ans ;
}


Measured memory_bytes: 1792
#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 dp[55][55][5050];

int main() {
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  dp[0][0][0] = 1;
  rep(i, n)rep(j, n)rep(k, 2500) if(dp[i][j][k]){
    dp[i + 1][j][k] += dp[i][j][k];
    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i) {
    ans += dp[n][i][i * a];
  }
  cout << ans << endl;
}

Measured memory_bytes: 108800
digits = "-0123456789"
def cross_point(P, Q):
    x0, y0, x1, y1 = P
    x2, y2, x3, y3 = Q
    dx0 = x1 - x0; dy0 = y1 - y0
    dx1 = x3 - x2; dy1 = y3 - y2

    s = (y0-y2)*dx1 - (x0-x2)*dy1
    sm = dx0*dy1 - dy0*dx1
    if s < 0:
        s = -s
        sm = -sm
    if s == 0:
        x = x0
        y = y0
    else:
        x = x0 + s*dx0/sm
        y = y0 + s*dy0/sm
    return x, y
def reflection(line, point):
    x0, y0, x1, y1 = line
    p, q = point
    x1 -= x0; y1 -= y0
    p -= x0; q -= y0
    cv = p*x1 + q*y1
    sv = p*y1 - q*x1
    cv2 = cv**2 - sv**2
    sv2 = 2*cv*sv
    dd = (p**2 + q**2)*(x1**2 + y1**2)
    if dd == 0:
        return x0 + p, y0 + q
    return x0 + (cv2 * p - sv2 * q) / dd, y0 + (sv2 * p + cv2 * q) / dd

def parse(S):
    S = S + "$"
    cur = 0
    def expr():
        nonlocal cur
        res = None
        while S[cur] == '(':
            cur += 1 # '('
            if S[cur] in digits:
                x = number()
                cur += 1 # ','
                y = number()
                r = (0, x, y)
            else:
                r = expr()
            cur += 1 # ')'
            if res is None:
                res = r
            else:
                if res[0] == r[0] == 0:
                    # (point)@(point)
                    res = (1, res[1], res[2], r[1], r[2])
                elif res[0] == r[0] == 1:
                    # (line)@(line)
                    x, y = cross_point(res[1:], r[1:])
                    res = (0, x, y)
                else:
                    # (line)@(point) or (point)@(line)
                    point, line = (res, r) if r[0] else (r, res)
                    x, y = reflection(line[1:], point[1:])
                    res = (0, x, y)
            if S[cur] != '@':
                break
            cur += 1 # '@'
        return res

    def number():
        nonlocal cur
        v = 0; mns = 0
        if S[cur] == '-':
            mns = 1
            cur += 1 # '-'
        while S[cur] in digits:
            v = 10*v + int(S[cur])
            cur += 1
        return -v if mns else v

    return expr()

def solve():
    s = input()
    if s == '#':
        return False
    res = parse(s)
    print("%.16f %.16f" % res[1:])
    return True
while solve():
    ...


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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,a,b) for(ll i=a-1;i>=b;i--)
#define vi vector<ll>
#define pii pair<int,int>
#define vii vector< pair<int,int> >
#define pb push_back
#define inf 1000000000000
#define hell 1000000007

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    vi a(n);
    rep(i,0,n)
        cin>>a[i];
    sort(begin(a),end(a));
    ll ans=0;
    rep(i,0,n-2){
        rep(j,i+1,n-1){
            ll id=lower_bound(begin(a),end(a),a[i]+a[j])-begin(a);
            ans+=id-j-1;
        }
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
using graph = vector<vector<int>>;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define all(x) (x).begin(),(x).end()
#define size(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define M 10000007
#define MAXR 100000

#define pb push_back
#define mp make_pair
#define f first
#define s second

template<class T> inline bool chmax(T &a,T b) { if (a<b) { a=b; return true; } return false; }
template<class T> inline bool chmin(T &a,T b) { if (b<a) { a=b; return true; } return false; }

struct uf {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> rcount;

    uf(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

};
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%M+M)%M) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= M) x -= M;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += M-a.x) >= M) x -= M;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= M;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime M
    mint inv() const {
        return pow(M-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};


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


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

int MomoneMomo(vvi &graph, vi &table, int pos)
{
    if (table[pos] == -1) {
        int ret = 0;
        for (auto i : graph[pos]) {
            ret = max(ret, MomoneMomo(graph, table, i) + 1);
        }
        return table[pos] = ret;
    } else {
        return table[pos];
    }
}

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

    int2(n, m);
    vvi graph(n, vi(0, 0));
    rep(i, m) {
        int2(a, b); a--; b--;
        graph[a].pb(b);
    }

    vi table(n, -1);
    int ans = 0;
    rep(i, n) {
        ans = max(ans, MomoneMomo(graph, table, i));
    }
    //rep(i, n) cout << table[i] << " "; cout << endl;

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
struct x{
	string a;
	int b,c;
};
bool cmp(x &a,x &b){
	if(a.a==b.a){
		if(a.b==b.b){
			return a.c<b.c;
		}	
		else{
			return a.b>b.b;
		}
	}
	else{
		return a.a<b.a;
	}
}
int main() {
	int n;
	cin>>n;
	x arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i].a>>arr[i].b;
		arr[i].c=i+1;
	}
	sort(arr,arr+n,cmp);
	for(int i=0;i<n;i++) cout<<arr[i].c<<'\n';
}

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

int main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	}
	
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
	  dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n, greater<>());
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += a[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int f(int x , int y, int z)
{
    return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main()
{
    int N;
    cin >> N;
    vector<int> res(N+1, 0);

    for (int x = 1; x * x <= N; ++x)
    {
        for (int y = 1; y * y <= N; ++y)
        {
            for (int z = 1; z * z <= N; ++z)
            {
                int ret = f(x, y, z);
                if (ret <= N)
                {
                    ++res[ret];
                }
            }
        }
    }
    for (int i = 1; i <= N; ++i)
    {
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int n,k;
ll dp[105][100005],a[105],dp1[100005];
int main(){
    cin>>n>>k;

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

    for(int i=1;i<=k;i++)
        dp[0][i]=0;

    dp[0][0]=1;

    for(int i=1;i<=n;i++){
        dp1[0]=1;
        for(int j=1;j<=k;j++)
            dp1[j]=(dp1[j-1]+dp[i-1][j])%hell;

        for(int j=k;j>=0;j--){
            if(j-a[i]>0)
                dp[i][j]=(dp1[j]-dp1[j-a[i]-1]+hell)%hell;
            else
                dp[i][j]=dp1[j];
        }

        // for(int j=0;j<=k;j++)
        //     cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
    }

    cout<<dp[n][k]%hell;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#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 per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; 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
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(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll H, W, h, w; cin >> H >> W >> h >> w;
    cout << (H*W) - (W*h) - (H*w) + (h*w) << endl;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        // int q = sc.nextInt();
        int[] h = new int[n];
        int[] a = new int[m];
        int[] b = new int[m];
        // int[] d = new int[q];

        int[] good = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            if (h[a[i] - 1] > h[b[i] - 1]) {
                good[b[i] - 1] = -1;
            } else if (h[b[i] - 1] > h[a[i] - 1]) {
                good[a[i] - 1] = -1;
            } else {
                good[a[i] - 1] = -1;
                good[b[i] - 1] = -1;
            }
        }

        int cnt = 0;

        for (int i = 0; i < n; i++) {
            if (good[i] == 0) {
                cnt++;
            }
        }

        System.out.println(cnt);
        sc.close();
    }

}

Measured memory_bytes: 61420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main(){
  int N;
  cin >> N;
  vector<int> v(2*N);
  for(int i=0;i<N*2;i++)
    cin >> v[i];
  sort(v.begin(),v.end());
  int ans=0;
  for(int i=0;i<N*2;i+=2)
    ans+=v[i];
  cout << ans << endl;
  return 0;
}


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

pair < int , int > Range[40] ;

queue < int > ans ;

bool have ;

int main(){
	#define NAME "Medium"
	//freopen( NAME".inp" , "r" , stdin ) ; freopen( NAME".out" , "w" , stdout ) ;
	
	Range[0] = make_pair(0, 1) ;

	for (int i = 1; i <= 31; ++ i){
		Range[i] = Range[i - 1] ;
		if(i % 2) Range[i].first -= (1 << i) ;
		else Range[i].second += (1 << i) ;
	}

	int x ; cin >> x ;

	for (int i = 31; i >= 1; -- i){
		int foo = x ;
		if(i % 2) foo += (1 << i) ;
		else foo -= (1 << i) ;
		int bar ;
		if(foo >= Range[i - 1].first && foo <= Range[i - 1].second) bar = 1, x = foo ;
		else bar = 0 ;
		if(bar) ans.push(bar), have = true ;
		else if(have) ans.push(bar) ;
	}

	ans.push(x) ;

	while(!ans.empty()) cout << ans.front(), ans.pop() ;

	return 0 ;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

X,A,B = I()
if abs(A-X) > abs(B-X):
    print('B')
else:
    print('A')

Measured memory_bytes: 9960
#include<stdio.h>

int parent(int );
int left(int );
int right(int );

int parent(int i){
  return (i/2);
  }
int left(int i){
  return 2*i;
}
int right(int i){
  return (2*i + 1);
}

int main( ){
  int i,n,pk,lk,rk;
  int T[250];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&T[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,T[i]);
    pk = parent(i);
    if(pk > 0) printf("parent key = %d, ",T[pk]);
    lk = left(i);
    if(lk <= n) printf("left key = %d, ",T[lk]);
    rk = right(i);
    if(rk <= n) printf("right key = %d, ",T[rk]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    if (s.length() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}

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

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

    set<string> st;
    rep(i, s.size()) {
        string t = "";
        rep(j, 5) {
            if (i + j == s.size())
                break;
            t.push_back(s[i + j]);
            st.insert(t);
        }
    }

    int cnt = 1;
    for (auto t : st) {
        if (cnt == k) {
            cout << t << endl;
            return 0;
        }
        ++cnt;
    }

    return 0;
}

Measured memory_bytes: 1664
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


int main(void){
  int N;
  cin >> N;
  int D;
  cin >> D;
  int a = 2 * D + 1;
  cout << (N + a - 1) / a << endl;





}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int *par, *size;
} UF_forest;

void UF_initialize(UF_forest *F, int n)
{
	int i;
	F->par = (int*)malloc(sizeof(int) * (n + 1));
	F->size = (int*)malloc(sizeof(int) * (n + 1));
	for (i = 1; i <= n; i++) {
		F->par[i] = i;
		F->size[i] = 1;
	}
}

void UF_merge(UF_forest *F, int u, int v)
{
	for (; F->par[u] != u; u = F->par[u]);
	for (; F->par[v] != v; v = F->par[v]);
	if (u == v) return;
	else if (F->size[u] > F->size[v]) {
		F->par[v] = u;
		F->size[u] += F->size[v];
	} else {
		F->par[u] = v;
		F->size[v] += F->size[u];
	}
}

int UF_root(UF_forest *F, int v)
{
	for (; F->par[v] != v; v = F->par[v]);
	return v;
}

int UF_size(UF_forest *F, int v)
{
	for (; F->par[v] != v; v = F->par[v]);
	return F->size[v];
}

int main()
{
	int i, N, M, A[100001], B[100001];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) scanf("%d %d", &(A[i]), &(B[i]));
	
	long long inconv[100001];
	UF_forest F;
	UF_initialize(&F, N);
	for (i = M, inconv[M] = (long long)N * (N - 1) / 2; i >= 1; i--) {
		if (UF_root(&F, A[i]) != UF_root(&F, B[i])) {
			inconv[i-1] = inconv[i] - UF_size(&F, A[i]) * UF_size(&F, B[i]);
			UF_merge(&F, A[i], B[i]);
		} else inconv[i-1] = inconv[i];
	}
	
	for (i = 1; i <= M; i++) printf("%lld\n", inconv[i]);
	fflush(stdout);
	return 0;
}

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int k; cin >> k;
    char safe = s[k-1];
    for (auto& i: s) {
        if (i != safe) i = '*';
    }
    cout << s << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N,A;
  
  cin >> N >> A;
  
  int X;
  X = N % 500;
    
  if (X<=A){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
 
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct UF {
  vector<int> parent_, rank_;

  UF(int N) : parent_(N + 5), rank_(N + 5, 1) {
    for (int i = 0; i <= N; ++i) {
      parent_[i] = i;
    }
  }

  int find_set(int x) {
    if (x != parent_[x]) {
      parent_[x] = find_set(parent_[x]);
    }
    return parent_[x];
  }

  void unite(int x, int y) {
    int a = find_set(x), b = find_set(y);
    if (a == b) { return; }
    if (rank_[a] > rank_[b]) {
      parent_[b] = a;
    }
    else {
      parent_[a] = b;
      if (rank_[a] == rank_[b]) { ++rank_[b]; }
    }
  }

  bool is_connected(int x, int y) {
    return find_set(x) == find_set(y);
  }

};

int main()
{
  int N; scanf("%d", &N);
  vector<pair<ll, int>> X(N), Y(N);
  ll x, y;
  for (int i = 0; i < N; ++i) {
    scanf("%lld %lld", &x, &y);
    X[i] = make_pair(x, i);
    Y[i] = make_pair(y, i);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  vector<pair<ll, pair<int, int>>> edges;
  for (int i = 0; i + 1 < N; ++i) {
    edges.push_back(make_pair(abs(X[i].first - X[i + 1].first),
                              make_pair(X[i].second, X[i + 1].second)));
    edges.push_back(make_pair(abs(Y[i].first - Y[i + 1].first),
                              make_pair(Y[i].second, Y[i + 1].second)));
  }

  sort(edges.begin(), edges.end());
  ll ans = 0;
  UF uf(N + 5);
  for (int i = 0; i < (int)edges.size(); ++i) {
    ll d = edges[i].first;
    int u = edges[i].second.first, v = edges[i].second.second;
    if (uf.is_connected(u, v)) { continue; }
    uf.unite(u, v);
    ans += d;
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
	long int N,M;
  	cin >>N >>M;
  vector<long int>p(M+1);
  vector<string>s(M+1);
  long int countac=0;
  long int countwa=0;
  vector<int>memoac(N+1);
  vector<int>memowa(N+1);
  for(long int i=0;i<M;i++){
  cin >>p.at(i) >>s.at(i);
  }
  for(long int i=0;i<M;i++){
  	if(s.at(i)=="WA"&&memoac.at(p.at(i))==0){
    memowa.at(p.at(i))+=1;
    }
    else if(s.at(i)=="AC"&&memoac.at(p.at(i))==0){
    countac+=1; memoac.at(p.at(i))=1;
    }  
    
  }
   for(long int i=0;i<=N;i++){
   	if(memoac.at(i)==1){
   	countwa+=memowa.at(i);
    }
   }
  cout <<countac <<' '<<countwa <<endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
    long long i,j,cter,n,k;
    while(scanf("%lld %lld",&n,&k)!=EOF){
        cter=0;
        for(i=1;i<=n-k;i++){
                j=i+k;
            cter+=(n/j)*i;
        if(n%j-k>=0){
            cter+=n%j-k+1;
        }
        }
        if(k==0){
            cter=n*n;
        }
        printf("%lld\n",cter);
    }
    return 0;
}

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

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	m = 99999999
	k = 0
	for i in 1:n
		if a[i]<m
			k += 1
		end
		m=min(m,a[i])
	end
	println(k)
end

main()

Measured memory_bytes: 192784
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n=in.nextLong();
        int num=0;
        for(long i=100;i<n;){
            i+=i/100;
            num++;

            if(i>=n){
                System.out.println(num);
                return;
            }

        }
    }
}


Measured memory_bytes: 35528
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	string a;
	vector<int> N;
	cin >> a;

	for(int i=0;i<a.size();i++)
	{
		int c = (int)(a[i] - '0');
		if(c==1){c=9;}
		else if(c==9){c=1;}
		cout << c;
	}
	cout << endl;

}

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

vector <int> re(vector <int> v, int n);
vector <int> cat(vector <int> v, int k, int n);

int main(void)
{
	int n, m, k;
	vector <int> v;
	
	cin >> n >> m;
	
	for (int i = 1; i <= (2 * n); i++){
		v.push_back(i);
	}
	
	for (int i = 0; i < m; i++){
		cin >> k;
		if (k == 0){
			v = re(v, n);
		}
		else {
			v = cat(v, k, n);
		}
	}
	
	for (int i = 0; i < (2 * n); i++){
		cout << v[i] << endl;
	}
	
	return 0;
}

vector <int> re(vector <int> v, int n)
{
	vector <int> tmp;
	int a = 0, b = n;
	for (int i = 0; i < (2 * n); i++){
		tmp.push_back(v[a]);
		tmp.push_back(v[b]);
		a++;
		b++;
	}
	
	return tmp;
}


vector <int> cat(vector <int> v, int k, int n)
{
	vector <int> tmp;
	int a = 0;
	for (int i = k; i < (2 * n); i++){
		tmp.push_back(v[i]);
	}
	for (int i = 0; i < k; i++){
		tmp.push_back(v[i]);
	}
	
	return tmp;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;

vector<pair<int,int> > nodes[100100];

class priority {
  public:
    bool operator() (const pair<int,int> &x, const pair<int,int> &y) const {
      return x.second > y.second;
    }
};


void dijkstra(int source, int n, vector<int> &dis) {
  vector<int> vis(n, 0);
  priority_queue<pair<int,int>, vector<pair<int,int> >, priority> pq;
  pq.push(make_pair(source, dis[source] = 0));
  while (!pq.empty()) {
    pair<int,int> now = pq.top();
    pq.pop();
    int no = now.first;
    int di = now.second;
    if (vis[no]) continue;
    vis[no] = 1;
    for (int i = 0; i < nodes[no].size(); i++) {
      pair<int,int> next = nodes[no][i];
      int nno = next.first;
      int ddi = next.second;
      if (!vis[nno] && di + ddi < dis[nno]) {
        pq.push(make_pair(nno, dis[nno] = di + ddi));
      }
    }
  }
}

int main() {
  int n, m, source, x, y, z;
  cin >> n >> m >> source;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    nodes[x].push_back(make_pair(y, z));
  }
  vector<int> dis(n, INT_MAX);
  dijkstra(source, n, dis);
  for (int i = 0; i < n; i++) {
    if (dis[i] == INT_MAX) {
      cout << "INF" << endl;
    } else {
      cout << dis[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 13372
import sys
input = sys.stdin.readline

N = int(input())

dp = [[0, 0, 0] for i in range(N)]
dp[0] = [int(i) for i in input().split()]
for i in range(1, N):
    V = [int(i) for i in input().split()]
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + V[0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + V[1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + V[2]

print(max(dp[N-1]))

Measured memory_bytes: 22772
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    int n;
    cin >> n;
    cout << n / 3 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] numbers = new int[n];
        for (int i = 0; i < n; i++) {
            numbers[i] = sc.nextInt();
        }
        
        Arrays.sort(numbers);
        int max = numbers[n - 1];
        int r = -1;
        
        double mid = max / 2.0;
        double minGap = max;
        for (int i = 0; i < n; i++) {
            double gap = Math.abs(mid - numbers[i]);
            if (gap < minGap) {
                minGap = gap;
                r = numbers[i];
            }
        }
        
        System.out.println(max + " " + r);
    }
}

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

#define fr                first
#define se                second
#define int               long long
#define pb                push_back
#define mp                make_pair
#define pii               pair<int,int>
#define vi                vector<int>
#define mi                map<int,int>
#define pq                priority_queue<int>
#define set_bits(x)       __builtin_popcountll(x)
#define mode               1000000007
#define inf               1e18                        //Defining infinity the overflow of int
#define ps(x,y)           fixed<<setprecision(y)<<x   //for defining the precision of the decimal upto y places. 
#define zrosetbits(x)     __builtin_ctzll(x)         //it will give no of 0's before the first 1 from the right.
#define mk(a,n,type)      type *a=new type[n];
#define test(t)           int t; cin>>t; while(t--)


//**********************************************************************************************************
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

#define safemap               unordered_map<int,int,custom_hash>

//*********************************************************************************************************


void io()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin.tie(0);


}


int32_t main()
{
  io();
  clock_t begin = clock();

  int te = 1;

  // test(t)
  // {
  int n;
  cin >> n ;

  int res = 0;

  if (n >= 400 and n <= 599)
    res = 8;
  else if (n >= 600 and n <= 799)
    res = 7;
  else if (n >= 800 and n <= 999 )
    res = 6;
  else if (n >= 1000 and n <= 1199 )
    res = 5;
  else if (n >=   1200 and n <= 1399 )
    res = 4;
  else if (n >= 1400 and n <= 1599 )
    res = 3;
  else if (n >= 1600 and n <= 1799 )
    res = 2;
  else if (n >= 1800 and n <= 1999 )
    res = 1;


  cout << res << "\n";


  // cout << "\n";
  te++;
// double c_time = (double) (clock() - begin) / CLOCKS_PER_SEC;
// cout << ps(c_time, 4) << " seconds\n";
  // }

  return 0;
}



Measured memory_bytes: 3640