akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

class help
{
    public:
     int a,b,k;
     
     help(int x,int y,int z){a=x; b=y; k=z;}
     
};


bool xsort(help &a,help&b)
{
   
         return a.a<b.a;
     
}
bool ysort(help &a,help&b)
{
   
         return a.b<b.b;
     
}



 int p[200000],sz[200000];
int find(int v){return (v==p[v])?v:p[v]=find(p[v]);}
void merge(int a,int b){
	a=find(a),b=find(b);
	if(a==b)return;
	if(sz[a]<sz[b])swap(a,b);
	p[b]=a,sz[a]+=sz[b];
}
        
int main() {
    
    
    
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++)p[i]=i;
    vector<help>arr;
    for(int i=0;i<n;i++)
    {
        int a,b;cin>>a>>b;a--;b--;
        arr.push_back(help(a,b,i));
    }
    sort(arr.begin(),arr.end(),xsort);
    
    set<int> set;
    unordered_map<int,int> tmap;
    
    for(int i=0;i<n;i++)
    {
        int val=-1*arr[i].b;
        auto it=set.upper_bound(val);
        if(it!=set.end())
        {
            int in=arr[tmap[*it]].k;
            merge(in,arr[i].k);
        }
        set.insert(val);
        tmap[val]=i;
    }
    
    set.clear(); tmap.clear();
    for(int i=n-1;i>=0;i--)
    {
        int val=arr[i].b;
        auto it=set.upper_bound(val);
        if(it!=set.end())
        {
            int in=arr[tmap[*it]].k;
            merge(in,arr[i].k);
        }
        set.insert(val);
        tmap[val]=i;  
    }
    
    
    sort(arr.begin(),arr.end(),ysort);
    
     set.clear();
     tmap.clear();
    
    for(int i=0;i<n;i++)
    {
        int val=-1*arr[i].a;
        auto it=set.upper_bound(val);
        if(it!=set.end())
        {
            int in=arr[tmap[*it]].k;
            merge(in,arr[i].k);
        }
        set.insert(val);
        tmap[val]=i;
    }
    
    set.clear(); tmap.clear();
    for(int i=n-1;i>=0;i--)
    {
        int val=arr[i].a;
        auto it=set.upper_bound(val);
        if(it!=set.end())
        {
            int in=arr[tmap[*it]].k;
            merge(in,arr[i].k);
        }
        set.insert(val);
        tmap[val]=i;  
    }
    tmap.clear();
    for(int i=0;i<n;i++)
    {
        tmap[find(i)]++;
    }
    for(int i=0;i<n;i++)
    cout<<tmap[find(i)]<<endl;
    
}


Measured memory_bytes: 24776
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 36

int main()
{
  int i, j, min, num, tem, sflag=0, flag=0;
  int count = 0;
  char barray[N][3], sarray[N][3];
  char temp[3];
  char a[N];
  int n[N];

  scanf("%d", &num);

  for(i=0;i<num;i++)
    {
      scanf("%s", barray[i]);
      strcpy(sarray[i],barray[i]);
      a[i] = barray[i][0];
      n[i] = atoi(&barray[i][1]);
    }

  /*for(i = 0; i < num; i++)
    {
      printf("%d ", n[i]);
    }
    printf("\n");*/
    
  for( i = 0; i < num-1; i++)
    {
      for( j = num-1; j >= i+1; j--)
	{
	  if(n[j] < n[j-1])
	    {
	      if(n[j] == n[j-1])sflag = 1;
	      tem = n[j];
	      n[j] = n[j-1];
	      n[j-1] = tem;
	      
	      strcpy(temp, barray[j]);
	      strcpy(barray[j], barray[j-1]);
	      strcpy(barray[j-1], temp);
	    }
	}
    }
  
  for( i = 0; i < num-1; i++)
    {
      printf("%s ", barray[i]);
    }
  printf("%s\n", barray[num-1]);
  if(sflag)printf("Not stable\n");
  else printf("Stable\n");

  flag = 0;
  sflag = 0;
   for(i=0;i<num;i++)
    {
      a[i] = sarray[i][0];
      n[i] = atoi(&sarray[i][1]);
    }
   
  for (i = 0; i < num-1; i++)
    {
      min = i;
      for (j = i + 1; j < num; j++)
	{
	  if (n[j] < n[min])
	    {
	      min = j;
	      flag = 1;
	    } 
	}
      if(flag)
	{
	  for(j=min-1;j>i;j--)
	    {
	      if(n[i]==n[j])sflag=1;
	    }
      tem = n[i];
      n[i] = n[min];
      n[min] = tem;

      strcpy(temp, sarray[i]);
      strcpy(sarray[i], sarray[min]);
      strcpy(sarray[min], temp);
      
      count++;
      flag = 0;
	}
    }
  
  for(i = 0; i < num-1; i++)
    {
      printf("%s ", sarray[i]);
    }
  printf("%s\n", sarray[num-1]);
  if(sflag)printf("Not stable\n");
  else printf("Stable\n");
 
  return 0;
}



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

