akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,ar[N][2],dp[N][3]; vector<ll> vc[N];
ll maxval(ll i,ll cl,ll p){
	// cout<<i<<" "<<p<<" "<<cl<<endl;
	if(dp[i][cl]!=-1){
		return dp[i][cl];
	}
	ll an=1,fl=0;
	if(cl==1){
		ll a=1,b=1;
		for(auto it:vc[i]){
			if(it==p) continue;
			a=(a*maxval(it,1,i))%mod;
		}
		for(auto it:vc[i]){
			if(it==p) continue;
			b=(b*maxval(it,2,i))%mod;
		}
		return dp[i][cl]=(a+b)%mod;
	}
	else{
		ll a=1;
		for(auto it:vc[i]){
			if(it==p) continue;
			a=(a*maxval(it,1,i))%mod;
		}
		return dp[i][cl]=a;
	}
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l;
	cin>>n;
	for(i=1;i<n;i++){
		cin>>ar[i][0]>>ar[i][1];
		vc[ar[i][0]].ps(ar[i][1]);
		vc[ar[i][1]].ps(ar[i][0]);
	}
	memset(dp,-1,sizeof(dp));
	ll an=maxval(1,1,0);
	cout<<an;
	return 0;	
}

Measured memory_bytes: 22660
w, h = list(map(int, input().split()))
xs = [int(input()) for _ in range(w)]
ys = [int(input()) for _ in range(h)]

x_cnt = w + 1
y_cnt = h + 1

i = 0
j = 0
xs.sort()
ys.sort()

ans = 0
while i < len(xs) or j < len(ys):
    if i >= len(xs) or (j < len(ys) and ys[j] < xs[i]):
        ans += x_cnt * ys[j]
        j += 1
        y_cnt -= 1
    else:
        ans += y_cnt * xs[i]
        i += 1
        x_cnt -= 1
print(ans)




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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!p)
#define until(p) while(!p)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int X[100100], Y[100100];

int value(char c){return c == 'A' ? 1 : 2;}

const std::string YESNO[2] = {"NO", "YES"};

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

    std::string S, T;
    std::cin >> S >> T;

    for(int i=0;i<S.size();++i){
        X[i] = value(S[i]);
    }

    for(int i=0;i+1<S.size();++i){
        X[i+1] += X[i];
    }

    for(int i=0;i<T.size();++i){
        Y[i] = value(T[i]);
    }

    for(int i=0;i+1<T.size();++i){
        Y[i+1] += Y[i];
    }    
    
    int Q;
    std::cin >> Q;

    for(int i=0;i<Q;++i){
        int a, b, c, d;
        std::cin >> a >> b >> c >> d;
        --a; --b; --c; --d;

        int v_s = X[b] - (a > 0 ? X[a-1] : 0),
            v_t = Y[d] - (c > 0 ? Y[c-1] : 0);
        std::cout << YESNO[v_s % 3 == v_t % 3] << std::endl;
    }
}


Measured memory_bytes: 1744
// In The Name Of God
#include <bits/stdc++.h>

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int HP = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

string s;
vector<string> v;
int k;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> s >> k;
	for (int sz = 1; sz < 7; sz++)
		for (int i = 0; i <= (int)s.size() - sz; i++)
			v.push_back(s.substr(i, sz));
	sort(v.begin(), v.end());
	v.resize( unique(v.begin(), v.end()) - v.begin() );
	cout << v[k - 1] << endl;
}

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

int n, m, k, x, y;
vector<pair<int,int>> p;
vector<int> col, row;

int main(){
    cin >> n >> m >> k;
    row.assign(n+1,0);
    col.assign(m+1,0);
    
    int mxr = 0, mxc=0;
    for(int i=0;i<k;i++){
        cin >> x >> y;
        p.push_back({x,y});
        row[x]++; col[y]++;
        mxr = max(row[x],mxr);
        mxc = max(col[y],mxc);
    }

    int qtd=0, qtdr=0, qtdc=0;
    for(int i=0;i<=n;i++)
        if(row[i]==mxr)
            qtdr++;
    
    for(int i=0;i<=m;i++)
        if(col[i]==mxc)
            qtdc++;

    for(auto par:p){
        if(row[par.first]==mxr && col[par.second]==mxc){
            qtd++;
        }
    }

    if(qtd == qtdr*qtdc)
        cout << mxr+mxc-1 << '\n';
    else
        cout << mxr+mxc << '\n';

    return 0;
}


