akhauriyash/Code-Regression huggingface dataset:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

l= "abcdefghijklmnopqrstuvwxyz"
n=int(input())
a=[1,26]
b=[1,26]
ans=[]
if n==1:
    print("a")
    exit()
for i in range(13):
    a.append(a[-1]*26)
    b.append(b[-1]+a[-1])
for i in range(15):
    if n<=b[i]:
        c=i
        m=n-b[i]-1
        break
for i in range(c,0,-1):
    m,ind=divmod(m,26)
    ans.append(l[ind])
ans=reversed(ans)
print(*ans,sep="")

Measured memory_bytes: 10364
#include <iostream>
using namespace std;
int main() {
  long x;
  cin >> x;
  long result = 0;
  for (int i=1; i < x+1; i++) {
  	if (i%3!=0 && i%5!=0) {
      result += i;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3192
#include<iostream>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
#define fr first
#define sc second
#define MAX 101
#define INFTY 1000000000
int cost[MAX][MAX];
int min_cost[MAX];
bool used[MAX];
int n,m;
int prim(){
  int res = 0;
  for(int i=0;i<n;i++){
    min_cost[i] = INFTY;
    used[i] = false;
  }
  min_cost[0] = 0;
  while( true ){
    int v = -1;
    for(int u=0 ; u < n ; u++ ){
      if( !used[u] && (v == -1 || min_cost[u] < min_cost[v]) ){
        v = u;
      }
    }
    if(v == -1) break;
    used[v] = true;
    res += min_cost[v];
    for(int u=0 ; u < n ; u++ ){
      min_cost[u] = min( min_cost[u] , cost[v][u] );
    }
  }
  return res;
}
int main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        cost[i][j] = INFTY;
      }
    }
    cin >> m;
    for(int i=0,a,b,c;i<m;i++){
      scanf("%d,%d,%d",&a,&b,&c);
      cost[a][b] = cost[b][a] = (c-100)/100;
    }
    cout  << prim() << endl;
  }
}

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

int main()
{
    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];

    int cnt=0;
    for(int i=0;i<=N-2;i++){
        for(int j=N-1;j-1>=i;j--){
            if(a[j-1]>a[j]) swap(a[j-1],a[j]),cnt++;
        }
    }
    for(int i=0;i<N;i++){
        cout<<a[i]<<(i==N-1? '\n':' ');
    }
    cout<<cnt<<endl;
    return 0;
}


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


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


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//ll INF = 100000000 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	string s ; cin >> s ;
	char c = s.at(0) ;
	vll one,zero ;
	if(c=='0') one.push_back(0) ;
	ll cnt = 0 ;
	for(int i=0;i<n;i++){
		if(c=='1'){
			if(s.at(i)=='1') cnt++ ;
			else{
				one.push_back(cnt) ;
				cnt = 1 ;
				c = '0' ;
			}
		}else{
			if(s.at(i)=='0') cnt++ ;
			else{
				zero.push_back(cnt) ;
				cnt = 1 ;
				c = '1' ;
			}
		}
	}
	if(c=='1') one.push_back(cnt) ;
	else{
		zero.push_back(cnt) ;
		one.push_back(0) ;
	}
	if(zero.size()<=k) cout << n << endl ;
	else{
		ll ans = 0 ;
		vll sum_zero(zero.size()+1,0) ;
		for(int i=1;i<=zero.size();i++) sum_zero.at(i) = sum_zero.at(i-1)+zero.at(i-1) ;
		vll sum_one(one.size()+1,0) ;
		for(int i=1;i<=one.size();i++) sum_one.at(i) = sum_one.at(i-1)+one.at(i-1) ;
		for(int i=0;i<zero.size()-k+1;i++){
			ll sub = sum_zero.at(i+k)-sum_zero.at(i)+sum_one.at(i+k+1)-sum_one.at(i) ;
			if(ans<sub) ans = sub ;
		}
		cout << ans << endl ;
	}
}


Measured memory_bytes: 2164
n = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if L[i] != L[j] != L[k] != L[i]:
        if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j]:
          ans += 1
print(ans)