int main() {
	int k, n, i, j;
	cin >> n >> k;
	vector<int> vec(n);
	for (i = 0; i < n; i++){
		cin >> vec.at(i);
	}
	
	
	int a, b, c;
	c = 0;
	a = 0;
	for (j = 0; j < k; j++ ){
		for (i = 0;i < n; i ++){
			if (a < vec.at(i)){
				a = vec.at(i);
				b = i;
			}
		}
		c += vec.at(b);
		vec.at(b) = 0;
		b = 0;
		a = 0;
	}
	cout << c << endl;
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    long long a,b;
    t = 1;
    while(t--) {
	 cin >> a >> b;
	 if(abs(a - b) % 2 == 0) 
	  cout << min(a , b) + abs(a - b) / 2 << endl;
	 else
	  cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
m = 0
res = []
# 1 idx
for i in range(n, 0, -1):
    # i の倍数でbit立っているものの個数を数える
    cnt = 0
    idx = 2
    while i * idx <= n:
        if ans[i * idx - 1]:
            cnt += 1
        idx += 1
    debug = cnt
    if cnt % 2 != a[i - 1]:
        ans[i - 1] = 1
        m += 1
        res.append(i)
print(m)
if m:
    print(*res)


Measured memory_bytes: 14056
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll i,N,M,a,b,next,f=0;
  cin>>N>>M;
  mat v(N);
  rep(i,M){
    cin>>a>>b;
    a--;b--;
    v[a].pb(b);
    v[b].pb(a);
  }
  vec ch(N,1),par(N,-1),ans;
  next=a;
  while(!f){
    ch[next]=0;f=1;
    for(auto i:v[next]){
      if(ch[i]){
        par[i]=next;
        next=i;
        f=0;
        break;
      }
    }
  }
  while(par[next]>=0){
    ans.pb(next+1);
    next=par[next];
  }
  f=0;
  while(!f){
    ch[next]=0;f=1;
    ans.pb(next+1);
    for(auto i:v[next]){
      if(ch[i]){
        next=i;
        f=0;
        break;
      }
    }
  }
  cout<<ans.size()<<endl;
  output(ans);
  return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  char alphabet[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  for(int i = 0; i < S.size(); i++){
    for(int j = 0; j < 26 ; j++){
      if(S[i] == alphabet[j]){
        cout << alphabet[(j + N)%26];
        break;
      }
    }
  }
  cout << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	int n, m, k; cin >> n >> m >> k;
	bool flag = false;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i*m + j*n - 2*i*j == k) flag = true;
		}
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

diff = []
for i in range(len(H)-1):
    diff.append(H[i+1]- H[i])

cnt = 0
ans = 0
for d in diff:
    if d<=0:
        cnt += 1
        ans = max(cnt, ans)
    else:
        ans = max(cnt, ans)
        cnt = 0
        
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 998244353;
const ll INF = 1001001001;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> l(k), r(k);
    rep(i, k)
    {
        cin >> l[i] >> r[i];
    }
    vector<ll> dp(n + 1);
    vector<ll> dpsum(n + 1);
    dp[1] = 1;
    dpsum[1] = 1;
    rep2(i, 2, n + 1)
    {
        rep(j, k)
        {
            ll li = i - r[j];
            ll ri = i - l[j];
            if (ri < 1)
            {
                continue;
            }
            if (li < 1)
            {
                li = 1;
            }
            dp[i] += MOD + dpsum[ri] - dpsum[li - 1];
            dp[i] %= MOD;
        }
        dpsum[i] = dpsum[i - 1] + dp[i];
        dpsum[i] %= MOD;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 6432
#include <stdio.h>
#define MAX 100
#define UNEXPLORED 0
#define FIRST_TIME 1
#define SECOND_TIME 2

int A[MAX][MAX];
int n, d[MAX], f[MAX], time, judge[MAX];
//d:1回目の時刻
//f:2回目の時刻
//time:時間測定
//judge:訪問した回数の記録

void dep_search(int u){
  int v;
  judge[u] = FIRST_TIME;
  d[u] = time++;
  for(v = 0; v < n; v++){
    if(A[u][v] == 0) continue;
    if(judge[v] == UNEXPLORED){
      dep_search(v);
    }
  }
  judge[u] = SECOND_TIME;
  f[u] = time++;
}

void depth(){
  int u;
  for(u = 0; u < n; u++){
    judge[u] = UNEXPLORED;
  }
  time = 1;

  for(u = 0; u < n; u++){
    if(judge[u] == UNEXPLORED){
      dep_search(u);
    }
  }

  for(u = 0; u < n; u++){
    printf("%d %d %d\n",u+1, d[u], f[u]);
  }
  
}

void Counting(int num, int data){
  A[num-1][data-1] = 1;
}

int main(){
  int i, j, k, num, data;

  scanf("%d",&n);
  //配列の初期化
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      A[i][j] = 0;
    }
  }
  
  //頂点の番号・出次数（接している頂点の数）を入力
  for(i = 0; i < n; i++){
    scanf("%d %d",&num, &k);
    if(k == 0) continue;
    else{
      //隣接する頂点を入力
      for(j = 0; j < k; j++){
        scanf("%d",&data);
        Counting(num, data);
      }
    } 
  }
  
  //深さ探索
  depth();
  
  //データ出力
  
  return 0;
}



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

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

    string s;
    cin >> s;

    set<char> saaadaaaaa;
    REP(i, s.size()) saaadaaaaa.insert(s[i]);
    if(saaadaaaaa.size() == 1){
        cout << 0 << endl;
        return 0;
    } 

    int mi = 100;
    for(char i = 'a'; i <= 'z'; i++){
        string a = s, b = "";
        while(a.size()){
            for(int j = 0; j < a.size() - 1; j++){
                if(a[j] == i or a[j + 1] == i){
                    b += i;
                }else b += a[j];
            }
            set<char> st;
            for(int j = 0; j < b.size(); j++){
                st.insert(b[j]);
            }
            if(st.size() == 1){
                mi = min(mi, (int)(s.size() - b.size()));
                break;
            }
            a = b;
            b = "";
        }
    }
    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=100010;