Measured memory_bytes: 9780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int ans[n];
  rep(i,0,n){
    ans[i]=0;
  }
  rep(i,0,n-1){
    int a;
    cin>>a;
    ans[a-1]++;
  }
  rep(i,0,n){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 4424
#include<iostream>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{	
	int n,mx=0; cin >> n;
	string s; cin >> s;
	for (int i = 1; i < n; ++i)
	{
		int c = 0;
		string s1 = s.substr(0, i);
		string s2 = s.substr(i, n - i);
		vector<int>a(26);
		vector<int>b(26);
		for (int h = 0; h < s1.size(); ++h)
			a[s1[h] - 'a']++;
		for (int h = 0; h < s2.size(); ++h)
			b[s2[h] - 'a']++;
		for (int h = 0; h < 26; ++h)
			if (a[h] > 0 && b[h] > 0)
				c++;
		mx = max(c, mx);
	}
	cout << mx;







}

Measured memory_bytes: 3644
#include <stdio.h>
#include <math.h>
#define pi acos(-1)

int main(void)
{
    double a, b, x;
    double s, ans;

    scanf("%lf%lf%lf", &a, &b, &x);
    s = x / a;
    
    if (s >= a * b / 2)
        ans = atan2((a * b - s) * 2 / a, a);
    else
        ans = atan2(b, 2 * s / b);

    printf("%.10f\n", ans * 360 / 2 / pi);

    return 0;
}

Measured memory_bytes: 384
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)7           __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846;
typedef vector<ll> vll ;
typedef vector<int> vii ;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}
void solve()
{
      ll a;cin>>a;
      string s;
      cin>>s;
      ll fou=(s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0')*1;
      //cout << fou << endl;
      ll ans=(a*fou)/100;
      cout << ans << endl;

}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    ll test_case=1;
   //cin>>test_case ;
    while(test_case--)
	{
		 solve();
	}

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a + b) cout << min(k, a) << "\n";
    else cout << a - (k - a - b) << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3640
///apigs property
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define md (s + e) / 2
#define mid (l + r) / 2
using namespace std;
typedef long long ll;
ll q, b[555555], k, l, m, n, o, p;
map < ll , ll > mp;
double a[555555] , dp[3005][3005];
vll adj[555555];
const ll mod = 1e9+7;
double mem(ll i , ll cnt){
	//cout << cnt << " ";
	if(n < cnt * 2)return 1;
	if((n - i + cnt) * 2 <= n)return 0;
	if(dp[i][cnt] != (double)mod)return dp[i][cnt];
	return  dp[i][cnt] = a[i] * mem(i + 1 , cnt + 1) + (1 - a[i]) * mem(i + 1 , cnt);
}
void solve(){
	cin >> n;
	for(ll i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	for(ll i = 0 ; i < n ; i++){
		for(ll j = 0 ; j < n ; j++){
			dp[i][j] = (double)mod;
		}
	}
	cout << fixed << setprecision(10) << mem(0 , 0) << endl;
}
int main() {
    fast ;
	// cin >> q;
    q = 1;
    while(q--){
    	solve();
	}
}



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

int main(){
  int x;

  scanf("%d",&x);

  if(x==3 || x==5 || x==7){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}


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

int main()
{

    int t;
    t=1;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n];
        int cnt=0;
        for(int i=0;i<n;i++)cin>>a[i];sort(a,a+n);
        for(int i=0;i<n-2;i++)
        {
            for(int j=i+1;j<n-1;j++)
            {
                for(int k=j+1;k<n;k++)
                {
                    if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k])
                    {
                            cnt++;
                    }
                }
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	pair<int,int> v[5];
	rep(i,5) cin>>v[i].second;
	rep(i,5) v[i].first=i;
	int ans=inf;
	do{
		int sum=0;
		rep(i,5){
			if(sum%10!=0) sum+=10-sum%10;
			sum+=v[i].second;
		}
		ans=min(ans,sum);


	}while(next_permutation(v,v+5));

	cout<<ans<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.nextLine();
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}
		int[] t = new int[m];
		for (int i = 0; i < m; i++) {
			t[i] = sc.nextInt();
		}

		long[][] dp = new long[s.length + 1][t.length + 1];
		long[][] sum = new long[s.length + 1][t.length + 1];
		dp[0][0] = 1;

		for (int i = 1; i <= s.length; i++) {
			for (int j = 1; j <= t.length; j++) {
				if (s[i - 1] == t[j - 1]) {
					dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
				}

				sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j] + MOD;
				sum[i][j] %= MOD;
			}
		}

		//for (int i = 0; i < sum.length; i++) {
		//	for (int j = 0; j < sum[i].length; j++) {
		//		System.out.print(sum[i][j]);
		//		System.out.print(" ");
		//	}
		//	System.out.println();
		//
		//}

		System.out.println(sum[s.length][t.length] + 1);
	}
}


Measured memory_bytes: 126832
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    A = list(map(int,input().split()))
    ans = 0
    for a in A:
        while a%2 == 0:
            ans += 1
            a >>= 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 10112