Measured memory_bytes: 68184
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	long N,M,T[105],P[105],X[105],L[105],sum=0;
	while(scanf("%ld",&N)!=EOF)
	{
		for(int i=1;i<=N;i++)
		{
			scanf("%ld",&T[i]);
			sum+=T[i];
		}
		scanf("%ld",&M);
		for(int i=1;i<=M;i++)
		{
			scanf("%ld%ld",&P[i],&X[i]);
			L[P[i]]=X[i]-T[P[i]];
			printf("%ld\n",sum+L[P[i]]);
		}	
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 2e5 + 1;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s; cin >> s;
    map<char, int> mp;
    for (int i = 0; i < s.size(); i++)
        mp[s[i]] = 1;
    if (mp['N'] + mp['S'] == 1 ||
        mp['E'] + mp['W'] == 1) {
            cout << "No";
            return 0;
        }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder output = new StringBuilder();
		int n = scan.nextInt();
		int m = scan.nextInt();
		int l = scan.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		long[][] AB = new long[n][l];
		
		// A,Bの成分を代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < l; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		// ABの成分の計算
		long sum_ij = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < l; j++) {
				for (int k = 0; k < m; k++) {
					sum_ij += A[i][k] * B[k][j];
				}
				AB[i][j] = sum_ij;
				sum_ij = 0;
			}
		}
		
		// 出力
		for (int i = 0; i < n; i++) {
			output.append(AB[i][0]);
			for (int j = 1; j < l; j++) {
				output.append(" ").append(AB[i][j]);
			}
			output.append('\n');
		}
		System.out.print(output);
		scan.close();
	}

}

Measured memory_bytes: 45068
def inc(s):
	ans = s[:-1]
	# print(ans)
	# print(chr(ord(s[-1]) + 1))
	ans += chr(ord(s[-1]) + 1)
	return ans


s = input()

# if s[0] == 'z':
# 	print(-1)
# 	exit(0)

w = []
for i in range(26):
	w += chr(i + ord('a'))
# print(w)
for l in w:
	if l not in s:
		print(s + l)
		exit(0)


for i in range(1, 26):
	# incerc sa inlocuiesc ultimele i
	ans = s[:-i]
	# print("ans " + ans)
	# print(ans[:-1])
	for l in w:
		if l not in ans[:-1] and ord(l) > ord(ans[-1]):
			print(ans[:-1] + l)
			exit(0)
	# print(ans)