int a[maxn];
int main(){
	int n,k,pos;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		if(a[i]==1) pos=i;
	}
	int ans=n+1;
	for(int i=0;i<k;i++){
		int l=max(pos-i,1),r=pos+(k-i)-1;
		ans=min(ans,(l-1+k-2)/(k-1)+(n-r+k-2)/(k-1)+1);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索


*/
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
using namespace std;
#define INF 3e18+7
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<double,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

int S[110000],Z[110000];
int C[1100];


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

    int N;
    ll sx,sy,tx,ty,x[1100],y[1100],r[1100];
    double d[1100];
    cin>>sx>>sy>>tx>>ty>>N;
    vector<P> V;
    for(int i=1;i<=N;i++){
        cin>>x[i]>>y[i]>>r[i];
        double t=sqrt((sx-x[i])*(sx-x[i])+(sy-y[i])*(sy-y[i]));
        t-=(r[i]);
        if(t<0) t=0;
        d[i]=t;
        V.push_back(P(t,i));
        //cout<<d[i]<<endl;
    }
    sort(V.begin(),V.end());
    int n;
    for(int i=0;i<=N-1;i++){
        int s;
        if(i==0) s=V[i].second;
        else s=n; 
        double m=INF;
        C[n]++;
        for(int j=1;j<=N;j++){
            if(C[j]) continue;

            int next=j;
            double t=sqrt( (x[s]-x[next])*(x[s]-x[next])+(y[s]-y[next])*(y[s]-y[next]) );
            t-=(r[s]+r[next]);
            if(t<0) t=0;
            chmin(d[next],d[s]+t);
            if(m>d[next]){
                m=d[next];
                n=next;
            }
        }
    }
    double ans=sqrt( (sx-tx)*(sx-tx)+(sy-ty)*(sy-ty) );
    for(int i=1;i<=N;i++){
        double t=sqrt( (x[i]-tx)*(x[i]-tx)+(y[i]-ty)*(y[i]-ty) );
        t-=r[i];
        if(t<0) t=0;
        chmin(ans,d[i]+t);
    }
    printf("%.15lf\n",ans);

}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

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

    ll N; cin >> N;
    ll dat[2][3];

    for (int i = 0;i < 2;i++){
        for (int j = 0;j < 3;j++){
            cin >> dat[i][j];
        }
    }

    vector<P> l;

    for (int i = 0;i < 3;i++){
        if(dat[0][i] < dat[1][i]){
            l.push_back(P(dat[0][i], dat[1][i]));
        }
    }

    ll NN = 0;

    if(l.size() == 1){
        NN = max(N%l[0].first+(N/l[0].first)*l[0].second,NN);
    }else if(l.size() == 2){
        for (ll i = 0;i*l[0].first <= N;i++){
            ll rem = N-i*l[0].first;
            NN = max(i*l[0].second+rem%l[1].first+(rem/l[1].first)*l[1].second,NN);
        }
    }else if(l.size() == 3){
        for (ll i = 0;i*l[0].first <= N;i++){
            for (ll j = 0;i*l[0].first+j*l[1].first <= N;j++){
                ll rem = N-i*l[0].first-j*l[1].first;
                NN = max(i*l[0].second+j*l[1].second+rem%l[2].first+(rem/l[2].first)*l[2].second,NN);
                //if(NN == 400) cout << i << " " << j << endl;
            }
        }
    }

    N = max(N,NN);
    //cout << N << endl;

    while(l.size()) l.pop_back();


    for (int i = 0;i < 3;i++){
        if(dat[0][i] > dat[1][i]){
            l.push_back(P(dat[1][i], dat[0][i]));
        }
    }


    NN = 0;

    if(l.size() == 1){
        NN = max(N%l[0].first+(N/l[0].first)*l[0].second,NN);
    }else if(l.size() == 2){
        for (ll i = 0;i*l[0].first <= N;i++){
            ll rem = N-i*l[0].first;
            NN = max(i*l[0].second+rem%l[1].first+(rem/l[1].first)*l[1].second,NN);
        }
    }else if(l.size() == 3){
        for (ll i = 0;i*l[0].first <= N;i++){
            for (ll j = 0;i*l[0].first+j*l[1].first <= N;j++){
                ll rem = N-i*l[0].first-j*l[1].first;
                //cout << i*l[0].first+j*l[1].first << endl;
                NN = max(i*l[0].second+j*l[1].second+rem%l[2].first+(rem/l[2].first)*l[2].second,NN);
            }
        }
    }

    N = max(N,NN);

    
    cout << N << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;