#include<stdio.h>
#include<string.h>
int MAX(int a,int b){return a<b?b:a;}
//int P[1010],L[1010],R[1010],H[1010],C=1;
int P[3][1010],H[1010],C=1;
//int hyouka(int i,int x){return N[i]<=x?N[i]<x?-1:0:1;}
char N[1010][110];
int hyouka(int i,char *s){return strcmp(s,N[i]);}
int h(int a){return H[P[2][a]]-H[P[1][a]];}
void rot(int a,int t){//L==1,R==2
  int b=P[3-t][a],r=P[0][a];
  P[1][r]==a?(P[1][r]=b):(P[2][r]=b);
  if(P[2][b])P[0][P[2][b]]=a;
  P[3-t][a]=P[t][b];
  P[t][b]=P[0][b];
  P[0][b]=P[0][a];
  P[0][a]=b;
  H[a]=MAX(H[P[1][a]],H[P[2][a]])+1;
  H[b]=MAX(H[P[1][b]],H[P[1][b]])+1;
}
void make(int p,int t,char *s){
  P[t][p]=C;
  P[0][C]=p;
  strcpy(N[C],s);
  H[C]=1;
  //if(p)H[p]=MAX(2,H[p]);
  C++;
}
int mfind(char *x){
  int i,j,r,n;
  if(C==1){
    make(0,1,x);
    return 1;
  }
  for(i=P[1][0];r=hyouka(i,x);i=n){//printf("%d %s\n",r,x);
    if(r<0){
      if(P[1][i]==0)make(i,1,x);
      n=P[1][i];
    }
    else{
      if(P[2][i]==0)make(i,2,x);
      n=P[2][i];
    }
  }//printf("%d\n",i);
  //for(j=0;j<C;j++){
  // printf(":%d %d %d %d %s\n",P[0][j],P[1][j],P[2][j],H[j],N[j]);
  //}
  for(j=P[0][i];j;j=P[0][j]){
    H[j]=MAX(H[P[1][j]],H[P[2][j]])+1;
    if(h(j)<-1){
      if(h(P[1][j])>0)rot(P[1][j],1);
      rot(j,2);
      break;
    }
    if(h(j)>1){
      if(h(P[2][j])<0)rot(P[2][j],2);
      rot(j,1);
      break;
    }
    if(h(j)==0)break;
  }//printf("%d\n",i);
  return i;
}      
void prim(int n){
  int i;
  if(P[1][n])prim(P[1][n]);
  for(i=0;i<H[n];i++)printf("  ");
  printf("%s\n",N[n]);
  if(P[2][n])prim(P[2][n]);
}
/*int main(){
  int n,i;
  //for(i=0;i<100;i++)H[i]=-1;
  char s[10];
  while(~scanf("%s",s)){
    printf("%d\n",mfind(s));
    for(i=0;i<C;i++){
      printf("%d %d %d %d %s\n",P[0][i],P[1][i],P[2][i],H[i],N[i]);
    }
    prim(P[1][0]);printf("end\n");
  }
  return 0;
}/*/
int main(){
  int i,l,max=0,mj=1,r,a[1010]={};
  char *c,*mi,s[1020];
  fgets(s,1010,stdin);
  mi=strtok(s," \n");
  a[mj=mfind(mi)]++;
  max=strlen(mi);
  // printf("%s\n",mi);
  while(c=strtok(NULL," \n")){
    //printf("%s\n",c);
    a[r=mfind(c)]++;
    //printf("%d\n",r);
    l=strlen(c);//printf("%s %d\n",mi,l);
    if(max<l){
      max=l;
      strcpy(mi,c);
    }//printf("a\n");
    if(a[r]>a[mj])mj=r;//printf("a\n");
  }
  //printf("%s %d\n",mi,mj);
  printf("%s %s\n",N[mj],mi);
  return 0;
  }//*/

Measured memory_bytes: 564
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

