akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

void array_sort(int a[], int head, int tail) {
  int i, j, t;
  for (i = head; i < tail; i++) {
    for (j = tail; j > i; j--) {
      if (a[j-1] > a[j]) {
	t = a[j-1];
	a[j-1] = a[j];
	a[j] = t;
      }
    }
  }
}

void page_sort(char w[][31], int p[], int n) {
  int i, j, head, tail;
  for (i = 0; i < n; i++) {
    for (j = 1; j < n - i; j++) {
      if (strcmp(w[i], w[i+j]) != 0)
	break;
    }
    head = i;
    tail = i + j - 1;
    if (head < tail)
      array_sort(p, head, tail);
  }
}

void word_sort(char w[][31], int p[], int n) {
  char s[31];
  int i, j, t;
  for (i = 0; i < n - 1; i++) {
    for (j = n - 1; j > i; j--) {
      if (strcmp(w[j-1], w[j]) > 0) {
	strcpy(s, w[j-1]);
	strcpy(w[j-1], w[j]);
	strcpy(w[j], s);
	t = p[j-1];
	p[j-1] = p[j];
	p[j] = t;
      }
    }
  }
}

int main(void) {
  char word[100][31];
  int page[100], i, j, n;

  i = 0;
  while (1) {
    if (scanf("%s %d", word[i], &page[i]) == EOF)
      break;
    i++;
  }
  n = i;

  word_sort(word, page, n);
  page_sort(word, page, n);

  for (i = 0; i < n; i++) {
    printf("%s\n", word[i]);
    printf("%d", page[i]);
    for (j = 1; j < n - i; j++) {
      if (strcmp(word[i], word[i+j]) != 0)
	break;
      printf(" %d", page[i+j]);
    }
    putchar('\n');
    i += j - 1;
  }
  return 0;
}

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

int main(){
     int N;
     while(cin>>N,N){
	  bool flag=false;
	  int pn;
	  cin>>pn;
	  int firstn=pn;
	  for(int i=1;i<N+1;i++){
	       int t;
	       if(i!=N)
		    cin>>t;
	       else t=-1;
	       if(t-pn==1){
		    pn=t;
		    continue;
	       }
	       if(flag)cout<<" ";
	       else flag=true;
	       if(firstn==pn)cout<<pn;
	       else cout<<firstn<<"-"<<pn;
	       pn=t;
	       firstn=t;
	  }
	  cout<<endl;
     }
}