if(x-r<0||y+r>H||y-r<0||x+r>W){
      cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
}
}

Measured memory_bytes: 1156
#include <iostream>
#include <cmath>
#include <vector>
#define F(i,L,R) for (long i = L; i < R; i++)
using namespace std;

int main() {
	long n{};
	long long sum{0};
	cin>>n;
	vector<long> a(n+1,0),b(n+1,0),c(n,0);
	F(i,1,n+1)
	    cin>>a[i];
	F(i,1,n+1)
	    cin>>b[i];
	F(i,1,n)
	    cin>>c[i];
	sum =b[a[1]];
	F(i,2,n+1){
	   sum+=b[a[i]];
	   if(a[i]==a[i-1]+1)
	    sum+=c[a[i-1]];
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3

int strength( char ch ) {
	if( ch > '0' && ch <= '9' ) return ch - '0';
	if( ch == 'T' ) return 10;
	if( ch == 'J' ) return 11;
	if( ch == 'Q' ) return 12;
	if( ch == 'K' ) return 13;
	if( ch == 'A' ) return 14;
}

int max( int p, int q ) {
	if( p > q ) return p;
	return q;
}

int main(void){

	string ans[] = { "NS", "EW" };

	while( true ) {
		
		int start = WEST;
		char trump;
		string cards[4][52/4];
		int tricks[2] = { 0 };

		cin >> trump;
		if( trump == '#' ) break;

		//カードの情報を取得する
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 52/4; j++) {
				cin >> cards[i][j];
			}
		}

		//シュミレート
		for( int i = 0; i < 13; i++) {
			int winner, rank;
			char suit;

			winner = start;
			rank = strength( cards[start][i][0] );
			suit = cards[start][i][1];

			for( int j = 1; j < 4; j++) {
				//スートが現在最強のものと同じ場合
				int tmp = ( start + j ) % 4;
				if( suit == cards[ tmp ][i][1] ){
					if( rank < strength( cards[ tmp ][i][0] ) ) {
						winner = tmp;
						rank = strength( cards[ tmp ][i][0] );
					}
				} else if( cards[ tmp ][i][1] == trump ) {
					//切り札が出る場合
					if( suit != trump ) {
						winner = tmp;
						suit = trump;
						rank = strength( cards[ tmp ][i][0] );
					} else {
						if( strength( cards[ tmp ][i][0] ) > rank  ) {
							winner = tmp;
							rank = strength( cards[ tmp ][i][0] );
						}
					}
				}
			}

			tricks[ winner % 2 ] ++;
			start = winner;

		}
		cout << ans[ tricks[EAST] > tricks[NORTH] ] << " " << max( tricks[EAST] , tricks[NORTH] ) - 6 << endl;

	}

	return 0;
}

Measured memory_bytes: 1200
<?php

$n = trim(fgets(STDIN));
$nums = explode(' ', trim(fgets(STDIN)));

sort($nums);

$sum = ($nums[0] + $nums[1]) / 2;

if ($n > 2) {
    for ($i = 2; $i < $n; $i++) {
        $sum = ($sum + $nums[$i]) / 2;
    }
}
echo $sum;

