akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
   
int main() {
          int r,g,b;
        scanf("%d %d %d", &r, &g, &b);  
        

          if(((r * 100) + (g * 10) + b) % 4 == 0){
         printf("YES");
         } else {
         printf("NO");
         }
         return 0;
         }

Measured memory_bytes: 128
import java.lang.Math;
import java.util.*;
 
class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	double i = sc.nextInt();
      	System.out.println(((double)Math.round(i*2*Math.PI*100))/100);
    
    
    }
 
 
}

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

int main(){
  int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
  int xd=tx-sx, yd=ty-sy;
  for(int i=0; i<xd; i++){
    cout << "R";
  }
  for(int i=0; i<yd; i++){
    cout << "U";
  }
  for(int i=0; i<xd; i++){
    cout << "L";
  }
  for(int i=0; i<yd; i++){
    cout << "D";
  }
  cout << "D";
  for(int i=0; i<=xd; i++){
    cout << "R";
  }
  for(int i=0; i<=yd; i++){
    cout << "U";
  }
  cout << "LU";
  for(int i=0; i<=xd; i++){
    cout << "L";
  }
  for(int i=0; i<=yd; i++){
    cout << "D";
  }
  cout << "R" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	
	int n,mulc,muld,M,C,X,I;
	char c[9],d[9];
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int cc=0,dd=0;
		for(int j=0;j<8;j++){c[j]=0;d[j]=0;}
		scanf("\n%s %s",&c,&d);
		mulc=1;muld=1;
		for(int j=0;j<8;j++){
			if(c[j]>49&&c[j]<58)mulc=c[j]-48;
			if(c[j]=='m'){cc+=mulc*1000;mulc=1;}
			if(c[j]=='c'){cc+=mulc*100;mulc=1;}
			if(c[j]=='x'){cc+=mulc*10;mulc=1;}
			if(c[j]=='i'){cc+=mulc*1;mulc=1;}
			if(d[j]>49&&d[j]<58)muld=d[j]-48;
			if(d[j]=='m'){dd+=muld*1000;muld=1;}
			if(d[j]=='c'){dd+=muld*100;muld=1;}
			if(d[j]=='x'){dd+=muld*10;muld=1;}
			if(d[j]=='i'){dd+=muld*1;muld=1;}
		}
		int e=cc+dd;
		M=e/1000;e-=M*1000;C=e/100;e-=C*100;X=e/10;I=e-X*10;
		if(M>1)cout<<M<<"m";if(M==1)cout<<"m";
		if(C>1)cout<<C<<"c";if(C==1)cout<<"c";
		if(X>1)cout<<X<<"x";if(X==1)cout<<"x";
		if(I>1)cout<<I<<"i";if(I==1)cout<<"i";
		cout<<endl;
	}
}

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

int main() {
  string S,T;
  int A,B;
  string U;
  
  cin >> S >> T >> A >> B >> U ;
  
  if(U==S)
    A=A-1;
  
  if(U==T)
    B=B-1;
  
  cout << A << " " << B << endl;
}
  

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

using namespace std;

int main()
{
	int a, b, c;
	int n;
	int count = 0;
	double d;

	cin >> n;

	for (a = 1; a <= n; a++) {

		for (b = 1; b <= n; b++) {

			if (a * b >= n)
				break;

			c = n / a * b;
			d = n / a * b;

			if (c == d)
				count++;

		}
	}

	cout << count << endl;

}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

const ll mod=1e9+7;

ll p_num[1000005];

ll modPow(ll a, ll n) {
    if(n==1)return a%mod;
    if (n%2==1)return(a*modPow(a,n-1))%mod;
    ll t=modPow(a,n/2);
    return (t*t)%mod;
}

ll modDiv(ll a,ll b){
    return (a%mod)*modPow(b,mod-2)%mod;
}



ll N;
ll A[10004];