Measured memory_bytes: 0
n= int(input())
x= [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for y in range(n):
    b,f,r,v = list(map(int, input().split()))
    x[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" {}".format(x[i][j][k]), end ="")
        print()
    if i < 3:
        print("#" * 20)


Measured memory_bytes: 5624
N = int(input())
hps = sorted(list(map(int, input().split())))

while len(hps) > 1:
    for i in range(1, len(hps)):
        hps[i] = hps[i] % hps[0]
    hps = sorted(set(hps))
    if 0 in hps:
        hps.remove(0)
print(hps[0])

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

int main() {
  int n;
  cin>>n;
  map<int,int> suki;
  for(int i=1; i<=n; i++){
    int a;
    cin>>a;
    suki[i]=a;
  }
  int ans=0;
  for(int i=1; i<=n; i++){
    if(i==suki[suki[i]]){
      ans++;
    }
  }
  ans/=2;
  cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll PM = -INF;
    ll Pm = INF;
    ll QM = -INF;
    ll Qm = INF;
    for(int i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        chmax(PM, x + y);
        chmin(Pm, x + y);
        chmax(QM, x - y);
        chmin(Qm, x - y);
    }
    ll ans = PM - Pm;
    chmax(ans, QM - Qm);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> LP;
int main()
{
  int a;
  cin >> a;
  if(a<1200)printf("ABC");
  else if(a<2800)printf("ARC");
  else printf("AGC");
}

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

using namespace std;

ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
} 



int main()
{
    ll n;
    ll index=0;
    string s;
    map <int, char> m;
    cin>>n;
    char ch;
    
    while(n){
        n--;
        ch = 'a' + (n % 26);
        s += ch;
        n = n / 26;
    }
    ll d=s.length();
    for(ll p=d-1;p>=0;p--){
        cout<<s[p];
    }
    return 0;
}

Measured memory_bytes: 3632
char s[3333],t[3333];
int dp[3333][3333];
i,j;
ans(i,j){
	i&&j?s[i-1]==t[j-1]?ans(i-1,j-1),putchar(s[i-1]):dp[i][j]==dp[i-1][j]?ans(i-1,j):ans(i,j-1):0;
}
main(l)
{
	gets(s);gets(t);l=strlen(t);
	for(i=0;i<strlen(s);i++)
	{
		for(j=0;j<l;j++)
		{
			dp[i+1][j+1]=s[i]-t[j]?fmax(dp[i+1][j],dp[i][j+1]):dp[i][j]+1;
		}
	}
	ans(i,j);
}

Measured memory_bytes: 41216
# -*- coding: utf-8 -*-

import collections

n, q = map(int, raw_input().split())
prolist = [raw_input().split() for i in range(n)]
prolist = collections.deque(prolist)
time_sum = 0
while len(prolist):
    process = prolist.popleft()
    time = int(process[1])
    if time <= q:
        time_sum += time
        print "%s %d" %(process[0], time_sum)
    else:
        time_sum += q
        process[1] = str(time-q)
        prolist.append(process)

Measured memory_bytes: 19932
#include<bits/stdc++.h>
#define ll long long
#define inf 100000000
#define pll pair<ll,ll>
#define magic ios_base::sync_with_stdio(false);cin.tie(nullptr)
using namespace std;
#define forn(i,n) for(ll i=1;i<=n;i++)
#define forRn(i,n) for(ll i=n;i>=1;i--)
#define forz(i,n) for(ll i=0;i<n;i++)
#define forRz(i,n) for(ll i=n-1;i>=0;i--)
#define forab(i,a,b) for(ll i=a;i<=b;i++)
#define mod 10007
#define has 3
ll gcd(ll x,ll y){ return y==0?x:gcd(y,x%y); }
ll lcm(ll x,ll y){ return x/gcd(x,y)*y; }


int main(void)
{
    magic;
    ll N;
    cin>>N;
    vector<pll> fir,sec;
    forn(i,N){
        ll x;
        cin>>x;
        fir.push_back({x,i});
        sec.push_back({x,i});
    }
    sort(sec.begin(),sec.end());
    reverse(sec.begin(),sec.end());
    forz(i,N){
        if(sec[0].second==fir[i].second){
            cout<<sec[1].first<<'\n';
        }
        else cout<<sec[0].first<<'\n';
    }
}


Measured memory_bytes: 10464
n = int(input())
ac,wa,tle,re = 0,0,0,0
for i in range(n):
    inp = input()
    if inp == 'AC':
        ac += 1
    elif inp == 'WA':
        wa += 1
    elif inp == 'TLE':
        tle += 1
    else:
        re += 1



print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(ac,wa,tle,re))

Measured memory_bytes: 9200
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    string S; cin >> S;
    S.pop_back();
    while(S.length() > 0) {
        if (S.length() % 2 != 0) {
            S.pop_back(); continue;
        }
        string a = S.substr(0, S.length() / 2), b = S.substr(S.length() / 2, S.length() / 2);
        if (a == b) {
            cout << S.length() << endl; break;
        }
        else S.pop_back();
    }
}


