akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
using namespace std;
const int maxn=1e5+10;

typedef pair<int,int> P;

int h[maxn],e[maxn],ne[maxn],idx,s[maxn],color[maxn];

void add(int a,int b){
    e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}

int main(){
    memset(h,-1,sizeof h);
    memset(s,0,sizeof s);
    memset(color,0,sizeof color);
    map<P,int> mp;
    vector<P> v;
    int n,a,b;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&a,&b);
        v.push_back({a,b});
        add(a,b);
        s[a]++,s[b]++;
    }
    int mx=-1;
    for(int i=1;i<=n;i++) mx=max(mx,s[i]);
    printf("%d\n",mx);
    queue<int> que;
    que.push(1);
    color[1]=0;
    while(!que.empty()){
        int u=que.front();que.pop();
        int d=1;
        for(int i=h[u];i!=-1;i=ne[i],d++){
            int v=e[i];
            if(d==color[u]) d++;
            color[v]=d;
            mp.insert({make_pair(u,v),d});
            que.push(v);
        }
    }
    for(auto p:v)
        cout << mp[p] << endl;
    return 0;
}

Measured memory_bytes: 9460
import sys

S = input()
T = input()

Sc = list(S)
Tc = list(T)

Sl = len(Sc)
newSc = Sc

for i in range(Sl):
    newSc = newSc[(Sl - 1):] + newSc[:(Sl - 1)]
    if Tc == newSc:
        print('Yes')
        sys.exit()

print('No')


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		for(int i = a ; i <= b ; i++) {
			String s = String.valueOf(i);
			String c = "" + s.charAt(0) + s.charAt(1);
			String d = "" + s.charAt(4) + s.charAt(3);
			if(Integer.valueOf(c) == Integer.valueOf(d)) {
				ans++;
			}
//			if(s.substring(0, 2).equals(s.substring(3))) {
//				ans++;
//			}
		}
		System.out.println(ans);
	}
}


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

using namespace std;