Measured memory_bytes: 4604
def main():
    n = int(input())
    s = input().strip()
    w = []
    count = 0
    for c in s:
        w.append(count)
        if c == 'W':
            count += 1
    e = []
    count = 0
    for c in s[::-1]:
        e.append(count)
        if c == 'E':
            count += 1
    e = e[::-1]
    print(min(i + j for i, j in zip(w, e)))


if __name__ == '__main__':
    main()


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

const int MAXN = 3001;

int Ls, Lt;
string s, t;

// 定義 dp[i][j]
// s_i, s_{i+1}, ..., s_{Ls - 1} の文字列と
// t_j, t_{j+1}, ..., t_{Lt - 1} の文字列に関する
// 「最長共通部分列」の解  ← 最長共通部分列の部分問題としての最長共通部分列
string dp[MAXN][MAXN];

int main()
{
    cin >> s >> t;
    Ls = s.size();
    Lt = t.size();

    for (int i = Ls - 1; i >= 0; --i)
    {
        for (int j = Lt - 1; j >= 0; --j)
        {
            if (s[i] == t[j])
            {
                if (dp[i + 1][j + 1].size() + 1 > dp[i + 1][j].size())
                {
                    if (dp[i + 1][j + 1].size() + 1 > dp[i][j + 1].size())
                        dp[i][j] = s[i] + dp[i + 1][j + 1];
                    else
                        dp[i][j] = dp[i][j + 1];
                }
                else if (dp[i + 1][j].size() > dp[i][j + 1].size())
                    dp[i][j] = dp[i + 1][j];
                else
                    dp[i][j] = dp[i][j + 1];
            }
            else
            { // とれない
                if (dp[i + 1][j].size() > dp[i][j + 1].size())
                    dp[i][j] = dp[i + 1][j];
                else
                    dp[i][j] = dp[i][j + 1];
            }
        }
    }
    cout << dp[0][0] << endl;

    return 0;
}