int main(){
    cin>>N;
    for(int i=0;i<N;++i)cin>>A[i];
    ll ans=0;
    for(int i=0;i<N;++i){
        ll x=A[i];
        for(ll j=2;j*j<=x;j++){
            ll k=0;
            while(x%j==0){
                k++;
                x/=j;
            }
            p_num[j]=max(k,p_num[j]);
        }
        if(x!=1)p_num[x]=max(1LL,p_num[x]);
    }
    ll X=1;
    for(int i=0;i<1000001;++i){
        for(int j=0;j<p_num[i];++j){
            X*=i;
            X%=mod;
        }
    }
    for(int i=0;i<N;++i){
        ans+=modDiv(X,A[i]);
        ans%=mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6656
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<ll,ll>

struct BIT
{
    std::vector<int> bit;
    
    BIT(int size) : bit(size, 0){ }
    
    void add(int k, int x) {
        while (k < bit.size()) {
            bit[k] += x;
            k += k &-k;
        }
    }
    int sum(int k) {
        int res = 0;
        while (k > 0) {
            res += bit[k];
            k -= k&-k;
        }
        return res;
    }
};

struct UnionFind {
    vector<int> data;
    
    UnionFind(int size) : data(size, -1) { }
    
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y)
        {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};


using namespace std;

struct Mod_comb
{
    const ll mod_;
    const int n_;
    std::vector<ll> fac;
    std::vector<ll> rev;

    Mod_comb() : Mod_comb(1e6+10, 1e9+7)
    {
    }

    ll qpow(ll a, ll b)
    {
        ll ret=1;
        while(b)
        {
            if(b&1)ret=(ret*a)%mod_;
            b>>=1;
            a=(a*a)%mod_;
        }
        return ret;
    }

    Mod_comb(int n, ll m) : mod_(m), n_(n), fac(n), rev(n)
    {
        fac.resize(n_);
        rev.resize(n_);
        fac[0] = 1;
        for(int i=1;i<n_;++i)
        {
            fac[i]=(fac[i-1]*i)%mod_;
        }
        rev[n_-1]=qpow(fac[n_-1],mod_-2);
        for(int i=n_-2;i>=0;--i)
        {
            rev[i]=(rev[i+1]*(i+1))%mod_;
        }
    }

    ll C(int n,int m)
    {
        if(m>n)
        {
           return 0;
        }
        return (((fac[n]*rev[m])%mod_)*rev[n-m])%mod_;
    }
};


int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    map<int, int> s;
    int left = -1;
    int right = -1;
    for(int i = 0;i < n+1;i++)
    {
        cin >> a[i];
        if(s.find(a[i]) != s.end())
        {
            right = i;
            left = s[a[i]];
        }
        s[a[i]] = i;
    }
    ll mod = 1e9+7;
    Mod_comb m(n+10, mod);

    cout << n << endl;
    for(int i = 2;i <= n+1;i++)
    {
        ll cc = m.C(n+1, i) - m.C(left + n - right, i-1) + mod;
        cc %= mod;
        cout << cc << endl;
    }
    return 0;
}

Measured memory_bytes: 7808
import Data.List
import Data.List.Split
import Data.Maybe
import qualified Data.ByteString.Char8 as B
readInt = fst . fromJust . B.readInt
main = mapM_ (print . solve) . chunksOf 2 . map (map readInt. B.words) . B.lines =<< B.getContents
solve [_,as] = (\x->((x+1)`div`2)*2-1) . length . group . sort $ as

Measured memory_bytes: 25980
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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



///////////////////////////




int main() {

	ll N;
	cin >> N;
	map<string, ll> mp;

	ll m=0;

	repn(i, N) {
		string s;
		cin >> s;
		mp[s]++;
		m = max(mp[s], m);
	}

	vector<string> ans;

	for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
		if (itr->second == m) { ans.push_back(itr->first); }
	}

	sort(ans.begin(), ans.end());

	rep(i, ans.size()) {
		cout << ans[i] << endl;
	}
	
	system("PAUSE");

}


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

int n;
vector<int> al[100005];


int dfs(int i){
    vector<int> child;
    
    for (auto &it:al[i]){
        child.push_back(dfs(it));
    }
    
    sort(child.begin(),child.end(),[](int i,int j){
        return i>j;
    });
    
    int m=-1;
    for (int x=0;x<child.size();x++){
        m=max(m,child[x]+x);
    }
    
    if (child.empty()) return 0;
    else return m+1;
}
int main(){
    scanf("%d",&n);
    int temp;
    for (int x=2;x<=n;x++){
        scanf("%d",&temp);
        al[temp].push_back(x);
    }
    
    printf("%d\n",dfs(1));
}

Measured memory_bytes: 13568
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**10]*n
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(max(0,i-k),i))
print(dp[n-1])


