akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i = 0; i < n; i++)
ll A[100010], B[100010];
ll N;

int main(void)
{
    cin >> N;
    REP(i, N) cin >> A[i] >> B[i];
    ll s = 0;
    for(ll i = N - 1; i >= 0; i--) {
        ll a = (A[i]+s)%B[i];
        s += (a>0)?(B[i] - a):0;
//        cout << i << " " << s << endl;
    }
    cout << s << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string.h> 
#include <stdio.h>
#include <queue>
using namespace std;
#define MAX 200000
#define rep(i, n) for(int i = 0;i < n;i++)

int main(){
    char o[50],e[50];
    int n;
    scanf("%s %s",o,e);
    if(strlen(o)<strlen(e))n=strlen(o);
    else n=strlen(e);
    rep(i,n){
        printf("%c%c",o[i],e[i]);
        if(i==n-1){
            if(strlen(o)>n)printf("%c",o[i+1]);
            else if(strlen(e)>n)printf("%c",e[i+1]);
            printf("\n");
        }
    }
    return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int d , n;

int main()
{
    _FastIO;    

    cin >> d >> n;
    if(n == 100)
        n++;
    cout << n;
    for(int i = 0; i < d; i++){
        cout << "00";
    }
    cout << endl;
    return 0;
}


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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 300 + 17;

int n, k, m, dp[MAXN][MAXN], sm[MAXN][MAXN], C[MAXN][MAXN];

int sum(int a, int b) { return (((a + b) % m) + m) % m; }
int mul(int a, int b) { return (1LL * a * b) % m; }

void prep() {
	for (int i = 0; i <= k; i++)
		dp[0][i] = 1, sm[0][i] = sum((i == 0? 0: sm[0][i - 1]), dp[0][i]);
	for (int i = 0; i <= n; i++)
		C[i][0] = 1, C[i][i] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < i; j++)
			C[i][j] = sum(C[i - 1][j], C[i - 1][j - 1]);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k >> m;
	prep();
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= k; j++) {
			for (int p = 0; p <= i - 1; p++)
				dp[i][j] = sum(dp[i][j], mul(sum(sm[p][k], -sm[p][j]), mul(dp[i - p - 1][j],  C[i - 1][p])));
			sm[i][j] = sum((j == 0? 0: sm[i][j - 1]), dp[i][j]);
		}
	cout << dp[n][0] << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
    int n,count=0;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i+=2){
      if(a[i]%2!=0)
            count++;
  
    }
    cout<<count;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second 
//#define int   long long
#define ll   long long
#define pii pair<int, int>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vl vector<long long>
#define vii vector< vector<int> >  
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
#define cd complex<double>
#define PI 4*atan(1)
#define pi 3.14159265358979323846//20 decimals
#define ld long double

const ll mod = 1000000007;
//const ll mod = 998244353;

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }

ll func(int a, int b, vll& cost, vl &v, vl &cu){
    if(a == b)return 0;
    if(cost[a][b] != -1){
        return cost[a][b];
    }

    ll min1 = LONG_LONG_MAX;
    for(int i = a; i<b; i++){
        ll c1 = func(a, i, cost, v, cu);
        ll c2 = func(i+1, b, cost, v, cu);
        min1 = min(c1 + c2, min1);
    }
    return cost[a][b] = min1 + cu[b] - ( (a > 0) ? cu[a-1] : 0 );
}

int main(){
    FAST
    int n;
    cin>>n;
    vl v;
    for(int i =0; i<n; i++){
        int u;
        cin>>u;
        v.pb(u);
    }
    vll dp(n+1, vl(n+1, -1));
    vl cu(n);
    cu[0] = v[0];
    for(int i = 1; i<n; i++){
        cu[i] = v[i];
        cu[i] += cu[i-1];
    }
    cout<<func(0, n-1, dp, v, cu)<<endl;
    return 0;
}

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


#define INF 1000000000000


signed main()
 {
   int n,k;
   cin>>n>>k;
   vector<int>x(n);
   rep(i,n){cin>>x[i];}
   int m=INF;
   rep(i,n-k+1){
     if((x[i]>=0&&x[i+k-1]>=0)||(x[i]<=0&&x[i+k-1]<=0)){
       m=min(m,max(abs(x[i]),abs(x[i+k-1])));
     }
     else m=min(m,min(2*abs(x[i])+x[i+k-1],abs(x[i])+2*x[i+k-1]));
   }
   cout<<m;
 }


Measured memory_bytes: 1024
#include <map>
#include <vector>
using namespace std;

int main(){
  int n,i,p,q,f;
  for(;scanf("%d",&n),n;){
    map<int,long long int>m;
    vector<int>v;
    for(;n--;){
      scanf("%d%d%d",&i,&p,&q);
      if(m.find(i)==m.end())v.push_back(i);
      m[i]+=(long long int)p*q;
    }
    for(f=i=0;i<v.size();i++){
      if(m[v[i]]>=1000000)printf("%d\n",v[i]),f=1;
    }
    if(!f)puts("NA");
  }
}