Measured memory_bytes: 841600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b) // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main()
{
  int x;
  cin >> x;
  cout << ((x == 7 || x == 5 || x == 3) ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
*l,=map(int,input().split())
a=Counter(l)
itm=len(set(l))
b=len(list(filter(lambda x:x[1]%2==0,a.items())))
if b%2:
  print(itm-1)
else:
  print(itm)

Measured memory_bytes: 21084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n, k;
	cin >> n >> k;
	Vec p(n);
	rep(i, n) cin >> p[i];

	sort(all(p));
	ll ans = 0;
	rep(i, k) ans += p[i];
	co(ans);

	return 0;
}


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

class Union_Find{
private:
  vector<int64_t> par;
  vector<int64_t> rank;
  vector<int64_t> num;

  int64_t find(int64_t x){
    if(par.at(x)==x){
      return x;
    }else{
      return par.at(x)=find(par.at(x));
    }
  }

public:
  Union_Find(int64_t n){
    par.resize(n);
    rank.resize(n,0);
    num.resize(n,1);
    for(int64_t i=0;i<n;i++){
      par.at(i)=i;
    }
  }

  void unite(int64_t x,int64_t y){
    x=find(x);
    y=find(y);
    if(x==y){
      return;
    }
    if(rank.at(x)<rank.at(y)){
      par.at(x)=y;
      num.at(y)+=num.at(x);
    }else if(rank.at(x)>rank.at(y)){
      par.at(y)=x;
      num.at(x)+=num.at(y);
    }else{
      par.at(x)=y;
      rank.at(y)++;
      num.at(y)+=num.at(x);
    }
  }

  bool same(int64_t x,int64_t y){
    return find(x)==find(y);
  }

  int64_t size(int64_t x){
    return num.at(find(x));
  }

};

int main(){
  Union_Find uni(13);
  uni.unite(1,3);
  uni.unite(3,5);
  uni.unite(5,7);
  uni.unite(7,8);
  uni.unite(8,10);
  uni.unite(10,12);
  uni.unite(4,6);
  uni.unite(6,9);
  uni.unite(9,11);
  int x,y;
  cin >> x >> y;
  if(uni.same(x,y)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
a,b = input().split()
a,b = [int(a), int(b)]
min_a = (a * 100) / 8
if min_a != ((a * 100) // 8):
  min_a += 0.5
  
max_a = ((a + 1) * 100) / 8
min_b = b * 10
max_b = (b + 1) * 10

if min_a >= min_b and min_a < max_b:
  print(int(min_a))
elif min_b >= min_a and min_b < max_a:
  print(min_b)
else:
  print('-1')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          998244353
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}

int cn[200005];  
void solve()
{
 
int n;
cin >> n ;
int a[n+1];

forf(i,2,n+1) cin >> a[i] , cn[a[i]]++;

for(int i=1;i<=n;i++) cout<<cn[i]<<endl;

}

int32_t main()
{
  pr_init();
  fastio;
  solve();

 }
      

Measured memory_bytes: 6680
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        x: isize,
        a: isize,
        b: isize,
    };
    println!("{}", ["A", "B"][((x - a).abs() > (x - b).abs()) as usize]);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }
int main()
{
    int N;
    cin >> N;
    int max_ = 0;
    for (int i=1; i<=100; i++) {
        for (int beki=2; beki<=100; beki++) {
            int num = pow(i, beki);
            if (num > N) {
                break;
            }

            if (num > max_) {
                max_ = num;
            }
        }
    }

    cout << max_ << endl;
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i, cnt = 0;
    char s[5], t[5];
    scanf("%s", &s);
    scanf("%s", &t);
    for(i = 0; i < strlen(t); i++)
    {
        if(s[i] == t[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

vector<char> cs;

vector<string> ans;

void solve(string &s, int pos, /* set<char> &se*/ int kinds, const int N) {
    // printf("pos: %d, kinds: %d\n", pos, kinds);
    if (pos == N) {
        ans.push_back(s);
        cout << s << endl;
        return;
    }

    // const int kinds = (int) se.size();
    for (int i = 0; i < kinds; i++) {
        char c = cs[i];
        s.push_back(c);
        // int next_kind = (c == 'a' + kinds) ? kinds + 1 : kinds;
        int next_kind = kinds;
        solve(s, pos + 1, next_kind, N);
        s.pop_back();
    }

    // if (pos == kinds) {
        s.push_back(cs[kinds]);
        solve(s, pos + 1, kinds + 1, N);
        s.pop_back();
    // }
}

int main(void) {
    int N;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cs.push_back('a' + i);
    }

    string str = "";
    solve(str, 0, 0, N);

    // sort(ans.begin(), ans.end());
    // for (auto &s : ans) {
    //     cout << s << endl;
    // }

    return 0;
}


Measured memory_bytes: 9588
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(4);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int res=2;
    for(int i=1;i<n-1;i++){
        if(s[i-1]!=s[i+1]){
            res+=n-2;
            break;
        }
    }
    if(res==2){
        cout<<"Second"<<"\n";
        return 0;
    }
    if(s[0]==s[n-1])res-=3;
    cout<<(res%2?"First":"Second")<<"\n";
}


Measured memory_bytes: 512
using System;

namespace _1041
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0)
                {
                    break;
                }
                int x = 0;
                for (int i = 0; i < n / 4; i++)
                {
                    x += int.Parse(Console.ReadLine());
                }
                Console.WriteLine(x);
            }
        }
    }
}

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int H, W;
int dr[2] = {0, 1};
int dc[2] = {1, 0};

void dfs(vector<string> &S, vector<vector<int>> &dist, vector<vector<bool>> &F, int r, int c, bool flip) {
    // cout << "# " << r << " " << c << " : " << dist[r][c] << endl;
    for (int i = 0; i < 2; i++) {
        int nr = r + dr[i];
        int nc = c + dc[i];
        if (nr < 0 || nr >= H || nc < 0 || nc >= W) continue;
        
        int nd = dist[r][c]; bool nf = flip;
        if (S[nr][nc] == '.') {
            nf = false;
        } else {
            if (!nf) {
                nf = true;
                nd++;
            }
        }
        
        if (dist[nr][nc] != -1 && dist[nr][nc] < nd) continue;
        if (dist[nr][nc] != -1 && F[nr][nc] == nf && dist[nr][nc] <= nd) continue;
        dist[nr][nc] = nd; F[nr][nc] = nf;
        dfs(S, dist, F, nr, nc, nf);
    }
}


int main() {
    cin >> H >> W;
    vector<string> S(H);
    REP(i, 0, H) cin >> S[i];

    vector<vector<int>> dist(H, vector<int>(W, -1));
    vector<vector<bool>> F(H, vector<bool>(W, false));
    if (S[0][0] == '.') {
        dist[0][0] = 0;
        dfs(S, dist, F, 0, 0, false);
    } else {
        dist[0][0] = 1; F[0][0] = true;
        dfs(S, dist, F, 0, 0, true);
    }

    cout << dist[H - 1][W - 1] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int ctg=0,ctp=0;
    ll ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='g' && ctg>ctp){
            ctp++;
            ans++;
        }
        else if(s[i]=='g'){
            ctg++;
        }
        else if(s[i]=='p' && ctg>ctp){
            ctp++;
        }
        else{
            ctg++;
            ans--;
        }
    }

    cout << ans << endl;
}

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