print(-1)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int a,b,n,ans;
	while(cin>>a>>b>>n){
		ans=0;
		a%=b;
		for(int i=0;i<n;i++){
			a*=10;
			ans+=a/b;
			a%=b;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define pi 2.0*acos(0.0)
#define INTM 1e18
#define mod 1e9+7
#define FOR(i,j,n)    for(ull i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    ll n,a;
    cin>>n;
    string s,ss,sss;
    FOR(i,0,n){
        cin>>a;
        s += to_string(a);
    }

    FOR(i,0,n){
        cin>>a;
        ss += to_string(a);
    }

    FOR(i,1,n+1){
        sss += to_string(i);
    }
    ll fi,li,counter = 0;
    do{
        counter++;
        if(sss == s) fi = counter;
        if(sss == ss) li = counter;
    }while(next_permutation(sss.begin(),sss.end()));
    cout<<abs(fi-li)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();


int main()
{
  int H,W,K;
  cin>>H>>W>>K;
  char s[H][W];
  REP(i,H)REP(j,W)cin>>s[i][j];
  int a[H][W];
  REP(i,H)REP(j,W)a[i][j]=0;
  bool exist[H];
  REP(i,H) exist[i] = false;
  int maxY=0;
  REP(i,H)REP(j,W){
    if (s[i][j]=='#'){
      exist[i] = true;
      maxY = i;
    }
  }
  int val = 1;
  for(int i=0;i<=maxY;i++){
    if (exist[i]){
      int cnt=0;
      for (int j=0;j<W;j++){
        if (s[i][j]=='#'){
          cnt++;
          if (cnt>1) val++;
        }
        a[i][j] = val;
      }
      val++;
    }
  }
  for (int i=maxY+1;i<H;i++){
    REP(j,W) a[i][j] = a[maxY][j];
  }
  int tmpidx=maxY;
  for (int i=maxY;i>=0;i--){
    if (!exist[i]){
      REP(j,W) a[i][j] = a[tmpidx][j];
    }else{
      tmpidx = i;
    }
  }
  REP(i,H){
    REP(j,W) cout<<a[i][j]<<' ';
    cout<<endl;
  }
  return 0;
}

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


int main(){
  int64_t X;
  cin >> X;
  for(int64_t i=-120;i<=120;i++){
    for(int64_t j=-120;j<=i;j++){
      int64_t A=i*i*i*i*i;
      int64_t B=j*j*j*j*j;
      if(X==A-B){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  
}


Measured memory_bytes: 3608
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
if s == 'Sunny':
    print('Cloudy')
if s == 'Cloudy':
    print('Rainy')
if s == 'Rainy':
    print('Sunny')

Measured memory_bytes: 3060
function Main(arg) {
 
    var N = arg.split("\n")[0] - 0;
    var A = arg.split("\n")[1].split(" ");
    var B = arg.split("\n")[2].split(" ");
    var C = arg.split("\n")[3].split(" ");

    var ans = 0;
    for (var i = 0; i < N; i++){
        ans += (B[A[i]-1] - 0);
        if (i >= 1) {
            var a = A[i] - 0;
            var b = A[i - 1] - 0;
            if (a - b === 1) {
                ans += (C[A[i] - 2]-0);
            }
        }
    }

    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
	int n;
	while(cin >> n && n){
		int k[101] = {0};
		for(int i = 0; i < n; ++i){
			cin >> k[i];
		}
		char s[128];
		scanf("%s", s);
		for(int i = 0; i < strlen(s); ++i){
			if(s[i] - k[i % n] <= 64 && s[i] <= 90){
				s[i] = s[i] - k[i % n] + 52;
				if(s[i] > 90)
					s[i] += 6;
			}
			else if(70 < s[i] - k[i % n] && s[i] - k[i % n] < 97 && s[i] >= 97){
				s[i] = s[i] - k[i % n] - 6;
			}
			else if(s[i] >= 97 && s[i] - k[i % n] <= 70){
				s[i] = 52 + s[i] - k[i % n];
			}
			else{
				s[i] -= k[i % n];
			}
		}
		printf("%s\n", s);
	}
	/*printf("%d\n", 'A');
	printf("%d\n", 'Z');
	printf("%d\n", 'a');
	printf("%d\n", 'z');
	printf("%d\n", '@');*/
	return 0;
}

Measured memory_bytes: 1140
#include <iostream>

int main() {
    while( true ) {
        int h , w ;
        std::cin >> h >> w ;
        if( h | w ) {
            for( int i = 0 ; i < h ; i++ ) {
                for( int ii = 0 ; ii < w ; ii++ ) {
                    if( ( i + ii ) % 2 == 0 ) {
                        std::cout << "#" ;
                    } else {
                        std::cout << "." ;
                    }
                }
                std::cout << std::endl ;
            }
            std::cout << std::endl ;
        } else {
            break ;
        }
    }
}




Measured memory_bytes: 3100
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    set<ll> s;
    while (k--)
    {
        ll d, a;
        cin >> d;
        while (d--)
            cin >> a, s.insert(a);
    }
    cout << n - s.size();
}

Measured memory_bytes: 3616
#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 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll modncr(ll a, ll b){
    ll X = 1,Y = 1;
    for(int i = 1; i < b+1;i++){
        X = (X*(a-i+1))%mod;
        Y = (Y*i)%mod;
    }
    Y = modInverse(Y,mod);
 
    return (X*Y)%mod;
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,a,b;
	cin>>n>>a>>b;

	ll an=(power(2,n,mod)-1+mod)%mod;
	an=(an-modncr(n,a)+mod)%mod;
	an=(an-modncr(n,b)+mod)%mod;
	cout<<an;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin>>n;
  int x=n%10;
  if(x==3)
    cout<<"bon"<<endl;
  else if(x==0||x==1||x==6||x==8)
    cout<<"pon"<<endl;
  else
    cout<<"hon"<<endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner io = new Scanner(System.in);
		int H = io.nextInt();
		int W = io.nextInt();
		int N = io.nextInt();
		int[][] map = new int[H][W];
		int color = 1;
		int num = io.nextInt();
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(num==0){
					color ++;
					num = io.nextInt();
				}
				if(i%2==0){
					map[i][j] = color;
				}else{
					map[i][W-1-j] = color;
				}
				num --;
			}
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				System.out.print(map[i][j]);
				System.out.print((j==W-1)?"\n":" ");
			}
		}
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

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

int main(void){
    int n = 0; 

    scanf("%d", &n);

    if(n / 100 == 1){
        printf("9");
        n -= 1 * 100;
    }else{
        printf("1");
        n -= 9 * 100;
    }

    if(n / 10 == 1){
        printf("9");
        n -= 1 * 10;
    }else{
        printf("1");
        n -= 9 * 10;
    }
    if(n == 1){
        printf("9");
    }else{
        printf("1");
    }
    printf("\n");
    return 0;

} 


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

int q,sum=0;
vector<pair<char,int> > v;
vector<char> f,b;
string s;

int main()
{
	cin >> s >> q;
	for(int i=0;i<q;i++)
	{
		int x;
		cin >> x;
		if(x == 1)
			sum++; 
		else
		{
			int y;
			char c;
			cin >> y >> c;
			y--;
			if((sum+y)%2)
				b.push_back(c);
			else
				f.push_back(c);
		}
	}
	if(sum%2)
	{
		for(int i=b.size()-1;i >= 0;i--)
			cout << b[i];
		for(int i=s.size()-1;i >= 0;i--)
			cout << s[i];
		for(int i=0;i<f.size();i++)
			cout << f[i];
	}
	else
	{ 
		for(int i=f.size()-1;i >= 0;i--)
			cout << f[i];
		for(int i=0;i<s.size();i++)
			cout << s[i];
		for(int i=0;i<b.size();i++)
			cout << b[i]; 	
	}	 
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n;
    x = n/2;
    y = n-x;
    cout<<((1.0)*y)/n;    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>a,b,c;
int main(){
	int n,i,j;
	scanf("%d",&n);
	a.resize(n+1);b.resize(n+1);c.resize(n+1);
	for(i=1;i<=n;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	int dp[n+1][4];
	dp[1][1]=a[1];
	dp[1][2]=b[1];
	dp[1][3]=c[1];
	for(i=2;i<=n;i++){
			dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
			dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
			dp[i][3]=max(dp[i-1][2],dp[i-1][1])+c[i];
	}
	int ans=max(dp[n][1],dp[n][2]);
	ans=max(ans,dp[n][3]);
	cout<<ans<<endl;
}

Measured memory_bytes: 2944
#include<stdio.h>

int w, h;
int map[50][50];

void visit(int x, int y){
	int i, j;
	if (x < 0 || x >= w || y < 0 || y >= h) return;
	if (map[y][x] == 0) return;
	map[y][x] = 0;
	for (i = -1; i <=1; i++){
		for (j = -1; j <=1; j++){
			visit(x + i, y + j);
		}
	}
}

int main(void){
	int i, j;
	int ans;
	while (scanf("%d %d", &w, &h), w != 0 || h != 0){
		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				scanf("%d", &map[i][j]);
			}
		}
		ans = 0;
		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				if (map[i][j]){
					ans++;
					visit(j, i);
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

int main(){

  long long MAX_N = 200002;
  long long n;
  long long k;
  cin >> n >> k;

  vector<pair<long long,long long>> count(MAX_N,pair<int,int>(0,0));
  vector<long long> move(n);
  for(long long i=0;i<n;i++){
    long long to;
    cin >> to;to--;
    move[i] = to;
  }

  bool flag = 0;//サイクルに入ったら旗をあげる
  long long repCount = 0;//リープ一周の移動数
  long long countToStsrt = 0;//ループが始まるまでの移動回数

  int now=0;
  while(k>0){
    count[now].first++;
    if(count[now].first==1)count[now].second = k;
    if(count[now].first==2 && flag==0){
      flag=1;
      repCount=count[now].second - k;
      k = k%repCount;
      for(int i=0;i<k;i++){
        now=move[now];
      }
      cout << now+1 << endl;
      break;
    }


    k--;//移動回数を減らす
    now=move[now];
    if(k==0)cout << now+1 << endl;
  }

}

Measured memory_bytes: 8004
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>



ll n;
int main() {
	cin >> n;
	ll cnt = 0;
	REPO(i, n) {
		string s = to_string(i);
		if (s.size() % 2 == 1)cnt++;
	}
	cout << cnt << endl;
}
	


Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  double x[N];
  string u[N];
  double sum = 0;
  for(int i=0;i<N;i++){
    cin >> x[i] >> u[i];
    if(u[i] == "JPY") sum += x[i];
    else sum += x[i]*380000.0;
  }
  cout << sum << endl;
  return 0;
}

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

int main(){
  int S;cin>>S;
  set<int> A;
  A.insert(S);
  int X=S;
  int M=2;
  while(true){
    if(X%2==1) X=3*X+1;
    else X/=2;
    if(A.count(X)) break;
    else{
      A.insert(X);
      M++;
    }
  }
  cout<<M<<endl;
}
    


Measured memory_bytes: 3512
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def euclid(a, b):
        if b == 0:
            return a
        else:
            return euclid(b, a % b)

    def multiple(a, b):
        return a * b // euclid(a, b)

    n, m = ns()
    s = list(input())
    t = list(input())

    gcd = multiple(n, m)

    s_idx = [gcd // n * i for i in range(n)]
    t_idx = [gcd // m * i for i in range(m)]
    t_set = set(t_idx)

    for idx in s_idx:
        if idx in t_set:
            if s[idx * n // gcd] != t[idx * m // gcd]:
                print(-1)
                exit(0)

    print(gcd)


if __name__ == '__main__':
    main()


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

class Program {
    static void Main(string[] args) {
        var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var c = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var d = new int[9];
        a.CopyTo(d, 0);
        b.CopyTo(d, 3);
        c.CopyTo(d, 6);
        bool flag = false;
        if (d[0] - d[1] == d[3] - d[4] && d[0] - d[1] == d[6] - d[7] && d[1] - d[2] == d[4] - d[5] && d[1] - d[2] == d[7] - d[8] && d[0] - d[3] == d[1] - d[4] && d[0] - d[3] == d[2] - d[5] && d[3] - d[6] == d[4] - d[7] && d[3] - d[6] == d[5] - d[8]) {
            flag = true;
        }
        Console.WriteLine(flag ? "Yes" : "No");
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(begin);i>=(end);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

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

	string alph = "abcdefghijklmnopqrstuvwxyz";
	if (S.size() != 26) {
		// cout<<"length is not 26"<<endl;
		FOR(i, 0, 25) {
			bool contained = false;
			FOR(j, 0, S.size() - 1) {
				if (S[j] == alph[i]) {
					contained = true;
					break;
				}
			}
			if (!contained) {
				cout << S << alph[i] << endl;
				return 0;
			}
		}
	}
	else {
		vec Sid(26, -1);
		FOR(i, 0, 25) {
			FOR(j, 0, 25) {
				if (S[i] == alph[j]) {
					Sid[i] = j;
					break;

				}
			}
		}
		// int len = 26;
		ll minSid = 25;
		IFOR(i, 25, 0) {
			// cout<<Sid[i]<<endl;
			if (Sid[i] < Sid[i - 1]) {
				continue;
			}
			else {
				IFOR(j, 25, i) {
					if (Sid[j] > Sid[i - 1]) {

						minSid = min(minSid, Sid[j]);
					}
				}
				string ans = S.substr(0, i - 1) + alph.substr(minSid, 1);
				cout << ans << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
/*
  -------------
  Prateek Celly
  DA-IICT
  -------------
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll x=b/c,y=a/c;
  if(a%c==0) y--;
  x-=y;
  ll p=b/d,q=a/d;
  if(a%d==0) q--;
  p-=q;
  ll lcm=(c*d)/__gcd(c,d);
  ll m=b/lcm,n=a/lcm;
  if(a%lcm==0) n--;
  m-=n;
  //cout<<x<<p<<'\n';
  cout<<b-a+1-x-p+m;
  return 0;
}


Measured memory_bytes: 256
(defparameter abcde
  (loop repeat 5
        collect (read)))

(defparameter k (read))

(defun f (abcde k)
  (let ((a (first abcde))
        (e (fifth abcde)))
    (if (<= (- e a) k)
        "Yay!"
        ":(")))

(princ (f abcde k))


Measured memory_bytes: 12264
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
    int N,K;
    int point;
    int number;
    scanf("%d%d",&N,&K);
    std::vector<int> counter(200000,0);
    for (size_t i = 0; i < N; i++) {
        scanf("%d",&number);
        ++counter[number];
    }
    sort(all(counter),std::greater<int>());

    int ans=0;
    while (true) {
        if(counter[K]==0 || K >= counter.size()){
            break;
        }
        ans+=counter[K];
        ++K;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  rep(i,n){
    cin >> x[i] >> u[i];
  }
  
  double ans;
  rep(i,n){
    if(u[i]=="JPY"){
      ans += x[i];
    }else{
      ans += x[i]*380000.0;
    }
  }
  cout << ans << endl;
}


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

int main(){
	int N, D, X;
	cin >> N >> D >> X;
	int A;
	for(int i=0; i<N; i++){
		cin >> A;
		if(D%A!=0){
			X += D/A+1;
		} else {
			X += D/A;
		}
	}
	cout << X << endl;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[]
cnt=0
for i in range(N):
    A+=[list(map(int,input().split()))]
    sum=0
    for j in range(M):
        sum+=A[i][j]*B[j]
    if sum+C > 0:
        cnt+=1
    
print(cnt)


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



int main() {
    int n;
    cin >> n;
    
    int mx1, mx2, n1, n2;
    mx1 = mx2 = 0;
    n1 = n2 = 0;
    rep(i,n) {
        int a;
        cin >> a;
        
        if(a > mx1) {
            mx2 = mx1;
            n2 = n1;
            mx1 = a;
            n1 = i;
        }
        else if(a > mx2) {
            mx2 = a;
            n2 = i;
        }
    }
    
    rep(i,n) {
        if(i == n1)
            cout << mx2 << endl;
        else
            cout << mx1 << endl;
    }
    
    
    return 0;
}




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

int main() {
    vector<string> inputs;
    for (int i = 0; i < 1000000; ++i) {
        string input; cin >> input;
        if (input == "=") break;
        inputs.push_back(input);
    }
    
    int ans = stoi(inputs[0]);
    for (int i = 2; i < inputs.size(); i += 2) {
        int num = stoi(inputs[i]);
        string ope = inputs[i - 1];
        
        if (ope == "+") ans += num;
        else if (ope == "-") ans -= num;
        else if (ope == "*") ans *= num;
        else if (ope == "/") ans /= num;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    pair<string,int> sleep[n];
    for(int i=0;i<n;i++){
        string s;
        int a;
        cin >> s >> a;
        sleep[i].first = s;
        sleep[i].second = a;
    }
    string time;
    cin >> time;
    bool flag = false;
    int count = 0;
    for(int i=0;i<n;i++){
        if(flag){
            count += sleep[i].second;
        }
        if(sleep[i].first==time) flag = true;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
A,B,C = map(int,input().split(" "))
num1 = max(A,B,C)
num3 = min(A,B,C)
num2 = A+B+C-num1-num3
if (num1*2-num2-num3)%2 == 1:
    print((num1*2-num2-num3)//2+2)
else:
    print((num1*2-num2-num3)//2)


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

ll gcd(ll x,ll y){
  while(y!=0){
    ll r=x%y;
    x=y;y=r;
  }
  return x;
}

struct frac{
  ll x,y;
  frac(ll x,ll y):x(x),y(y){
    reduce();
  }
  frac operator+(const frac& f)const{
    return frac(x*(f.y)+f.x*(y),y*f.y);
  }
  frac operator-(const frac& f)const{
    return frac(x*(f.y)-f.x*(y),y*f.y);
  }
  frac operator*(const frac& f)const{
    return frac(x*f.x,y*f.y);
  }
  void reduce(){
    ll g=gcd(x,y);
    x/=g;
    y/=g;
    if(y<0){
      x=-x;y=-y;
    }
  }
};


int main(void) {
  ll n;
  cin >> n;
  frac t(4, n);
  REP(i, 1, 3501) {
    if (4 * i <= n) { continue; }
    REP(j, 1, 3501) {
      if (4.0 / n - 1.0 / i - 1.0 / j <= 0) { continue; }
      frac q = t - frac(1, i) - frac(1, j);
      if (q.x == 1 && q.y >= 1) {
	cout << i << " " << j << " " << q.y << endl;
	return 0;
      }
    }
  }
  assert (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

int n,arr[100],x,sum=0,ans;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
	cin>>n>>x;
	rep(i,0,n-1)
		cin>>arr[i],sum+=arr[i];
	sort(arr,arr+n);
	x-=sum;
	n+=x/arr[0];
	cout<<n;

}
	

Measured memory_bytes: 3588
#include <cstdio>
#define N 100005
int n;
struct edge{
    int to,next;
}e[N<<1];
int head[N],cnt;
void add(int u,int v){
    e[++cnt]=(edge){v,head[u]};
    head[u]=cnt;
}
int son[N];
int path[N],len;
bool dfs(int x,int fa){
    bool p=x==n;
    for(int i=head[x];i;i=e[i].next){
        int v=e[i].to;
        if(v==fa)continue;
        p|=dfs(v,x);
    }
    son[fa]+=son[x]+1;
    if(p){
        path[++len]=x;
        return true;
    }
    return false;
}
int main(){
    scanf("%d",&n);
    for(int i=1,u,v;i<n;++i){
        scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    dfs(1,0);
    int ans=0;
    for(int i=len;i>len/2;--i)
        ans+=son[path[i]]-son[path[i-1]];
    printf("%s\n",ans*2>n?"Fennec":"Snuke");
    return 0;
}

Measured memory_bytes: 7552
#include<iostream>
using namespace std;
int main()
{
	int n,h=0,m=0;
	char c;
	cin>>n;
	while(n--)
	{
		cin>>c;
		if(c=='I')h++;
		else h--;
		if(h>m)m=h;
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  if(a==1) a+=13;
  if(b==1) b+=13;
  if(a>b){
    cout << "Alice" << endl;
  }else if(a<b){
    cout << "Bob" << endl;
  }else{
    cout << "Draw" << endl;
  }
}

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

int main(){
    int a, b, c;
    cin >> a >> b;
    c = a + b;
    if(a % 3 == 0){
        cout << "Possible" << endl;
    }else if(b % 3 == 0){
        cout << "Possible" << endl;
    }else if(c % 3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
 }

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

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=2e5,mo=1e9+7;

int n,o,p;
ll f[N],a[N],k;

ll ksm(ll o,ll t)
{
	ll y=1;
	for(;t;t>>=1,o=o*o%mo)
	if(t&1)y=y*o%mo;
	return y;
}

int main()
{
	cin>>n>>k;
	for(int i=1;i*i<=n;++i)
	if(n%i==0){
		a[++o]=i;
		if(i*i%n)a[++o]=n/i;
	}
	sort(a+1,a+o+1); 
	ll ans=0;
	fo(i,1,o){
		f[i]=ksm(k,(a[i]+1)>>1);
		fo(l,1,i-1)if(a[i]%a[l]==0)f[i]=(f[i]-f[l]+mo)%mo;
		(a[i]&1)?ans=(ans+f[i]*a[i])%mo:ans=(ans+(f[i]*a[i]>>1))%mo;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#line 1 "test/DSL_1_A.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=jp"
#line 1 "data_structure/unionfind.hpp"


#line 1 "macro/macros.hpp"



/*
@title Macro
@category template
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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 int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;

const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";


#line 4 "data_structure/unionfind.hpp"
/*
@title 素集合データ構造(UnionFind Tree)
@category データ構造
@docs ../docs/data_structure/unionfind.md
*/
struct UnionFind{
    int n;
    vector<int> Parent;
    vector<int> sizes;
    UnionFind(int _n):n(_n),Parent(_n),sizes(_n,1){ rep(i,n)Parent[i]=i; }
    //find the root of x
    int root(int x){
        if(x!=Parent[x]){
        Parent[x] = root(Parent[x]);
        }
        return Parent[x];
    }
    //merge x and y
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        Parent[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return root(x) == root(y); }
    int size(int x){ return sizes[root(x)]; }
    int group_num(){
        set<int> s;
        for(int i = 0; i < n; ++i){
            s.insert(root(i));
        }
        return int(s.size());
    }
};

#line 3 "test/DSL_1_A.test.cpp"

int main(){
    int N, Q;
    cin >> N >> Q;
    UnionFind Tree(N);
    while(Q--){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            Tree.unite(x, y);
        }
        if(com == 1){
            cout << Tree.same(x, y) << endl;
        }
    }
}



Measured memory_bytes: 3312
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($X,$Y) =  explode(" ",trim(fgets(STDIN)));
$A = explode(" ",trim(fgets(STDIN)));

$tot = array_sum($A);
$half = intdiv($tot,2);
$amari = 0;
if ($half *2 != $tot) $amari=1;

$sum = 0;
$left = 0;
$right = 0;
for($i=0;$i<$N;$i++) {
  $sum +=$A[$i];
  if ($half <= $sum) {
    $prev = $sum - $A[$i];
    if ($tot == $sum || abs($half-$prev)<abs($half-$sum)) {
      //最後まで行ったらひとつ前のから
      //ひとつ前のほうがhalfとの差が少ないときは？
      $sum-=$A[$i];
    }
    //半分超えてしまった
    $left=abs($sum-$half);
    break;
  }
}
printf("%d\n",$left+abs(($tot-$sum)-$half));


Measured memory_bytes: 23200
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		String S = scan.next();

		char input[] = S.toCharArray();

		Arrays.sort(input);

		if (input[0] == input[1]) {
			System.out.println("No");
		} else if (input[1] == input[2]) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


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

template <typename T>
class imos3 {
	int n, m, l;
	vector<vector<vector<T>>> v;
public:
	imos3(int n, int m, int l) : n(n), m(m), l(l), v(n + 1, vector<vector<T>>(m + 1, vector<T>(l + 1))) {}
	T& val(int i, int j, int k) { assert(0 <= i && i < n && 0 <= j && j < m && 0 <= k && k < l); return v[i + 1][j + 1][k + 1]; }
	void add(int li, int lj, int lk, int ri, int rj, int rk, T x) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		assert(0 <= lk && lk <= rk && rk <= l);
		val(li, lj, lk) += x;
		if (ri < n) val(ri, lj, lk) -= x;
		if (rj < m) val(li, rj, lk) -= x;
		if (rk < l) val(li, lj, rk) -= x;
		if (rj < m && rk < l) val(li, rj, rk) += x;
		if (ri < n && rk < l) val(ri, lj, rk) += x;
		if (ri < n && rj < m) val(ri, rj, lk) += x;
		if (ri < n && rj < m && rk < l) val(ri, rj, rk) -= x;
	}
	void build() {
		for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++)  for (int k = 0; k <= l; k++) v[i][j][k] += v[i - 1][j][k];
		for (int i = 0; i <= n; i++) for (int j = 1; j <= m; j++)  for (int k = 0; k <= l; k++) v[i][j][k] += v[i][j - 1][k];
		for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++)  for (int k = 1; k <= l; k++) v[i][j][k] += v[i][j][k - 1];
	}
	T sum(int li, int lj, int lk, int ri, int rj, int rk) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		assert(0 <= lk && lk <= rk && rk <= l);
		return v[ri][rj][rk] - v[li][rj][rk] - v[ri][lj][rk] - v[ri][rj][lk]
			+ v[ri][lj][lk] + v[li][rj][lk] + v[li][lj][rk] - v[li][lj][lk];
	}
};

void press(vector<ll>& v, int& size, vector<ll>& vs) {
	vs = v;
	sort(vs.begin(), vs.end());
	vs.erase(unique(vs.begin(), vs.end()), vs.end());
	for (auto& val : v) {
		val = lower_bound(vs.begin(), vs.end(), val) - vs.begin();
	}
	size = vs.size();
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K, h, w, d;
	cin >> N >> K;
	vector<ll> x(N * 2), y(N * 2), z(N * 2);
	for (int i = 0; i < N * 2; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}
	vector<ll> xs, ys, zs;
	press(x, h, xs), press(y, w, ys), press(z, d, zs);
	imos3<int> im(h, w, d);
	for (int i = 0; i < N; i++) {
		im.add(x[i * 2], y[i * 2], z[i * 2], x[i * 2 + 1], y[i * 2 + 1], z[i * 2 + 1], 1);
	}
	im.build();
	ll res = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int k = 0; k < d; k++) {
				if (im.val(i, j, k) >= K) {
					res += (xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]) * (zs[k + 1] - zs[k]);
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 7336
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n; cin >> n;
    vector<string> s(n);
    map<string, ll> m;

    REP(i,n) {
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
        m[s[i]] ++;
    }

    ll ans = 0;
    for(auto v : m) {
        ans += (v.second - 1 ) *  v.second / 2;
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

ll median (ll x, ll y, ll z) {
	vl a = {x,y,z};
	sort(all(a));
	return a[1];
}

void brute(ll m) {
	vl p(m);
	iota(all(p),1);
	vl cnt(m+1);
	do {
		vl a = p;
		while (sz(a) > 1) {
			vl na(sz(a)-2);
			FOR(i,0,sz(na)) na[i] = median(a[i],a[i+1],a[i+2]);
			a = na;
		}
		if (!cnt[a[0]]) {
			cout << a[0] << endl;
			FOR(i,0,m) cout << p[i] << " \n"[i+1 == m];
		}
		cnt[a[0]]++;
	} while (next_permutation(all(p)));
	FOR(i,1,m+1) cout << i << " " << cnt[i] << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//brute(11);
	ll n, x; cin >> n >> x;
	
	if (x == 1 || x == 2*n-1) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	
	bool flip = x > n;

	vl a(2*n+1);

	if (flip) x = 2*n-x;

	a[n-1] = x;
	
	FOR(i,n,2*n-1) a[i] = i+1;
	ll cur = n;
	FOR(i,0,n-1) {
		if (cur == x) cur--;
		a[i] = cur--;
	}
	
	if (flip) FOR(i,0,2*n-1) a[i] = 2*n-a[i];

	FOR(i,0,2*n-1) cout << a[i] << "\n";

}



Measured memory_bytes: 3072
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s;
    R(s);
    int an=0;
    for(int i=0;i<SZ(s)-1-i;i++){
        if(s[i]!=s[SZ(s)-1-i])an++;
    }
    W(an);
    return 0;
}


Measured memory_bytes: 256