Measured memory_bytes: 0
import math
def P(p, q):
  return math.factorial(p)//math.factorial(p-q)

def cmb(p, q):
  return P(p, q)//math.factorial(q)

n,k = map(int,input().split())
#print(n,k)

ans = []

x = 0
a = 1
if n-k == 1:
  b = 2
  x = (2 + a * b)%(1000000007)
elif n-k > 1:
  b = cmb(n-k-1, 1)
  x = (2 + a * b)%(1000000007)
else:
  x = 1
ans.append(x)

x = 0
if k == 1:
  a = 1
else:
  a = cmb(k-1, 1)
if n-k == 1:
  b = 1
elif n-k == 2:
  b = cmb(n-k-1, 1) * 2 + 1
elif n-k > 2:
  b = cmb(n-k-1, 2) + cmb(n-k-1, 1) * 2 + 1
else:
  b = 0
x = (a * b)%(1000000007)
ans.append(x)

#print(ans)

 
for i in range(3,k+1):
  x = 0
  a = cmb(k-1, i-1)#青玉の並べ方
  if n-k-1 < i-2:
    b = 0
  elif n-k-1 < i-1:
    b = cmb(n-k-1, i-2)
  elif n-k-1 < i:
    b = cmb(n-k-1, i-1) * 2 + cmb(n-k-1, i-2)
  else:
    b = cmb(n-k-1,i) + cmb(n-k-1, i-1) * 2 + cmb(n-k-1, i-2)
  x = (a * b)%(1000000007)
  ans.append(x)

for i in range(k):
  print(ans[i])

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

typedef long long ll;
static const int MOD = 1e9+7;
static const ll INF = 1ll<<60;

int main(){

    int X,Y;
    bool flag = false;

    cin>>X>>Y;

    for(int kame=0; kame<=100; kame++){
        for(int tsuru=0; tsuru<=100; tsuru++){
            if(kame+tsuru == X){
                if(kame*4+tsuru*2 == Y) flag = true;
            }   
        }
    }

    cout<<(flag ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 3596
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    ll n; cin >> n;
    cout << n*(n-1)/2  << endl;
}

Measured memory_bytes: 256
n = gets.to_i
a= gets.split.map(&:to_i)
b=[0]
for num in 0..n-1 do
  if b.last + 1 == a[num]
    b << a[num]
  end  
end
if a.include?(1)
  if b.length == n+1
    p 0
  else 
    p n - b.length + 1
  end
else    
  p -1
end

Measured memory_bytes: 16900
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<int>> d(c, vector<int>(c)), k(n, vector<int>(n)), p(3, vector<int>(c));
  cin >> d >> k;
  for (int i = 0; i < c; ++i) {
    for (int y = 0; y < n; ++y){
      for (int x = 0; x < n; ++x) {
        p[(y + x) % 3][i] += d[k[y][x] - 1][i];
      }
    }
  }
  int res = numeric_limits<int>::max();
  for (int i = 0; i < c; ++i) {
    for (int j = 0; j < c; ++j) {
      if (i == j) continue;
      for (int k = 0; k < c; ++k) {
        if (i == k || j == k) continue;
        chmin(res, p[0][i] + p[1][j] + p[2][k]);
      }
    }
  }
  cout << res << endl;
}



Measured memory_bytes: 1280
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
 
int main() {
    char s[1201], g;
    int i = 0, j, a[26] = {0}, k, h;
    while(scanf("%c", &s[i]) != EOF) ++i;
    k = i;
    for (h = 0; h <= i; ++h) {
        if (isupper(s[h])) s[h] = tolower(s[h]);
        for (j = 0; j < 26; ++j) {
            g = 'a' + j;
            if (s[h] == g) {
                ++a[j];
                break;
            }
        }
    }
    for (i = 0; i < 26; ++i) {
        g = 'a' + i;
        printf("%c : %d\n", g, a[i]);
    }
}


Measured memory_bytes: 2148
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
    char W[11], T[1001];
    
    
    scanf("%s", W);
    int ans = 0;
    for (;;) {
        scanf("%s", T);
        if (!strcmp(T, "END_OF_TEXT"))
            break;
        for (char *p = T; *p; p++)
            *p = tolower(*p);
        if (!strcmp(T, W))
            ans++;
    }
    printf("%d\n", ans);

    return 0;
}



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

