akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

vector<int> divisor(int n)
{
    vector<int> value;
    FOR(i, 1, pow(n, 0.5) + 1)
    {
        if (i <= sqrt(n))
        {
            if (n % i == 0)
            {
                value.push_back(i);
                if (i * i != n)
                {
                    value.push_back(n / i);
                }
            }
        }
    }
    return value;
}

ll M = 1000000007;
typedef pair<int, int> P;
int main()
{
    vector<bool> pripri(1e5,false);//0 origin
    FOR(i, 1, 1e5 + 1)
    {
        if (i % 2 == 1)
        {
            if (divisor(i).size() ==2 && divisor((i + 1) / 2).size() == 2)
            {
                //cout<<i<<endl;
                pripri[i-1] = true;
            }
            
        }
    }
    vector<int>acc(1e5+1,0);//1 origin 0は計算用
    int sum=0;
    rep(i,1e5){
        if(pripri[i]){
            sum++;
        }
        acc[i+1]=sum;
    }
    int q;
    cin>>q;
    rep(i,q){
        int l,r;
        cin>>l>>r;
        printf("%d\n",acc[r]-acc[l-1]);
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;

int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<int> l(Q), r(Q);
    for (int i = 0; i < Q; i++) cin >> l.at(i) >> r.at(i);

    vector<int> sum(N, 0);
    for (int i = 0; i < N - 1; i++) {
        if (S.at(i) == 'A' && S.at(i + 1) == 'C') sum.at(i + 1) = sum.at(i) + 1;
        else sum.at(i + 1) = sum.at(i); 
    }

    for (int i = 0; i < Q; i++) cout << sum.at(r.at(i) - 1) - sum.at(l.at(i) - 1) << endl;

    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
const int D = 365;
VL p(D);
VL l(D, 0);
VVL up(D, VL(26));
void calc(ll& now, int x, int d) { // 今のスコア、どれを選んだか、何日目か(0-indexed)
	l[x] = d + 1;
	now += up[d][x];
	rep(j, 26) {
		now -= p[j] * ((d + 1) - l[j]);
	}
}
ll test(ll now, int x, int d) { // その選択をしてみる
	ll tmp = now;
	int old = l[x];
	l[x] = d + 1;
	tmp += up[d][x];
	rep(j, 26) {
		tmp -= p[j] * ((d + 1) - l[j]);
	}
	l[x] = old;
	return tmp - now;
}
int main() { // とりあえずgreedyにやる
	int d;
	cin >> d;
	ll now = 0;
	rep(i, 26) cin >> p[i];
	rep(i, d) rep(j, 26) cin >> up[i][j];
	rep(i, d) {
		ll diff = UNDER;
		int select = -1;
		rep(j, 26) {
			if (chmax(diff, test(now, j, i))) select = j;
		}
		cout << select + 1 << endl;
		calc(now, select, i);
	}
	// cout << now << endl;
	return 0;
}

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


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  unordered_map<string,int> mp;
  vector<string> strs;
  int n;
  cin>>n;
  string s;
  for(int i = 0; i < n; i++) {
      cin>>s;
      strs.push_back(s);
  }
  
  string sorted;
  int64_t count = 0;
  for(int i = 0; i < n; i++) {
     sort(strs[i].begin(),strs[i].end());
     sorted = strs[i];
     
     if(mp.find(sorted) != mp.end()) {
         count += mp[sorted];
         mp[sorted] += 1;
     }
     else {
         mp[sorted] = 1;
     }
      
  }
  
  
  cout<<count<<"\n";
  
  
  return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<typename M,typename N=M>struct SegmentTree{
   using F=function<M(M,M)>; using G=function<M(M,N)>;
   int sz; vector<M> data; const F f; const G g; const M m1;
   SegmentTree(int n,const F f,const G g,const M &m1):f(f),g(g),m1(m1){
      sz=1; while(sz<n)sz<<=1; data.assign(2*sz,m1);
   }
   void build(vector<M> v){
      rep(i,0,v.size())data[i+sz]=v[i];
      for(int k=sz-1;k>0;k--)data[k]=f(data[2*k],data[2*k+1]);
   }
   void update(int k,const N &x){
      k+=sz; data[k]=g(data[k],x);
      while(k>>=1)data[k]=f(data[2*k],data[2*k+1]);
   }
   M query(int a,int b){
      M L=m1,R=m1;
      for(a+=sz,b+=sz;a<b;a>>=1,b>>=1){
         if(a&1)L=f(L,data[a++]);
         if(b&1)R=f(data[--b],R);
      } return f(L,R);
   }
   M operator[](const int &k)const{return data[k+sz];}
};

vector<int> pos[301010];

int main(){
   int h,w,n; cin>>h>>w>>n;
   SegmentTree<int,int> seg(w,
   [](int a,int b){return max(a,b);},
   [](int a,int b){return a+b;},0);
   vector<int> cnt(w,0);
   rep(i,0,n){
      int x,y; cin>>x>>y; x--; y--;
      pos[x].push_back(y); cnt[y]++;
   }
   seg.build(cnt);
   int res=0;
   rep(i,0,h){
      for(auto& x:pos[i])seg.update(x,-1);
      chmax(res,(int)pos[i].size()+seg.query(0,w));
      for(auto& x:pos[i])seg.update(x,1);
   }
   cout<<res<<endl;
   return 0;
}

Measured memory_bytes: 26216
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline long long read(){
	long long x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(long long a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(long long a){
    write(a); puts("");
}
long long ans,tong[30],n;
char ch[200005];
int main(){
    scanf("%s",&ch);
    long long len=strlen(ch); n=len;
    for(long long i=0;i<len;i++)tong[ch[i]-'a']++;
    ans=n*(n+1)/2+1;
    for(long long i=0;i<26;i++)ans-=tong[i]*(tong[i]+1)/2;
    writeln(ans);
}

Measured memory_bytes: 888
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

v1 = v[::2]
v2 = v[1::2]

cv1 = Counter(v1).most_common(2)
cv2 = Counter(v2).most_common(2)

if cv1[0][0] != cv2[0][0]:
    print(n - cv1[0][1] - cv2[0][1])
else:
    p1 = cv1[0][1] + cv2[1][1] if len(cv2) >= 2 else n - cv1[0][1]
    p2 = cv2[0][1] + cv1[1][1] if len(cv1) >= 2 else n - cv2[0][1]
    print(n - max(p1, p2))

Measured memory_bytes: 15972
n = int(input())
max_step = 0
step = 0
pre_h = 0
for h in map(int, input().split()):
  if h <= pre_h:
    step += 1
  else:
    if max_step < step:
      max_step = step
    step = 0
  pre_h = h
print(max([max_step, step]))

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

int main(){
	int n;scanf("%d",&n);
	char str[55];scanf("%s",str);
	int ans=0;
	for(int i=0;i+2<n;i++){
		if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
MOD = int(1e9+7)

if __name__ == "__main__":
    n = int(input())
    a = [int(i) for i in input().split()]

    sum_a = sum(a) % MOD

    result = 0 

    for value in a:
        sum_a -= value
        result = int(result + value * sum_a) % MOD
    
    print(result)

Measured memory_bytes: 31420
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
#define DD 1
#else
#define DD 0
#endif
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void gg1(){write2(-1);exit(0);}
	void gg2(){puts("NO");exit(0);}
	
	const double eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=2e5+10;
	
	int a[N];
	void main()
	{
		int h=qread(),n=qread();int sum=0;fo(i,1,n) sum+=qread();
		puts(sum>=h?"Yes":"No");
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	#endif
	srand(time(0));
	mine::main();
	if(DD) cerr<<"Time: " <<1.0*clock()/CLOCKS_PER_SEC<<"s";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
   string s1;
   string s2;
   cin>>s1>>s2;
   s2.erase(s2.end()-1);
   if(s1==s2)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int main()
{
    int x,y;
    double a;
    cin>>x>>y;
    a = (double) y/x;
    if(a<=4 && a>=2 && y>x && y%2==0){
        cout<<"Yes";
        
            
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

///////////////////////////////////////////////////////////////////////////
ll d[1005] = {},cnt[1005] = {},ww[1005] = {};
vector<pair<ll,ll>> e[1005];
vector<ll> w[1005];
ll n,m;

int main(){
	cin >> n >> m;
	
	rep(i,1,n)d[i] = linf;
	    
    rep(i,0,m){
        int a,b,c;
        cin >> a >> b >> c;
        e[a-1].pb(make_pair(b-1,-c));
        w[b-1].pb(a-1);
    }

    queue<ll> q;
    q.push(n-1);
    ww[n-1] = 1;
    
    while(!q.empty()){
        ll s = q.front();
        q.pop();

        for(auto it:w[s]){
            if(ww[it] == 0){
                q.push(it);
                ww[it] = 1;
            }
        }
    }
   
    bool flag = 1;
    while(flag){
        flag = 0;
        rep(i,0,n){
            if(d[i] != linf && ww[i] == 1){
                for(auto it:e[i]){
                    
                    ll f = it.ft,s=it.sd;

                    if(d[f] == linf || d[f] > d[i]+s){
                        d[f] = d[i]+s;
                        flag = 1;
                        cnt[f]++;

                        if(cnt[n-1] > n){
                            P("inf");
                            return 0;
                        }
                    }
                }
            }
        }
    }

    cout << - d[n-1] << endl;
	return  0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

int main() {
    int sum = 0, tr = 0;
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
            int c;
            cin >> c;
            if(i == j)
                tr += c;
            sum += c;
        }
    }
    cout << (sum == 3 * tr ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t[1000];
int  main()
{
    memset(t,0,1000);
    int n;
    int m,p,x;
    cin>>n;
    ll sum = 0;
    for(int i=0; i<n; i++)
    {
        cin>>t[i];
        sum +=t[i];
    }

    cin>>m;
    while(m--)
    {
        cin>>p>>x;
        cout<<sum - t[p-1] + x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def main():
    N = int(input())
    d = list(map(int, input().split()))

    distance = [0] * (N + 1)

    for _d in d:
        distance[_d] += 1

    if d[0] != 0 or distance[0] != 1:
        print(0)
        return

    ans = 1
    for i in range(1, (N + 1)):
        n = distance[i-1]
        r = distance[i]
        ans = ans * n ** r
        ans = ans % MOD
        # print(ans)

    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 53172
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d%d", &a, &b);

    if(a <= 5){
        printf("%d\n", 0);
        return 0;
    }

    printf("%d\n", a <= 12 ? b / 2 : b);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    double x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    cout << fixed << setprecision(5) << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;

    return 0;
}

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

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

typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;

int K,S;
int ans;

int main(){ 

cin.tie(0);
ios::sync_with_stdio(false);

cin>>K>>S;

rep(i,K+1){
	rep(j,K+1){
		if((i+j<=S)&&(i+j>=S-K)) ans++;
	}
}

cout<<ans<<endl;

}


Measured memory_bytes: 256
def main():
    h, w = [int(e) for e in input().split()]

    if h == 1 or w == 1:
        print(1)
    elif h*w % 2 == 0:
        print(h*w//2)
    else:
        print(h*w//2 + 1)

if __name__ == "__main__":
    main()


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

int main(){
    int n,m,min = 1000000000,ans = 0;
    cin >> n >> m;
    int a[n],b[n],c[m],d[m];
    for(int i = 0;i < n;i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0;i < m;i++){
        cin >> c[i] >> d[i];
    }
    for(int i = 0;i < n;i++,min = 10000000000,ans = 0){
        for(int j = 0;j < m;j++){
            if(min > fabs(a[i]-c[j])+fabs(b[i]-d[j])){
                min = fabs(a[i]-c[j])+fabs(b[i]-d[j]);
                ans = j+1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  const int MAX = 2e5;
  const long long MOD = 1e9 + 7;
  const long long MODINV = 500000004;

  int N; cin >> N;
  long long A[MAX];
  for (int i = 0; i < N; i++) cin >> A[i];

  long long sum = 0;
  for (int i = 0; i < N; i++) {
    sum = (sum + A[i]) % MOD;
  }

  long long sqr = (sum * sum) % MOD;

  long long mid = 0; 
  for (int i = 0; i < N; i++) {
    mid = mid + ((A[i] * A[i]) % MOD) % MOD;
  }

  long long top = (sqr - mid) % MOD;
  if (top < 0) top += MOD;

  long long ans = (top * MODINV) % MOD;

  cout << ans << endl;
}

Measured memory_bytes: 5208
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,m,x[200001],y[200001],ansx=0,ansy=0,mod=1e9+7;
    cin>>n>>m;
    rep(i,n) cin>>x[i];
    rep(i,m) cin>>y[i];
    rep(i,n-1) ansx=(ansx+(i+1)*(n-i-1)%mod*(x[i+1]-x[i])%mod)%mod;
    rep(i,m-1) ansy=(ansy+(i+1)*(m-i-1)%mod*(y[i+1]-y[i])%mod)%mod;
    cout<<ansx*ansy%mod;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c;
  ll res=0;
  rep(i,4){
    cin>>c;
    if(c=='2')res++;
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define ll long long

using namespace std;

ll dp[105][100005];

int main()
{
    ll n,w;
    //weight,value
    pair<ll,ll>arr[105];
    cin>>n>>w;
    for(int i=0;i<n;i++)
        cin>>arr[i].first>>arr[i].second;
    for(int i=0;i<=w;i++)
    {
        if(i>=arr[0].first)
            dp[0][i]=arr[0].second;
    }
    // outer loop on rows --> items
    for(int i=1;i<n;i++)
    {
        // inner loop on columns --> weights
        for(int j=0;j<=w;j++)
        {
            if(j<arr[i].first)
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                //          not taken  , taken
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i].first]+arr[i].second);
            }
        }
    }
    cout<<dp[n-1][w]<<'\n';
    return 0;
}

Measured memory_bytes: 80128
#include<iostream>

using namespace std;

int count=0,ans;
int array[11],senbei[2][11][10001];

void loop(int n,int height,int width)
{
	if(n==height)
	{
		int addtable=0;
		for(int i=0;i<width;i++)
		{
			int table=0;
			for(int j=0;j<height;j++)
			{
				table+=senbei[array[j]][j][i];
			}
			addtable+=max(table,height-table);
		}
		ans=max(addtable,ans);
		return ;
	}
	array[n]=0;
	loop(n+1,height,width);
	array[n]=1;
	loop(n+1,height,width);
	return ;
}

int main()
{
	int h,w;
	for(;;)
	{
		cin >> h >> w;
		if(h==0)
			break;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				cin >> senbei[0][i][j] ;
				senbei[1][i][j]=(senbei[0][i][j]+1)%2;
			}
		}
/*
		cout << "senbei1" << endl;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				cout << senbei[0][i][j] << " "  ;
			}
			cout << endl;
		}
		cout << "senbei2" << endl;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				cout << senbei[1][i][j] << " "  ;
			}
			cout << endl;
		}
//*/		
		ans=0;
		loop(0,h,w);
		cout << ans << endl;
	}
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a == 5 && b ==5 && c ==7)    cout << "YES" << endl;
  else if (a == 5 && b ==7 && c ==5)    cout << "YES" << endl;
  else if (a == 7 && b ==5 && c ==5)    cout << "YES" << endl;
  else   cout << "NO" << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    int n,m,x,t,i,sum=0,ans=0,a[110];
    memset(a,0,sizeof(a));
    cin>>n>>m>>x;
    for(i=0; i<m; i++)
    {
        scanf("%d",&t);
        a[t]=1;
    }
    for(i=0; i<=x; i++)
        ans+=a[i];
    for(i=x; i<=n; i++)
        sum+=a[i];
    ans=min(ans,sum);
    cout<<ans<<endl;
    return 0;
}


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

int main(){
	long long n;
	cin >> n;
	map<string, long long> a;
	for(int i = 1;i <= n;i++){
		string str;
		cin >> str;
		a[str]++;
	}
	
	cout << "AC x " << a["AC"] << "\n";
	cout << "WA x " << a["WA"] << "\n";
	cout << "TLE x " << a["TLE"] << "\n";
	cout << "RE x " << a["RE"] << "\n";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 10000
using namespace std;

struct edge{int to, cap, rev;};
vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});  
}


//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

//s??????t???????????§???????±???????
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}


int main(){
  int n,m;
  cin>>n>>m;
  
  int A[1001],B[1001];
  for(int i=0,a,b;i<m;i++){
    cin>>A[i]>>B[i];
    add_edge(A[i],B[i],1);
    add_edge(B[i],A[i],1);
  }
  int s,t;
  cin>>s>>t;
  cout <<max_flow(s,t)<<endl;

  vector<int> ans;  
  for(int i=0;i<m;i++){
    int a=A[i],b=B[i];
    int flg=0;
    for(int j=0;j<G[a].size();j++)
      if(G[a][j].to==b&&G[a][j].cap>=1)flg=1;
    if(flg) ans.push_back(i+1);
  }

  cout <<ans.size()<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
  
  
  return 0;
}

Measured memory_bytes: 3472
use std::io;

fn main() {
    let mut te = String::new();
    io::stdin().read_line(&mut te).unwrap();
    let mut t = ' '; 
    for i in te.chars(){
        if &t == &i {
            println!("Bad");
            return;
        }
        t = i;
    }
    println!("Good");
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
long long int n,r,an;

int main(){
	scanf("%lld",&n);
	r = 26;
	stack<long long int>s;
    while(n){
    	an = n%r;
    	if(an == 0){
    		an = 26;
    		n = n/r;
    		n --;
    	}else{
    		n = n/r;
    	}
        s.push(an);
    }
    while(!s.empty()){
        printf("%c",(int)s.top()+'a'-1);
        s.pop();
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3672
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
new_a_list = [[0, 0]]
a_sum = 0
for i in range(0, n):
    a_sum += a_list[i]
    if a_sum <= k:
        new_a_list.append([i + 1, a_sum])
    else:
        break

best = len(new_a_list) - 1
b_sum = 0
a_sum = new_a_list[-1][1]
a_count = new_a_list[-1][0]
flag = 1
for i in range(0, m):
    b_sum += b_list[i]
    while True:
        if b_sum <= k - a_sum:
            if best < i + 1 + a_count:
                best = i + 1 + a_count
            break
        if a_count == 0:
            flag = 0
            break
        a_count -= 1
        a_sum = new_a_list[-(len(new_a_list) - a_count)][1]
    if flag == 0:
        break
print(best)

Measured memory_bytes: 55980
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	ll dp[3][M]={};
	int n,a,b,c;
	cin>>n;
	cin>>a>>b>>c;
	dp[0][1]=a,dp[1][1]=b,dp[2][1]=c;
	rep(i,2,n+1){
		cin>>a>>b>>c;
		//select a;
		dp[0][i]=max(dp[1][i-1]+a,dp[2][i-1]+a);
		//select b;
		dp[1][i]=max(dp[0][i-1]+b,dp[2][i-1]+b);
		//select c;
		dp[2][i]=max(dp[0][i-1]+c,dp[1][i-1]+c);
	}
	int ans=0;
	ans=max({dp[0][n],dp[1][n],dp[2][n]});
	print(ans);
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt(); int d = stdIn.nextInt();
        int[][] x = new int[n][d];

        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                x[i][j] = stdIn.nextInt();
            }
        }

        int count = 0;
        double t = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = 0; i + j + 1 < n; j++){
                for(int k = 0; k < d; k++){
                     t += Math.pow(x[i][k] - x[i + j + 1][k], 2);
                }
                if(Math.pow((int)Math.sqrt(t), 2) == t) count++;
                t = 0;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21716
N = int(input())
S = sorted([''.join(sorted(input())) for _ in range(N)])
prev = ''
ans = 0
n = 0
for i in range(N):
    if S[i]!=prev:
        ans += n*(n-1)//2
        prev=S[i]
        n=1
    else:
        n+=1
ans += n*(n-1)//2
 
print(ans)

Measured memory_bytes: 11408
#include <iostream>
#include <cstring>

using namespace std;

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

  if(n[0] == '7' || n[1] == '7' || n[2] == '7') {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

  


Measured memory_bytes: 3036
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


N, X = map(int, input().split())
x = list(map(int, input().split()))
dx = [0] * N
ans = abs(X - x[0])
for i in range(1, N):
    dx[i] = abs(X - x[i])
    ans = gcd(ans, dx[i])
print(ans)

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

typedef long long ll;

int main() {
    string s;
    cin >> s;
    
    if(s.length()>9){
        cout << "NO" << endl;
        return 0;
    }
    
    map<char,int> m;
    int f=0; bool F=true;
    for(int i=0; i<s.length(); i++){
        m[s[i]]++;
        if(s[i]=='K'){
            if(f==0) f++;
            else F=false;
        }
        if(s[i]=='I'){
            if(f==1) f++;
            else F=false;
        }
        if(s[i]=='H'){
            if(f==2) f++;
            else F=false;
        }
        if(s[i]=='B'){
            if(f==3) f++;
            else F=false;
        }
        if(s[i]=='R'){
            if(f==4) f++;
            else F=false;
        }
        if(!F){
            cout << "NO" << endl;
            return 0;
        }
    }
    for(int i=0; i<s.length()-1; i++){
        if(s[i]=='A' && s[i+1]=='A'){
            cout << "NO" << endl;
            return 0;
        }
    }
    bool flag=true;
    for(auto itr=m.begin(); itr!=m.end(); itr++){
        if(itr->first == 'K' || itr->first == 'I' || itr->first == 'H' || itr->first == 'B' ||
           itr->first == 'R'){
            if(itr->second > 1 || itr->second == 0) flag = false;
        }
        else if(itr->first == 'A'){
            if(itr->second > 4) flag = false;
        }
        else flag = false;
    }
    if(m['A']==0){
        if(m.size() < 5) flag=false;
    } else {
        if(m.size() < 6) flag=false;
    }
    if(s[0]!='A' && s[0] != 'K') flag=false;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='K'){
            if(s[i+1] != 'I' || s[i+2] != 'H') flag=false;
        }
    }
    if(!flag){
        cout << "NO" << endl;
    }
    else
        cout << "YES" << endl;
    
    
}


Measured memory_bytes: 256
import copy

N = int(input().strip())
P = list(map(int, input().strip().split()))
ans = 0
min = 1e10
for i in range(N):
  #Q = copy.copy(P[0:i+1])
  #Q.sort()
  #print(P)
  #print(Q)
  #if Q[0] >= P[i]:
  #  ans += 1
  if P[i] < min:
    min = P[i]
    ans += 1
  """
  flag = True
  for j in range(0, i):
    if P[i] > P[j]:
      flag = False
      break
  if flag:
    ans += 1
  """
  
print(ans)

Measured memory_bytes: 25256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i,k) ans += p[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;

struct edge
{
	int to;
	int cost;
};

vector<long long> score_list;
vector< vector <edge> > Vs_list;


void UpdateScore(int now)
{
	for (auto e : Vs_list[now]) {
		if (score_list[e.to] == -1) {
			score_list[e.to] = score_list[now] + e.cost;
			UpdateScore(e.to);
		}
	}
}

int main()
{
	int N;

	cin >> N;

	Vs_list = vector< vector <edge> >(N);
	score_list = vector<long long>(N, -1);

	int a, b, c;
	for (int ni = 0; ni < N-1; ni++) {
		cin >> a >> b >> c;
		a--;
		b--;
		Vs_list[a].push_back(edge{ b,c });
		Vs_list[b].push_back(edge{ a,c });
	}

	int Q, K;

	cin >> Q >> K;
	K--;

	vector<int> Xs(Q);
	vector<int> Ys(Q);

	int x, y;
	for (int qi = 0; qi < Q; qi++) {
		cin >> x >> y;
		Xs[qi] = x - 1;
		Ys[qi] = y - 1;
	}

	score_list[K] = 0;
	UpdateScore(K);

	long long ans;
	for (int qi = 0; qi < Q; qi++) {
		ans = score_list[Xs[qi]] + score_list[Ys[qi]];
		cout << ans << endl;
	}

	return 0;
}



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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"

void Main() {
    int n, d;
    cin >> n >> d;
    int m = 0;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(i == m + d){
            m = i + d + 1;
            ++ans;
        }
    }
    if(m < n){
        ++ans;
    }
    cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

class IO
{
    int idx;
    string[] input;

    public IO(TextReader reader)
    {
        input = reader.ReadToEnd().Split(new[] { " ", "\n", "\r" },
            StringSplitOptions.RemoveEmptyEntries);
    }

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO(In));
        Out.Flush();
    }

    static HashSet<int>[] gr;

    public static void Solve(IO io)
    {
        var n = io.I;
        var m = io.I;

        gr = new HashSet<int>[n + 1];
        for (var i = 1; i <= n; i++) gr[i] = new HashSet<int>();

        for (var i = 0; i < m; i++)
        {
            var a = io.I;
            var b = io.I;
            gr[a].Add(b);
        }

        foreach (var v in gr[1])
        {
            if (gr[v].Contains(n))
            {
                io.Write("POSSIBLE");
                return;
            }
        }

        io.Write("IMPOSSIBLE");
    }
}

Measured memory_bytes: 70484
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(a) (int)(a).size()

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;
double EPS = 1e-11;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

//素因数分解O(√n)
vector<pair<ll, ll>> MakePrimeList(ll x) {
    vector<pair<ll, ll>> res;
    for(ll k=2; k*k<=x; k++) {
        if(x % k == 0) {
            ll cnt = 0;
            while(x % k == 0){
              x /= k;
              cnt++;
            }
            res.pb({k, cnt});
        }
    }
    if(x > 1) res.push_back({x, 1});
    return res;
}


void solve(){
  ll N;
  cin >> N;
  vector<ll> X(N);
  rep(i, N) cin >> X[i];
  ll ans = INFL;
  for(ll i = 0; i <=100; i++){
    ll sum = 0;
    rep(j, N){
      sum += (X[j] - i) * (X[j] - i);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
}


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

//  2進数ならば baseNumber を  2 とする
// 10進数ならば baseNumber を 10 とする
int GetDigitsCount(int targetNumber, int baseNumber=10) {
	int digitsCount = 0;
	while (targetNumber != 0) {
		digitsCount++;
		targetNumber /= baseNumber;
	}
	return digitsCount;
}

int main() {

	int n, c; cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (GetDigitsCount(i) % 2 == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3568
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[10];
int main()
{
    scanf("%s",a);
    if(strlen(a)==2) printf("%s",a);
    else
    {
        for(int i=2;i>=0;i--)
            printf("%c",a[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int a[150 * 150][2];

int comp(int h1, int w1, int h2, int w2){
	int sum1,sum2;
	sum1 = h1 * h1 + w1 * w1;
	sum2 = h2 * h2 + w2 * w2;
	
	if(sum1 == sum2 && h1 < h2){ return 1; } 
	if(sum1 < sum2){ return 1; }
	return 0;
}

int main(){

int h, w;
int i, j;
int H = 150, W = 150;

while(1){
	scanf("%d%d",&h , &w);
	if(h == 0 && w == 0) break;
	H = 150, W = 150;

	for (i = 1; i <= 150; i++){
		for (j = 1; j <= 150; j++){
			if(!(i < j)) continue;
			if(comp(h, w, i , j)){
				if(comp(i, j , H, W)){
					H = i;
					W = j;
				}
			}
		}
	}
	printf("%d %d", H , W);
	printf("\n");
}
	return 0;
}

Measured memory_bytes: 604
N=int(input())
L=list(map(int,input().split()))
M=[0]*N
count=0
while(1):
	count=0
	for i in range (N-1):
		if L[i]>L[i+1]:
			if M[i]==1:
				print("No")
				exit()
			else:
				L[i]-=1
				M[i]=1
		else:
			count+=1
	if count==(N-1):
		print("Yes")
		exit()


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

int main()
{
    priority_queue<int> queue;
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        queue.push(a);
    }

    int alice = 0;
    int bob = 0;
    int i = 0;
    while (!queue.empty()) {
        if (i % 2 == 0) {
            alice += queue.top();
            queue.pop();
        } else {
            bob += queue.top();
            queue.pop();
        }
        i++;
    }
    cout << alice - bob << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main() 
{
	char a;
	cin>>a;
	if(a=='A')
	cout<<'A';
	if(a=='B')
	cout<<'A';
	if(a=='C')
	cout<<'A';
	if(a=='D')
	cout<<'A';
	if(a=='E')
	cout<<'A';
	if(a=='F')
	cout<<'A';
	if(a=='G')
	cout<<'A';
	if(a=='H')
	cout<<'A';
	if(a=='I')
	cout<<'A';
	if(a=='J')
	cout<<'A';
	if(a=='K')
	cout<<'A';
	if(a=='L')
	cout<<'A';
	if(a=='M')
	cout<<'A';
	if(a=='N')
	cout<<'A';
	if(a=='O')
	cout<<'A';
	if(a=='P')
	cout<<'A';
	if(a=='Q')
	cout<<'A';
	if(a=='R')
	cout<<'A';
	if(a=='S')
	cout<<'A';
	if(a=='T')
	cout<<'A';
	if(a=='U')
	cout<<'A';
	if(a=='V')
	cout<<'A';
	if(a=='W')
	cout<<'A';
	if(a=='X')
	cout<<'A';
	if(a=='Y')
	cout<<'A';
	if(a=='Z')
	cout<<'A';
	if(a=='a')
	cout<<'a';
	if(a=='b')
	cout<<'a';
	if(a=='c')
	cout<<'a';
	if(a=='d')
	cout<<'a';
	if(a=='e')
	cout<<'a';
	if(a=='f')
	cout<<'a';
	if(a=='g')
	cout<<'a';
	if(a=='h')
	cout<<'a';
	if(a=='i')
	cout<<'a';
	if(a=='j')
	cout<<'a';
	if(a=='k')
	cout<<'a';
	if(a=='l')
	cout<<'a';
	if(a=='m')
	cout<<'a';
	if(a=='n')
	cout<<'a';
	if(a=='o')
	cout<<'a';
	if(a=='p')
	cout<<'a';
	if(a=='q')
	cout<<'a';
	if(a=='r')
	cout<<'a';
	if(a=='s')
	cout<<'a';
	if(a=='t')
	cout<<'a';
	if(a=='u')
	cout<<'a';
	if(a=='v')
	cout<<'a';
	if(a=='w')
	cout<<'a';
	if(a=='x')
	cout<<'a';
	if(a=='y')
	cout<<'a';
	if(a=='z')
	cout<<'a';
	
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
    ll n; cin >> n;
    int a [2][n];
    rep(i,2){
        rep(j,n){
            cin >> a[i][j];
        }
    }
    int ans_max = 0;
    rep(i,n){
        int sum = 0;
        rep(j,n){
            if(j <= i)sum += a[0][j];
            if(j >= i)sum += a[1][j];
        }
        if(sum > ans_max)ans_max = sum;
    }
    print(ans_max);
}


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

int main(){
    int x;
    cin >> x;
    for (int i = 0; i <= 1000; i++){
        if (100 * i <= x && x <= 105 * i){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << 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() {
	string s;
	cin >> s;
	int a = 0;
	for (int i = 0; i < s.size(); i++) {
		a += (s[i]) - '0';
	}
	int b = stoi(s);
	if (b % a == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define double long double
#define endl '\n'
#define For(i,a,n) for(int i=(a);i<=(n);i++)
#define RFor(i,a,n) for(int i=(n);i>=(a);i--)
#define Set(a,val) memset((a),(int)(val),sizeof((a)))
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) (int)x.size()
#define Min(a,b) a = min(a,b)
#define Max(a,b) a = max(a,b)
const int MOD = 1e9 + 7;
int MulMod(int a,int b){ return (a*b)%MOD; }
int AddMod(int a,int b){ return (a+b)%MOD; }

const int MAXN = 100;
int a[MAXN];

void solving(){
    int n; cin>>n;
    For(i,1,n) cin>>a[i];

    int money = 1000;

    For(i,2,n){
        if(a[i] > a[i-1]){
            int stocks = money/a[i-1];
            money -= stocks*a[i-1];
            money += stocks*a[i];
        }
    }

    cout<<money<<endl;
}    

signed main(){
    F_IO;

    int t = 1; 
    // cin>>t;

    For(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solving();
    }
}

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

const int INF = 1e+10;

int main(void) {
	// 入力
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> C(N);
	vector<vector<int>> A(N, vector<int>(M));

	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}

	int ans = INF;
	for (int bit = 0; bit < (1 << N); bit++) {
		int cost = 0;
		vector<int> D(M);
		for (int i = 0; i < N; i++) {
			if (bit >> i & 1) {
				cost += C[i];
				for (int j = 0; j < M; j++) {
					D[j] += A[i][j];
				}
			}
		}
		bool ok = true;
		for (int i = 0; i < M; i++) {
			if (D[i] < X) {
				ok = false;
				break;
			}
		}
		if (ok) ans = min(ans, cost);
	}
	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3636
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, C, K = LI()
    T = [I() for _ in range(N)]
    T.sort()

    t = T[0]
    cnt = 0
    ans = 0
    for i in T:
        cnt += 1
        if cnt > C or i > t + K:
            ans += 1
            cnt = 1
            t = i
    ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    ll n,k;
    cin>>n>>k;
    ll a[3];
    for(int i=0;i<3;i++) cin>>a[i];
    string t;
    cin>>t;
    ll ans = 0;
    string s = "spr";
    for(int i=0;i<k;i++){
        for(int j=0;j<3;j++){
            if(s[j] == t[i]){
                ans += a[j];
            }
        }
    }
    for(int i=k;i<n;i++){
        if(t[i]==t[i-k]){
            if(i+k < n){
                t[i] = '.';
            }
        }
        else{
            for(int j=0;j<3;j++){
                if(s[j]==t[i]){
                    ans += a[j];
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int n,val[maxn];
int main()
{
	scanf("%d",&n);
	int a=-1,na=0,b=-1,nb=0,c=-1,nc=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&val[i]);
		if(a==-1 || a==val[i]) a=val[i],na++;
		else if(b==-1 || b==val[i]) b=val[i],nb++;
		else if(c==-1 || c==val[i]) c=val[i],nc++;
		else { puts("No"); return 0; }
	}
	if(a==0 && na==n) return puts("Yes"),0;
	if(n%3==0 && na==n/3 && nb==2*n/3 && a==0) return puts("Yes"),0;
	if(n%3==0 && na==2*n/3 && nb==n/3 && b==0) return puts("Yes"),0;
	if(n%3==0 && na==n/3 && nb==n/3 && nc==n/3 && (a^b)==c) return puts("Yes"),0;
	puts("No");
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    sort (a , a + n);
    for (int i = 0; i < n; i ++) {
        if (a[i] != a[i + 1]) {
            ans++;
        }
    }
    if (ans % 2 == 0) {
        cout << ans - 1;
    }
    else {
    cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	static char a[];
	static int id;
	static int n;

	public static int exp() {
		int left = term();
		while (true) {
			int c = a[id++];
			if (c == '+') {
				int right = term();
				left += right;
			} else if (c == '-') {
				int right = term();
				left -= right;
			} else {
				id--;
				break;
			}
		}
		return left;
	}

	public static int term() {
		int left = fact();
		while (true) {
			int c = a[id++];
			if (c == '*') {
				int right = fact();
				left *= right;
			} else if (c == '/') {
				int right = fact();
				left /= right;
			} else {
				id--;
				break;
			}
		}
		return left;
	}

	public static int fact() {
		int c = a[id++];
		if (c == '+') {
			return exp();
		} else if (c == '-') {
			return -exp();
		} else if (c == '(') {
			int left = exp();
			id++;
			return left;
		} else {
			int x = c - '0';
			while (true) {
				if (Character.isDigit(a[id])) {
					x *= 10;
					x += a[id++] - '0';
				} else {
					break;
				}
			}
			c = x;
		}
		return c;
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		while (m-- != 0) {
			a = sc.next().toCharArray();
			id = 0;
			n = a.length;
			System.out.println(exp());
		}
	}
}

Measured memory_bytes: 17172