int main(void)
{
    string weather[] = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;

    for (int i = 0; i < 3; i++)
    {
        if (s == weather[i])
        {
            if (i == 2)
            {
                cout << weather[0] << endl;
                return 0;
            }
            else
            {
                cout << weather[i + 1] << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

def prime(x):
    res = []
    arr = [True for _ in range(x + 1)]
    
    for i in range(2, x + 1):
        if arr[i]:
            j = i + i
            while j < x + 1:
                arr[j] = False
                j += i
    
    for i in range(2, x + 1):
        if arr[i]:
            res.append(i)

    return res

ans = []
for i in prime(55555):
    if i % 10 == 1:
        ans.append(i)
        if len(ans) == n:
            print(' '.join(map(str, ans)))
            exit()

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> s(n);
    REP(i, n) cin >> s[i];

    ll ans = 0;
    FOR(d, 1, n+1) {
        ll l = 0, r = n-1;
        ll ret = 0;
        while(1) {
            l += d;
            if(l >= n) break;
            ret += s[l];
            r -= d;
            if(r%d==0 && r<=l) break;
            if(r<d) break;
            ret += s[r];
            chmax(ans, ret);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main() {
    while (true) {
        int a, b; cin >> a >> b;
        if (a == 0 && b == 0) break;
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) cout << '#';
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    S = input(str)
    if S == "Sunny":
        print("Cloudy")
    elif S == "Cloudy":
        print("Rainy")
    else:
        print("Sunny")
    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3468
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=100100;
int i,j,k,n,m,ch,ff,nm;
int a[N];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void R(ll &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(ll x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
int main() {
	R(n);R(m);
	for (i=1;i<=n;i++) {
		R(a[i]);
		if (a[i]&1) nm++;
	}
	if (m==1 && !nm) return puts("0"),0;
	if (m==0 && !nm) {
		W(1ll<<n);puts("");
		return 0;
	}
	W(1ll<<n-1);puts("");
}

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

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

	vector<long> a(n);

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

	cin >> q;

	for (int i = 0; i < q; i++) {
		int b, e, k;
		cin >> b >> e >> k;

		vector<long>::iterator ib = a.begin(), ie = a.begin();
		ib += b;
		ie += e;

		cout << count(ib, ie, k) << endl;
	}

	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
int main()
{
  int a,b,c,i,x=0;
  scanf("%d%d%d",&a,&b,&c);
  for(i=a;i<=b;i++){
    if(c%i==0){
      x++;
    }
  }
  printf("%d\n",x);
  return 0;
}

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

struct UnionFind{
    vector<int> par;

    UnionFind(int n):par(n,-1){};
    void init(int n){par.assign(n,-1);}

    int root(int x){
        if(par[x]<0)return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    long long N,M;cin>>N>>M;
    vector<int> A(M),B(M);
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i],--A[i],--B[i];
    }

    UnionFind uf(N);
    long long cur=N*(N-1)/2;
    vector<long long> res;
    for(int i=0;i<M;i++){
        res.push_back(cur);

        int a=A[M-1-i],b=B[M-1-i];
        if(uf.issame(a,b))continue;

        long long sa=uf.size(a),sb=uf.size(b);
        cur-=sa*sb;
        uf.merge(a,b);
    }

    reverse(res.begin(),res.end());
    for(int i=0;i<res.size();i++)cout<<res[i]<<endl;
}

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int H,W,N;
int sx,sy;
string S,T;

int dpt[200020][2];
int dpy[200020][2];

int main(){
  cin>>H>>W>>N;
  cin>>sx>>sy;
  cin>>S;
  cin>>T;

  dpt[0][0]=sx;
  dpt[0][1]=sx;
  dpy[0][0]=sy;
  dpy[0][1]=sy;
  for(int i=0;i<N;i++){
    dpt[i+1][0]=dpt[i][0];
    dpt[i+1][1]=dpt[i][1];
    dpy[i+1][0]=dpy[i][0];
    dpy[i+1][1]=dpy[i][1];

    if(S[i]=='U'){
      dpt[i+1][0]=dpt[i][0]-1;
    }else if(S[i]=='D'){
      dpt[i+1][1]=dpt[i][1]+1;
    }else if(S[i]=='L'){
      dpy[i+1][0]=dpy[i][0]-1;
    }else{
      dpy[i+1][1]=dpy[i][1]+1;
    }

    if(dpt[i+1][0]<=0||dpt[i+1][1]>H){
      cout<<"NO"<<endl;
      return 0;
    }
    if(dpy[i+1][0]<=0||dpy[i+1][1]>W){
      cout<<"NO"<<endl;
      return 0;
    }
    

    if(T[i]=='U'){
      dpt[i+1][1]=max(dpt[i+1][1]-1,1);
    }else if(T[i]=='D'){
      dpt[i+1][0]=min(dpt[i+1][0]+1,H);
    }else if(T[i]=='L'){
      dpy[i+1][1]=max(dpy[i+1][1]-1,1);
    }else{
      dpy[i+1][0]=min(dpy[i+1][0]+1,W);
    }
  }

  cout<<"YES"<<endl;

  return 0;
}


Measured memory_bytes: 3848
using System;

namespace CABC
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int counter = 0;
            for (int A = 1; A <= N; A++)
            {
                counter += (N - 1) / A;
            }
            Console.WriteLine(counter);
        }
    }
}


Measured memory_bytes: 27452
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int x = abs(a.front() - a.back());

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
int digit(int a){
    int count = 0;
    for (int i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }     
    }
    return count;
}
//pow(x,n) == x^n

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

int x,y,z,sum = 0,l;
cin >> x >> y >> z;
l = x-z;
sum = y+z;

    cout << l / sum << endl;







//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n ;
    cin >> n ;
    vector<plvl> v;
    forn(i , 1 , 2*n ) {
      ll x , y;
      cin >> x >> y;
      if(i <= n ){
        v.pb({{x , y} , 0}) ;
      }
      else {
        v.pb({{x , y} ,  1}) ;
      }
    }
    sort(all(v)) ;
    multiset<ll > s;
    ll ans = 0 ;
    forn(i , 1 , 2*n ) {
       if(v[i-1].se == 0 ){
        s.insert(v[i-1].fi.se) ;
       }
       else{
         if(ll(s.sz) == 0){
            con ; 
         }
         ll foo = *s.begin();
         ll y = v[i-1].fi.se ;
         if(foo >= y) con ;
         auto it = s.lower_bound(y);
         if(it == s.begin()){
            ll res = *it;
            if(res == y){
                con ;
            }
            else if(res < y){
                ++ans ;
                s.erase(it);
            }
         }
         else {
            --it ;
            s.erase(it);
            ++ans ;
         }
       }
    }
    cout << ans << el ;
    ro;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int d[10] = {};
  ll a, b, c;
  cin >> a >> b >> c;
  
  d[a]++;
  d[b]++;
  d[c]++;
  if (d[5] == 2 && d[7] == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    for(int i = 1; i < n; ++i){
        if(a[i] + a[i-1] > x){
            if(a[i-1] > x){
                ans += a[i];
                a[i] = 0;
                ans += a[i-1] - x;
                a[i-1] = x;
            }
            else{
                ans += a[i] + a[i-1] - x;
                a[i] -= a[i] + a[i-1] - x;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3972
#include<iostream>
using namespace std;
int main()
{
   unsigned int max, n, sum, temp ;
   n = max = sum = 0;
   cin >> n;
   while (n --)
   {
     cin >> temp;
     max = max > temp ? max : temp;
     sum += temp;
   }
   if(sum > 2*max )
     cout << "\nYes" << endl;
   else 
     cout << "\nNo" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
const Int Inf = 1e17;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; if(n>1)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  cin>>n>>m; int a[n],ans=0; rep(i,n)cin>>a[i];
  x=*min_element(a,a+n);
  rep(i,n){
    if(a[i]!=x){
      ans++; ok=0;
      rep(j,m-1){
        if(i+j>=n)END
        if(a[i+j]==x)ok=1;
        else a[i+j]=x;
      }
      if(ok)a[i+m-1]=x;
    }
  }
  END
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long A,B;
    cin >> A >> B;
    cout << A * B << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 2E4 + 100;
int p[N], a[N], b[N];

int main() {
    int n; cin >> n;
    FOR (i, 1, n + 1) cin >> p[i];
    FOR (i, 1, n + 1) {
        a[i] = i * N;
        b[i] = (n + 1 - i) * N;
    }
    FOR (i, 1, n + 1) a[p[i]] += i;
    FOR (i, 1, n + 1) printf("%d ", a[i]);
    puts("");
    FOR (i, 1, n + 1) printf("%d ", b[i]);
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_ABC088_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] strs = Console.ReadLine().Split(' ');
            List<int> a = new List<int>();

            foreach (string str in strs)
            {
                a.Add(int.Parse(str) * -1);
            }

            a.Sort();

            int alice = 0;
            int bob = 0;
            int index = 0;

            foreach (int a_ in a)
            {
                int a__ = a_ * -1;
                if (index % 2 == 0)
                {
                    alice += a__;
                }
                else
                {
                    bob += a__;
                }

                ++index;
            }

            Console.WriteLine(alice - bob);
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>

using namespace std;

int main(){
    int x,h,m,s;
    
    cin>>x;
    
    h=(x/60)/60;
    m=(x-(h*60*60))/60;
    s=(x-(h*60*60))-60*m;
    cout<<h<<":"<<m<<":"<<s<<endl;
    
    return 0;
}


Measured memory_bytes: 3092
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, M) = Slice2<long>();
            var Xi = Sarray();Array.Sort(Xi);
            var dif = new long[M - 1];//区間
            for (var i = 0; i < M - 1; ++i)
                dif[i] = Xi[i + 1] - Xi[i];
            Array.Sort(dif);
            var cnt = 0L;
            for (var i = 0; i < M - 1 - (N - 1); ++i)
                cnt += dif[i];
            WriteLine(cnt);
        }


        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 37592
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
          string s;int w;
          cin>>s>>w;
          for(int i=0;i<s.size();i+=w)cout<<s[i];
          cout<<endl;
        
}

        


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
    int w, a, b, sa;
    cin >> w >> a >> b;
    if(a+w < b) {
        sa = b - (a+w);
    } else if(b+w < a) {
        sa = a - (b+w);
    } else if(a+w < b || a < b+w) {
        sa = 0;
    }
    cout << sa << "\n";
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int D;
    cin>>D;
    vi c(26),last(26,0);
    rep(i,26)cin>>c[i];
    vii s(D,vi(26));
    rep(i,D){
        rep(j,26){
            cin>>s[i][j];
        }
    }
    ll sum=0;
    rep(i,D){
        int m=0,n=0;
        rep(j,26){
            if(m<s[i][j]){
                m=s[i][j];
                n=j;
            }
        }
        sum+=m;
        last[n]=i+1;
        rep(j,26){
            sum-=c[j]*(i+1-last[j]);
        }
        cout<<n+1<<endl;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3692
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    vector<int> A(3);
    for (int i = 0; i < 3; ++i)
        cin >> A[i];

    sort(A.rbegin(), A.rend());

    int ret = 0;
    int back = A[0];
    for (int i = 0; i < 3; ++i)
    {
        ret += abs(A[i] - back);
        back = A[i];
    }

    cout << ret;
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

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

#define int long long

using namespace std;

static const int N=234567;

int a[N];

signed main()
{
    int n;
    int sum=0;
    scanf("%lld",&n);
    int t;
    scanf("%lld",&t);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    for(int i=2;i<=n;i++)
    {
        sum+=min(a[i]-a[i-1],t);
    }
    cout<<sum+t<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb push_back
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string hlo="hello";
string Y="YES\n";
string Ys="Yes\n";
string N="NO\n";
string No="No\n";
string sp=" ";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
bool isprm(ll a){for(ll i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E' ) return true; return false;}
/*int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
//bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,d,e,x,t,n,k,m,p,q,r,y,z,yy,sum=0,ct=0,flag=0;
    string s,s1,s2,s3,s4;
    char ch,ch1,ch2;
    deque<ll>d1,d2,d3;
    vector<string>vs1;
    string ss1;
    map<ll,ll>mp;
    //map<ll,ll>::iterator it;
    set<char>st1,st2;
    //set<ll>::iterator iter = st.begin();
    vector<pair<ll,ll> >v;
    double x1,y1,x2,y2,x3,y3,x4,y4;
    sum=0; ll mx=0,mn=3487327628458454875,cp=0;
    ll HR,MN,mnt,hrs,c1=0,c2=0; flag=0;
    ct=0; flag=0; cp=0;
    vector<ll>v1,v2,v3;
    //cin.ignore();
    //getline(cin,s);


         mn=3487327628458454875; flag=0,cp=0;
         cin>>s;
         for(ll i=0;i<s.sz;i++)
         {
             cp+=s[i]-'0';
         }
         if(cp%9==0) cout<<Ys<<endl;
         else cout<<No<<endl;

     return 0;
}


Measured memory_bytes: 3788
require 'set'

n = gets.to_i
xs = []

n.times do
  x, l = gets.split.map(&:to_i)
  xs << [x - l, x + l]
end

events = []
xs.each_with_index do |x, i|
  events << [x[0], 1, i] << [x[1], -1, i]
end

events.sort!

open_index = nil
remove_count = 0

removed_ends = Set.new

events.each do |x|
  q, oc, i = x

  if open_index == nil
    if oc == 1
      open_index = i
    else
      # ????
    end
  else
    if oc == 1
      if xs[open_index][1] > xs[i][1]
        removed_ends << open_index
        open_index = i
      else
        removed_ends << i
      end

      remove_count += 1
    else
      unless removed_ends.include?(i)
        open_index = nil
      end
    end
  end
end

p (n - remove_count)


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

int main () {
  int n;
  cin >> n;
  int rate[9];
  set<int> red;
  for (int i = 0; i < 9; i++) {rate[i] = 0;}
  for (int i = 0; i < n; i++) {
    int sub;
    cin >> sub;
    if (sub >= 3200) {
      rate[8]++;  
    }  
    else {
      int j = sub / 400;
      rate[j]++;
      red.insert(j);  
    }
  } 
  if (red.size() == 0) {
    cout << 1 << " " << rate[8] << endl;  
  } 
  else {
    cout << red.size() << " " << red.size() + rate[8] << endl;  
  }
}

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

int main() 
{ 
    ll n, a,b,p=0,s=0,q=0;
    cin>>n>>a>>b;
     s=(a+b);
     p=n/s;
     q=n%s;
    if((n%s)==0)
    cout<<(p*a);
    else
    {
        if(q>a)
        {
            q=a;
        }
        cout<<(p*a)+q;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        int rate = sc.nextInt();
        if(rate < 1200){
            System.out.println("ABC");
        }else if(1200 <= rate && rate < 2800){
            System.out.println("ARC");
        }else if(rate >= 2800){
            System.out.println("AGC");
        }
    }
}

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

int main(void){
	int i,cnt=0,ans=0,num=0;
	char n[100000];
	scanf("%s",n);
	
	for (i = 0; n[i] != '\0'; ++i) cnt++;
	
	if (cnt == 6){
		printf("90909\n");
	}else if (cnt == 2){
		printf("9\n");
	}else if (cnt == 4){
		printf("909\n");
	}else{
		num = atoi(n);
		if (cnt == 1)
		{
			for (int i = 0; i < num; ++i)
			{
				ans++;
			}
		}
		else if (cnt == 3){
			ans = 9;
			for (int i = 100; i <= num; ++i)
			{
				ans++;
			}
		}
		else if (cnt == 5){
			ans = 909;
			for (int i = 10000; i <= num; ++i)
			{
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A;
  cin >> A;
  int X = A.size();
  int M, N;
  M = N = 0;
  rep(i, X) {
    if(A.at(i) == 'A') {
      M = i;
      break;
    }
  }
  for(int i = X - 1; i >= 0; i--) {
    if(A.at(i) == 'Z') {
      N = i;
      break;
    }
  }
  cout << N - M + 1 << endl;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
int a;
cin >>a;
cout <<a+a*a+a*a*a;

return 0;
}






ll gcd(ll a, ll b){

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

}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;


ll ans,mx,mn=1e8,sum;
int main(){
	ll n,k;
	cin>>n>>k;
	for(int i=0; i<k; i++){
		ll a,b;
		cin>>a>>b;
		mx = max(mx,a);
		mn=min(mn,b);
	}
	cout<<max(0ll,(mn-mx)+1);
}


Measured memory_bytes: 256
S = str(input())

if S == 'SUN':
    print('7')
elif S == 'MON':
    print('6')
elif S == 'TUE':
    print('5')
elif S == 'WED':
    print('4')
elif S == 'THU':
    print('3')
elif S == 'FRI':
    print('2')
elif S == 'SAT':
    print('1')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
//cout<<""<<endl;

int main(){
  int N;
  string S;
  cin>>   N;
  vvi D(N,vi (2));
  rep(i,N){
    rep(j,2)cin>>D[i][j];
  }
  ll cnt=0;
  bool ok=false;
  rep(i,N){
    if(D[i][0]==D[i][1]){
      cnt++;
    }
    else cnt=0;
    if(cnt>=3){
      ok=true;
      break;
    }
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}



Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX 10000003
using namespace std;
void solve()
{
    ll n,sum;  cin>>n>>sum;
    ll val[n],weight[n];
    rep(i,0,n) cin>>weight[i]>>val[i];
    vector<vector<ll>> dp(n+1,vector<ll>(sum+1,0));
    rep(i,1,n+1)
    {
        rep(j,1,sum+1)
        {
            if(weight[i-1]<=j) dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-weight[i-1]]);
            else dp[i][j]=dp[i-1][j];
        }
    }cout<<dp[n][sum];
}
int main()
{
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    return 0;
}

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

void swap(int& a, int& b)
{
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
}

int main()
{
        int a, b;

        while(1){
                cin >> a >>b;
                if(a==0 && b==0){ break; }
                if(a>b){swap(a,b);}
                cout << a << " " << b << endl;
        }
        return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> list [100001];
vector<bool> visited(100001, false);
vector<int> topo;
void dfs(int u){
    visited[u] = true;
    for(int v:list[u]){
        if(!visited[v])
            dfs(v);
    }
    topo.push_back(u);
}
int main() {
    int n, m, a, b;
    cin >> n >> m;
    
    while(m--){
        cin >> a >> b;
        list[a].push_back(b);
    }
    
    for(int i=1;i<=n;i++){
        if(!visited[i]) dfs(i);
    }
    
    vector<int> dp(n+1, 0);
    reverse(topo.begin(), topo.end());
    int ans = 0;
    for(int i=0;i<=n-1;i++){
        int u = topo[i];
        // cout << u << endl;
        for(int v:list[u]){
            if(dp[v] < dp[u] + 1)
                dp[v] = dp[u] + 1;
            ans = max(ans, dp[v]);
        }
    }
    
    cout << ans;
    
	return 0;
}


Measured memory_bytes: 11512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    double res = 0;
    priority_queue<double, vector<double>, greater<double>> pq;
    FOR(i, 0, n)
    {
        double a; cin >> a;
        pq.push(a);
    }
    res = pq.top();
    pq.pop();
    while (!pq.empty())
    {
        res += pq.top();
        res /= 2;
        pq.pop();
    }
    cout << res;
    return 0;
}



Measured memory_bytes: 3772
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[1010][1010];
std::vector<ll> G[1000010];

ll comp( ll i, ll j ) {
  if( i > j )
    std::swap( i, j );

  return i*1000+j;
}

ll deg[1000010], top[1000010];

int main()
{
  std::cin >> N;

  rep( i, N ) {
    rep( j, N-1 )
      std::cin >> A[i][j], --A[i][j];

    rep( j, N-2 ) {
      ll from = comp( i, A[i][j] );
      ll to = comp( i, A[i][j+1] );
      G[from].emplace_back( to );
      ++deg[to];
    }
  }

  std::vector<ll> que;
  ll p = 0;

  memset( top, -1, sizeof(top) );

  rep( i, N ) rep( j, i ) if( !deg[comp(i,j)] )
    que.emplace_back( comp(i,j) );

  while( !que.empty() ) {
    std::vector<ll> vs;

    for( auto v : que ) {
      top[v] = p;
      
      for( auto u : G[v] ) {
        --deg[u];

        if( !deg[u] )
          vs.emplace_back( u );
      }
    }

    ++p;

    que = vs;
  }

  rep( i, N ) rep( j, i ) if( top[comp( i, j )] == -1 ) {
    std::cout << -1 << std::endl;

    return 0;
  }

  std::cout << p << std::endl;

  return 0;
}

Measured memory_bytes: 65160
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}


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

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

	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i + 1] != s[i]) ans++;
	}	

	ans += 1;

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

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

int main(){
  int N; cin >> N;
  int Nsum = N*(N+1)/2;
  int div, S;
  for (int i=2; i<=Nsum; i++){
    if (Nsum%i==0){
      div = i;
      S = Nsum/i;
      break;
    }
  }
  // cout << S << endl;
  vector<int> number(N), memNum, order;
  for (int i=N; i>0; i--){
    number[N-i] = i;
  }
  int M = 0;
  int n = N;
  while(order.size()<N){
    int cnt = 0;
    int now = S;
    for (int i=0;i<N; i++){
      if (number[i]==0) continue;
      if (number[i]>now) continue;
      cnt++;
      now -= number[i];
      order.push_back(number[i]);
      number[i] = 0;
      if(now==0){
        n -= cnt;
        M += n*cnt;
        memNum.push_back(cnt);
        break;
      }
    }
  }
  cout << M << endl;
  int start = 0;
  for (auto k: memNum){
    for (int i=start; i<start+k; i++){
      for (int j=start+k; j<N; j++){
        cout << order[i] << ' ' << order[j] << endl;
      }
    }
    start += k;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <iomanip>

using namespace std;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
#define INF 1 << 30;

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; }
typedef long long ll;
typedef pair<ll, ll> pll;

vector<pair<ll, ll>> pF;


int main(){
    int N, M;
    cin >> N >> M;
    vector<pll> abs;
    rep(i, N){
        ll a, b;
        cin >> a >> b;
        pll tmp = {a, b};
        abs.push_back(tmp);
    }
    sort(abs.begin(), abs.end());

    ll ans = 0;
    ll now = 0;
    rep(i, abs.size()){
        if((now - M) * (now + abs[i].second- M) <= 0){
            ans += abs[i].first * (M - now);
            break;
        }
        now += abs[i].second;
        ans += abs[i].first * abs[i].second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll a; cin >> a;
    ll b; cin >> b;
    cout << (b+a-3) / (a - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;	//using vi = vector<int>;

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

int main()
{
	int a, b;
	int ans = 0;
	cin >> a >> b;

	for (int i = a; i <= b; i++) {
		if (i / 10000 == i % 10 && (i % 10000) / 1000 == (i % 100) / 10)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;

int main() {
	int n;
	int m;
	cin >> n >> m;

	vector<int> vec(n+1,0);

	for (int i = 0; i < 2 * m; i++) {

		int x;
		cin >> x;

		vec.at(x)++;


	}

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

		cout << vec.at(i) << endl;

	}




}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
    string s;
    cin >> s;
    string ans = "CODEFESTIVAL2016";
    int cnt=0;
    for(int i=0;i<16;i++){
        if(s.at(i) != ans.at(i)){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
from sys import stdin
from functools import reduce

def gcd(a, b):
	while b: a, b = b, a % b
	return a

N, X = [int(x) for x in stdin.readline().rstrip().split()]
x_lst = sorted(set([abs(int(x)-X) for x in stdin.readline().rstrip().split()]))

if len(x_lst) == 1:
  print(x_lst[0])
else:
  prev_x = x_lst[0]
  for x in x_lst[1:]:
    prev_x = gcd(prev_x, x)
    if prev_x == 1: break
  print(prev_x)

Measured memory_bytes: 14692