long long n, d, x, y, ans;
int main() {
	cin >> n >> d;
	while(n--) {
		scanf("%lld%lld", &x, &y);
		if(x*x + y*y <= d*d) ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3724
#include<stdio.h>
#include<string.h>


char *reverse(char *s) {

	int i;
	char answer[strlen(s)];
	int length = strlen(s);

	memset(answer,'\0',sizeof(char));

	for(i=0;i<=strlen(s)-1;i++)
		answer[i]=s[strlen(s)-1-i];

	strcpy(s,answer);
	s[length] = '\0';
	return s;
}

int main() {

	int m;
	char c[80];
	char s1[80],s2[80];
	char temp1[80],temp2[80];
	char s1_rev[80],s2_rev[80];
	char A[600][80];
	int a,i,j,k,l,x;
	int A_max;
	int answer;
	int length;

	scanf("%d\n",&m);

	//???????????????????????§?¨????????§?
	for(a=0;a<m;a++) {

		answer=0; //??????;
		fgets(c,sizeof(c),stdin);
		c[strlen(c)-1]='\0';
		length = strlen(c);

		for(i=0;i<600;i++)
			for(j=0;j<73;j++)
				A[i][j]='\0';

		//???????????????
		for(j=1;j<strlen(c);j++) {
			for(x=1;x<=8;x++){
				memset(s1,'\0',sizeof(char));
				memset(s2,'\0',sizeof(char));
				memset(temp1,'\0',sizeof(char));
				memset(temp2,'\0',sizeof(char));
				memset(s1_rev,'\0',sizeof(char));
				memset(s2_rev,'\0',sizeof(char));

				strncpy(s1,c,j);
				strncpy(s2,c+j,strlen(c)-j+1);
				s1[j]='\0';
				s2[strlen(c)-j+1]='\0';
				strcpy(temp1,s1);
				strcpy(temp2,s2);
				strcpy(s1_rev,reverse(temp1));
				strcpy(s2_rev,reverse(temp2));

				switch(x) {
				case 1:
					//s1,s2????????????(c)
					strcpy(A[8*(j-1)],c);
					break;
				case 2:
					//s1???????????¢
					strcpy(A[8*(j-1)+1],strcat(s1_rev,s2));
					break;
				case 3:
					//s2???????????¢
					strcpy(A[8*(j-1)+2],strcat(s1,s2_rev));
					break;
				case 4:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+3],strcat(s1_rev,s2_rev));
					break;
					//????????????s1,s2?????¢
				case 5:
					//s1.s2????????????
					strcpy(A[8*(j-1)+4], strcat(s2,s1));
					break;
					//s1???????????¢
				case 6:
					strcpy(A[8*(j-1)+5],strcat(s2_rev,s1));
					break;
					//s2???????????¢
				case 7:
					strcpy(A[8*(j-1)+6],strcat(s2,s1_rev));
					break;
				case 8:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+7],strcat(s2_rev,s1_rev));
					break;
				}
			}
		}
		A_max=8*(strlen(c)-1);

		for(k=0;k<A_max;k++) {
			if(k==0)
				answer++;
			else {
				for(l=0;l<k;l++) {
					if(!strcmp(A[l],A[k]))
						break;
					else if(l==k-1) {
						//printf("%d\n",k);
						answer++;
					}
				}
			}

		}
		printf("%d\n",answer);
	}

	return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define nax (int)2e5+1
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n" 
#define INF (int)1e9
#define eps (long double)1e-9
using namespace std;


int main(){
	fast;
	ll n;
	cin >> n;
	vector<ll> v(n+1);
	//set<int> s;
	map<ll,ll> m;
	for(ll i = 1; i<= n;i++){
		cin >> v[i];
		if(i - v[i] >= 2){
			m[i-v[i]]++;
		}
	}
	ll ans = 0;
	for(ll i = 1;i<= n;i++){
		ans += m[i+v[i]];
	}
	cout<<ans;
	
	
	
	return 0;
}
	


Measured memory_bytes: 18400
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    string str;
    int K;
    cin >> str;
    cin >> K;
    set<string> st;
    for(int i=0; i<str.size(); i++) {
        for(int j=i+1; j<=min((int)str.size(), i+K); j++) {
            int cnt=0;
            bool if_break=false;
            if(st.size()<K) {
                st.insert(str.substr(i, j-i));
            } else {
                for(auto itr=st.begin(); itr!=st.end(); itr++) {
                    if(cnt<=K) {
                        if(*itr>str.substr(i, j-i)) {
                            st.insert(str.substr(i, j-i));
                            break;
                        }
                    } else {
                        if_break=true;
                        break;
                    }
                    cnt++;
                }
            }
            if(if_break) break;
        }
    }
    
    int idx=1;
    for(auto itr=st.begin(); itr!=st.end(); itr++) {
        if(idx==K) {
            cout << *itr << endl;
            break;
        }
        idx++;
    }


    return 0;
    
}

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

typedef long long ll;

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

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  ll s;
  scanf("%lld",&s);

  int ans = 10000;
  while(s > 100){
    int tmp = abs(753 - s % 1000);
    ans = min(tmp, ans);
    s /= 10;
  }

  printf("%d",ans);

  return 0;
}