int main() {
	int64_t x;cin>>x;
	// そのまま出力
	bitset<32> bs(x);
	cout<<bs<<endl;

	// ビット反転して出力
	bitset<32> rev_bs = ~bs;
	cout<<rev_bs<<endl;

	// 左シフトして出力
	bitset<32> lshift_bs = bs << 1;
	cout<<lshift_bs<<endl;

	// 右シフトして出力
	bitset<32> rshift_bs = bs >> 1;
	cout<<rshift_bs<<endl;
	
  return 0;
}



Measured memory_bytes: 3140
#include<stdio.h>

int main(void){

	int n;
	int digit = 0; 

	scanf("%d", &n);

	int m;

	m = n;

	while(m != 0){
		m = m /  10;
		digit++;
	}
	



	n = n % 10;

	if(n==2||n==4||n==5||n==7||n==9){
		printf("hon");
	}
	

	else if(n==0||n==1||n==6||n==8){
		printf("pon");
	} 
	else if(n==3)
		printf("bon");

	return 0;
}

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

using namespace std;
int legth(int a){

}
int main(){
    int x,y,a,b=0,c=0,d=0,e=0,ans=0,k=0;
    int g[101000],r[101000];
    while(1){
            fill(g,g+101000,0);
    fill(r,r+101000,0);
    cin >> x >> y;
    if(x==0&&y==0)break;
    for(int u=0;u<y;u++){
        cin >> a;
        g[a]=1;
    }

    for(int y=1;y<=x;y++){
            if(g[y]==1){
                b++;
                k=0;
                if(y==x){
                     r[y]=b;
    r[y-b-1]=b;
                }
            }else{
        if(k==0){
        r[y]=b;
    r[y-b+1]=b;
       }
        k=1;
    b=0;
            }

        if(c<b)c=b;
    }
    ans=c;
    if(g[0]==1){

        for(int j=1;j<x+1;j++){
        if(g[j]!=1){

                d=r[j]+r[j+2]+1;

        if(e<d)e=d;
    }
        }
    }
    if(ans<e)ans=e;


    b=0;
    cout << ans << endl;
    c=0;
    ans=0;
    }
return 0;
}

Measured memory_bytes: 1948
def main():
    N = int(input())
    A = list(map(int, input().split()))
    for a in A:
        if a % 2 == 0 and a % 3 != 0 and a % 5 != 0:
            print("DENIED")
            return
    print("APPROVED")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38576
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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 int MOD = 1000000007;
int rui(int a, int b) {
    if(b == 0) {
        return 1;
    }
    return rui(a, b - 1) * a;
}
int main() {
    string s;
    bool kekka;
    kekka = true;
    cin >> s;
    string gyaku = s;
    reverse(gyaku.begin(), gyaku.end());
    if(s != gyaku) {
        kekka = false;
    }
    string mae = s.substr(0, s.size() / 2);
    string gmae = mae;
    reverse(gmae.begin(), gmae.end());
    if(mae != gmae) {
        kekka = false;
    }
    string ato = s.substr(s.size() / 2 + 1);
    string gato = ato;
    reverse(gato.begin(), gato.end());
    if(ato != gato) {
        kekka = false;
    }
    if(kekka) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a[1000], b[1000], i, j, n;
    
    scanf("%d", &n);
    for(i=0; i < n; i++)
    { 
        scanf("%d", &a[i]); 
        b[n-i-1] = a[i];
    }
    
    for(j=0; j < n ; j++)
    { 
        printf("%d", b[j]);
        if(j!=n-1)
            printf(" ");
    }
    
    printf("\n");
    return 0;
    
}


Measured memory_bytes: 2048
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        double a = in.nextInt();
        double b = in.nextInt();
        double x = in.nextInt();

        // first case
        double tanTheta = 2 * b / a - 2 * x / Math.pow(a, 3);
        double s2 = a * b - a * a * tanTheta;
        if (tanTheta >= 0 && s2 >= 0) {
            out.println(Math.atan(tanTheta) / Math.PI * 180);
            return;
        }
        tanTheta = a * b * b / (2 * x);
        out.println(Math.atan(tanTheta) / Math.PI * 180);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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 int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    vl sum(n,0);
    sum[0] = a[0];
    rep(i,n-1) sum[i+1] = sum[i]+a[i+1];
    ll ans = linf;
    rep(i,n-1) {
        chmin(ans,abs(sum[i]-(sum[n-1]-sum[i])));
    }
    cout << ans << endl;
}


Measured memory_bytes: 2688
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    N = input()
    AB = [inputs() for _ in range(int(N))]
    AB.sort(key=lambda x: x[1])
    time = 0
    for a, b in AB:
        time += a
        if time > b:
            return 'No'
    return 'Yes'


