akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar

using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
const int N= (int) 1e5+10;
int n;
V<int> a[N];
int nim[N];

void input()
{
	cin>>n;
	up(i,1,n-1)
	{
		int x,y; cin>>x>>y;
		a[x].pb(y); a[y].pb(x);
	}
}
void dfs(int u,int p)
{
	nim[u]= 0;
    for (auto v: a[u])
		if (v!=p)
		{
			dfs(v,u);
			nim[u]^= (nim[v]+1);
		};
}
void solve()
{
	dfs(1,-1);
	if (nim[1]) cout<<"Alice"; else cout<<"Bob";

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive
    #define TASK "tmp"
  //  freopen(TASK".inp","r",stdin);
   // freopen(TASK".out","w",stdout);

    input();
    solve();

    return 0;
}


Measured memory_bytes: 12416
#include <stdio.h>
int f(int n)
{
    int sum = 0;
    while(n)
    {
        int x = n%10;
        sum+=x;
        n/=10;
    }
    return sum;
}
int main (void)
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n%f(n)==0)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	long N;cin>>N;
	long long count_pairs = 0; 

	// count total pairs 
	for (long i = 1; i <= sqrt(N - 1); ++i) { 
		for (long j = i; j * i < N; ++j) 
			++count_pairs; 
	} 

	// multiply by 2 to get ordered_pairs 
	count_pairs *= 2; 

	// subtract redundant pairs (a, b) where a==b. 
	count_pairs -= long(sqrt(N - 1)); 

	// return answer 
	cout<<count_pairs<<"\n"; 
	return 0;
}

Measured memory_bytes: 3664
x, k, d = gets.chomp.split.map(&:to_i)

if (x.abs / d) >= k
  puts x.abs - (d * k)
elsif (k - (x.abs / d)) % 2 == 0
  puts x.abs - (d * (x.abs / d))
else
  puts (d * ((x.abs / d) + 1)) - x.abs
end

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n;
    cin >> n;

    vector<int64_t> a(n), b(n);
    for (auto i : irange(0L, n)) {
        cin >> a[i] >> b[i];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if (n % 2 == 0) {
        cout << (b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1]) + 1
             << endl;
    } else {
        cout << b[n / 2] - a[n / 2] + 1 << endl;
    }
}

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

int main(){
  string n;
  cin>>n;
  for(int i=0;i<3;i++){
    if(n.at(i)=='1'){n.at(i)='9';}
    else{n.at(i)='1';}
  }
  
  cout <<n<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();

		System.out.println(solve(H, W, N));
	}

	private static int solve(int h, int w, int n) {
		if (h > w) w = h;
		return (n / w) + ((n % w > 0) ? 1 : 0);
	}
}


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

int main() {
    int N, K; cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    ll mx, cnt, cost, ans = MAX;
    rep(i, (1<<N)) {
        mx = cnt = cost = 0;
        rep(j, N) {
            if (mx < a[j]) {
                cnt++;
                mx = a[j];
            }
            else if ((i>>j)&1) {
                cost += mx - a[j] + 1;
                mx++;
                cnt++;
            }
        }
        if (cnt >= K) ans = min(ans, cost);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}




int main(){
  int N;
  cin>>N;
  string s="";
  string ans;
  int num=N;
  while(num!=0){
    int r=num%2;
    //rの偶奇判断のため1タス
    if(r<0){
      r+=2;
    }
    num=(num-r)/-2;
    ans+='0'+r;
  }
  reverse(ans.begin(),ans.end());
  if(ans.size()==0){
    cout<<0<<endl;
  }else{
    cout<<ans<<endl;
  }






  

  



}


  

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/


/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/

ll solve(){
    cin >> n;  
    a.resize(n);
    REP(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    bool flag = true;
    REP(i, n-1){
        if(a[i] == a[i+1]){flag = false;}
    }
    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int a,b,c;
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		if(a>b+c)
		{
			System.out.println("0");
		}
		else
		{
			System.out.println(Math.abs(b+c-a));
		}
	}
}

Measured memory_bytes: 21716
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    char ch;
    while(cin>>ch)
    {
        if(ch=='9') cout<<'1';
        else cout<<'9';
    }
}


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

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

    int n; cin >> n;
    int v[n]; for (int i = 0; i < n; ++i) cin >> v[i];

    map<int, int> odds, evens;
    odds[0] = 0; evens[0] = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) odds[v[i]] = odds.count(v[i]) > 0 ? odds[v[i]] + 1 : 1;
        else evens[v[i]] = evens.count(v[i]) > 0 ? evens[v[i]] + 1 : 1;
    }

    vector< pair<int, int> > odds_v(odds.size()), evens_v(evens.size());
    copy(odds.begin(), odds.end(), odds_v.begin());
    copy(evens.begin(), evens.end(), evens_v.begin());

    sort(odds_v.begin(), odds_v.end(), [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });
    sort(evens_v.begin(), evens_v.end(), [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });

    if (odds_v[0].first != evens_v[0].first) {
        cout << n - odds_v[0].second - evens_v[0].second << endl;
    } else {
        cout << min(n - odds_v[0].second - evens_v[1].second, 
                n - odds_v[1].second - evens_v[0].second) << endl;
    }

    return 0;
}