Measured memory_bytes: 1656
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
#define LL long long
int main(){
	LL N;
	cin>>N;
	LL tmp=N;
	char str[20];
	LL sum=0,c=0,tmpc;
	while(tmp){
		tmp/=10;
		c++;
	}
	tmpc=c;
	while(N){
		sum+=N%10;
		str[--tmpc]='0'+N%10;
		N/=10;
	}
	//printf("%s\n",str);
	if(sum-(str[0]-'0')==9*(c-1)){
		printf("%lld\n",sum);
	}else{
		printf("%lld\n",(str[0]-'0')+9*(c-1)-1);
	}
}

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

     signed main(){
int n,m;
cin>>n>>m;
int a[n-1];
for(int i=0;i<n-1;i++)cin>>a[i];
int b[n][m];
for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>b[i][j]
;
int t[m],ans=0,ans2=0;
for(int i=0;i<n;i++){
    ans2=0;
    for(int j=0;j<m;j++){
        t[j]=b[i][j];
        ans2+=t[j];
    }
    ans=max(ans2,ans);
    for(int j=i+1;j<n;j++){
        ans2-=a[j-1];
        for(int k=0;k<m;k++)if(t[k]<b[j][k]){
            ans2+=(b[j][k]-t[k]);
            t[k]=b[j][k];
        }
        ans=max(ans,ans2);
    }

}
cout<<ans<<endl;

     }


 


 






    





      

        


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

using namespace std;

int main(){
	int N;
	int valid[100];
	int know[100][100];
	while(cin >> N, N){
		memset(know, 0, sizeof(know));
		for(int i=0;i<N;i++){
			int M; cin >> M;
			for(int j=0;j<M;j++){
				int c; cin >> c;
				know[i][c-1] = 1;
			}
		}
		for(int i=0;i<N;i++) valid[i] = 1;
		int K; cin >> K;
		for(int i=0;i<K;i++){
			int c; cin >> c; c--;
			for(int j=0;j<N;j++){
				if(!know[j][c]) valid[j] = 0;
			}
		}
		int res = -1;
		bool ok = true;
		for(int i=0;i<N;i++){
			if(valid[i]){
				if(res != -1) ok = false;
				res = i+1;
			}
		}
		cout << (ok ? res : -1) << endl;
	}
}

Measured memory_bytes: 1208
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    long N = Long.parseLong(sc.nextLine());
    long ans = (N / 11) * 2;
    if(N % 11 == 0){
    }else if(N % 11 <= 6){
      ans++;
    }else{
      ans += 2;
    }
    
    System.out.println(ans);
  }
}

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

using namespace std;
typedef long long ll;

int main() {
  int a, b;
  cin >> a >> b;

  int sockets = 1;
  int count = 0;
  while (sockets < b) {
    sockets += (a - 1);
    ++count;
  }

  cout << count;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
using namespace std;
struct card{
	char letter,num;
}; 
void swap(int x,int y,struct card A[])
{
	struct card tmp;
	tmp=A[x];
	A[x]=A[y];
	A[y]=tmp;
}
void bubble(struct card A[],int n){
	int i,j;
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(A[j].num<A[j-1].num)
				swap(j-1,j,A);
		}
	}
}
void selection(struct card A[],int n){
	int i,j,min;
	for(i=0;i<n;i++){
		min=i;
		for(j=i+1;j<n;j++){
			if(A[j].num<A[min].num)
				min=j;
		}
		if(min!=i)
			swap(min,i,A);
	}
}
bool isStable(struct card A[],struct card B[],int n){
	int i;
	for(i=0;i<n;i++){
		if(A[i].letter!=B[i].letter)
			return false;
	}
	return true;
}
int main(int argc, char *argv[]) {
	card c1[36],c2[36];
	int n,i,j;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>c1[i].letter>>c1[i].num;
	}
	for(i=0;i<n;i++){
		c2[i]=c1[i];
	}
	bubble(c1,n);
	selection(c2,n);
	for(i=0;i<n;i++){
		cout<<c1[i].letter<<c1[i].num;
		if(i!=n-1)
			cout<<" ";
		else
			cout<<endl;
	}
	cout<<"Stable"<<endl;
	for(i=0;i<n;i++){
		cout<<c2[i].letter<<c2[i].num;
		if(i!=n-1)
			cout<<" ";
		else
			cout<<endl;
	}
	if(isStable(c1,c2,n)){
		cout<<"Stable"<<endl;
	}else{
		cout<<"Not stable"<<endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll get(ll x, ll y) {
  return (x / y);
}

int main() {
  int n; read(n);
  map <int, int> cnt;
  for(int i = 0; i < n; i++) {
    int x; cin >> x;
    cnt[x]++;
  }
  int ans = 0;
  for(auto x : cnt) {
    if(x.second < x.first) {
      ans += x.second;
    }
    else {
      ans += x.second - x.first;
    }
  }
  print(ans);
}

Measured memory_bytes: 4736
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    a[0] = toupper(a[0]);
    b[0] = toupper(b[0]);
    c[0] = toupper(c[0]);
    cout << a[0] << b[0] << c[0] << endl;
    return 0;
}

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

using namespace std;