if __name__ == '__main__':
    print(main())


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

#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int main(void)
{
	lli N; cin >> N;
	vector<int> S;
	while (N != 0) {
		int tmp = (N % 2 != 0) ? 1 : 0;
		S.push_back(tmp);
		N = (N - tmp) / (-2);
		
	}
	if (S.size() == 0)cout << 0;
	for (int i = S.size()-1; i >= 0;i--)cout << S[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
num = int(input())
xs  = [int(n) for n in input().split()]
ys  = [int(n) for n in input().split()]

def calc_distance(xs, ys, p):
    sums = sum([abs(x-y) ** p for x,y in zip(xs, ys)])
    return sums ** (1.0 / p)

for index in range(1,4):
    print(calc_distance(xs, ys, index))

print(max(abs(x-y) for x,y in zip(xs,ys)))


Measured memory_bytes: 5648
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
for i in range(N+1):
  if i == N:
    print(cnt, end='')
  elif A[i] <= B[i]:
    cnt += A[i]
    tmp = B[i]-A[i]
    if A[i+1] >= tmp:
      A[i+1] = A[i+1]-tmp
      cnt += tmp
    else:
      cnt += A[i+1]
      A[i+1] = 0
  elif A[i] > B[i]:
    cnt += B[i]

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,a,b,c) for(int i=a;i<=b;i=i+c)
#define int long long
#define endl "\n"
#define mod 1000000007
#define double long double
#define pb push_back
#define mk make_pair
#define swap(x,y) (x^=y^=x^=y)
#define TT int ttt;cin>>ttt;while(ttt--)

using namespace std;

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
bool isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

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

double min(double a,double b){
    if(a<b){
        return a;
    }
    return b;
}

int32_t main(){
    IOS
    int n,k;
    cin>>n>>k;
    map<int,int>m;
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int a;
            cin>>a;
            m[a]++;
        }
    }
    cout<<n-m.size()<<endl;
}


Measured memory_bytes: 3672
def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    K = int(buflist[1])
    buf = input()
    buflist = buf.split()
    V = list(map(int, buflist))
    max_value = 0
    for i in range(min(N+1, K+1)):
        push_limit = K - i
        for j in range(i+1):
            jewel = []
            for k in range(-i+j, j):
                jewel.append(V[k])
            jewel = list(sorted(jewel))
            value = sum(jewel)
            for k in range(push_limit):
                if k >= len(jewel):
                    break
                if jewel[k] < 0:
                    value += -jewel[k]
                else:
                    break
            if value > max_value:
                max_value = value
    print(max_value)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
 
using ll = long long;
using namespace std;
 
#define MOD 998244353
 
int main() {
  int N, S;
  cin >> N >> S;
  vector<int> A(N);
  for (int i = 0; i< N; i++) cin >> A[i];
  vector<ll> dp(S+1, 0);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    vector<ll> next(S+1, 0);
    (dp[0] += 1) %= MOD;
    for (int j = 0; j <= S; j++) {
      (next[j] += dp[j]) %= MOD;
      if (j+A[i] <= S) (next[j+A[i]] += dp[j]) %= MOD;
    }
    swap(next, dp);
    (ans += dp[S]) %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int gcd(int x,int y){
	if(y==0)return x;
	else return gcd(y,x%y);
}

int main(){
	int N,K;
	cin>>N>>K;
	int mx,GCD,x;
	cin>>x;
	mx=x;
	GCD=x;
	rep(i,N-1){
		int y;
		cin>>y;
		mx=max(y,mx);
		GCD=gcd(y,GCD);
	}
	if(K%GCD==0&&K<=mx)cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x;
  
  cin >> x;
  
  if(x % 11 == 0){
    cout << (x / 11) * 2 << endl;
  }else if(x % 11 > 6){
    cout << (x / 11) * 2 + 2 << endl;
  }else if(x % 11 <= 6){
    cout << (x / 11) * 2 + 1 << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <time.h> 
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 100010
#define inf 1001000100
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char ,int>
#define pi pair<int ,int>
#define pii pair <pi,pi>
using namespace std;
int arr[nax];
int ans[nax];
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int n,k;
  sd2(n, k);
  for(int i = 1; i <= n; i++)
    sd(arr[i]);
  for(int i = 2; i <= n; i++)
  {
      int cans = INT_MAX;
      for(int j = 1; j <= k; j++)
      {
          if(i -j < 1)
            break;
          cans = min(cans, ans[i - j] + abs(arr[i] - arr[i - j]));
      }
      ans[i] = cans;
  }
  printf("%d\n", ans[n]);
  return 0;
}

Measured memory_bytes: 1024