LL cal(LL A) {
	LL ans = 0;
	if (A >= 3) {
		ans += A * (A - 1) * (A - 2);
	}
	if (A >= 2) {
		ans += A * (A - 1) * 3;
	}
	ans += A;
	return ans;
}
void solve() {
	int N, K;
	cin >> N >> K;
	LL A = N / K;
	LL ans = 0;
	ans = cal(A);

	if (K % 2 == 0) {
		LL B = N / (K / 2);
		B -= A;
		ans += cal(B);
	}
	cout << ans << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
if (n=gets.chomp.split("").map(&:to_i)).uniq.size==1
  puts n.join("")
else
  if n[1]==n[0]
    if n[2]<n[1]
      puts n[0].to_s*3
      exit
    end
  elsif n[1]<n[0]
    puts n[0].to_s*3
    exit
  end
  puts (n[0]+1).to_s*3
end


Measured memory_bytes: 1788
#include<cmath>
#include<iostream>
using namespace std;
int n,a[101],minn=101,maxx=-101,sum,ans=1919810;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		minn=min(minn,a[i]);
		maxx=max(maxx,a[i]);
	}
	for(int i=minn;i<=maxx;i++)
	{
		sum=0;
		for(int j=1;j<=n;j++)
		{
			sum+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,a[200005],b[200005],dp[200005];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]]=i;
        dp[i]=1;
    }
    for(int i=1;i<=n;i++)
        if(b[a[i]-1]<i)dp[i]=dp[b[a[i]-1]]+1;
    int maxx=0;
    for(int i=1;i<=n;i++)
        maxx=max(maxx,dp[i]);
    printf("%d\n",n-maxx);
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
    int a,b,c,n;
    scanf("%d%d",&a,&b);
    if(a>=1 && a<=9 && b>=1 && b<=9)
    {
        printf("%d\n",a*b);
    }
    else printf("-1\n");
    return 0;
}



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

int main()
{
    while (true)
    {
        ll m, f, r;
        cin >> m >> f >> r;

        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }

        if (m == -1 || f == -1)
        {
            cout << "F" << endl;
            continue;
        }

        ll sum = m + f;
        if (sum >= 80)
        {
            cout << "A" << endl;
        }
        else if (sum >= 65)
        {
            cout << "B" << endl;
        }
        else if (sum >= 50)
        {
            cout << "C" << endl;
        }
        else if (sum >= 30)
        {
            if (r >= 50)
            {
                cout << "C" << endl;
            }
            else
            {
                cout << "D" << endl;
            }
        }
        else
        {
            cout << "F" << endl;
        }
    }
}


Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main(){
	long long x,y,i,j,k,c,s,d,gcd=0;
	while(cin>>x>>y){
		if(x==0&&y==0)
			cout<<"0"<<endl;
		if(x>y){
			for(j=1;j<=x;j++){
				k=x%j;
				c=y%j;
				if(k==0&&c==0){
					gcd=j;
				}
				if(j==x){
					cout<<gcd<<endl;
				}
			}
		}else{
			for(j=1;j<=y;j++){
				s=x%j;
				d=y%j;
				if(s==0&&d==0){
					gcd=j;
				}
				if(j==y){
					cout<<gcd<<endl;
				}
			}
		}

	}
	return 0;
}

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