Measured memory_bytes: 3564
// 2017-02-21
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m, n) {
		vector<pair<int, pair<int, int>>> v;
		for (int i = 0; i < m; i++) {
			int t, s, d;
			cin >> t >> s >> d;
			v.push_back(make_pair(t, make_pair(s - 1, d - 1)));
		}
		sort(begin(v), end(v));
		bool a[20000] = {true};
		int c = 1;
		for (int i = 0; i < m; i++) {
			int s, d;
			s = v[i].second.first;
			d = v[i].second.second;
			if (a[s] && !a[d]) {
				a[d] = true;
				c++;
			}
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 3384
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		@SuppressWarnings("resource")
		Scanner sc= new Scanner(System.in);

		int MAX = 1000000;
		int[] prime = new int[MAX];

		prime[0] = prime[1] = 0;
		for (int i = 2; i < MAX; i++){
			prime[i] = 1;
		}
		for (int i = 2; i < 1001; i++){
			if (prime[i] == 1){
				for (int j = 2 * i; j < MAX; j += i){
					prime[j] = 0;
				}
			}
		}


		while(sc.hasNext()){
			int number = Integer.parseInt(sc.nextLine());
			int count = 0;

			for(int i=2;i<=number;i++){
				count += prime[i];
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 24512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    ll N, K;
    cin>>N>>K;
    ll min, max;
    ll ans = 0;
    for(ll i=K;i<=N+1;++i){
        if(i%2==0){
            min = i/2*(i-1)%mod;
            max = (i*N - i/2*(i-1)+mod)%mod;
            max %= mod;
        }
        else {
            min = (i-1)/2*i%mod;
            max = (i*N - (i-1)/2*i+mod)%mod;
        }
        ans += (max-min+1+mod)%mod;
        ans %= mod;
    }
    if(ans<0)cout<<ans+mod<<endl;
    else cout<<ans<<endl;
}



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

const int N = 2e5 + 100, LOG = 20, M = 1 << LOG;

int n, v, x[N], dp_l[M], dp_r[M], go_l[N][LOG], go_r[N][LOG];
vector<int> vec;

void input() {
	cin >> n >> v;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; (v >> i); i++)
		vec.push_back(v >> i);
	vec.push_back(0);
	reverse(vec.begin(), vec.end());
}

void ready() {
	for (int j = 0; j < vec.size(); j++) {
		go_r[n - 1][j] = n - 1;
		for (int i = n - 2; i >= 0; i--)
			if ((x[i + 1] - x[i]) > vec[j])
				go_r[i][j] = i;
			else
				go_r[i][j] = go_r[i + 1][j];

		go_l[0][j] = 0;
		for (int i = 1; i < n; i++)
			if ((x[i] - x[i - 1]) > vec[j])
				go_l[i][j] = i;
			else
				go_l[i][j] = go_l[i - 1][j];
	}
}

void calc_dp() {
	for (int mask = 1; mask < (1 << vec.size()); mask++) {
		dp_l[mask] = 1;
		for (int i = 0; i < vec.size(); i++)
			if (mask & (1 << i)) {
				int prev = mask ^ (1 << i);
				if (dp_l[prev] == n)
					dp_l[mask] = n;
				else
					dp_l[mask] = max(dp_l[mask], go_r[dp_l[prev]][i] + 1);
			}
	}
	
	for (int mask = 1; mask < (1 << vec.size()); mask++) {
		dp_r[mask] = 1;
		for (int i = 0; i < vec.size(); i++)
			if (mask & (1 << i)) {
				int prev = mask ^ (1 << i);
				if (dp_r[prev] == n)
					dp_r[mask] = n;
				else
					dp_r[mask] = max(dp_r[mask], n - go_l[n - dp_r[prev] - 1][i]);
			}
	}
}

set<int> st;
void solve() {
	for (int i = 0; i < n; i++)
		st.insert(i);
	for (int mask = 0; mask < (1 << (vec.size() - 1)); mask++) {
		int a = mask, b = ((1 << (vec.size() - 1)) - 1) ^ a;
		if ((dp_l[a] + dp_r[b]) >= n) {
			st.clear();
			continue;
		}
		
		int l = dp_l[a], r = n - dp_r[b] - 1; // [)
		if (go_r[l][vec.size() - 1] < r || go_l[r][vec.size() - 1] > l)
			continue;
		l = go_l[l][vec.size() - 1], r = go_r[r][vec.size() - 1];
		
		while (true) {
			auto it = st.lower_bound(l);
			if (it != st.end() && *it <= r)
				st.erase(it);
			else
				break;
		}
	}

	for (int i = 0; i < n; i++)
		if (st.find(i) != st.end())
			cout << "Impossible\n";
		else
			cout << "Possible\n";
}

int main() {
	input();
	ready();
	calc_dp();
	solve();
}


Measured memory_bytes: 51456
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	ll mx=-1,mx1=-1,cnt=0,a[n],idx=0;
	rep(i,0,n){cin>>a[i];mx=max(mx,a[i]);}
	rep(i,0,n)if(a[i]==mx)cnt++,idx=i;
	if(cnt==2)rep(i,0,n)cout<<mx<<"\n";
	else{
		rep(i,0,n)if(i!=idx)mx1=max(mx1,a[i]);
		rep(i,0,n){
			if(i!=idx)cout<<mx<<"\n";
			else cout<<mx1<<"\n";
		}
	}
	
	
	
	return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
int mi, ma;

signed main() {
	cin >> n;
	mi = 0, ma = n + 5;
	while (ma - mi > 1) {
		int md = (ma + mi) / 2;
		int s = abs(md*1.08);
		if (s == n) {
			cout << md << endl;
			return 0;
		}
		else if (s < n)mi = md;
		else ma = md;
	}
	cout << ":(" << endl;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
using lint = long long int;

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

    reverse(S.begin(), S.end());

    if (P == 2 or P == 5) {
        lint ans = 0;
        for_(i,0,N) {
            int c = int(S[i] - '0');
            if (c % P == 0) ans += N - i;
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> pow10(N, 1);
    for_(i,1,N) pow10[i] = (pow10[i-1] * 10) % P;

    vector<int> cnt(P, 0);
    cnt[0] = 1;

    lint ans = 0;
    int x = 0;
    for_(i,0,N) {
        x = (x + int(S[i] - '0') * pow10[i]) % P;
        ans += cnt[x];
        ++cnt[x];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int sum = 0;
    for(int i = 0; i < 3; i++){
        int x;
        cin >> x;
        sum += x;
    }
    if(sum >= 22) cout << "bust";
    else cout << "win";

    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef complex<double> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()

#define debug(x) cout<<#x<<": "<<x<<endl

double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

bool isConvex(VP ps) {
  int n = ps.size();
  vector<bool> ccw(n);
  rep(i,n) ccw[i] = cross(ps[(i+1)%n]-ps[i], ps[(i+2)%n]-ps[i])>0;
  rep(i,n-1) if(ccw[i]!=ccw[i+1]) return false;
  return true;
}

int main(void){
    double xa,ya,xb,yb,xc,yc,xd,yd;
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
        &xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){
        if(isConvex({{xa,ya},{xb,yb},{xc,yc},{xd,yd}})){
            cout<<"YES"<<endl;
        }else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3208
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int x = sc.NextInt();
        Console.WriteLine(10 - x / 200);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27520
import sys

class Node:
    def __init__(self, value, p = None, l = None, r = None):
        self.key = value
        self.p = p
        self.left = l
        self.right = r

def getroot(x):
    if x.p != None:
        return getroot(x.p)
    return x

def preorder(x, A):
    if x == None:
        return
    A.append(x.key)
    preorder(x.left, A)
    preorder(x.right, A)

def inorder(x, A):
    if x == None:
        return
    inorder(x.left, A)
    A.append(x.key)
    inorder(x.right, A)

def postorder(x, A):
    if x == None:
        return
    postorder(x.left, A)
    postorder(x.right, A)
    A.append(x.key)

def ptree(root):
    pre = [""]
    ino = [""]
    preorder(root, pre)
    inorder(root, ino)
    print(" ".join(map(str,ino)))
    print(" ".join(map(str,pre)))

def insert(Tree, root, z):
    y = None # x ??????
    x = root  # 'T ??????'
    while x != None:
        y = x # ???????¨????
        if z.key < x.key:
            x = x.left # ?????????????§????
        else:
            x = x.right # ?????????????§????
    z.p = y

    Tree.append(z)
    if y == None: # T ???????????´???
        return z
    elif z.key < y.key:
        y.left = z # z ??? y ?????????????????????
    else:
        y.right = z # z ??? y ?????????????????????
    return root

def main():

    """ ????????? """
    num = int(input().strip())
    istr = sys.stdin.read()
    cmds = list(istr.splitlines())
    Tree = []
    root = None
    for i in range(num):
        cmd = cmds[i][0]
        if cmd == "i":
            n = Node(int(cmds[i][7:]))
            root = insert(Tree, root, n)
        elif cmd == "p":
            ptree(root)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 242860
local a = io.read("*n")
local b = io.read("*n")
local c = io.read("*n")
function test(a,b,c)
    local num1 = a*10 +b+c
    local num2 = a+b*10+c
    local num3 = c*10+a+b
    print(math.max(num1,num2,num3))
end
test(a,b,c)

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precise cout.precision(8); cout << fixed;
#define seed srand(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
using namespace std;

void solve() {
    int N, i; cin >> N;
    string X; cin >> X;
    int popcount = 0, pos = -1;
    for(i = 0; i < N; i += 1) {
        if(X[i] == '1') {
            popcount += 1;
            pos = i;
        }
    }
    if(popcount == 0) {
        for(i = 0; i < N; i += 1) {
            cout << 1 << endl;
        }
        return;
    }
    if(popcount == 1) {
        if(pos == N - 1) {
            for(i = 0; i < N - 1; i += 1) {
                cout << 2 << endl;
            }
            cout << 0 << endl;
        }
        else {
            for(i = 0; i < N - 1; i += 1) {
                if(i == pos) {
                    cout << 0 << endl;
                }
                else {
                    cout << 1 << endl;
                }
            }
            cout << 2 << endl;
        }
        return;
    }
    vector<int> plus(N), minus(N);
    plus[0] = 1 % (popcount + 1);
    minus[0] = 1 % (popcount - 1);
    for(i = 1; i < N; i += 1) {
        plus[i] = (plus[i - 1] * 2) % (popcount + 1);
        minus[i] = (minus[i - 1] * 2) % (popcount - 1);
    }
    int valPlus = 0, valMinus = 0;
    for(i = 0; i < N; i += 1) {
        if(X[i] == '1') {
            valPlus = (valPlus + plus[N - 1 - i]) % (popcount + 1);
            valMinus = (valMinus + minus[N - 1 - i]) % (popcount - 1);
        }
    }
    for(i = 0; i < N; i += 1) {
        int temp;
        if(X[i] == '1') {
            temp = valMinus;
            temp = (temp - minus[N - 1 - i] + (popcount - 1)) % (popcount - 1);
        }
        else {
            temp = valPlus;
            temp = (temp + plus[N - 1 - i]) % (popcount + 1);
        }
        int cnt = 1;
        while(temp != 0) {
            temp = (temp % __builtin_popcount(temp));
            cnt += 1;
        }
        cout << cnt << endl;
    }
}

int main() {
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5148
#include <cstdio>
#include <queue>

int main() {
    int n_items, n_tickets;
    scanf("%d %d\n", &n_items, &n_tickets);

    int price;
    std::priority_queue<int> prices;
    for (int i = 0; i < n_items; i++) {
        scanf("%d", &price);
        prices.push(price);
    }

    for (int i = 0; i < n_tickets; i++) {
        price = prices.top();
        prices.pop();
        prices.push(price / 2);
    }

    long long total = 0;
    while (!prices.empty()) {
        total += prices.top();
        prices.pop();
    }
    std::printf("%lld\n", total);

    return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
	int n;
	char s[51];
	cin >> n >> s;
	int cnt = 0;

	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef int ll;
typedef long double ld;
const ll N = 10005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

vector<ll> adj[N];
ll val[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  ll edge[n + 5][2];
  bool marked[n + 5];
  memset(marked, false, sizeof(marked));
  for (ll i = 1; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    edge[i][0] = x;
    edge[i][1] = y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  ll arr[n + 5];
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];

  sort(arr + 1, arr + n + 1);
  reverse(arr + 1, arr + n + 1);
  ll neighbour[n + 5];
  memset(neighbour, 0, sizeof(neighbour));
  ll pos = 1;
  for (ll it = 1; it <= n; it++) {
    ll max1 = 0;
    ll nindx;
    for (ll i = 1; i <= n; i++) {
      if (marked[i])
        continue;
      max1 = max(max1, neighbour[i]);
      if (max1 == neighbour[i])
        nindx = i;
    }
    marked[nindx] = true;
    val[nindx] = arr[pos++];

    for (ll x : adj[nindx])
      neighbour[x]++;
  }
  ll res = 0;
  for (ll i = 1; i < n; i++) {
    res += min(val[edge[i][0]], val[edge[i][1]]);
  }
  cout << res << en;

  for (ll i = 1; i <= n; i++)
    cout << val[i] << " ";

  cout << en;
  return 0;
}

Measured memory_bytes: 1152
from collections import Counter


class UnionFind:
    def __init__(self, x):
        self.p = [e for e in range(x)]
        self.rank = [0] * x

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        self.link(self.find_set(u), self.find_set(v))

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def link(self, u, v):
        if self.rank[u] > self.rank[v]:
            self.p[v] = u
        else:
            self.p[u] = v
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1


n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]

uf = UnionFind(n)

for a, b in ab:
    a -= 1
    b -= 1
    uf.unite(a, b)

for i in range(n):
    uf.find_set(i)

counter = Counter(uf.p)

ans = [counter[uf.p[i]] - 1 for i in range(n)]


def f(li):
    for e1, e2 in li:
        e1 -= 1
        e2 -= 1
        if uf.same(e1, e2):
            ans[e1] -= 1
            ans[e2] -= 1


f(ab)
f(cd)

print(*ans)


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

int main(){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    int cnt = 0;
    rep(i, n){
        if (x - a.at(i) >= 0){
            x -= a.at(i);
            cnt ++;
            if (i + 1 == n && x != 0) cnt --;
        }
        else break;   
    }
    cout << cnt << endl;
    return 0;
}

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

int n;
int p1=0,p2=0;
char ch[110];

int main()
{
    scanf("%s",ch);
    n=strlen(ch);
    for(int i=0;i<n;i++)
    {
        if(ch[i]=='C')
            p1=1;
        if(p1==1 && ch[i]=='F')
            p2=1;
        if(p1==1 && p2==1)
        {
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int dp[2][100010];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n);
  rep(i, n) cin >> a[i];
  vint sum(n+1);
  rep(i, n) sum[i+1] = sum[i]+a[i];
  int pans = 0, d = 0;
  rep(i, n) {
    if(i%2 && sum[i+1]+d >= 0) {
      pans += sum[i+1]+d+1;
      d -= sum[i+1]+d+1;
    } else if(!(i%2) && sum[i+1]+d <= 0) {
      pans -= sum[i+1]+d-1;
      d -= sum[i+1]+d-1;
    }
  }
  int nans = 0, e = 0;
  rep(i, n) {
    if(i%2 && sum[i+1]+e <= 0) {
      nans -= sum[i+1]+e-1;
      e -= sum[i+1]+e-1;
    } else if(!(i%2) && sum[i+1]+e >= 0) {
      nans += sum[i+1]+e+1;
      e -= sum[i+1]+e+1;
    }
  }
  cout << min(pans, nans) << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int cnt[5];
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cnt[a]++;
    cnt[b]++;
    cnt[c]++;
    if(cnt[5]==2&&cnt[7]==1)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  int n = S.size();
  if(S[n-1] != 's') {
    cout << S + "s" << endl;
  }else {
    cout << S + "es" << endl;
  }


}


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

using ll = long long;

int main()
{
    int N, T, A;
    std::cin >> N >> T >> A;
    std::vector<int> H(N);

    for (int i = 0; i < N; i++)
    {
        std::cin >> H[i];
    }

    int index = 1;
    double minTmp = std::abs(T - (double)H[0] * 0.006 - A);
    for (int i = 1; i < N; i++)
    {
        double tmp = std::abs(T - (double)H[i] * 0.006 - A);
        if (minTmp > tmp)
        {
            minTmp = tmp;
            index = i + 1;
        }
    }

    std::cout << index << std::endl;

}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int k, x;
    cin >> k >> x;

    for(int i = x - k + 1 ; i < x + k ; ++i){
        cout << i;
        if(i < x + k - 1){
            cout << ' ';
        }else{
            cout << endl;
        }
    }

    return 0;
}

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

int main()
{
   int n = 0;
    std::cin >> n;
    
    int a = 0;
    int b = 0;
    int c = 0;
    std::vector<std::vector<int>> happiness(n, std::vector<int>(3)); 
    
    std::cin >> a >> b >> c;
    // 初日
    happiness.at(0).at(0) = a;
    happiness.at(0).at(1) = b;
    happiness.at(0).at(2) = c;
    
    for(int index = 1; index < n; ++index)
    {
        std::cin >> a >> b >> c;
        happiness.at(index).at(0) = (std::max)(happiness.at(index - 1).at(1),happiness.at(index - 1).at(2)) + a;
        happiness.at(index).at(1) = (std::max)(happiness.at(index - 1).at(0),happiness.at(index - 1).at(2)) + b;
        happiness.at(index).at(2) = (std::max)(happiness.at(index - 1).at(0),happiness.at(index - 1).at(1)) + c;
    }
    
    std::cout << (std::max)({happiness.back().at(0), happiness.back().at(1), happiness.back().at(2)}) << std::endl;
}


Measured memory_bytes: 5760
/*
	@author: cheerioskun
*/
#pragma GCC target("popcnt")
#include "bits/stdc++.h"
#define f first
#define sc second
#define pb push_back
#define MOD 1000000007L
#define inf 0x3f3f3f3f
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
using namespace std;

int dp[3003][3003];
// sindex will be two bits. First bit tells me if I should go right or not. Second tells down or not;
int sindex[3003][3003];
int main(){
	fast_io
	string s, t;
	cin>>s>>t;
	int n = s.size(), m = t.size();
	for(int i = 0;i <= n; ++i){
		for(int j = 0;j <= m; ++j){
			dp[i][j] = 0;
			sindex[i][j] = 0;
		}
	}
	for(int i = n - 1;i >= 0; --i){
		for(int j = m - 1;j >= 0; --j){
			if(s[i] == t[j]){
				dp[i][j] = 1 + dp[i + 1][j + 1];
				sindex[i][j] = 3;
			}else{
				int op1 = dp[i][j + 1];
				int op2 = dp[i + 1][j];
				if(op1 > op2){
					dp[i][j] = op1;
					sindex[i][j] = 1;
				}else{
					dp[i][j] = op2;
					sindex[i][j] = 2;
				}
			}
		}
	}

	int i = 0, j = 0;
	while(sindex[i][j] > 0){
		if(s[i] == t[j]){
			cout<<s[i];
		}
		int tempi = (sindex[i][j] == 2) || (sindex[i][j] == 3);
		int tempj = (sindex[i][j] == 1) || (sindex[i][j] == 3);
		i += tempi;
		j += tempj;

	}
	cout<<endl;
	#ifndef ONLINE_JUDGE
    	cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}



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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;

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

	int n; std::cin >> n;
	int ans = n / 2;
	if (n % 2 == 0) ans--;
	std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;

int main() {
	LL K;
	cin >> K;
	int r = K % 50;
	cout << 50 << endl;
	for (int i = 0; i < 50; i++) {
		LL a = i + K / 50;
		if (i < r) a += 50 - (r - 1);
		else a -= r;
		if (i > 0) cout << " ";
		cout << a;
	}
	cout << endl;
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}
bool cmp(pint a, pint b) { return a.second < b.second; }
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,m;
  cin>>n>>m;
  vector<pint> v(m);
  rep(i,m) cin>>v[i].first>>v[i].second;
  sort(ALL(v),cmp);
  ll ans=0;
  ll endtime=0;
  rep(i,m){
    if(v[i].first>=endtime){
      endtime=v[i].second;
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=100010;
const int P=1000000007;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;//a-b昇順
}
//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ
//	cout<<(n-2)*180<<endl;
//	string s="hoge";
//	cout<<ans<<endl;
//	int  n  ,a  ,b  ,c  ,d  ,e  ,f  ;
//	cin  >>n  >>a  >>b  >>c  >>d  >>e  >>f  ;

/*
	memset(b, '\0', sizeof(b));
初期化*/
/*
	len = strlen(s);
文字列長さ*/
/*
	string s;
	s.size()
*/
/*ソート
	qsort(b, 10, sizeof(int), compare_int);
*/
/*
	char s[N];
	strlen(s)
/*
	if(  <  )puts("YES");
	else puts("NO");
*/

int main(){
	int n, b[N],ans=0;
	memset(b, '\0', sizeof(b));
	cin>>n;
	rep(i, n){
		cin>>b[i];
	}
	qsort(b, n, sizeof(int), compare_int);

	ans= b[n/2] -b[n/2-1] ;
	cout<<ans<<endl;



}

Measured memory_bytes: 1020
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    vvi a(N, vi(N));
    REP(i, N)
    {
        REP(j, N)
        {
            cin >> a[i][j];
        }
    }
    vi f(1 << N);
    REP1(p, (1 << N) - 1)
    {
        REP(i, N)
        {
            REP(j, N)
            {
                if (i < j and ((p >> i) & 1) and ((p >> j) & 1))
                {
                    f[p] += a[i][j];
                }
            }
        }
    }
    vi dp(1 << N);
    REP1(i, (1 << N) - 1)
    {
        ll j = i;
        while (j > 0)
        {
            CH(max, dp[i], f[j] + dp[i - j]);
            j = (j - 1) & i;
        }
    }
    OUT(dp[(1 << N) - 1]);
}

Measured memory_bytes: 1280
#include "ctype.h"
#include <iostream>
#include <string>

int main(int argc, char const* argv[])
{
	std::string str;
	int i = 0;

	std::getline(std::cin, str);

	for (size_t i = 0; i < str.size(); i++)
	{
		if (isupper(str[i]))
		{
			str[i] = tolower(str[i]);
			std::cout <<  str[i];
		}
		else if (islower(str[i]))
		{
			str[i] = toupper(str[i]);
			std::cout << str[i];
		}
		else
			std::cout << str[i];
	}

	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

const int mod = 1000000007;
const int N = 200010;
vector<int> v[2];

bool cmp(int x, int y) {
	return x > y;
}

long double sum[2][N];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	int zeros = 0;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		if (x < 0) v[0].push_back(-x);
		else if (x > 0) v[1].push_back(x);
		else zeros++;
	}

	sort(v[0].begin(), v[0].end(), cmp);
	sort(v[1].begin(), v[1].end(), cmp);

	for (int i = 0; i < 2; i++) {
		for (int j = 1; j <= v[i].size(); j++)
			sum[i][j] = sum[i][j - 1] + log(v[i][j - 1] * 1.0);
	}

	bool flag = false;

	long double mx = -1e30;
	int x = -1, y = -1;
	for (int i = 0; i <= v[0].size() && i <= m; i += 2) {
		int j = m - i;
		if (j > v[1].size()) continue;
		if (mx < sum[0][i] + sum[1][j]) {
			mx = sum[0][i] + sum[1][j];
			x = i, y = j;
			flag = true;
		}
	}

	if (flag) {
		int ans = 1;
		for (int i = 0; i < x; i++)
			ans = 1LL * ans * v[0][i] % mod;
		for (int i = 0; i < y; i++)
			ans = 1LL * ans * v[1][i] % mod;
		printf("%d\n", ans);
		return 0;
	}

	if (!flag) {
		if (zeros) {
			printf("0\n");
			return 0;
		}
	}

	memset(sum, 0, sizeof(sum));
	sort(v[0].begin(), v[0].end());
	sort(v[1].begin(), v[1].end());

	mx = 1e30;
	x = -1, y = -1;
	for (int i = 0; i < 2; i++) {
		for (int j = 1; j <= v[i].size(); j++)
			sum[i][j] = sum[i][j - 1] + log(v[i][j - 1] * 1.0);
	}

	for (int i = 0; i <= v[0].size() && i <= m; i ++) {
		int j = m - i;
		if (j > v[1].size()) continue;
		if (mx > sum[0][i] + sum[1][j]) {
			mx = sum[0][i] + sum[1][j];
			x = i, y = j;
		}
	}


	int ans = 1;
	for (int i = 0; i < x; i++)
		ans = 1LL * ans * v[0][i] % mod;
	for (int i = 0; i < y; i++)
		ans = 1LL * ans * v[1][i] % mod;
	ans = mod - ans;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 10148
#include <stdio.h>
 
int main()
{
  char a[4],b[4];
  scanf("%s%s",&a,&b);
  char c[7];
  int i;
  int k;
  i = 0;
  while (a[i])
  {
    c[i] = a[i];
    i++;
  }
  while (b[k])
  {
    c[i] = b[k];
    i++;
    k++;
  }
  c[i] = '\0';
  int d;
  i = 0;
  d = 0;
  while (c[i + 1])
  {
    d += c[i] - '0';
    d *= 10;
    i++;
  }
  d += c[i]-'0';
  i = 0;
  while (i * i < d)
  {
    i++;
  }
  if (i*i == d)
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const INFINITY = math.MaxInt64/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	k := stdin.ReadInt()

	a := make([]int, k+1)
	for x := k; x >= 1; x-- {
		a[x] = ModPow(k/x, n)
		for y := x * 2; y <= k; y += x {
			a[x] -= a[y]
			if a[x] < 0 {
				a[x] += MOD
			}
		}
	}

	sum := 0
	for x := 1; x <= k; x++ {
		sum += x * a[x] % MOD
		sum %= MOD
	}

	stdout.Println(sum)
}

const MOD = 1000000007

var FCT = []int{1}

func ModPow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x = (x * x) % MOD
			y /= 2
		} else {
			z = (z * x) % MOD
			y--
		}
	}
	return z
}

func ModInv(x int) int {
	return ModPow(x, MOD-2)
}

func C(n, r int) int {
	for i := len(FCT); i <= n; i++ {
		FCT = append(FCT, FCT[i-1]*i%MOD)
	}
	return FCT[n] * (ModInv(FCT[n-r]) * ModInv(FCT[r]) % MOD) % MOD
}

func H(n, r int) int {
	return C(n+r-1, r)
}

func NoCacheC(n, r int) int {
	numer := 1
	denom := 1
	for i := 0; i < r; i++ {
		numer = numer * (n - i) % MOD
		denom = denom * (i + 1) % MOD
	}
	return numer * ModInv(denom) % MOD
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

struct UnionFind {
	vector<int> data;
	// ?????????
	void init(int n) {
		data.assign(n, -1);
	}
	// x ??¨ y ?????????
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	// x ??¨ y ?????????????????????????????????
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	// x ??????????????????????´???°????±???????
	int size(int x) {
		return -data[root(x)];
	}
	// ????????¢???
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
};

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

	UnionFind uf;
	uf.init(n);

	rep(i, q) {
		int c, x, y;
		cin >> c >> x >> y;

		if (c == 0) {
			uf.unionSet(x, y);
		} else {
			cout << uf.findSet(x, y) << endl;
		}
	}
}

Measured memory_bytes: 1232