Measured memory_bytes: 53216
#include <stdio.h>
int main(void){
    int n, a[100000+5];
    scanf("%d", &n);
    for(int i=0; i<n; i++)scanf("%d", &a[i]);
    
    int ans=0;
    for(int i=0; i<n; i++){
        int j, h;
        ans++;
        
        for(j=i+1; j<n; j++)if(a[j-1]>a[j])break;
        for(h=i+1; h<n; h++)if(a[h-1]<a[h])break;
        
        if(j>h)i=j-1;
        else i=h-1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
#define sz 2

using namespace std;

int a[ 3 ];

int main() {
	scanf( "%d%d%d", &a[ 0 ], &a[ 1 ], &a[ 2 ] );
	sort( a, a + 3 );
	if( ( a[ 0 ] == a[ 1 ] && a[ 1 ] != a[ 2 ] ) || ( a[ 0 ] != a[ 1 ] && a[ 1 ] == a[ 2 ] ) )
		printf( "Yes" );
	else
		printf( "No" );
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  string s;
  cin >> s;
  int r = 0;
  rep(i,s.size())r = (r+s[i]-'0')%9;
  if(r == 0)cout << "Yes" << "\n";
  else cout << "No\n";
  

  return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
string S; int A, B;
bool numbers(string Q) {
	for (int i = 0; i < Q.size(); i++) {
		if ('0' <= Q[i] && Q[i] <= '9')continue;
		return false;
	}
	return true;
}
int main() {
	cin >> A >> B >> S;
	if (S[A] != '-')cout << "No" << endl;
	else {
		string V = S.substr(0, A);
		string W = S.substr(A + 1, B);
		if (numbers(V) == true && numbers(W) == true) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
 
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;

    if(500*a >= b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
typedef long long ll;
typedef pair<ll, ll> P;
map<long long, long long> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
bool bitcheck(int x, int y) { return (x >> y) & 1; }
signed main() {
    string s;
    cin >> s;
    ll n = s.size();
    ll sum = 0;
    REP(i, 1 << (n - 1)) {
        string t;
        REP(j, n) {
            t.push_back(s[j]);
            if (j == n - 1 || bitcheck(i, j)) {
                //cout << t << endl;
                sum += stol(t);
                t = "";
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#define ll long long
#define vi vector<ll>
#define vs vector<string>
#define fr(i, k, n) for (ll i = k; i < n; i++)
#define rep(i, n) fr(i, 0, n)
#define alll(v) v.begin(), v.end()
#define mp(a, b) make_pair(a, b)
#define rdd(a) ll a; cin >> a
#define rrd rdd(a); rep(i, a)
//min({a,b,c,d})などの記法
using namespace std;
template <class X> void pr(X x) { cout << x << endl; }
template <class X> void prr(X x) { for (auto it : x) { cout << it << endl; } }

int func(int x){
    return x*x+30;
}
int main() {
    string s;
    cin >>s;
    int n;
    cin >>n;
    char a='a';
    for(int i=0;i<s.size()&&n>0;i++){
        auto d = 26 - int(s[i]-'a');
        d%=26;
        if(d <= n){
            n-=d;
            s[i]='a';
        }
    }
    s[s.size()-1]+=n%26;
    pr(s);
    return 0;
}


Measured memory_bytes: 576
/*
ID: taoxiaa1
PROG: lamps
LANG: C++
*/
//URAL ID:248353QC
#include<bits/stdc++.h>
using namespace std;
//FILE *in, *out;
//in = fopen("lamps.in", "r");
//out = fopen("lamps.out", "w");
//ofstream fout("lamps.out");
//ifstream fin("lamps.in");
int s[100005];
int main()
{
    int n;
    scanf("%d",&n);
    int maxn=0,id;
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
        if(s[i]>=maxn){
            maxn=s[i];
            id=i;
        }
    }
    s[id]=0;
    int a=maxn/2,b=-1;
    for(int i=0;i<n;i++){
        int c=abs(s[i]-maxn/2);
        if(c<a){
            a=c;
            b=i;
        }
    }
    printf("%d %d\n",maxn,s[b]);
    return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys


def main():
    S = int( sys.stdin.readline() )

    dp = [0]*(S+1)
    dp[0] = 1
    mod = 10**9 + 7

    for i in range(3, S+1):
        cnt = 0

        for j in range(3, i+1):
            cnt += dp[i-j]
            cnt %= mod
        
        dp[i] = cnt


    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
#include <algorithm>
    #include <bitset>
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <ctime>
    #include <deque>
    #include <functional>
    #include <iomanip>
    #include <iostream>
    #include <list>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <utility>
    #include <vector>
    #include <tuple>
     
     
    using namespace std;
     
    long gcd(long x, long y)
    {
        long r;
     
        if(x == 0 || y == 0) {
            return 0;
        }
     
        while((r = x % y) != 0) {
            x = y;
            y = r;
        }
        return y;
    }
     
    long lcm(long x, long y)
    {
        return (x * y / gcd(x, y));
    }
     
    int main(){
     
    	long long N, M, L, lc, B;
    	string S, T;
     
    	cin >> N >> M;
    	cin >> S;
    	cin >> T;
     
    	L = lcm(N, M);
    	B = min(N, M);

    	long ln = L/N;
    	long lm = L/M;
    	long lb = L/B;
			for(long long i = 0; i< L; i+=lb){
				if(i % ln == 0){
					if(i % lm == 0){
						if(S[i/ln] != T[i/lm]){
							cout << -1 << endl;
							return 0;
						}
					}
				}
			}
          
    	cout << L << endl;
    	return 0;
    }


Measured memory_bytes: 512
#include <cstdio>

int main() {
  int n;
  scanf("%d", &n);

  int max_a = 0;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a > max_a) {
      max_a = a;
      res = a + b;
    }
  }
  printf("%d\n", res);
}


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

int main(void) {
    char c[4];
    cin >> c;
    int A = c[0] - '0';
    int B = c[1] - '0';
    int C = c[2] - '0';
    int D = c[3] - '0';
    int flg = 0;
    int sum;
    while (sum != 7) {
        sum = A;
        if (flg & 1) sum += B;
        else sum -= B;
        if (flg & 2) sum += C;
        else sum -= C;
        if (flg & 4) sum += D;
        else sum -= D;
        flg++;
    }
    flg--;
    cout << A;
    cout << ( (flg & 1) ? '+' : '-' );
    cout << B;
    cout << ( (flg & 2) ? '+' : '-' );
    cout << C;
    cout << ( (flg & 4) ? '+' : '-' );
    cout << D;
    cout << '=' << 7 << endl;
    return 0;
}


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<long long int, P> Q;

bool ss(P a, P b) {
	if (a.first != b.first && a.first != b.second && a.second != b.first && a.second != b.second) {
		return true;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	vector<long long int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<Q> b;
	vector<Q> c;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			b.push_back(Q(a[j]-a[i], P(a[i], a[j])));
			c.push_back(Q(a[j]+a[i], P(a[i], a[j])));
		}
	}
	double MAX = 0.0;
	int sz = b.size();
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	for (int i = 0; i < sz; i++) {
		if (ss(b[0].second, c[i].second)) {
			MAX = max(MAX, (double)c[i].first / (double)b[0].first);
		}
		if (ss(b[i].second, c[sz - 1].second)) {
			MAX = max(MAX, (double)c[sz-1].first / (double)b[i].first);
		}
	}
	printf("%.10f\n", MAX);
	return 0;
}

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

int main(){
   string s;
   cin >> s;
   int ans;
   if(s == "SUN") ans = 7;
   else if(s == "MON") ans = 6;
   else if(s == "TUE") ans = 5;
   else if(s == "WED") ans = 4;
   else if(s == "THU") ans = 3;
   else if(s == "FRI") ans = 2;
   else if(s == "SAT") ans = 1;
   cout << ans << endl;
}

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

const int INF = 1e9 + 1;

void printVector(const std::vector<int> &a) {
  std::size_t n = a.size();
  for (std::size_t i = 0; i < n; i++) {
    std::cout << a[i];
    if (i < n - 1)
      std::cout << " ";
    else
      std::cout << std::endl;
  }
}

int merge(std::vector<int> &a, int left, int mid, int right) {
  int nL = mid - left, nR = right - mid;
  std::vector<int> L(nL + 1, INF), R(nR + 1, INF);
  for (int i = 0; i < nL; i++) {
    L[i] = a[left + i];
  }
  for (int i = 0; i < nR; i++) {
    R[i] = a[mid + i];
  }

  int i = 0, j = 0;
  for (int k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      a[k] = L[i];
      ++i;
    } else {
      a[k] = R[j];
      ++j;
    }
  }
  return i + j;
}

int mergeSort(std::vector<int> &a, int left, int right) {
  if (left + 1 < right) {
    int c;
    int mid = (left + right) / 2;
    c = mergeSort(a, left, mid);
    c += mergeSort(a, mid, right);
    c += merge(a, left, mid, right);
    return c;
  }
  return 0;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  int count = mergeSort(a, 0, n);
  printVector(a);
  std::cout << count << std::endl;
}



Measured memory_bytes: 6788
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define P pair
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))

template <ll MOD>
class ModLL {
private:
    ll d_;

private:
    void normalize() { d_ = (MOD + d_ % MOD) % MOD; }

public:
    ModLL() {}
    ModLL(ll d) : d_(d % MOD) {}

    ll get() const { return d_; }

    operator ll() { return d_; }

    ModLL& operator=(const ModLL& rhs)
    {
        d_ = rhs.d_;
        normalize();
    }

    ModLL& operator+=(const ModLL& rhs)
    {
        d_ += rhs.d_;
        normalize();
        return *this;
    }

    ModLL& operator-=(const ModLL& rhs)
    {
        d_ -= rhs.d_;
        normalize();
        return *this;
    }

    ModLL& operator*=(const ModLL& rhs)
    {
        d_ *= rhs.d_;
        normalize();
        return *this;
    }

    // assume that rhs isn't divided by MOD and MOD is prime.
    ModLL& operator/=(const ModLL& rhs);
};

template <ll MOD>
ModLL<MOD> pow(ModLL<MOD> a, ModLL<MOD> b)
{
    if (b == 0) return 1;
    if (b == 1) return a;
    if (b % 2 == 0) {
        auto r = pow<MOD>(a, b / 2);
        r *= r;
        return r;
    }
    auto r = pow<MOD>(a, b / 2);
    r *= r;
    r *= a;
    return r;
}

template <ll MOD>
ModLL<MOD>& ModLL<MOD>::operator/=(const ModLL<MOD>& rhs)
{
    /*
       // literally divide
    d_ /= rhs.d_;
    normalize();
    return *this;
    */
    *this *= pow<MOD>(rhs, MOD - 2);
    return *this;
}

using LL = ModLL<1'000'000'007>;

ll n, a[200000], b[200000];
LL s[200000];

int main()
{
    //
    cbuf(b, -1);
    cin >> n;
    rep(i, 0, n + 1) { cin >> a[i]; }
    ll d1, d2, d3;
    rep(i, 0, n + 1)
    {
        if (b[a[i]] != -1) {
            d1 = b[a[i]];
            d3 = n - i;
            d2 = n - d1 - d3 - 1;
            break;
        }
        b[a[i]] = i;
    }

    LL f(1), l(1);

    rep(k, 1, n + 2)
    {
        f *= n - k + 2;
        // f *= pow(k, 1000000005);
        f /= k;
        auto t = f;
        if (k == 1) {
            t -= 1;
        }
        else if (k - 1 <= d1 + d3) {
            l *= d1 + d3 - k + 2;
            // l *= pow(k - 1, 1000000005);
            l /= k - 1;
            t -= l;
        }
        cout << t << endl;
    }
}


Measured memory_bytes: 3712
#abc088_c

table = 3.times.map { gets.split.map(&:to_i) }
table2 = table.transpose

diffs = table[0].each_cons(2).map { |a,b| a - b }
diffs2 = table2[0].each_cons(2).map { |a,b| a - b }

if table.all? { |row| row.each_cons(2).map { |a,b| a - b } == diffs } &&
   table2.all? { |row| row.each_cons(2).map { |a,b| a - b } == diffs2 }
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		PrimeNumberGenerator pg = new PrimeNumberGenerator();
		
		while(true){
			int n = Integer.parseInt(br.readLine());
			
			if(n == 0){
				break;
			}
			
			int prime = 0;
			for(int i = n + 1; i <= 2*n ; i++){
				if(pg.isPrime(i)){
					prime++;
				}
			}
			
			System.out.println(prime);
		}
		
	}

}

class PrimeNumberGenerator {
    private boolean[] isPrime= new boolean[100000001];
 
    public PrimeNumberGenerator() {
        //Date from = new Date();
        Arrays.fill(isPrime, true);
 
        isPrime[0] = false;
        isPrime[1] = false;
        isPrime[2] = true;
 
        for(int i = 3; i <= Math.sqrt( isPrime.length ); i+=2){
            /*
            if(i % 2 == 0){
                isPrime[i] = false;
                continue;
            }
            */
 
            if(isPrime[i] == false){
                continue;
            }
 
            for(int j = i * 2; j <= isPrime.length - 1; j += i){
                isPrime[j] = false;
            }
        }
        //Date to = new Date();
        //System.out.println("init takes "+ (to.getTime() - from.getTime())+ "milli sec");
    }
 
    public boolean isPrime(int index){
        if(index % 2 == 0 && index != 2){
            return false;
        }
        return isPrime[index];
    }
}

Measured memory_bytes: 123576
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	if(n < 3 || __builtin_popcount(n) == 1){
		cout << "No" << endl;
		return 0;
	}
	//assert(n % 4);
	
	cout << "Yes" << endl;
	vector<pi> ans;
	ans.emplace_back(1, 2);
	ans.emplace_back(2, 3);
	ans.emplace_back(3, 1 + n);
	ans.emplace_back(1 + n, 2 + n);
	ans.emplace_back(2 + n, 3 + n);
	
	int N = (n + 3) / 4 * 4;
	if(n % 4 == 0){
		N--;
		ans.emplace_back(n, n - 3);
		ans.emplace_back(n ^ (n - 3) ^ 1, n + n);
	}
	for(int i = 4; i <= N; i += 4){
		if(i <= n) ans.emplace_back(1, i);
		if(i + 1 <= n) ans.emplace_back(1, i + 1);
		
		if(i + 1 <= n) ans.emplace_back(i, i + 1 + n);
		if(i + 1 <= n) ans.emplace_back(i + 1, i + n);
		if(i + 2 <= n) ans.emplace_back(i + 1, i + 2 + n);
		
		
		if(i + 2 <= n) ans.emplace_back(2, i + 2);
		if(i + 3 <= n) ans.emplace_back(3, i + 3);
		
		if(i + 3 <= n) ans.emplace_back(i + 2, i + 3 + n);
	}
	int cnt = 0;
	for(pi i : ans){
		cnt++;
		cout << i.first << " " << i.second << endl;
	}
	dbg(n, cnt);
	assert(cnt == 2 * n - 1);
	return 0;
}

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

int main_wa(int x, int y) {
    int ret;
    if (x == 0 || y == 0) {
        if (x == 0 && y < 0) ret = -y + 1;
        else if (x == 0 && y == 0) ret = 0;
        else if (x == 0 && y > 0) ret = x + y;
        else if (y == 0 && x < 0) ret = -x; // -3 0
        else if (y == 0 && x > 0) ret = x + 1; // 5 0
    } else if (x > 0 && y > 0) {
        if (y >= x) { // 5 7
            ret = y - x;
        } else { // 7 5 -> -7 5 -> -5 5 -> 5 5
            ret = 1 + x - y + 1;
        }
    } else if (x < 0 && y < 0) {
        if (y >= x) { // -13 -2
            ret = y - x;
        } else { // -2 -13 -> 2 -13 -> 13 -13
            ret = 1 + x - y + 1;
        }
    } else {
        if (y <= -x) { // -17 4 -> -4 4
            ret = -x - y + 1;
        } else { // -4 17 -> 4 17 -> 17 17
            ret = 1 + y - (-x);
        }
    }
    return ret;
}

/*
int main_ac(int x, int y) {
    int ret = 1e9 + 7;
    if (x <= y) ret = min(ret, y - x);
    if (-x <= y) ret = min(ret, y - (-x) + 1);
    if (-x <= -y) ret = min(ret, (-y) - (-x) + 2);
    if (x <= -y) ret = min(ret, (-y) - x + 1);
    return ret;
}

random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rand100(-100, 100);
*/

int main() {
    
    int x, y;
    cin >> x >> y;
    out(main_wa(x, y));
    /*
    while (1) {
        int x = rand100(mt);
        int y = rand100(mt);
        int a = main_wa(x, y), b = main_ac(x, y);
        if (a != b) {
            out(x << " " << y << " " << a << " " << b);
            break;
        }
    }
    */
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);
  	long long n;cin>>n;
  	if(n%1000==0)cout<<0;
  	else cout<<1000-n%1000;
   
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i==0&&n/i>=1&&n/i<=9){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
unsigned long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001], sec[100001];
long long int iremono2[100001], check[100001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char rev[100001];
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい

int main()
{
	cin >> a>>b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

template<class T>
struct SegmentTree{
    using F=function<T(T,T)>;
    const F f;
    const T init;
    int sz;
    vector<T> seg;
    SegmentTree(int n,const T init,const F f):init(init),f(f){
        sz=1;
        while(sz<n) sz<<=1;
        seg.resize(sz<<1,init);
    }
    // 代入
    void set(int id,T x){
        seg[id+sz]=x;
    }
    // 構築
    void build(){
        for(int k=sz-1;k>0;k--){
            seg[k]=f(seg[2*k],seg[2*k+1]);
        }
    }
    // 更新
    void update(int id,T x){
        id+=sz;
        seg[id]=x;
        while(id>>=1){
            seg[id]=f(seg[2*id],seg[2*id+1]);
        }
    }
    // [l,r)の結果を取得
    T get(int l,int r){
        T L=init,R=init;
        l+=sz,r+=sz;
        for(;l<r;l>>=1,r>>=1){
            if(l&1) L=f(L,seg[l++]);
            if(r&1) R=f(seg[--r],R);
        }
        return f(L,R);
    }
    // debug
    void debug(){
        int i=1;
        for(int r=2;r<=2*sz;r<<=1){
            while(i<r){
                cout<<seg[i++]<<" ";
            }
            cout<<"\n";
        }
    }
};
// verify
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
int main(){
    int n,q; cin>>n>>q;
    SegmentTree<int> seg(n,(1ll<<31)-1,[](int a,int b){return min(a,b);});
    while(q--){
        int com,x,y; cin>>com>>x>>y;
        if(com==0) seg.update(x,y);
        else cout<<seg.get(x,y+1)<<endl;
        // seg.debug();
    }
    return 0;
}



Measured memory_bytes: 3908
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
typedef long long Long;

const int N = 1e5 + 5;

Long a[N];
Long memo_min[N];
Long memo_max[N];

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n;
  cin >> n;

  for (int i = 0; i <= n; ++i) {
    cin >> a[i];
  }
  memo_min[n] = memo_max[n] = a[n];
  for (int i = n - 1; i >= 0; --i) {
    memo_min[i] = (memo_min[i + 1] + 1) / 2;
    memo_min[i] += a[i];
  }

  for (int i = n - 1; i >= 0; --i) {
    memo_max[i] = memo_max[i + 1] + a[i];
  }

  if (memo_min[0] > 1 || memo_max[0] < 1) {
    cout << -1 << endl;
    return 0;
  }

  Long res = 1;
  Long prev = 1;

  for (int i = 1; i <= n; ++i) {
    prev = min(2 * (prev - a[i - 1]), memo_max[i]);
    res += prev;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 5964
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> has(n);
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;
    for (int j = 0; j < d; ++j) {
      int tmp;
      cin >> tmp;
      --tmp;
      has[tmp] = true;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (!has[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

int N, K;
vector<int> way[2005];
vector<pair<int, int>> edge;
int visited[2005];
int res;

int main(){
    scanf("%d%d", &N, &K);
    if(K == 0){ printf("%d", N-1); return 0; }
    for(int i=0; i<N-1; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        way[u].push_back(v);
        way[v].push_back(u);
        edge.push_back({u,v});
    }
    if(K%2){
        for(int i=0; i<edge.size(); i++){
            for(int i=1; i<=N; i++) visited[i] = 0;
            queue<pair<int,int>> q;
            int cur=0, lim = (K+1)/2;
            q.push({edge[i].first,1});
            q.push({edge[i].second,1});
            while(!q.empty()){
                int pos = q.front().first;
                int dist = q.front().second;
                q.pop();
                if(dist > lim || visited[pos]) continue;
                cur++;
                res = max(res, cur);
                visited[pos] = 1;
                for(int i=0; i<way[pos].size(); i++) q.push({way[pos][i],dist+1});
            }
        }
    } else{
        for(int i=1; i<=N; i++){
            for(int i=1; i<=N; i++) visited[i] = 0;
            queue<pair<int,int>> q;
            int cur=0, lim = K/2;
            q.push({i,0});
            while(!q.empty()){
                int pos = q.front().first;
                int dist = q.front().second;
                q.pop();
                if(dist > lim || visited[pos]) continue;
                cur++;
                res = max(res, cur);
                visited[pos] = 1;
                for(int i=0; i<way[pos].size(); i++) q.push({way[pos][i],dist+1});
            }
        }
    }
    printf("%d", N-res);
    return 0;
}

Measured memory_bytes: 384
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B;
    scan(A, B);
    writeln((A + B) % 24);
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

i64 dp[2][3001][3001];

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  rep(i, 2) rep(j, 3001) rep(k, 3001) dp[i][j][k] = -1e18;
  function<i64(int, int, int)> rec = [&](int turn, int l, int r) {
    if (r - l == 1) {
      if (turn == 0) return (i64) a[l];
      if (turn == 1) return (i64) -a[l];
    }
    if (dp[turn][l][r] != -1e18) return dp[turn][l][r];
    i64 ret = -1e18;
    if (turn == 0) {
      amax(ret, rec(1 - turn, l + 1, r) + a[l]);
      amax(ret, rec(1 - turn, l, r - 1) + a[r - 1]);
    } else {
      ret = 1e18;
      amin(ret, rec(1 - turn, l + 1, r) - a[l]);
      amin(ret, rec(1 - turn, l, r - 1) - a[r - 1]);
    }
    return dp[turn][l][r] = ret;
  };
  cout << rec(0, 0, n) << endl;
}


Measured memory_bytes: 141440
from collections import Counter

H, W = map(int, input().split())

SS = []
for _  in range(H):
    for a in list(input()):
        SS.append(a)

S = Counter(SS)


cwh = 0
ok = True
corner = 0
for c in S.values():
    if c >= 4:
        corner += c // 4
        c = c % 4
    if c == 0:
        continue
    elif c == 3:
        if H % 2 == 1 and W % 2 == 1:
            cwh += 1
        else:
            ok = False
    elif c == 1:
        if H % 2 == 1 and W % 2 == 1:
            cwh += 1
        else:
            ok = False

if cwh >= 2 or not ok:
    ans = 'No'
else:
    ans = 'Yes'
    if corner < (W//2)*(H//2):
            ans = 'No'
    if H % 2 == 1 and W % 2 == 1:
        if cwh != 1:
            ans = 'No'
print(ans)


Measured memory_bytes: 3444
# -*- coding: utf-8 -*-
N = int(input())

counter = 0
for i in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        counter += 1
    else:
        counter = 0
    if counter == 3:
        break

print("Yes" if counter == 3 else "No")

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

using namespace std;

typedef long long LL;
#define N 120000
#define INF 0x3f3f3f3f3f3f3f3fLL

LL a[N],n,m,t,f[N],g[N];

int main(){
	scanf("%lld%lld%lld",&n,&m,&t);
	for (LL i=1;i<=n;++i) scanf("%lld",a+i);
	g[0]=-a[1]*2;
	for (LL i=1,j=0;i<=n;++i){
		for (;t<2*(a[i]-a[j+1]);++j);
		f[i]=min(j>0?g[j-1]+a[i]*3:INF,f[j]+a[i]-a[j]+t);
		g[i]=min(g[i-1],f[i]-a[i]-a[i+1]*2);
	}
	printf("%lld\n",f[n]+m-a[n]);
	
	return 0;
}
			

Measured memory_bytes: 2560
function main() {
  input.forEach(function(str) {
    var
    num = str.split(' ').map(parseFloat);
    if(num.length !== 4 || str.indexOf('0 0 0 0') === 0) return;
    console.log(expr(num));
  });
}

var
op = ['+','-','*']
ex = ['(@%@)%(@%@)','@%(@%@)%@','@%@%@%@', '(@%(@%@))%@'];
function format(txt,a,b){
 var
 i,j = i = 0;
 return txt.replace(/@/g,function(){
  return a[i++];
 }).replace(/%/g,function(){
  return b[j++];
 });
}
function perm(xs) {
 var
 x, i, len = xs.length,
 ret = [];
 if(len === 0) return [[]];
 for(i = 0; i < len; i++){
  x = xs.shift();
  ret = ret.concat(perm(xs).map(function(ys){
   return (ys.unshift(x), ys);
  }));
  xs.push(x);
 }
 return ret;
}
function expr(src){
 var
 i,j,k,m,n,r;
 src = perm(src); 
 for(i = 0; i < 24; i++)for(j = 0; j < 3; j++)for(k = 0; k < 3; k++)for(m = 0; m < 3; m++)for(n = 0; n < 3; n++){
  r = format(ex[n],src[i],[op[j],op[k],op[m]]);
      if(eval(r) === 10) return r;
 }
 return 0;
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 16800
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
const double PI=4*atan(1);
using namespace std;
#define MOD 1000000007

int findmin(int a,int b) {
    return a<b?a:b;
}
int findmax(int a,int b) {
    return a>b?a:b;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,n;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++) {
		cin>>p[i];
	}
	sort(p,p+n);
	long sum=0;
	for(int i=0;i<k;i++) {
		sum+=p[i];
	}
	cout<<sum<<"\n";
    cout.flush();
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t,c;
	inline void gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			c=s==t?EOF:*s++;
		}else c=*s++;
	}
	template<class IT>inline void gi(IT &x){
		x=0;gc();while(c<'0'||c>'9')gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
	}
	char buf0[20];int a;
	template<class IT>inline void pi(IT x){
		if(x<0){putchar('-');x=-x;}
		do buf0[++a]=x%10+48;while(x/=10);
		while(a)putchar(buf0[a--]);
		putchar('\n');
	}
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=200005;
struct node{
	int a,L,R,l,r;
	inline bool operator<(const node &x)const{
		return a<x.a||(a==x.a&&L<x.L);
	}
}z[N],x[N],y[N];ll ans,ant;
inline void calcs(int i,int j,int r){
	ll t=0ll;
	for(;j<=r;++i,++j)ans+=(t+=x[i].l)*x[j].r;
//	printf("i=%d j=%d r=%d ans=%lld\n",i,j,r,ans);
}
inline void calct(int i,int j,int r){
	ll t=0ll;
	for(;j<=r;++i,++j)ant+=(t+=z[i].l)*z[j].r;
//	printf("i=%d j=%d r=%d ant=%lld\n",i,j,r,ant);
}
inline void dbg(int X){
	int i;
	rep(i,1,X)printf("a=%d L=%d R=%d l=%d r=%d\n",x[i].a,x[i].L,x[i].R,x[i].l,x[i].r);puts("X");
}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int n,m,mn,X=0,Y=1,Z,T,i,j,k,l,c;
	scanf("%d%d",&n,&m);ans=n;
	rep(i,1,n){
		scanf("%d",&y[i].a);
		y[i].L=y[i].R=i;
		y[i].l=y[i].r=1;
	}
	sort(y+1,y+n+1);
	while(X||Y<=n){
		if(Y<=n){
			mn=y[Y].a;
			if(X)cmin(mn,x[X].a);
			while(y[Y].a==mn)x[++X]=y[Y++];
		}else mn=x[X].a;
		sort(x+1,x+X+1);
//		dbg(X);
		x[X+1].L=0;
		Z=0;
//		printf("===X=%d\n",X);
		for(i=j=1;i<=X;i=++j){
			for(;x[j+1].L==x[j].R+1;++j);
			c=(l=j+1-i)/m;
//			printf("i=%d j=%d\n",i,j);
			if(c){
				T=Z;
				REP(k,0,c){
					++T;
					z[T].a=mn+1;
					z[T].L=x[i+k*m    ].L;
					z[T].R=x[i+k*m+m-1].R;
					z[T].l=z[T].r=0;
				}
				z[T++].R=x[j].R;
				calcs(i  ,i+m-1,  j);
				rep(k,i+m-1,j)z[Z+(k-i+1)/m].r+=x[k].r;
				per(k,j-m+1,i)z[T-(j-k+1)/m].l+=x[k].l;
				calct(Z+1,Z+m  ,--T);
				Z=T;
			}
		}
		X=Z;
		rep(i,1,X)x[i]=z[i];
//		dbg(X);
	}
	printf("%lld",ans-ant);
	return 0;
}

Measured memory_bytes: 10496
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N,D= ints_raw()
    Xs = []
    for _ in range(N):
        Xs.append(ints_raw())
    ans = 0
    for i in range(1,N):
        for j in range(i):
            Xi = Xs[i]
            Xj = Xs[j]
            d2 = sum([(Xi[k]-Xj[k])**2 for k in range(D)])
            if math.sqrt(d2).is_integer():
                ans+=1
    return ans

print(main())


Measured memory_bytes: 38384
n = int(input())

t = []
for i in range(1,n+1):
  s,p = tuple(input().split())
  p = int(p)
  t.append((s,p,i))
t = sorted(t,key = lambda a:a[1],reverse=True)
t = sorted(t,key = lambda a:a[0])

for _,_,i in t:
  print(i)

Measured memory_bytes: 3060