int main(){
	int N, W;
	ll sum = 0;
	cin >> N >> W;
	ll w[N], v[N];
	for(int i=0; i<N; i++){
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	ll impossible = 100000000001;
	ll dp[N][sum+1];
	for(int i=0; i<sum+1; i++){
		if(i == 0){
			dp[0][i] = 0;
		}else if(i <= v[0]){
			dp[0][i] = w[0];
		}else{
			dp[0][i] = impossible;
		}
	}
	for(int i=1; i<N; i++){
		for(int j=0; j<sum+1; j++){
			if(j < v[i]){
				dp[i][j] = min(w[i], dp[i-1][j]);
			}else{
				dp[i][j] = min(w[i] + dp[i-1][j-v[i]], dp[i-1][j]);
			}
		}
	}
	for(int i=0; i<sum; i++){
		if(dp[N-1][i] <= W && dp[N-1][i+1] > W){
			cout << i << endl;
			return 0;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <queue>
using namespace std;

vector<vector<long long> > g;


int main(){
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n + 1);
    for(int i = 1; i <= n; ++i) cin >> a[i];
    g.resize(n + 1);
    long long fr, to;
    for(int i = 0; i < k; ++i){
        cin >> fr >> to;
        g[fr].push_back(to);
        g[to].push_back(fr);
    }
    long long c = n;
    for(int i = 1; i <= n; ++i){
        for(int j = 0; j < g[i].size(); ++j){
            if(a[i] <= a[g[i][j]]){
                c--;
                break;
            }
        }
    }
    cout << c;
}

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

#define a9 1000000000

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int N, K, S; cin >> N >> K >> S;
	rep(i, K) cout << S << ' ';
	rep(i, N-K) {
		if(S == a9) cout << 1 << ' ';
		else cout << a9 << ' ';
	}
	cout << endl;
}


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

int main()
{
  int N, D;
  cin >> N >> D;
  if (N % (2 * D + 1) == 0)
    cout << N / (2 * D + 1) << endl;
  else
    cout << N / (2 * D + 1) + 1 << endl;
}



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

int main()

{
    string s,k;
    cin>>s>>k;
    int cnt=0;
    for(int i=0;i<s.length();i++)
    {
        
        if(s[i]!=k[i]){
        s[i]=k[i];
        cnt++;}
    }
   cout<<cnt;
   return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;


void solve(){
  int a, b, c; cin >> a >> b >> c;
  if(a + b >= c) cout << "Yes\n";
  else cout << "No\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int N,K;
string s;
main()
{
	cin>>N>>K>>s;
	vector<int>a;
	if(s[0]=='0')a.push_back(0);
	int p=1;
	for(int i=1;i<N;i++)
	{
		if(s[i]!=s[i-1])
		{
			a.push_back(p);
			p=1;
		}
		else p++;
	}
	a.push_back(p);
	if(s[N-1]=='0')a.push_back(0);
	vector<int>sum;
	sum.push_back(a[0]);
	int pre=a[0];
	for(int i=1;i<a.size();i+=2)
	{
		pre+=a[i]+a[i+1];
		sum.push_back(pre);
	}
	int ans=0;
	if(sum.size()<=K+1)
	{
		cout<<sum[sum.size()-1]<<endl;
	}
	else
	{
		int m=0;
		for(int i=K;i<sum.size();i++)
		{
			ans=max(ans,sum[i]-sum[i-K]+a[(i-K)*2]);
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 1272
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    S = list(input())

    obj = S[0]
    cnt = 1
    L = []
    for i in range(1, len(S)):
        if S[i] == obj:
            cnt += 1
        else:
            L.append(cnt)
            obj = S[i]
            cnt = 1
    L.append(cnt)

    # print(L)
    print(len(L) - 1)


if __name__ == '__main__':
    solve()


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

int main() {
	long N;
	cin >>N;
	vector<long> A(N-1),B(N);
	for(int i=0;i<N-1;i++){
		cin >>A.at(i);
		B.at(i)=0;
	}
	B.at(N-1)=0;
	sort(A.begin(), A.end());
	long k=0;
	B.at(0)=1;
	for(int i=1;i<N-1;i++){
		if(A.at(i-1)==A.at(i)){
			B.at(k)++;
		}
		else{
			k+=(A.at(i)-A.at(i-1));
			B.at(k)++;
		}
	}
	for(int i=0;i<N;i++){
		cout <<B.at(i)<<endl;
	}

}

Measured memory_bytes: 6424
#include <cstdio>

int main(){
    int N, T, E;
    scanf("%d %d %d", &N, &T, &E);

    for(int i=1;i<=N;i++){
        int x;
        scanf("%d", &x);

        int t;
        for(t=0;t<T-E;t+=x);
        if(t <= T+E){printf("%d\n", i); return 0;}
    }
    puts("-1");
}

Measured memory_bytes: 1024
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <typeinfo>
#include <stdlib.h>


using namespace std;


int main(int argc, char* argv[]){
// 1 selectionSort(A, N) // N個の要素を含む0-オリジンの配列A
// 2   for i が 0 から N-1 まで
// 3     minj = i
// 4     for j が i から N-1 まで
// 5       if A[j] < A[minj]
// 6         minj = j
// 7     A[i] と A[minj] を交換

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

  for(int i=0; i<n; i++){
    minj = i;
    for(int j=i; j<n; j++){
      if (a[j] < a[minj]){
        minj = j;
      }
    }
    tmp = a[i];
    a[i] = a[minj];
    a[minj] = tmp;
    // for(int i=0; i<n-1; i++){
    //   cout << a[i] << " ";
    // }
    // cout << a[n-1] << endl;
    if(minj != i){
      cnt ++;
    }
  }

  for(int i=0; i<n-1; i++){
    cout << a[i] << " ";
  }
  cout << a[n-1] << endl;
  cout << cnt << endl;
}



Measured memory_bytes: 3088
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 01:08:13 2020

@author: shinba
"""

a,b = map(str,input().split())

n = int(a+b)

for i in range(4,int(n**(0.5))+1):
    if i**2 == n:
        print("Yes")
        break
else:
    print("No")


Measured memory_bytes: 9352
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	long long int a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if (v*t - w * t >= abs(a - b)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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



int main(){
  long long a,b,s;
  cin>>a>>b;
  for(int i=1;i<=min(a, b);i++){
    if(a%i==0 && b%i==0){
      s=i;
    }
  }
  cout << a*b/s;
}

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

int main(void)
{
	int len = 0,i;
	char str[16];
	
	fgets(str,sizeof(str),stdin);
	for(i=0;i<strlen(str)-1;i++)
	{
		switch(str[i])
		{
			case '0':str[len] = '0';
					 len++;
					 break;
			
			case '1':str[len] = '1';
					 len++;
					 break;
			
			default :if(len > 0)
					{
						len--;
					}
					break;
		}
	}
	
	for(i=0;i<len;i++)
	{
		printf("%c",str[i]);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Repi(i, a, b) for(int i = int(a); i < (int)(b); i++)
#define Repl(i, list) for(int i : list)
#define Sort(v) sort(v.begin(), v.end())
#define lli long long int
template<typename _T> void Out(_T x) { cout << x << endl; }
template<typename _T> void PrintVec(vector<_T> vec) { Rep(i, vec.size()) { cout << vec.at(i) << " "; } cout << endl; }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main()
{
    // input
    int X;
    cin >> X;

    // output
    if (X > 2 && X % 2 == 0)
    {
        X++; // 必ず奇数にする
    }
    while (1) {
        if (IsPrime(X)){
            Out(X);
            break;
        } else {
            X += 2;
        }
    }

    return 0;
}

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

int main()
{
    
    /*
    string s1;
    getline( cin, s1 );
    int n1 = s1.size();
    */
    int x, a;
    cin >> x >> a;
    
    if( x >= a ) {
        cout << "10" << endl;
    }
    else {
        cout << "0" << endl;
    }
      
    return 0;
}


Measured memory_bytes: 384
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          long[] tmp = ReadLine().Split(' ').Select(long.Parse).ToArray();
          long k = tmp[2] - tmp[1] - tmp[0];
 
          if(k > 0 && k * k > 4 * tmp[0] * tmp[1]) WriteLine("Yes");
          else WriteLine("No");
      }
   }
}

Measured memory_bytes: 13268
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan =new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		int k = Integer.parseInt(scan.next());scan.nextLine();
		int[] a = new int [n];
		Arrays.fill(a, 0);
		for (int i = 0;i < n;++i){
			++a[Integer.parseInt(scan.next())-1];
		}

		Arrays.sort(a);
		int rem=0;
		int i;
		for (i = 0;i < n;  ++i){
			if (a[i] != 0)break;
		}
		int ans=0;
		for (int j = i;j < (n-i)-k+i; ++j){
			ans+=a[j];
		}
		System.out.print(ans);


	}
}
//end


Measured memory_bytes: 51004
#include<stdio.h>

int main(){

	int a,n,b,f,r,v,i,j,k;
	int a1[3][10]={0},a2[3][10]={0},a3[3][10]={0},a4[3][10]={0};
	scanf("%d",&n);
	
	for(i=0; i<n; i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		if(b==1) a1[f-1][r-1]+=v;
		if(b==2) a2[f-1][r-1]+=v;
		if(b==3) a3[f-1][r-1]+=v;
		if(b==4) a4[f-1][r-1]+=v;
	}
	for(a=1; a<=4; a++){
		for(i=0; i<3; i++){
			for(j=0; j<10; j++){
				if(a==1) printf(" %d",a1[i][j]);
				if(a==2) printf(" %d",a2[i][j]);
				if(a==3) printf(" %d",a3[i][j]);
				if(a==4) printf(" %d",a4[i][j]);
			}
		printf("\n");
		}
		if(a!=4) printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e,x,y,z,h,j,k;
    cin>>a>>b>>c>>d>>e;
    x=abs(a);
    y=x*c;
    h=b-a;
    j=h*e;
    z=b*e;
    if(a<0){
        k=y+d+z;
        cout<<k<<endl;
    }
    else if(a>0){
        cout<<j<<endl;
    }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, K;
  cin >> N >> K;

  int star = (N - 1) * (N - 2) / 2;
  
  if (K > star)
  {
    cout << -1 << endl;
    return 0;
  }

  int M = (N - 1) + (star - K);
  cout << M << endl;
  
  int m = 0;
  for (int i = 0; i < N - 1; i++)
  {
    cout << 1 << " " << i + 2 << endl;
    m++;
  }
  if (M == m) return 0;
  for (int i = 2; i <= N; i++)
  {
    for (int j = i + 1; j <= N; j++)
    {
      cout << i << " " << j << endl;
      m++;
      if (M == m) return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int a,b,n;
	while(1){
		cin>>a>>b;
		if(a+b==0) break;
		cin>>n;
		vector<vector<int> > d(a,vector<int>(b,0));
		//vector<vector<int> > f(a,vector<int>(b));
		rep(i,0,n){
			int x,y;
			cin>>x>>y;
			x--;
			y--;
			d[x][y]=-1;
		}
		rep(i,0,b){
			rep(j,0,a){
				if(i==0 && j==0) d[0][0]=1;
				else if(d[j][i]==-1) d[j][i]=-1;
				else if(i==0) d[j][0]=max(0,d[j-1][0]);
				else if(j==0) d[0][i]=max(0,d[0][i-1]);
				else d[j][i]=max(0,d[j-1][i])+max(0,d[j][i-1]);
				//o(" "<<j<<" "<<i<<" "<<d[j][i]);
			}
		}
		o(d[a-1][b-1]);
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vl a(n);
  REP(i, n) { cin >> a[i]; }
  vl b1(60), b0(60);

  REP(i, n) {
    REP(j, 60) {
      if ((a[i] >> j) % 2 == 0) {
        b0[j]++;
      } else {
        b1[j]++;
      }
    }
  }
  ll ans = 0;
  REP(i, n - 1) {
    REP(j, 60) {
      ll base = (1LL << j) % MOD;
      if ((a[i] >> j) % 2 == 0) {
        ans = (ans + (base * b1[j]) % MOD) % MOD;
      } else {
        ans = (ans + (base * b0[j]) % MOD) % MOD;
      }
    }
    REP(j, 60) {
      if ((a[i] >> j) % 2 == 0LL) {
        b0[j]--;
      } else {
        b1[j]--;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
mod = 1_000_000_007

gets
a = gets.split.map &:to_i

tmp0 = a.sum ** 2
tmp1 = a.sum { |e| e ** 2 }
puts (tmp0 - tmp1) / 2 % mod

# tmp0 = a.sum
# tmp0 = ((tmp0 % mod) ** 2) % mod

# tmp1 = a.sum { |e| e ** 2 }

# tmp1 %= mod

# ans = tmp0 < tmp1 ? tmp0 - tmp1 + mod : tmp0 - tmp1

# if ans.odd?
#   puts (ans + mod) / 2
# else
#   puts ans / 2
# end


Measured memory_bytes: 30692
class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数
        self.rank = [0] * (n + 1)

    def find(self, x):  # xの根となる要素番号を返す
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def getNodeLen(self, x):
        return -self.root[self.find(x)]


N, M = map(int, input().split())
P = list(map(int, input().split()))
uf = UF_tree(N)
for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(x, y)

ans = 0
for i, p in enumerate(P, start=1):
    if uf.isSame(i, p):
        ans += 1

print(ans)


Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    if (n == 0)cout << "0\n";
    else {
        string ans = "";
        while (n) {
            if (n % 2 == 0)ans = "0" + ans;
            else {
                ans = "1" + ans;
                --n;
            }
            n /= -2;
        }
        cout << ans << "\n";
    }
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, rt = 1, mx[nsz + 5], pr[nsz + 5], dp[nsz + 5][3], ans[nsz + 5];
vector<int> g[nsz + 5];

void dfs(int u = rt) {
    loop (i, g[u].size()) {
        int v = g[u][i];
        if (v == pr[u])  continue;
        pr[v] = u;
        mx[v] = max(mx[u], u);
        dfs(v);
    }
    if (u > mx[u]) {
        dp[u][0] = 1;
        loop (i, g[u].size()) {
            int v = g[u][i];
            if (v == pr[u])  continue;
            if (v <= mx[u]) {
                dp[u][0] += dp[v][1];
            }
        }
    } else if (pr[u] == mx[u]) {
        dp[u][0] = 1;
        dp[u][1] = u <= mx[pr[u]];
        loop (i, g[u].size()) {
            int v = g[u][i];
            if (v == pr[u])  continue;
            if (v <= mx[u]) {
                dp[u][0] += dp[v][0];
            }
            if (u <= mx[pr[u]] && v <= mx[pr[u]]) {
                dp[u][1] += dp[v][2];
            }
        }
    } else {
        dp[u][0] = dp[u][1] = dp[u][2] = 1;
        loop (i, g[u].size()) {
            int v = g[u][i];
            if (v == pr[u])  continue;
            if (v <= mx[u]) {
                dp[u][0] += dp[v][0];
            }
            if (v <= mx[pr[u]]) {
                dp[u][1] += dp[v][1];
            }
            if (v <= mx[mx[pr[u]]]) {
                dp[u][2] += dp[v][2];
            }
        }
    } 
    if (u == rt)  return;
    if (u > mx[u]) {
        ans[u] = dp[u][0];
    } else if (pr[u] == mx[u]) {
        ans[u] = dp[u][0] - dp[u][1];
    } else {
        ans[u] = 0;
    }
}

void pre(int u = rt) {
    loop (i, g[u].size()) {
        int v = g[u][i];
        if (v == pr[u])  continue;
        ans[v] += ans[u];
        pre(v);
    }
}

int main() {
    scanf("%d", &n);
    cont (i, n - 1) {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs();
    pre();
    circ (u, 2, n) {
        printf("%d ", ans[u]);
    }
}

Measured memory_bytes: 29696
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


s = list(input())
ans = True
li = list("abcdefghijklmnopqrstuvwxyzC")

if s[0]!="A":
    ans = False
memo = s[2:-1]
if not("C" in memo):
    ans = False
C_cnt = 0
for i in range(1,len(s)):
    if not(s[i] in li):
        ans = False
    if s[i] == "C":
        C_cnt += 1

if ans and C_cnt==1:
    print("AC")
else:
    print("WA")










Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;


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

  ll ans = 0;
  ll temp;
  for(ll  i=0; i<n; ++i){
    cin>>temp;
    if( temp % 2 ==0){
      while( temp % 2 == 0){
        temp = temp / 2;
        ans++;
      }
    }
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
class Card:
	def __init__(self, mark, num, order):
		self.mark = mark
		self.num = num
		self.order = order
	def __str__(self):
		return self.mark + ' ' + str(self.num)

def quick_sort(cards, p, r):
	if p < r:
		q = partition(cards, p, r)
		quick_sort(cards, p, q - 1)
		quick_sort(cards, q + 1, r)

def partition(cards, p, r):
	x = cards[r].num
	i = p - 1
	for j in range(p, r):
		if cards[j].num <= x:
			i += 1;
			swap(cards, i, j)
	swap(cards, i + 1, r)
	return i + 1

def swap(cards, i, j):
	tmp = cards[i]
	cards[i] = cards[j]
	cards[j] = tmp

def check_stability(cards):
	for i in range(1, len(cards)):
		c1 = cards[i-1]
		c2 = cards[i]
		if c1.num == c2.num and c1.order > c2.order:
			return False
	return True

n = int(input())
cards = []
for i in range(n):
	mark, num = map(str, input().split())
	cards.append(Card(mark, int(num), i))

quick_sort(cards, 0, n - 1)
stable = check_stability(cards)
if stable == True:
	print('Stable')
else:
	print('Not stable')
for i in range(n):
	print(cards[i])



Measured memory_bytes: 29648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  int count=0;
  vector<int> a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  int b=1;
  for(int i=0;i<N;i++){
    count++;
    b=a.at(b-1);
    if(b==2)break;
  }
  if(count<N)cout<<count<<endl;
  else cout<<-1<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
using namespace std;

int main()
{
	cout << fixed << setprecision(6);
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> als(n);
	for (auto& a : als)cin >> a;

	vector<vector<int>> cls(h, vector<int>(w));

	pair<int, int> pos(0, 0), vec(1, 0);
	int cnt = 0;
	for (auto a: als) {
		++cnt;
		for (int i = 0; i < a; ++i) {
			cls[pos.first][pos.second] = cnt;
			if (pos.first + vec.first < 0 || pos.first + vec.first >= h ||
				pos.second + vec.second < 0 || pos.second + vec.second >= w ||
				cls[pos.first + vec.first][pos.second + vec.second] != 0) {
				auto temp = vec.first;
				vec.first = -vec.second;
				vec.second = temp;
			}
			pos.first += vec.first;
			pos.second += vec.second;

		}
	}

	for (auto cr : cls) {
		cout << cr[0];
		for (int i = 1; i < w; ++i) {
			cout << " " << cr[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cmath>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define ll long long
using namespace std;
int fact(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}
int main(){
    int n;
    cin>>n;
    double x[n],y[n],ans=0;
    vector<int> v;
    rep(i,0,n){
        cin>>x[i]>>y[i];
        v.emplace_back(i);
    }
    int num=fact(n);
    do{
        double sum=0;
        rep(j,0,n-1){
            double dx=(double)pow(abs(x[v[j]]-x[v[j+1]]),2.0);
            double dy=(double)pow(abs(y[v[j]]-y[v[j+1]]),2.0);
           sum+=sqrt(dx+dy);
        }
        ans+=sum;
    } while (next_permutation(v.begin(), v.end()));
        
    printf("%.9lf\n",ans/num);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int  F[45]={};
int fib(int n){
  if(n==0||n==1)return 1;
  if(F[n]!=0)return F[n];
  return F[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n;
  cin>>n;
  cout<<fib(n)<<endl;
}

  



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main()
{
  ll a, b, k;
  cin >> a>> b>> k;
  ll na, nb;
  ll c = 0;
  if(a < k){
    na = 0;
    ll tmp = k - a;
    nb = max(b -tmp, c);
  }else{
    na = a -k;
    nb = b;
  }
  cout << na << " " << nb <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

int a[200010];
int b[200010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n; cin >> n;
    REP(i, n) cin >> a[i];
    
    int q; cin >> q;
    REP(i, q){
        int k; cin >> k;
        int ptr= lower_bound(a, a+n, k) - a;
        cout << ptr << endl;
    }
	return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <vector>

using namespace std;

vector <int> v[100000];

int dfs(int x, int y) {
    int g = 0, i;
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;
        
        g ^= dfs(v[x][i], x) + 1;
    }
    
    return g;
}

int main() {
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n - 1; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    if (dfs(0, -1) == 0) {
        puts("Bob");
    } else {
        puts("Alice");
    }
    
    return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const int inf=1e18;

int32_t main(){
	IOS;
	char c;
	cin>>c;
	cout<<(char)(c+1)<<endl;
} 

Measured memory_bytes: 256