Measured memory_bytes: 6144
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
        string a,b;
        cin>>a>>b;
        a+=b;
        double out=0;
        int flag=0;
        for(int i=1;i<=a.size();i++)
        {
            out+=(a[i-1]-48)*pow(10,a.size()-i);
        }
        for(int i=1;i*i<=out;i++)
        {
            if(i*i==out)
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
            cout<<"No";
        else
            cout<<"Yes";
        return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef struct D
{
	int x,y,d,h[2];
}D;

D tmp;
char M[55][55];
bool f[55][55]={0};
int H,W,flg[55][55][4],s[3],g[2],mv[9][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};

void dbg()
{
	for(int i=0;i<=H+1;i++,puts(""))
		for(int j=0;j<=W+1;j++)
			putchar(M[i][j]);
}

int main() 
{
	memset(flg,0x7f,sizeof(flg));
	scanf("%d%d\n",&H,&W);
	for(int i=1;i<=H;i++)
		gets(M[i]+1);
	for(int i=0;i<=H+1;i++)
	{
		M[i][0]=M[i][W+1]='#';
		if(i==0||i==H+1)
			for(int j=1;j<=W;j++)
				M[i][j]='#';
	}
	for(int i=0;i<=H+1;i++)
		for(int j=0;j<=W+1;j++)
		{
			if(M[i][j]=='G')
			{
				g[0]=i;g[1]=j;
				M[i][j]='.';
			}
			else if(M[i][j]!='#'&&M[i][j]!='.')
			{
				f[i][j]=1;
				tmp.x=j;
				tmp.y=i;
				switch(M[i][j])
				{
				case '^':tmp.d=0;break;
				case '>':tmp.d=2;break;
				case 'v':tmp.d=4;break;
				case '<':tmp.d=6;break;
				}
				M[i][j]='.';
				tmp.h[0]=tmp.y+mv[(tmp.d+2)%8][0];
				tmp.h[1]=tmp.x+mv[(tmp.d+2)%8][1];
			}
		}
	//dbg();
	for(int c=0;c<10000&&(tmp.y!=g[0]||tmp.x!=g[1]);c++)
	{
		int fx=(tmp.x+mv[tmp.d][1]),fy=(tmp.y+mv[tmp.d][0]);
		int frx=tmp.x+mv[(tmp.d+1)%8][1],fry=tmp.y+mv[(tmp.d+1)%8][0];
		int rx=tmp.x+mv[(tmp.d+2)%8][1],ry=tmp.y+mv[(tmp.d+2)%8][0];
		int brx=tmp.x+mv[(tmp.d+3)%8][1],bry=tmp.y+mv[(tmp.d+3)%8][0];
		//printf("%d %d %d | %d %d\n",tmp.y,tmp.x,tmp.d,tmp.h[0],tmp.h[1]);
		if(M[ry][rx]=='.'&&(tmp.h[0]==bry&&tmp.h[1]==brx))
		{
			tmp.d=(tmp.d+2)%8;
		}
		else if(M[fy][fx]=='#')
		{
			tmp.d=(tmp.d-2+8)%8;
			tmp.h[0]=tmp.y+mv[(tmp.d+2)%8][0];
			tmp.h[1]=tmp.x+mv[(tmp.d+2)%8][1];
		}
		else
		{
			tmp.y+=mv[tmp.d][0];
			tmp.x+=mv[tmp.d][1];
			if(tmp.h[0]==bry&&tmp.h[1]==brx)
			{
				tmp.h[0]+=mv[tmp.d][0];
				tmp.h[1]+=mv[tmp.d][1];
			}
			f[tmp.y][tmp.x]=1;
		}
	}
	if(tmp.y!=g[0]||tmp.x!=g[1])puts("-1");
	else
	{
		int r=0;
		for(int i=0;i<=H+1;i++)
			for(int j=0;j<=W+1;j++)
				r+=f[i][j];
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 1256
x,y=map(int, input().split())
ans=0
if x!=0 and x==-y:
    ans+=1
elif x*y<0:
    ans+=abs(x+y)+1
else:
    if x>y:
        ans+=1+(x!=0 and y!=0)
        x,y=-x,-y
    ans+=y-x
print(ans)

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;


public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        long K = sc.nextLong();
        long X = sc.nextLong();
        if(500*K>=X){
            out.println("Yes");
        }
        else{
            out.println("No");
        }

        out.flush();
    }    
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

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

int main() {
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < S.length(); i++) {
        S = S[S.length() - 1] + S.substr(0, S.length() - 1);
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
//********rev 2;
#include <iostream>
#include <list>
#include <cctype>

using namespace std;

// data class
class D {
public:
	int n;
	int sets;

	list<D*> child;

	D() :child() {
		n = 0;
		sets = 0;
	};
};

// global var for input
char c[10002];

// get inputs
int get(D *d, int &l) {
	int sum = 0;
	if (c[l] == '[') { // if has datasets
		// loop for all sets
		list<int> ilist;
		while (c[l] == '[') {
			D *dd = new D();
			++l; // INFO: skip '['
			// INFO: rec.
			ilist.push_back(get(dd, l));
			// add to childlen
			d->child.push_back(dd);
			// inc. sets
			d->sets++;
			l++; // INFO: skip ']'
		}
		ilist.sort([](int &i1, int &i2){return i1 < i2;});
		auto iter = ilist.begin();
		for (int i = 0; i < d->sets / 2 + 1; i++) {
			sum += *iter;
			iter++;
		}
		d->n = sum;
		return sum;
	} else { // if has NO datasets (== only num)
		// char[] to num
		int num = c[l] - '0';
		for (l++; isdigit(c[l]); l++) {
			num = num * 10 + (c[l] - '0');
		}
		d->n = num / 2 + 1;
		return d->n;
	}
}

// solve from data
int ans(D *d) {
	if (d->sets == 0) { //if has NO datasets
		return d->n / 2 + 1; // min points for win
	}
	// else
	
	// function: conversion d with n
	auto func = [](D *d1, D *d2){return d1->n < d2->n;};
	// sort
	d->child.sort(func);
	// get lowlevel answer list
	// lowlevel ans list
	list <int> ilist;
	// iterator
	auto it = d->child.begin();
	for (int i = 0; i < d->sets; i++) {
		D *cur = *it;
		ilist.push_back(ans(cur));
		it++;
	}
	// sort for min
	ilist.sort([](int &i1, int &i2){return i1 < i2;});

	//get sum (== minpoints for win in thislevel)
	int sum = 0;
	auto iit = ilist.begin();
	for (int i = 0; i < d->sets / 2 + 1; i++) {
		sum += *iit;
		iit++;
	}
	return sum;
}

// solve
void solve() {
	int n;
	// input dataset length
	cin >> n;
	for (int i = 0; i < n; i++) {
		// input dataset
		cin >> c;
		D *d = new D();
		// INFO: 1: skip first '['
		int l = 1;
		// string to dataobj;
		get(d, l);
		// get answer
		//cout << ans(d) << endl;
		cout << d->n << endl;
		delete d;
	}
}



//----main----
int main(void) {
	solve();
}

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

#define o(output) cout << output << endl

using namespace std;

string s;
int a,b,c,d,e;
char A,B;
priority_queue<int,vector<int>,greater<int> >small;

int main(){
  cin >> a >> A >>B;
  b = A-'0';
  c = B-'0';
  if((10*b+c)%4==0)o("YES");
  else o("NO");
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        System.out.println(execute(arr, n));
        sc.close();
    }

    private static int execute(int[] arr, int length) {
        int[] dp = new int[length];
        dp[0] = 0;
        dp[1] = Math.abs(arr[1] - arr[0]);
        for (int i = 2; i < length; i++) {

            dp[i] = Math.min(dp[i - 2] + Math.abs(arr[i] - arr[i - 2]), dp[i - 1] + Math.abs(arr[i] - arr[i - 1]));

        }
        return dp[length - 1];
    }
}


Measured memory_bytes: 50776
import sys
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    X = list(itertools.accumulate(A))
    Y = sum(A)

    ans = float("inf")
    for i in range(N - 1):
        x = abs(X[i] - (Y - X[i]))
        ans = min(ans, x)

    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 24132
def round_up(n):
    if n%10 != 0:
        return n + 10 - (n%10)
    else:
        return n

def round_up_count(n):
    if n%10 != 0:
        return 10 - n%10
    else:
        return 0

orders = []

max_rc = 0
last_order_index = 0
last_order_time = 0

for i in range(5):
    order = int(input())
    orders.append(order)
    last_order_time += round_up(order)
    rc = round_up_count(order)
    if max_rc <= rc:
        last_order_index = i
        max_rc = rc

print(last_order_time - round_up_count(orders[last_order_index]))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
int cs[25],ct[25];
char s[200005],t[200005];
int main(){
	scanf("%s",s);
	scanf("%s",t);
	int l=strlen(s);
	for(int i=0;i<l;i++){
		cs[s[i]-'a']++;
		ct[t[i]-'a']++;
	}
	for(int i=0;i<26;i++)
		if(cs[s[i]-'a']!=ct[t[i]-'a']){
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

vector<pair<ll, ll>> factorize(ll N) {
  vector<pair<ll, ll>> res;
  ll n = N;
  for (ll p = 2; p*p <= n; p++) {
    if (N%p != 0) continue;
    int count = 0;
    while (N%p == 0) {
      count++; // pで割れる回数をカウント
      N /= p;
    }
    res.push_back(make_pair(p, count));
  }
  if (N != 1) res.push_back(make_pair(N, 1)); // 最終的にNが素数のとき
  return res;
}

vl getFactors(ll N) {
  vector<pair<ll, ll>> f = factorize(N);
  vl res;
  res.push_back(1);
  for (int i = 0; i < f.size(); i++) {
    int s = res.size();
    for (int j = 0; j < s; j++) for (int k = 0; k < f[i].second; k++) {
      res.push_back(res[j]*pow(f[i].first, k+1));
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vl factors = getFactors(M);
  for (int i = factors.size()-1; i >= 0; i--) {
    if (M/factors[i] >= N) {
      cout << factors[i] << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 512
import java.util.*;

import static java.lang.System.*;

public class Main {
    // 2^40 = 1_099_511_627_776
    // 2^39 =   549_755_813_888
    public static final int MAX_BIT = 39;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();

        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }

        int[] oneBitNums = new int[MAX_BIT + 1];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= MAX_BIT; j++) {
                if ((A[i] >> j & 1) == 1) {
                    oneBitNums[j]++;
                }
            }
        }

        int[] xBits = new int[MAX_BIT + 1];
        for (int i = MAX_BIT; i >= 0; i--) {
            if (oneBitNums[i] <= N / 2) {
                xBits[i] = 1;
            }
        }

        long X = 0;
        for (int i = MAX_BIT; i >= 0; i--) {
            if (xBits[i] == 1) {
                long num = (long) Math.pow(2.0, i);
                // K以下を保証する
                if (X + num <= K) {
                    X += num;
                }
            }
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += X ^ A[i];
        }

        out.println(ans);
    }
}

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

//highlight color RGB = [70,70,70]
#define asll unsigned long long
#define ll long long
#define ld long double
#define imt int
#define pii pair<int,int>
#define st first
#define nd second
#define kj <<" "<<
#define kjb <<" ";
#define dg <<","<<
#define ml <<endl;
#define co cout<<
#define ter cout<<endl;
#define sibi cout<<"TES"<<endl;
#define tes(x) cout<<"TES "<<x<<endl;
#define psbk(x) push_back(x);
#define For(x,a,b) for(int x=(a);x<(b);x++)
#define FOR(x,n) for(int x=0;x<(n);x++)
#define kera(x,m) for( int i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml}
#define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml
#define kkor(p) cout<<"("<<p.x dg p.y <<")" ml
#define m_p make_pair
asll M=1e9+7;
int n,m,tc;
int p,q,r;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	cin>>n;
	r=0;
	int hasil=0;
	FOR(i,n){
		cin>>p>>q;
		if(p==q){
			r++;
			if(r==3){
				hasil=1;
			}
		}
		else{
			r=0;
		}
	}
	if(hasil){
		cout<<"Yes"<<endl;
	}
	else{
		co "No" ml
	}
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=105,L=105;
const ll inf=(ll)1e18;
int a[N];
struct edge{int a,b;ll c,f;
  edge(int u,int v,ll cap):a(u),b(v),c(cap),f(0){}};
struct flow{
  const static ll inf = 1e18;//set s=source,t=sink,nodeCt
  int Dlevel[L],Dptr[L],s,t,nodeCt;
  queue<int> Q;vector<edge> E;vi ad[L] ;
  void addEdge(int a,int b,ll c,bool directed=1){
    if(a==b)return ;//1 based index
    ad[a].pb(sz(E)),E.pb(edge(a,b,c));
    ad[b].pb(sz(E)),E.pb(edge(b,a,directed?0:c)); }
  bool Dbfs(void){FEN(i,nodeCt)Dlevel[i]=0;Q.push(s),Dlevel[s]=1;
    while(!Q.empty()){int levelsz=sz(Q),v;
      while(levelsz--){v=Q.front();Q.pop() ;
	for(auto &e:ad[v]) if(!Dlevel[E[e].b]&&E[e].f<E[e].c){
	    Dlevel[E[e].b]=Dlevel[v]+1;
	    Q.push(E[e].b);}}}
    return Dlevel[t]>0;}//by default edges are undirected
  ll Ddfs(int x,ll flow){if(!flow) return 0;if(x==t) return flow ;
    for(int &pt=Dptr[x];pt<sz(ad[x]);++pt){
      int e=ad[x][pt];//call dinic()
      if(Dlevel[E[e].b]==Dlevel[x]+1){
	if(ll pushed=Ddfs(E[e].b,min(flow,E[e].c-E[e].f))){
	  E[e].f+=pushed;E[e^1].f-=pushed;return pushed;}}}
    return 0 ;}
  ll dinic(void){ll flow=0;while(Dbfs()){FEN(i,nodeCt)Dptr[i]=0;
      while(ll pushed=Ddfs(s,inf)) flow += pushed ;} return flow ;}
  void reset(void){for(auto &e:E)e.f=0;}};//!!!don't forget to set L
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  ll ans=0;
  rep(i,1,n+1) cin>>a[i],ans+=max(0,a[i]);
  flow curr;
  curr.s=1; curr.t=n+2; curr.nodeCt=n+2;
  rep(i,1,n+1)
    {
      if(a[i]<=0) curr.addEdge(1,i+1,-a[i]);
      else curr.addEdge(i+1,n+2,a[i]);
    }
  rep(i,1,n+1)
    for(int j=2*i;j<=n;j+=i)
      curr.addEdge(i+1,j+1,inf);
  cout<<ans-curr.dinic()<<endl;
  return 0 ;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];

int main(){
	int n,k,q;
	cin >> n >> k >> q;
	for(int i = 1;i <= q;i++){
		int c; scanf("%d",&c);
		a[c]++;
	}
	for(int i = 1;i <= n;i++){
		a[i] += k;
		a[i] -= q;
		if(a[i] <= 0) printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int h, w, i, j;
   
    char a[102][102];
   
      
    scanf("%d %d", &h, &w);

    for( i = 1 ; i <= h ; i = i + 1){

         scanf("%s", a[i]);

         }


    for( i = 0 ; i < w + 2 ; i = i + 1 ){    

         printf("#");

         }

    printf("\n");

   
    for( i = 1 ; i <= h ; i = i + 1){

         printf("#%s#\n", a[i]);

         }


    for( i = 0 ; i < w + 2 ; i = i + 1 ){    

         printf("#");

         }

    printf("\n");


    return 0;
                                                          
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n, a, b,some,sum=0;
    ll cnt = 0;
    cin >>n >> a >> b;
    REP(i, n) {
        some = i;
        sum = 0;
        while (some > 9) {
            sum += some % 10;
            some /= 10;
        }
        sum += some;
        if (a <= sum && sum <= b)cnt += i;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
LL A,B,V,W,T,D;
int main(){
	cin>>A>>V>>B>>W>>T;
	D=abs(A-B);
	if (V<W) return puts("NO"),0;
	if (T*(V-W)>=D) puts("YES"); else puts("NO");
	return 0;
}

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

n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [list(map(int, input().split())) for _ in range(m)]

t_sum = sum(t)

for p, x in px:
    ans = t_sum - t[p-1] + x
    print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int n,ans=1000000001,t;
  int a[201];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    t=0;
    while(a[i]%2==0){
      t++;
      a[i]/=2;
    }
    if(t<ans) ans=t;
  }
  printf("%d",ans);

  return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main()
{
    int N;
    cin >> N;
    int p[N];
    REP(i, N)
    {
        cin >> p[i];
        p[i]--;
    }

    int ans = 0;
    bool isSame = (p[0] == 0);
    for(int i = 1; i < N; ++i)
    {
        if (isSame)
        {
            ans++;
            // スワップする
            int tmp = p[i];
            p[i] = p[i - 1];
            p[i - 1] = tmp;
        }
        isSame = (p[i] == i);
    }

    if (isSame)
    {
        ans++;
    }
    
    cout << ans << endl;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int n;
    cin >> n;
    n++;
    V<int> a(n);
    rep(i,n) cin >> a[i];
    // pair = (min, max);
    V<Pl> cnt(n);
    cnt[n-1] = make_pair(a[n-1], a[n-1]);
    for(int i = n-2; i >= 0; i--) {
        cnt[i].fi = (cnt[i+1].fi+1)/2 + a[i];
        cnt[i].se = cnt[i+1].se + a[i];
    }
    if(!(cnt[0].fi <= 1 && 1 <= cnt[0].se)) {
        cout << -1 << endl;
        return 0;
    }
    // rep(i,n) cout << cnt[i].fi << " " << cnt[i].se << endl;
    V<ll> ans(n);
    ans[0] = 1;
    Rep(i,n-1) {
        ans[i] = min(cnt[i].se, (ans[i-1]-a[i-1])*2);
    }
    ll sum = 0;
    rep(i,n) {
        // cout << ans[i] << endl;
        sum += ans[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
ll cnt;
int main() {
    cin>>s;

    ll right=s.size()-1;
    while(right>=0){
        if(s[right]=='W') break;
        right--;
    }

    ll left=right;
    while(left>=0){
        if(s[left]=='B' && left!=right){
            cnt+=(right-left);
            right-=1;
            s[left]='W';
        }
        left--;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int H = sc.nextInt();
		int W = sc.nextInt();

		int N = sc.nextInt();

		int[] a = nextIntArray1origin(sc, N);

		sc.close();

		int[][] c = new int[H][W];

		int idx = 1;

		for (int h = 0; h < H; h++) {
			if (h % 2 == 0) {
				for (int w = 0; w < W; w++) {
					if (a[idx] == 0) {
						idx++;
					}
					c[h][w] = idx;
					a[idx]--;
				}
			} else {
				for (int w = W - 1; w >= 0; w--) {
					if (a[idx] == 0) {
						idx++;
					}
					c[h][w] = idx;
					a[idx]--;
				}
			}
		}

		for (int h = 0; h < H; h++) {
			out.println(join(" ", c[h]));
		}

	}

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

	@SuppressWarnings("unused")
	private String join(String delimiter, int[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 31480
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 200001;
 
int main(){
    int N;
    int A[MAX];
    int first = 0;
    int second = 0;
    int index = 0;

    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> A[i];
        if(A[i] > first){
            second = first;
            first = A[i];
            index = i;
        }else if(A[i] > second){
            second = A[i];
        }
    }

    for(int i = 0;i < N;i++){
        if(i == index){
            cout << second << endl;
        }else{
            cout << first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] c = new int[10][10];
        for(int i=0;i<10;i++){
        	for(int j=0;j<10;j++){
        	    c[i][j]=sc.nextInt();
        	}
        }
        int[][] A = new int[H][W];
        int[] wall = new int[10];
        for(int h=0;h<H;h++){
        	for(int w=0;w<W;w++){
        	    A[h][w]=sc.nextInt();
        	    if(A[h][w]>=0) wall[A[h][w]]++;
        	}
        }
        
        int distance[] = new int[10];//to 1
        for(int i=0;i<10;i++){
        	distance[i] = c[i][1];
        }
        for(int t=0;t<10;t++){
        	for(int i=0;i<10;i++)for(int j=0;j<10;j++){
        	    if(distance[i]>c[i][j]+distance[j]){
        	        distance[i]=c[i][j]+distance[j];
        	    }
        	}
        }
        
        long ans = 0;
        for(int i=0;i<10;i++) ans += distance[i]*wall[i];
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 46696
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <set>
using namespace std; typedef long long ll; const int MINF=-1e9; typedef pair<int,int> P;

int main() {
  int n; cin>>n; ll an=0;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  int b[n]; for(int i=0;i<n;i++) b[a[i]-1]=i;
  set<ll> s1; set<ll, greater<ll>> s2;
  for(int i=0,j=b[0];i<n;i++,j=b[i]) { // iがある場所がj
    auto it1=s1.lower_bound(j); // 右側
    auto it2=s2.lower_bound(j); // 左側
    ll x1, x2;
    if (it1 == s1.end()) x1=n-1-j+1;
    else {ll val=*it1; x1=val-j;}
    if (it2 == s2.end()) x2=j+1;
    else {ll val=*it2; x2=j-val;}
    //cout<<i<<" "<<j<<" "<<x1<<" "<<x2<<" "<<an<<endl;
    an+=x1*x2*(i+1);
    s1.insert(j); s2.insert(j);
  }
  cout<<an<<endl;
}

Measured memory_bytes: 21376
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

vector<int> v[100001];
int col[100001];
map<pair<int, int>, int> idx;

int K = 0;

void visit(int from, int to, int color) {
  int c = 1;
  for (int next : v[to]) {
    if (next == from) {
      continue;
    }
    if (c == color) {
      c++;
    }

    int i = idx[make_pair(to, next)];
    col[i] = c;
    visit(to, next, c);
    K = max(K, c);
    c++;
  }
}

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

  vector<bool> visited(N + 1, false);

  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;

    v[a].push_back(b);
    v[b].push_back(a);
    idx[make_pair(a, b)] = i;
    idx[make_pair(b, a)] = i;
  }

  visit(0, 1, 0);

  cout << K << endl;
  for (int i = 0; i < N - 1; i++) {
    cout << col[i] << endl;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 19840
#include <iostream>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int n;
int x[100];
ll dp[21][100];
 
int main(){
    cin >> n;
    rep(i,n) cin >> x[i];
    dp[x[0]][0] = 1;
    for(int i = 1; i < n-1; i++){
        for(int j = x[i]; j < 21; j++) dp[j-x[i]][i] += dp[j][i-1];
        for(int j = 0; j < 21-x[i]; j++) dp[j+x[i]][i] += dp[j][i-1];
    }
    cout << dp[x[n-1]][n-2] << endl;
}

Measured memory_bytes: 1176
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

const ll INF = 1e18L;

int N;
ll A[300][300];
vector<tuple<ll, int, int>> v;
ll cost[300][300];

signed main(){
	cin >> N;
	rep(i, N){
		rep(j, N){
			cin >> A[i][j];
			if(i < j) v.pb({ A[i][j],i,j });
			cost[i][j] = INF;
			if(i == j) cost[i][j] = 0;
		}
	}
	sort(all(v));

	ll ans = 0;
	rep(i, v.size()){
		int a = get<1>(v[i]);
		int b = get<2>(v[i]);
		if(cost[a][b] < A[a][b]){
			cout << -1 << endl;
			return 0;
		}
		if(cost[a][b] == A[a][b]) continue;
		cost[a][b] = A[a][b];
		cost[b][a] = A[b][a];
		ans += A[a][b];
		rep(j, N){
			rep(k, N){
				cost[j][k] = min(cost[j][k], cost[j][a]+cost[a][b]+cost[b][k]);
				cost[j][k] = min(cost[j][k], cost[j][b]+cost[b][a]+cost[a][k]);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5512
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5+7;
const int M = 1e9+7;

int pre[maxn];

int find(int x)
{
    return x==pre[x]?x:pre[x]=find(pre[x]);
}

signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i = 1; i <= n; i++) pre[i] = i;
    for(int i = 1,x,y; i <= m; i++) 
    {
        cin>>x>>y;
        x = find(x);
        y = find(y);
        pre[x] = y;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) 
    {
        if(i == find(i)) ans++;
    }
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 4424
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  cout << max(0,a-2*b) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define maxn 55
using namespace std;
int n,a[maxn],b,minnum=0,pos;
bool tag;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
	scanf("%d",&a[i]);
	if(abs(a[i])>minnum) {
		minnum=abs(a[i]);
		if(a[i]<0) tag=true;
		else tag=false;
		pos=i;
			}
	}
	if(minnum==0)
	{
		cout<<0;
		return 0;
	}
	cout<<2*n<<endl;
if(tag)   {
	cout<<pos<<' '<<1<<endl;
	cout<<pos<<' '<<1<<endl;
	for(int i=n;i>=2;--i)
	{
		cout<<1<<' '<<i<<endl;
		cout<<1<<' '<<1<<endl;
	}
return 0;
}
if(!tag)
{
	cout<<pos<<' '<<n<<endl;
	cout<<pos<<' '<<n<<endl;
	for(int i=1;i<=n-1;++i)
	{
		cout<<n<<' '<<i<<endl;
		cout<<n<<' '<<n<<endl;
	}
	return 0;
}
return 0; 
}

Measured memory_bytes: 256
#template
def inputlist(): return [int(j) for j in input().split()]
#template

def pow_k(a,n,mod):
    if n == 0:
        return 1
    if n % 2 ==0:
        return pow_k(a*a % mod,n//2,mod)
    else:
        return a * pow_k(a,n-1,mod) % mod
def modinv(a, mod):
    return pow(a, mod-2, mod)
def combination_list(n, mod):
    lst = [1]
    for i in range(1, k+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
def chofuku_cmb(n, r, mod=10**9+7):
    return combination(n+r-1, r, mod)

S = int(input())
mod = 10**9+7
if S < 3:
    print(0)
    exit()
N = S // 3
d = S % 3
ans = 0
for i in range(N):
    if i != 0:
        d += 3
    tmp = chofuku_cmb(N-i,d,mod)
    ans += tmp
    ans %= mod
ans %= mod
print(ans)

Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

void print(vector<vector<int>>& g) {
  for (auto v : g) {
    printVec(v);
  }
  cout << "--------------" << endl;
}

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> G(h, vector<char>(w));
  vector<vector<int>> dis(h, vector<int>(w));
  vector<P> start_positions;
  rep (i, h) {
    rep (j, w) {
      cin >> G[i][j];
      if (G[i][j] == '.') {
        start_positions.push_back(make_pair(i, j));
      }
    }
  }

  vector<int> py = { 0, 0, 1, -1 };
  vector<int> px = { 1, -1, 0, 0 };
  int ans = 0;
  for (auto v : start_positions) {
    rep (i, h) rep (j, w) dis[i][j] = -1;
    dis[v.first][v.second] = 0;
    queue<P> sts;
    sts.push(v);
    while (!sts.empty()) {
      //print(dis);
      int x, y;
      y = sts.front().first;
      x = sts.front().second;
      sts.pop();

      for (int i = 0; i < 4; i++) {
        int next_y, next_x;
        next_y = y + py[i];
        next_x = x + px[i];
        if (0 <= next_y && 0 <= next_x && next_y < h && next_x < w) {
          if (G[next_y][next_x] == '.' && dis[next_y][next_x] == -1) {
            sts.push(make_pair(next_y, next_x));
            dis[next_y][next_x] = dis[y][x] + 1;
            ans = max(ans, dis[next_y][next_x]);
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
A = int(input())
B = int(input())
if A == 1:
  if B == 2:
    print(3)
  else:
    print(2)
elif A == 2:
  if B == 1:
    print(3)
  else:
    print(1)
else:
  if B == 1:
    print(2)
  else:
    print(1)
  

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
using namespace std;
const int MOD = 1e9 +7;

// 0-index

struct SegmentTree{
    ll n;
    vector<ll> node;
    SegmentTree(ll n_){
        n=1;
        while(n<n_) n*= 2;
        node.resize(2*n-1);
        for(ll i=0;i<2*n-1;i++) node[i] = INT_MAX;
    }
    void update(ll k,ll a){
        k += n-1;
        node[k]=a;
        while(k>0){
            k=(k-1)/2;
            node[k]=min(node[k*2+1],node[k*2+2]);
        }
    }
    ll query(ll a,ll b,ll k,ll l,ll r){
        if(r<=a || b<=l) return INT_MAX;
        if(a<=l && r<=b) return node[k];
        else{
            ll vl = query(a,b,k*2+1,l,(l+r)/2);
            ll vr= query(a,b,k*2+2,(l+r)/2,r);
            return min(vr,vl);
        }
    }
    ll query(ll a,ll b){
        return query(a,b,0,0,n);
    }
};

int main(){
    int n,q;
    cin>>n>>q;
    SegmentTree sg(n);
    rep(i,q){
        int c,x,y;
        cin>>c>>x>>y;
        if(c) cout<<sg.query(x,y+1)<<endl;
        else sg.update(x,y);
    }
    return 0;
}


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

int main() {
	string s,t;
	cin >> s >> t;
	
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	int size = min(s.size(), t.size());
	for (int i = 0; i < size; i++) {
		if (s.at(i) == t.at(i)) {
			continue;
		}
		else if (s.at(i) < t.at(i)) {
			cout << "Yes" << endl;
			return 0;
		}
		else if (s.at(i) > t.at(i)) {
			cout << "No" << endl;
			return 0;
		}
	}if (s.size() < t.size()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] cards = new int[4][13];
		for (int i = 0; i < n; i++) {
			String suit = sc.next();
			int rank = sc.nextInt();
			int sn = -1;
			switch (suit) {
				case "S": sn = 0; break;
				case "H": sn = 1; break;
				case "C": sn = 2; break;
				case "D": sn = 3; break;
			}
			cards[sn][rank - 1] = 1;
		}
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) {
				if (cards[i][j] == 0) {
					String suit = null;
					switch (i) {
						case 0: suit = "S"; break;
						case 1: suit = "H"; break;
						case 2: suit = "C"; break;
						case 3: suit = "D"; break;
					}
					System.out.printf("%s %d\n", suit, j + 1);
				}
			}
		}
	}
}


Measured memory_bytes: 26528
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  bool even = true;
  rep(i,n) {
    if(a[i] % 2 == 1) {
      even = false;
    }
  }
  if(even) {
    cout << "second" << endl;
  } else {
    cout << "first" << endl;
  }

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        String S = sc.next();
        char[] sca = S.toCharArray();
        int cnt=1;
        if(sca.length == 1){
            System.out.println(1);
            return;
        }
        for(int i=1;i<N;i++){
            if(sca[i] != sca[i-1]){
                cnt++;
            }
        }
        System.out.println(cnt);
        return;
    }
}



Measured memory_bytes: 26580