int main() {
	int n, cnt;
	string s;

	cnt = 0;
	cin >> n >> s;
	for (int i = 1; i < n; ++i) {
		if (s[i] != s[i - 1]) {
			++cnt;
			++i;
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3360
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, A, B, C, D = map(int, input().split())
    S = input()

    ret = 'No'
    if C<D:
        pathBtoD=S[B-1:D]
        pathAtoC=S[A-1:C]
        if pathBtoD.find('##')==-1 and pathAtoC.find('##')==-1:
            ret = 'Yes'
    else:
        pathBtoD=S[B-1:D]
        pathAtoC=S[A-1:C]
        pathBtoD2 = S[B-2:D+1]
        if pathBtoD.find('##')==-1 and pathAtoC.find('##')==-1:
            if pathBtoD2.find('...')!=-1:
                ret = 'Yes'
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, m;

inline void solve(){

    cin >> n >> m;

    vector<int> div;

    for(int i = 1; i*i <= m; i++) {
        if(m%i==0) {
            div.bash(i);
            if(m/i != i)
                div.bash(m/i);
        }
    }
    
    sort(ALL(div));
    int ans = 1;

    for(auto&& x : div) {
        if((ll)x*n <= m){
            ans = x;
        }
    }

    cout << ans << endl;
    
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


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

using namespace std;

int MAX_N = 10000000;
vector<int> cnt(MAX_N, 0);

int main() {
  int r, s, p;
  cin >> r >> s >> p;
  for (int i = 0; i < p; i++) {
    int x, y;
    cin >> x >> y;
    int sum = r + 1 - x;
    if (y <= s) {
      sum += s + 1 - y;
    } else {
      sum += y - s;
    }
    //cerr << sum << endl;
    cnt[sum]++;
  }
  int ret = 0;
  for (int i = 1; i < MAX_N; i++) {
    if (cnt[i] == 0) continue;
    ret = i;
    if (cnt[i] == 1) {
      continue;
    }
    cnt[i + 1] += cnt[i] - 1;
  }
  cout << ret << endl;
}



Measured memory_bytes: 41732
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int X;
	cin >> X;

	cout << (2199 - X) / 200 << "\n";

	return 0;
}



Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  cout << (a <= x && x <= a + b ? "YES" : "NO") << endl;
}



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

int main() {
	int a, b, r;
	char op;
	while (true) {
		cin >> a >> op >> b;
		switch (op) {
		case '+':
			r = a + b;
			break;
		case '-':
			r = a - b;
			break;
		case '*':
			r = a * b;
			break;
		case '/':
			r = a / b;
			break;
		}
		if (op == '?') {
			break;
		}
		cout << r << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
# frozen_string_literal: true

n = gets
array = gets.split.map(&:to_i)

array.select!(&:even?)
ans = true
array.each do |e|
  if e % 5 == 0 || e % 3 == 0
    next
  else
    ans = false
  end
end

if ans
  puts 'APPROVED'
else
  puts 'DENIED'
end


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    string ans = "No";
    if (A == B && B != C) ans = "Yes";
    if (B == C && C != A) ans = "Yes";
    if (C == A && A != B) ans = "Yes";
    cout << ans << endl;
return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a < 9 && b < 9) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

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

int main(){
    string x;
    cin >> x;
    int n = 0;
    while(true){
        string y;
        cin >> y;

        if(y == "END_OF_TEXT"){
            break;
        }

        for(int i = 0; i < y.size();i++){
            if(isalpha(y[i])){
                if(isupper(y[i])){
                y[i] = tolower(y[i]);
                }
            }
        }

        if(y == x){
            n++;
        }

    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		final var n = scanner.nextInt();
		final var m = scanner.nextInt();
		var l = 1;
		var r = n;
		for (var i = 1; i <= m; i++) {
			var ll = scanner.nextInt();
			var rr = scanner.nextInt();
//			System.out.println(ll);
			if(l < ll) l = ll;
			if(r > rr) r = rr;
			if(r < l) {
				System.out.println(0);
				scanner.close();
				return;
			}
		}
		System.out.println(r - l + 1);
		scanner.close();
	}

}


Measured memory_bytes: 58268
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[] r = new int[n];
        int[] g = new int[n];
        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            if (s[i] == 'R') r[i]++;
            if (s[i] == 'G') g[i]++;
            if (s[i] == 'B') b[i]++;
        }
        int[] rs = new int[n+ 1];
        int[] gs = new int[n + 1];
        int[] bs  = new int[n + 1];
        for (int i = 0 ; i < n ; i++) {
            rs[i + 1] = rs[i] + r[i];
            gs[i + 1] = gs[i] + g[i];
            bs[i + 1] = bs[i] + b[i];
        }
        long ans = 0;
        for (int i = 1 ; i < n - 1 ; i++) {
            if (s[i] == 'R') {
                for (int j = 0 ; j < i ; j++) {
                    if (s[j] == 'B') {
                        ans += gs[n] - gs[i];
                        if (i + i - j < n && s[i + i - j] == 'G') {
                            ans -= 1;
                        }
                    }
                    if (s[j] == 'G') {
                        ans += bs[n] -bs[i];
                        if (i + i - j < n && s[i + i - j] == 'B') {
                            ans -= 1;
                        }
                    }
                }
            }
            if (s[i] == 'G') {
                for (int j = 0 ; j < i ; j++) {
                    if (s[j] == 'B') {
                        ans += rs[n] - rs[i];
                        if (i + i - j < n && s[i + i - j] == 'R') {
                            ans -= 1;
                        }
                    }
                    if (s[j] == 'R') {
                        ans += bs[n] - bs[i];
                        if (i + i - j < n && s[i + i - j] == 'B') {
                            ans -= 1;
                        }
                    }
                }
            }
            if (s[i] == 'B') {
                for (int j = 0 ; j < i ; j++) {
                    if (s[j] == 'G') {
                        ans += rs[n] - rs[i];
                        if (i + i - j < n && s[i + i - j] == 'R') {
                            ans -= 1;
                        }
                    }
                    if (s[j] == 'R') {
                        ans += gs[n] - gs[i];
                        if (i + i - j < n && s[i + i - j] == 'G') {
                            ans -= 1;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 29280
#include <iostream>

using namespace std;
int main(){ 
    string S;
    cin >> S;
    int A=0,B=0,C=0;
    for (int i=0;i<3;i++) {
        if (S[i]=='a') ++A;
        else if (S[i]=='b') ++B;
        else ++C;
    }
    if (A*B*C==0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1100;
ll a[maxn], b[maxn], c[maxn];
ll n, m, k, x;

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

    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    for(int i=1;i<=m;i++) {
        cin>>b[i];
    }
    for(int i=1;i<=k;i++) {
        cin>>c[i];
    }

    vector<ll>v;
    for(int i=1;i<=m;i++) {
        for(int j=1;j<=k;j++) {
            v.pb(b[i] + c[j]);
        }
    }

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

    if(v.size() > x) {
        vector<ll>nv;
        for(int i=0;i<x;i++) {
            nv.pb(v[i]);
        }
        v = nv;
    }

    vector<ll>result;
    for(int i=1;i<=n;i++) {
        for(ll   j:v) {
            result.pb(a[i] + j);
        }
    }
    sort(result.rbegin(), result.rend());

    for(int i=0;i<x;i++) {
        cout<<result[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 43364
#include <bits/stdc++.h>
using namespace std;
long long mapp[230][230];
int num[220];
int n,m,r;
struct node
{
    int a,b,c;
}arr[220*220];
int pre[220*220];
long long sum;
bool cmp(node aa,node bb)
{
    if(aa.c==bb.c) return aa.a<bb.a;
    if(aa.a==bb.a) return aa.b<bb.b;
}
void floyd()
{//求任意两点最短路。
    for(int k = 1;k <= n;k++)
    {//枚举是否有一点 k ,从点 i 到 点 j 经过点 k 的距离会比原先 i 到 j 的距离更短。
        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <= n;j++)
            {
                if(mapp[i][k]+mapp[k][j]<mapp[i][j])
                {
                    mapp[i][j]=mapp[i][k]+mapp[k][j];
                }
            }
        }
    }
}
void slove()
{//枚举所有情况(最多 8!)
    sort(num ,num  + r);
    while (next_permutation(num ,num + r)){//求a[i]的全排列。
        long long all = 0;
        for(int i = 1;i < r;i++) all += mapp[num[i]][num[i - 1]];
        sum = min(sum,all);
    }
}

int main()
{
    while(~scanf("%d%d%d",&n,&m,&r))
    {
        memset(mapp,0,sizeof(mapp));
        memset(num,0,sizeof(num));
        int a,b,c;
        for(int i=0;i<r;i++)
        {
            scanf("%d",&num[i]);
        }
        for(int i=1;i<230;i++)
        {
            for(int j=1;j<230;j++)
            {
                if(i==j)
                {
                    mapp[i][j]=0;
                    mapp[j][i]=0;
                }
                else
                {
                    mapp[i][j]=100000000000000;
                    mapp[j][i]=100000000000000;
                }
            }
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            if(mapp[a][b]==0 || c<mapp[a][b])
            {
                mapp[a][b]=c;
                mapp[b][a]=c;
            }
        }
        sum=100000000000;
        floyd();
        slove();
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;
int main()
{
	int arr[5];
	bool flag = false;
	cin >> arr[1] >> arr[2] >> arr[3];
	sort(arr + 1 , arr + 4);
	if((arr[2] - arr[1]) == (arr[3] - arr[2]))flag = true;
	if((arr[3] - arr[1]) == (arr[2] - arr[3]))flag = true;
	if((arr[1] - arr[2]) == (arr[3] - arr[1]))flag = true;
	if((arr[3] - arr[2]) == (arr[1] - arr[3]))flag = true;
	if((arr[1] - arr[3]) == (arr[2] - arr[1]))flag = true;
	if((arr[2] - arr[3]) == (arr[1] - arr[2]))flag = true;
	if(flag)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
	}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]Getting Started - Rectangle

            string line = Console.ReadLine().TrimEnd();
            string[] array = line.Split(' ');

            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);

            int area = a * b;
            int edgeLength = (a + b) * 2;

            Console.WriteLine("{0} {1}",area,edgeLength);
        }
    }
}



Measured memory_bytes: 7828
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int k,n;
    cin >> k >> n;
    vector<int> a(n),d(n);
    rep(i,n) cin >> a[i];
    rep(i,n-1) d[i]=a[i+1]-a[i];
    d[n-1]=a[0]+k-a[n-1];
    sort(d.begin(),d.end());
    cout << k-d[n-1] << endl;
}

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

// using namespace std;

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

using ll = long long;

void Main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  int sum = 0;
  for (auto &ai : a) {
    std::cin >> ai;
    sum ^= ai;
  }

  int x = 0;
  for (int i = 0; i < a.size(); ++i) {
    x = x ^ a[i] ^ a[i];
  }
  if (sum == x) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\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: 640
#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;

const int MAX = 100 + 5;
int a[4] = {1, -1, 0, 0};
int b[4] = {0, 0, -1, 1};

int readchar()
{
    for(;;)
    {
        int ch = getchar();
        if(ch != '\n' && ch != '\r') return ch;
    }
}

int main()
{
    int w, h;
    char s[MAX][MAX];
    queue<int> q;
    while(cin >> h >> w && (w || h))
    {
        queue<int> q;
        for(int i = 0; i < h; ++i)
            for(int j = 0; j < w; ++j)
            {
                s[i][j] = readchar();
            }


        int ans = 0;
        for(int j = 0; j < h; ++j)
            for(int k = 0; k < w; ++k)
            {
                if(s[j][k] != '.')
                {
                    char c = s[j][k];
                    s[j][k] = '.';
                    q.push(j * 100 + k);
                    ans++;
                    while(!q.empty())
                    {
                        int var = q.front();
                        q.pop();
                        for(int i = 0; i < 4; ++i)
                        {
                            int x = var / 100 + a[i];
                            int y = var % 100 + b[i];
                            if(x >= 0 && y >= 0 && x < h && y < w && s[x][y] == c)
                            {
                                s[x][y] = '.';
                                q.push(x * 100 + y);
                            }
                        }
                    }
                }
            }
        cout << ans << endl;
    }
    return 0;

}

Measured memory_bytes: 1228
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 1e5+9;
ll a[sz],p[sz];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    FAST
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
        p[i]--;
    }
    for(i=0;i<n;i++)
    {
        cin>>a[i];

    }
    ll ans = low;
    ll z =k;
    unordered_map<ll,ll> ma;
    ma.reserve(8196);
    ma.max_load_factor(1.0);
    for(i=0;i<n;i++)
    {


        ll now = 0;
        x = i;
        y = 0;
        k  =z;
        while(k>0)
        {
            if(ma.find(x)!=ma.end())
            {
                if(k/y!=0)
                {
                    now+= ((k/y)-1)*now;
                    k -= ((k/y)-1)*y;
                }
                ma.clear();
                y = 0;
            }

            now+= a[p[x]];
            //v.pb(now);

            ma[x]  =1;
            x = p[x];
            k--;
            y++;
            //cout<<x<<" "<<now<<" "<<k<<endl;
            ans = max(ans,now);
        }
        //cout<<i<<" "<<now<<endl;
        ans = max(ans,now);
        ma.clear();
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3896
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

struct node { int t,next; }a[200010];

int head[100010],fa[100010],in[100010],num[100010],n,m,rt,tot;
bool flag;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void add(int x,int y) { a[++tot].t=y;a[tot].next=head[x];head[x]=tot; }

inline void dfs(int x,int y)
{
	if (in[x]==1) { fa[x]=num[x];return; }
	fa[x]=num[x]<<1;
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		if (t==y) continue;
		dfs(t,x);fa[x]-=fa[t];
	}
}

inline void work(int x,int y)
{
	if (in[x]==1) return;
	int hh=0;
	if (fa[x]>num[x]) { flag=false;return; }
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		if (t==y) continue;
		if (fa[t]>num[x]-fa[x]) hh+=fa[t]+fa[x]-num[x];
		if (hh>fa[x]) { flag=false;return; }
	}
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		if (t==y) continue;
		work(t,x);
		if (!flag) return;
	}
}

int main()
{
	n=rd();tot=0;
	for (int i=1;i<=n;i++) num[i]=rd();
	if (n==2)
	{
		if (num[1]==num[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	for (int i=1;i<n;i++)
	{
		int x=rd(),y=rd();
		add(x,y);add(y,x);
		in[x]++;in[y]++;
	}
	for (int i=1;i<=n;i++) if (in[i]>1) { rt=i;break; }
	dfs(rt,0);
	if (fa[rt]) { puts("NO");return 0; }
	flag=true;work(rt,0);
	if (flag) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 5376
int a[100000];

int main() {
  int n;
  scanf("%d", &n);
  int xor_sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    xor_sum ^= a[i];
  }

  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    for (int i = 0; i < n; i++) {
      int y = a[i] ^ (a[i] - 1);
      if (y == x) {
        xor_sum ^= y;
        ans += 1;
        break;
      }
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
int main() {
    fio;
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (ll i = 1; i < n; i++) {
        if (a[i - 1] <= a[i]) {
            continue;
        }
        else {
            ans += a[i - 1] - a[i];
            a[i] += (a[i - 1] - a[i]);
        }
    }
    if (ans >= 0)
        cout << ans << endl;
    else {
        cout << "0" << endl;
    }
    return 0;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=10000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

int n;

int main(){
	Init();
	cin>>n;
	ll res=Pow(3,n);
	for(int i=n/2+1;i<=n;i++) res=(res-2*nCk(n,i)*Pow(2,n-i)%mod+mod)%mod;
	cout<<res<<endl;
}

Measured memory_bytes: 78336
import sys
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    P = list(map(int,input().split()))
    PS = sorted(P)
    count =0
    for i in range(N):
        if P[i]!=PS[i]:
            count +=1

    if count==0 or count ==2:
        print("YES")
    else:
        print("NO")



if __name__ == "__main__":
    main()


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

int main() {
    // insert code here...
    int N;
    cin >>N;
    int a[N];
    for(int i=0;i<N;i++){
        
        cin >>a[i];
    }
    
    sort(a,a+N); //配列を昇順にする。
    
    for(int i=0;i<N;i++){
        
        if(a[i]==a[i+1]){
            
            cout << "NO" <<endl;
            return 0;
        }
    }
    
    cout << "YES" <<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	
	int N,A,B;
	scanf("%d%d%d",&N,&A,&B);
	
	if((B-1-A)%2==1){
		printf("\nAlice\n\n");
	}else {
		printf("\nBorys\n\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 128
n = int(input())
H = list(map(int,input().split()))
ans = 0
tmp = 0
for i in range(n-1):
  #print(H[i],H[i+1])
  if H[i] >= H[i+1]:
    #print(H[i],H[i+1])
    tmp += 1
  else:
    ans = max(ans,tmp)
    tmp = 0
ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 14352
#include<stdio.h>

int main(void)
{
  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);

  if(a<b)
    {
      if(b<c)
	printf("Yes\n");
      else
	printf("No\n");
    }
  else
    printf("No\n");
}



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

using namespace std;

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

  string s;
  cin >> s;
  int n = s.length();
  int num = 0;
  for (int i = 0; i < n; i++) {
    num += (s[i] == '0');
  }
  cout << 2 * min(num, n - num) << '\n';
  return 0;
}

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

int main() {
  vector<int> a(10001);
  int count = 0;
  while (true) {
    int tmp;
    cin >> tmp;
    if (tmp == 0) break;
    a.at(count) = tmp;
    count++;
  }

  for (int i = 0; i < count; i++) {
    cout << "Case " << i + 1 << ": " << a.at(i) << endl;
  }
}


Measured memory_bytes: 3104
s=input()
d=s.split()

operater=["+","*","-","/"]
cal=[]
k=0
for i in range(len(d)):
    if d[i] not in operater:
        cal.append(int(d[i]))
        k+=1
    else:
        j=operater.index(d[i])
        if j==0:
            x=cal[k-1]+cal[k-2]
        elif j==1:
            x=cal[k-1]*cal[k-2]
        elif j==2:
            x=cal[k-2]-cal[k-1]
        else:
            x=cal[k-2]/cal[k-1]
        cal.pop()
        cal.pop()
        cal.append(x)
        print
        k-=1
print(cal[0])


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

void solve(long long N, long long K, std::vector<long long> p)
{
    long long res = 0;
    for (long long i = 0; i < K; i++)
    {
        res += p[i];
    }

    // cout << res << endl;

    long long max = res;
    for (long long i = K; i < N; i++)
    {
        if (res + p[i] - p[i - K] > max)
        {
            max = res + p[i] - p[i - K];
        }
        res += p[i] - p[i - K];
    }

    double num = static_cast<double>(K + max);
    cout << setprecision(10) << (num / 2.0) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> p(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 1792
parseInt(x) = parse(Int, x)

function main()
	n,p=map(parseInt,split(readline()))
	y = Int[]
	x = p
	i = 2
	if n*log(i) > log(x)
		print(1)
	elseif n == 1
		print(p)
	else
		while i^n <= x
			if x%(i^n) == 0
				push!(y,i)
				x = div(x, i^n)
			else
				i += 1
			end
		end
		k = 1
		for i in 1:length(y)
			k *= y[i]
		end
		print(k)
	end
end

main()

Measured memory_bytes: 169036
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	const int MAX_N=101,MAX_W=10001,inf=-1;int dp[MAX_N][MAX_W],N,W,v[MAX_W],w[MAX_W];
	memset(dp,inf,sizeof(dp));
	cin>>N>>W;
	for(int i=1;i<=N;i++){cin>>v[i]>>w[i];}
	for(int j=0;j<=W;j++){dp[0][j]=0;}
	for(int i=1;i<=N;i++){
		for(int j=0;j<=W;j++){
			if(j - w[i] >= 0 && j-w[i]<=W)
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}
			else
			{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}

Measured memory_bytes: 5128