akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll N = 1e5 + 3;
const ll INF = 1e18 + 7;

ll n, m, q, a[N], b[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n >> m >> q;
	for (ll i = 1; i <= n; ++i) cin >> a[i];
	for (ll i = 1; i <= m; ++i) cin >> b[i];
	
	a[0] = b[0] = -INF;
	a[n+1] = b[m+1] = INF;
	sort(a, a + (n += 2));
	sort(b, b + (m += 2));
	
	while (q--) {
		ll x, xa[2], xb[2];
		cin >> x;
		xa[0] = x - a[lower_bound(a, a + n, x) - a - 1];
		xa[1] = *lower_bound(a, a + n, x) - x;
		xb[0] = x - b[lower_bound(b, b + m, x) - b - 1];
		xb[1] = *lower_bound(b, b + m, x) - x;
		
		ll r = INF;
		r = min(r, max(xa[0], xb[0]));
		r = min(r, max(xa[1], xb[1]));
		r = min(r, 2*xa[0] + xb[1]);
		r = min(r, 2*xa[1] + xb[0]);
		r = min(r, 2*xb[0] + xa[1]);
		r = min(r, 2*xb[1] + xa[0]);
		cout << r << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
char in[303000];
int W[303000];
int main()
{
	int n,i,Min=500000,cou=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
        scanf(" %c",&in[i]);
        if(in[i]=='W'){
            cou++;
        }
        W[i]=cou;
	}
    for(i=0;i<n;i++){
        if(n-1-i-W[n-1]+W[i]+W[i-1]<Min){
            Min=n-1-i-W[n-1]+W[i]+W[i-1];
        }
    }
    printf("%d",Min);
    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in); 
		
		int n = scan.nextInt();
		ArrayList<Integer> num = new ArrayList<Integer>();
		
		for(int i = 0; i < n; i++){
			num.add(scan.nextInt());
		}
		
		Collections.reverse(num);
		
		for(int i = 0; i < num.size(); i++){
			int b = num.get(i);
			System.out.print(b);
			if(i != n - 1){
				System.out.print(" ");
			}
			
		}
		System.out.println();
		}
	}
	
	

Measured memory_bytes: 26348
R,G,B,N = map(int,input().split())
cnt = 0
for r in range((N // R) + 1):
    for g in range((N - (r * R)) // G + 1):
        V = N - (r * R + g * G)
        if V >= 0 and V % B == 0:
            cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
void chmin(int &a, int b) {if(a > b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int h, w;
    cin >> h >> w;
    int c[10][10];
    int a[h+1][w+1];
    repn(i,0,9)repn(j,0,9) cin >> c[i][j];
    rep(i,0,h)rep(j,0,w) cin >> a[i][j];

    repn(k,0,9){
        repn(i,0,9){
            repn(j,0,9){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    ll ans = 0;

    rep(i,0,h){
        rep(j,0,w){
            if(a[i][j] == -1 || a[i][j] == 1){
                continue;
            }else{
                ans += c[a[i][j]][1];
            }
        }
    }
    cout << ans << endl;
}

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

const int md = 1000000007;

inline int add(int a, int b) 
{
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int sub(int a, int b) 
{
	a -= b;
	if (a < 0) a += md;
	return a;
}
inline int mul(int a, int b) 
{
	return (int)((long long)a * b % md);
}
inline int po(int a, int b) 
{
	int r = 1;
	while (b) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}
inline int inv(int a) 
{
	return po(a, md - 2);
}
inline int di(int a, int b) 
{
	return mul(a, inv(b));
}

const int N = 500000;
int fact[N + 1];

inline int Cnk(int n, int k) 
{
	return di(fact[n], mul(fact[k], fact[n - k]));
}

void init() 
{
	fact[0] = 1;
	for (int i = 1; i <= N; ++i) fact[i] = mul(i, fact[i - 1]);
}

int main() 
{
	init();
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		int t = Cnk(n, i);
		t = mul(t, di(fact[m], fact[m - i]));
		t = mul(t, po(di(fact[m - i], fact[m - n]), 2));
		if (i & 1) ans = sub(ans, t);
		else ans = add(ans, t);
	}
	printf("%d\n", ans);
	return 0;
}


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

const int MAX_N=101;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int B=20,S=19,N=(B+S)*5,U=B*10,M=(2*N+U)*333;
    int n,y,m,d,ans;
    cin >> n;
    for (int i=0;i<n;++i){
        cin >> y >> m >> d;
        ans=(y-1)/3*(2*N+U)+(y-1)%3*N;
        ans+=(y%3!=0?(m-1)/2*(B+S)+(m-1)%2*B:(m-1)*B);
        ans+=d-1;
        cout << M-ans << endl;
    }
}


Measured memory_bytes: 3080
#include<string.h>


int main(){
  
  char u[256][20], t[256][20];
  int n, m, i, j, cnt=0;

  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%s", u[i]);
  scanf("%d", &m);
  for(i=0;i<m;i++) scanf("%s", t[i]);

  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(strcmp(t[i],u[j])==0){
	if(cnt%2==0){
	  printf("Opened by %s\n", t[i]);
	  cnt++;
	  break;
	}else{
	  printf("Closed by %s\n", t[i]);
	  cnt++;
	  break;
	}
      }
      if(j==n-1) printf("Unknown %s\n", t[i]);
    }
  }
  
  return 0;
}

Measured memory_bytes: 616
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int s1,s2;
	s1=a+b;
	s2=c+d;
	if (s1>s2)
	  cout<<"Left"<<endl;
	else if (s1<s2)
		   cout<<"Right"<<endl;
		 else if (s1=s2)
		   	    cout<<"Balanced"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

ll D[20005];
int n;
struct box{
    int w, v, s;
    bool operator< (box b){
        return s + w < b.s + b.w;
    }
} B[1005];

int main(){
    fio;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> B[i].w >> B[i].s >> B[i].v;
    }
    sort(B,B+n);
    for(int i = 0; i < n; i++){
        for(int j = B[i].s; j >= 0; j--){
            D[j + B[i].w] = max(D[j + B[i].w], D[j] + B[i].v);
        }
    }
    cout << *max_element(D,D+20001) << '\n';
}


Measured memory_bytes: 384
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

int main()
{
	string s;
	cin>>s;
	string vb,ve;
	int q;
	cin>>q;
	int tool=0;
	while(q--)
	{
		int ti;
		cin>>ti;
		if(ti==1)
		{
			tool^=1;
		}
		else
		{
			int fi;
			char ci;
			cin>>fi>>ci;
			if(fi==1)
			{
				if(tool==0)
				{
					vb.push_back(ci);
				}
				else ve.push_back(ci);
			}
			else
			{
				if(tool==0)
				{
					ve.push_back(ci);
				}
				else vb.push_back(ci);
			}
		}
	}
	reverse(vb.begin(),vb.end());
	//cout<<vb<<" "<<ve<<endl;
	vb+=s;
	vb+=ve;
	if(tool==1) reverse(vb.begin(),vb.end());
	cout<<vb<<endl;
}		

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){ 
  ll N,A,Q,B,C,S;
  vector<ll> vec(100000,0);
  cin >> N;
  S = 0;
  for(ll i = 0; i < N; i++){
    cin >> A;
    S += A;
    vec[A] += 1;
  }
  cin >> Q;
  for(ll i = 0; i < Q; i++){
    cin >> B >> C;
    S += (C - B)*vec[B];
    vec[C] += vec[B];
    vec[B] = 0;
    cout << S << endl;
  }
  
}


Measured memory_bytes: 3876
#include<cstdio>
#define MAXN 100006
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> road[MAXN];
int n,u,v,du[MAXN],vis[MAXN];
queue<int> q;
int main()
{
	//freopen("blackwhite.in","r",stdin);
	//freopen("blackwhite.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		road[u].push_back(v);
		road[v].push_back(u);
		du[u]++;
		du[v]++;
	}
	for(int i=1;i<=n;i++)
		if(du[i]==1) q.push(i);
	while(!q.empty())
	{
		int now=q.front();
		q.pop();
		if(vis[now]) continue;
		if(du[now]==1)
		{
			for(int i=0;i<(int)road[now].size();i++)
			{
				int nex=road[now][i];
				if(!vis[nex])
				{
					vis[nex]=vis[now]=1;
					for(int j=0;j<(int)road[nex].size();j++)
					{
						int nnex=road[nex][j];
						if(vis[nnex]) continue;
						du[nnex]--;
						if(du[nnex]==1) q.push(nnex);
					}
					break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			printf("First");
			return 0;
		}
	printf("Second");
}

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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  for (ll i = 0; i < N; i++) A[i]--;

  if (K <= 1e6) {
    ll temp = 0;
    for (ll i = 0; i < K; i++) {
      temp = A[temp];
    }
    cout << (temp + 1) << '\n';
    return 0;
  }
  
  vector<ll> X(N, -1);
  ll temp = 0;
  ll l;
  ll s = 0;
  for (ll i = 0; i < N + 100; i++) {
    X[temp] = i;
    temp = A[temp];
    if (X[temp] >= 0) {
      s = X[temp];
      l = (i + 1) - s;
      break;
    }
  }
  K = s + ((K - s) % l);

  temp = 0;
  for (ll i = 0; i < K; i++) {
    temp = A[temp];
  }
  cout << (temp + 1) << '\n';
  return 0;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    string S; cin >> S;
    ll ans = 0;
    
    for(int i = 0; i < S.size()-1; i++){
        if(S[i] == S[i+1]) continue;
        else ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
def main():
    S = input()
    T = input()

    ans = len(T)
    for i in range(len(S)-len(T)+1):
        tmp = 0
        for j in range(len(T)):
            if S[i+j] == T[j]:
                tmp += 1
        if len(T)-tmp < ans:
            ans = len(T)-tmp

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
<?php
fscanf(STDIN, "%d", $n);
$x = explode(' ', trim(fgets(STDIN)));
$sum = array_sum($x);
$p = round($sum / $n);

$ans = 0;
foreach($x as $v) {
	$ans += ($v - $p) ** 2;
}
echo $ans;


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

struct card{
	char c; int x;
};

#define max 100000
struct card  L[max / 2 + 2], R[max / 2 + 2];

void merge(card A[], int n, int left, int mid, int right)
{
	int i, j;
	int n1, n2;
	n1 = mid - left;
	n2 = right - mid;
	for (i = 0; i < n1; i++)L[i] = A[left + i];
	for (i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1].x = R[n2].x = INT_MAX;
	i = 0; j = 0;
	for (int k = left; k < right; k++)
	{
		if (L[i].x > R[j].x)
			A[k] = R[j++];
		else A[k] = L[i++];
	}
}

void mergesort(card A[], int n, int left, int right)
{
	if (left + 1 < right)    
	{
		int mid = (left + right) / 2;
		mergesort(A, n, mid, right);
		mergesort(A, n, left, mid);
		merge(A, n, left, mid, right);                      
	}
}

int partition(card A[], int p, int r)
{
	card x = A[r];
	int i = p - 1;
	for (int j = p; j <= r - 1; j++)
	{
		if (A[j].x <= x.x)
		{
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

void quicksort(card A[], int p, int r)
{
	int q;
	if (p < r)
	{
		q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
}

bool comperation(card A[],card B[], int n)
{
	for (int i = 0; i < n; i++)
		if (A[i].c != B[i].c)
			return false;
	return true;
}

int main()
{
	card A[max], B[max];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i].c >> A[i].x;
		B[i] = A[i];
	}

	quicksort( B, 0, n - 1);
	mergesort(A, n, 0, n);

	if (comperation(A, B, n))cout << "Stable" << endl;
	else cout << "Not stable" << endl;

	for (int i = 0; i < n; i++)
	{
		cout << B[i].c << " " << B[i].x << endl;
	}
	return 0;
}



Measured memory_bytes: 5360
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,t;
    cin >> n >> t;
    V vec(n);
    rep(i, n) cin >> vec[i];
    V Max(n);
    for (int i = n - 1; i >= 0;i--){
        if(i==n-1){
            Max[i] = vec[i];
        }else{
            Max[i] = max(Max[i + 1], vec[i]);
        }
    }
    ll maxreg=0;
    ll res = 0;
    rep(i,n){
        if(Max[i]-vec[i]==maxreg){
            res++;
        }else if(Max[i]-vec[i]>maxreg){
            maxreg=Max[i]-vec[i];
            res = 1;
        }
    }
    cout << res << endl;
}


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

int main(void)
{
	
	while(1) {
		char str_1[100];
		char str_2[300];
		int i;
		int j = 0;
		
		if(scanf("%s", str_1) != EOF) {
			for(i = 0; i < strlen(str_1); i++) {
				if(str_1[i] == '@') {
					int k;
					for(k = 0; k < str_1[i + 1] - '0'; k++) {
						str_2[j] = str_1[i + 2];
						j++;
					}
				}
				else if(str_1[i - 1] == '@' || str_1[i - 2] == '@')
					continue;
				else {
					str_2[j] = str_1[i];
					j++;
				}
			}
		for(i = 0; i < j; i++)
			printf("%c", str_2[i]);
		putchar('\n');
		}
		else break;
	}
	
	
	return 0;
}


Measured memory_bytes: 524
#create date: 2020-06-27 21:00

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def g(n):
    return n * (n+1) // 2

def main():
    n = ni()
    ans = 0
    div = [0] * (n+1)
    for i in range(1, n+1):
        for j in range(1, n//i+1):
            div[i*j] += 1
    #print(div)
    for i in range(1, n+1):
        ans += i * div[i]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 151556
#include<iostream>

using namespace std;

int main()
{

	int a, b, x;
	cin >> x >> a >> b;

	if (abs(x-a) < abs(x-b) )
	{
		cout << "A" << endl;
	}
	else
	{
		cout << "B" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main (String[] args) {
        final Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        int[] numbers = new int[length];

        int max = 0;
        int count = 0;
        for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
            if (numbers[i] == 2) {
                count++;
            }
        }

        for (int number : numbers) {

            boolean flg = true;
            if (number % 2 == 0) {
              continue;
            }

            for (int i = 3; i <= Math.sqrt(number); i += 2) {
                if (number % i == 0) {
                    flg = false;
                    break;
                }
            }

            if (flg){
              count++;
            }

        }

        System.out.println(count);
    }
}



Measured memory_bytes: 41204
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    m,d=parseMap(split(readline()))
    ans=0
    for i in 1:m
        for j in 1:d
            if (j÷10)>=2 && (j%10)>=2 && (j÷10)*(j%10)==i
                ans+=1
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 150036
#include<cstdio>
using namespace std;
char s[100001];
char t[100001];
int a[100000];
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	scanf("%s",s);
	for(i=0;i<2;i++)
	{
		for(j=0;j<2;j++)
		{
			if(i==0)
			{
				a[0]=0;
			}
			else
			{
				a[0]=1;
			}
			if(j==0)
			{
				a[1]=0;
			}
			else
			{
				a[1]=1;
			}
			for(k=2;k<n;k++)
			{
				if(s[k-1]=='o')
				{
					if(a[k-1]==0)
					{
						a[k]=a[k-2];
					}
					else
					{
						a[k]=1-a[k-2];
					}
				}
				else
				{
					if(a[k-1]==0)
					{
						a[k]=1-a[k-2];
					}
					else
					{
						a[k]=a[k-2];
					}
				}
			}
			if(s[n-1]=='o')
			{
				if(a[n-1]==0)
				{
					if(a[n-2]!=a[0])
						continue;
				}
				else
				{
					if(a[n-2]==a[0])
						continue;
				}
			}
			else
			{
				if(a[n-1]==0)
				{
					if(a[n-2]==a[0])
						continue;
				}
				else
				{
					if(a[n-2]!=a[0])
						continue;
				}
			}
			if(s[0]=='o')
			{
				if(a[0]==0)
				{
					if(a[n-1]!=a[1])
						continue;
				}
				else
				{
					if(a[n-1]==a[1])
						continue;
				}
			}
			else
			{
				if(a[0]==0)
				{
					if(a[n-1]==a[1])
						continue;
				}
				else
				{
					if(a[n-1]!=a[1])
						continue;
				}
			}
			for(k=0;k<n;k++)
			{
				if(a[k]==0)
				{
					t[k]='S';
				}
				else
				{
					t[k]='W';
				}
			}
			printf("%s\n",t);
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
pair<ll,ll> p[ohara];
unordered_map<ll,ll> mp;
unordered_map<ll,ll> ac;
map<ll,ll> af;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i];
        p[i]=make_pair(b[i],a[i]);
        mp[b[i]]=i;
    }
    sort(p,p+m);
    rep(i,m){
        af[p[i].first]=ac[p[i].second]+1;
        ac[p[i].second]++;
    }
    rep(i,m){
        s=to_string(a[i]);
        rep(j,6-Size(s))cout<<"0";
        cout<<s;
        ans=af[b[i]];
        s=to_string(ans);
        rep(j,6-Size(s))cout<<"0";
        cout<<s<<"\n";
    }
    return 0;
}


Measured memory_bytes: 23716
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    string S;
    cin >> S;
    int X = 0, Y = 0;
    for(int i = 0; i < S.size(); i++) {
        S[i] == '0' ? X++ : Y++;
    }
    cout << 2 * min(X, Y) << endl;
    return 0;
}

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

#define MAX_N 1000006

long long int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1];   // is_prime[i]がtrueならばiは素数

// n以下の素数の数を返す
long long int sieve(long long int n) {
    long long int p = 0;
    for (long long int i = 0; i <= n; i++)
        is_prime[i] = true;
    is_prime[0] = false;
    is_prime[1] = false;
    for (long long int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (long long int j = 2 * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    int a, d, n;
    sieve(MAX_N);
    while(cin >> a >> d >> n, a != 0){
        while(n > 0){
            if(is_prime[a]){
                n--;
                if(n <= 0)break;
            }
            a += d;
        }
        cout << a << endl;
    }

    return 0;
}



Measured memory_bytes: 4668
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;


int main() {
    ll a, b;
    cin >> a >> b;
    ll m, M;

    m = min(a, b);
    M = max(a, b);
    int d = M;

    while(1){
        if(M % m == 0) {
            cout << M << endl;
            return 0;
        }else{
            M += d;
        }
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();

    Map<Integer, Integer> memo = new HashMap<>();

    int maxN = 0;
    int bunshi = 0;
    for (int i = 1; i <= N; i++) {
      int n = powern(i, K);
      if (i == 1) {
        maxN = n;
      }
      bunshi = bunshi + power2(maxN - n, memo);
    }
    int bunbo = N * power2(maxN, memo);

    System.out.println((double) bunshi / bunbo);
  }
  /*
  private static int power2(int n, Map<Integer, Integer> memo) {
    Integer cached = memo.get(n);
    if (cacehd != null) {
      return cached;
    }

    int ret = 1;
    for (int i = 0; i < n; i++) {
      ret = ret * 2;
    }
    memo.put(n, ret);
    return ret;
  }
  */

  private static int power2(int n, Map<Integer, Integer> memo) {
    Integer cached = memo.get(n);
    if (cached != null) {
      return cached;
    }

    if (n == 0) {
      return 1;
    }

    int tmp = power2(n/2, memo);
    int ret = tmp * tmp;
    if (n % 2 != 0) {
      ret = ret * 2;
    }
    memo.put(n, ret);

    return ret;
  }


  private static int powern(int a, int K) {

    int work = a;
    int ret = 0;

    while (work < K) {
      work = work * 2;
      ret++;
    }

    return ret;
  }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define max 1000000
int main()
{
    int t, a[10] = {0};
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        if (s[0] == 'A')
            a[0]++;
        else if (s[0] == 'W')
            a[1]++;
        else if (s[0] == 'T')
            a[2]++;
        else
        {
            a[3]++;
        }
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    set<string> kind;
    string s;
    cin>>s;
    INT(k);
    char c='a';
    int i,n=s.length();
    while(kind.size()<k){
        vector<pair<string,int>> point;
        for(i=0;i<n;i++){
            if(s[i]==c){
                if(i+1<n)point.push_back(make_pair(s.substr(i,2),i));
                else point.push_back(make_pair("zz",i));
            }
        }
        sort(all(point));
        for(int i=0;i<point.size();i++){
            if(kind.size()>k&&point[i].first!=point[0].first)break;
            for(int j=1;point[i].second+j<=n;j++){
                kind.insert(s.substr(point[i].second,j));
                if(j>=k)break;
            }
        }
        c++;
    }
    skip: 
    i=0;
    for(auto key:kind){
        i++;
        if(i==k){
            out(key);
            return 0;
        }
    }
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define endl '\n'
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	int a, b;
	cin >> a >> b;
	cout << (b-1+a-2)/(a-1) << endl;	
	
}



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

using namespace std;

int n;
vector<int> v;

int main() {
    cin >> n;
    v.resize(2*n);
    for (int i = 0; i < 2*n; i++) cin >> v[i];
    sort(v.rbegin(),v.rend());
    int u  = 0;
    for (int i = 1; i < 2*n; i += 2) u += v[i];
    cout << u << "\n";
}

Measured memory_bytes: 256
h,w = map(int,input().split())

a = [0]*h
b = []
for i in range(0,h):
  a[i] = input()
  
i = 0
tmp = 0
for i in range(0,h):
  if a[i].count(".") == w:
    tmp += 1
  else:
    b.append(a[i])
    
#print(b) 

b = list(zip(*b))
#print(b)
c = []
h = h - tmp
#print(h)
tmp = []

for i in range(0,w):
  if b[i].count(".") == h:
    continue
  else:
    c.append(b[i])
    
#print(c)

c = list(zip(*c))

for i in c:
  i = ''.join(i)
  print(i)


Measured memory_bytes: 38384
#include <stdio.h>

double round(double x)
{
  double dst;
  if (x<0) {
    dst = (double)(int)((-x)*1000+0.5);
    x = -dst/1000;
  } else {
    dst = (double)(int)(x*1000+0.5);
    x = dst/1000;
  }
  return x;
}

int main(void) {
  double a,b,c,d,e,f,x,y,dst1,dst2;
  
  while (scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)==6) {
    x = (e*c-b*f)/(a*e-b*d);
    y = (a*f-d*c)/(a*e-b*d);
    x = round(x);
    y = round(y);
    printf("%.3lf %.3lf\n",x,y);
  }
  
  return 0;
  
}

Measured memory_bytes: 652
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashSet<Integer> hs = new HashSet<Integer>();
    for(int i = 0;i<n;i++){
      hs.add(sc.nextInt());
    }
    System.out.println(hs.size());
  }
}


Measured memory_bytes: 22740
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    W, H = map(int, readline().split())
    if W == 0:
        return False
    MP = [list(map(int, input().split())) for i in range(H)]
    C = [[0]*W for i in range(H)]
    for j in range(W):
        cur = 0
        for i in range(H-1, -1, -1):
            if MP[i][j]:
                cur += 1
            else:
                cur = 0
            C[i][j] = cur
    D = [[0]*W for i in range(H)]
    E = [[0]*W for i in range(H)]
    for i in range(H):
        st = []
        for j in range(W):
            c = C[i][j]
            last = j
            while st and c <= st[-1][0]:
                p, k = st.pop()
                last = k
                d = min(j - k, p)
                for e in range(k, j-d+1):
                    D[i][e] = max(D[i][e], d)
            st.append((c, last))
        while st:
            p, k = st.pop()
            d = min(W - k, p)
            if d:
                for e in range(k, W-d+1):
                    D[i][e] = max(D[i][e], d)
        st.append((W, 0))

    S = []
    Z = [0]*(W*H)
    ALL = 0
    for i in range(H):
        for j in range(W):
            if MP[i][j]:
                ALL |= 1 << (i*W + j)
            if E[i][j] < D[i][j]:
                S.append(i*W + j)
                Z[i*W + j] = D[i][j]
            E[i][j] = e = max(E[i][j], D[i][j])
            if e > 1:
                E[i+1][j] = max(E[i+1][j], e-1)
                E[i][j+1] = max(E[i][j+1], e-1)
                E[i+e-1][j+e-1] = max(E[i+e-1][j+e-1], 1)

    SN = len(S)
    L = max(W, H)
    T = [0]*(L+1)
    for d in range(1, L+1):
        v = 0
        for i in range(d):
            for j in range(d):
                v |= 1 << (i*W + j)
        T[d] = v
    BS = [0]*SN; CS = [0]*SN
    for i in range(SN):
        s = S[i]
        BS[i] = T[Z[s]] << s
        CS[i] = 1 << s

    memo = [{} for i in range(SN)]
    def dfs(i, state):
        if i == SN:
            if state == ALL:
                return 0
            return W*H
        if state in memo[i]:
            return memo[i][state]
        r = W*H
        if state & CS[i]:
            r = min(r, dfs(i+1, state))
        if state & BS[i] != BS[i]:
            r = min(r, dfs(i+1, state | BS[i]) + 1)
        memo[i][state] = r
        return r
    write("%d\n" % dfs(0, 0))
    return True
while solve():
    ...


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------
const int INF = 1e9+1000;
ll n, a, b;
ll h[111111];

int main() {
   cin >> n >> a >> b;
   rep (i, n) cin >> h[i];

   ll c = a - b;
   ll left = 0, right = INF;
   while (left+1 < right) {
      ll mid = (left + right) / 2;
      ll t = 0;
      rep (i, n) {
         ll x = max(h[i] - b * mid, 0LL);
         t += (x+c-1)/c;
      }
      if (t <= mid) {
         right = mid;
      } else {
         left = mid;
      }
   }
   cout << right << endl;

   return 0;
}

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

int main(){

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

	ll n;
	cin>>n;

	vector<ll> v(n),dp(n);
	for(ll i=0;i<n;++i) cin>>v[i];

	dp[0] = 0;
	dp[1] = abs(v[1]-v[0]);

	for(ll i=2;i<n;++i){
		dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]), dp[i-2] + abs(v[i]- v[i-2]));
	}

	cout<<dp[n-1]<<"\n";

	return 0;
}

Measured memory_bytes: 4756
l=input().split()
n=int(l[0])
x=int(l[1])
m=int(l[2])
hashi=dict()
pref=0
count=0
prefix=[]
for i in range(n):
    if(i==0):
        ans=x%m
    else:
        ans=ans*ans
        ans%=m
    if(ans in hashi):
        period=i-(hashi[ans][0])
        num1=hashi[ans][0]
        k=(n-num1)//period
        rem=(n-(num1+k*period))
        count=count+prefix[num1]
        count=count+k*(pref-hashi[ans][1])
        for j in range(rem):
            if(j!=0):
                ans=ans*ans
            ans%=m
            count+=ans
        break
    hashi[ans]=(i,pref)
    prefix.append(pref)
    pref+=ans
print(max(pref,count))


Measured memory_bytes: 77296
#include <cstdio>
#define ll long long
#define Mod 1000000007
#define Maxm 1000
#define Maxn 510000
int pri[Maxm+5];
int num[Maxm+5];
int len;
int f[Maxn+5],finv[Maxn+5],inv[Maxn+5];
void fj(int n){
	len=0;
	for(int i=2;(ll)i*i<=n;i++){
		if(n%i==0){
			pri[++len]=i;
			while(n%i==0){
				num[len]++;
				n/=i;
			}
		}
	}
	if(n>1){
		pri[++len]=n;
		num[len]=1;
	}
}
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1){
			ans=(ll)ans*a%Mod;
		}
		a=(ll)a*a%Mod;
		b>>=1;
	}
	return ans;
}
void init(){
	f[0]=f[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<=Maxn;i++){
		f[i]=(ll)f[i-1]*i%Mod;
	}
	for(int i=Maxn;i>0;i--){
		inv[i]=ksm(i,Mod-2);
	}
	for(int i=2;i<=Maxn;i++){
		finv[i]=(ll)finv[i-1]*inv[i]%Mod;
	}
}
int C(int n,int k){
	if(n<k){
		return 0;
	}
	if(n<0||k<0){
		return 0;
	}
	return (int)((ll)f[n]*finv[k]%Mod*finv[n-k]%Mod);
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	init();
	fj(m);
	int ans=1;
	for(int i=1;i<=len;i++){
		ans=(ll)ans*C(num[i]+n-1,num[i])%Mod;
	}
	printf("%d\n",ans);
	return 0;
}


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

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    ll sum = 0;
    for (size_t i = 0; i < N; i++)
    {
        ll x;
        cin >> x;
        sum += x;
        a[i] = x;
    }
    ll snuke = 0;
    ll arai = sum;
    ll sub = LONG_MAX;
    for (size_t i = 0; i < N - 1; i++)
    {
        snuke += a[i];
        arai -= a[i];
        sub = min(sub, abs(snuke - arai));
    }
    cout << sub << endl;
    return 0;
}


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


int main(void)
{
	long int i, j;
	long int n, k;
	long int sum;
	long int max;
	long int count;
	long int a[100];
	long int b[100];
	long int c[100];
	
	scanf("%ld", &n);
	
	sum = n * n * n;
	
	printf("%ld\n", sum);
	
	
	return 0;
}


Measured memory_bytes: 128
def get_next_int():
    return int(float(input()))
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])

def main():
    n = get_next_int()
    values = get_next_ints()
    costs = get_next_ints()
    
    total = 0
    for value, cost in zip(values, costs):
        if value > cost:
            total += (value - cost)
    
    print(total)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  vector<string>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  ll b=1;
  if(a>1){
    for(ll i=0;i<a-1;i++){
      if(vec.at(i)!=vec.at(i+1)){
        b+=1;
      }
    }
  }
  cout<<b<<endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    long double a, b, h, m;
    scanf("%Lf %Lf %Lf %Lf",&a,&b,&h,&m);
    long double hdeg, mdeg, hrad, mrad, hx, hy, mx, my;
    hdeg = 360.0L / 12.0L * h + (360.0L / 12.0L) / 60.0L * m;
    mdeg= 360.0L / 60.0L * m;
    hrad = hdeg * M_PI / 180.0L;
    mrad = mdeg * M_PI / 180.0L;
    hx = cos(hrad) * a;
    hy = sin(hrad) * a;
    mx = cos(mrad) * b;
    my = sin(mrad) * b;
    long double dist = pow(
        abs(hy - my) * abs(hy - my) +
        abs(hx - mx) * abs(hx - mx), 0.5);
    printf("%.9Lf\n", dist);
    return 0;
}

Measured memory_bytes: 4188
a = list(map(int, input().split()))

if a[0] > 0:
	if a[3] < 0:
		print(a[0] * a[3])
	else:
		print(a[1] * a[3])

elif a[1] < 0:
	if a[2] < 0:
		print(a[0] * a[2])
	else:
		print(a[1] * a[2])
else:
	if a[3] < 0:
		print(a[0] * a[2])
	elif a[2] > 0:
		print(a[1] * a[3])
	else:
		if a[0] * a[2] > a[1] * a[3]:
			print(a[0] * a[2])
		else:
			print(a[1] * a[3])
        

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        siz.assign(sz_, 1LL);  // assign: 再代入
        par.resize(sz_);  // resize: 再確保
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    //ll N; cin >> N;
    ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    vector<pll> pe(M);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        pe[i]=mp(a-1,b-1);
    }
    vector<ll> ans(M);
    ans[M-1]=N*(N-1)/2;
    UnionFind tree(N);
    for(int i=M-1;i>0;i--){
        int a,b;
        a=pe[i].F;
        b=pe[i].S;
        if(tree.issame(a,b))ans[i-1]=ans[i];
        else{
            ans[i-1]=ans[i]-tree.size(a)*tree.size(b);
            tree.merge(a,b);
        }
    }
    rep(i,M){
        cout << ans[i] << endl;
    }
    


}

/*



 */


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-5
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() 
{
    fastio
    ll n, k;
    cin>>n>>k;
    vector<int> vec(n+1);
    for(int i = 1; i<=n; ++i) {
        cin>>vec[i];
    }

    map<int, int> mp;
    vector<int> pos;
    pos.push_back(1);
    mp[1] = 1;
    ll ind = -1;
    int cur = vec[1];
    for(int j = 2; ; ++j) {
        if(mp[cur]) {
            ind = mp[cur];
            break;
        }
        pos.push_back(cur);
        mp[cur] = j;
        cur = vec[cur];
    }

    if(k>=ind-1) {
        k -= ind-1;
        reverse(all(pos));
        for(int i = 0; i<ind-1; ++i) pos.pop_back();
        reverse(all(pos));
    }
    cout<<pos[k%(ll)(pos.size())]<<endl;
}

Measured memory_bytes: 13868
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
vector<int> A;
vector<vector<vector<int>>> dp;

void DP(int turn, int front, int have) {
	//先手
	if (turn == 0) {
		for (int n = front + 1; n < N + 2; n++) {
			if (dp[1][n][n - 1] == INT_MAX)DP(1, n, n - 1);
			dp[0][front][have] = max(dp[0][front][have], dp[1][n][n - 1]);
		}
		dp[0][front][have] = max(dp[0][front][have], abs(A[N + 1] - A[have]));
	}
	else {
		for (int n = front + 1; n < N + 2; n++) {
			if (dp[0][n][n - 1] == -1)DP(0,n, n - 1);
			dp[1][front][have] = min(dp[1][front][have], dp[0][n][n - 1]);
		}
		dp[1][front][have] = min(dp[1][front][have], abs(A[N + 1] - A[have]));
	}
}

int main() {
	cin >> N;
	A.resize(N + 2);
	cin >> A[0] >> A[1];
	for (int n = 2; n < N + 2; n++)cin >> A[n];
	dp.resize(2);
	dp[0].resize(N + 2, vector<int>(N + 2, -1));
	dp[1].resize(N + 2, vector<int>(N + 2, INT_MAX));
	DP(0, 2, 1);
	cout << dp[0][2][1] << endl;
	return 0;
}

Measured memory_bytes: 31744
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    if(A == 1 && B == 1) {
        cout << "Draw" << endl;
    } else if(A == 1) {
        cout << "Alice" << endl;
    } else if(B == 1) {
        cout << "Bob" << endl;
    } else {
        if(A == B) {
            cout << "Draw" << endl;
        } else if(A < B) {
            cout << "Bob" << endl;
        } else {
            cout << "Alice" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
//03/05/2020
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'


#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

//Number Theory
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

//Geometry
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan2( double(y1-y2) , double(x1-x2));}


/*Containers*/
vector<ll>v;
deque<ll>dq;
stack<ll>stk;
map<ll,ll>mp;
unordered_map<ll,ll>ump;
set<ll>st;
multiset<ll>mst;
unordered_set<ll>ust;
unordered_multiset<ll>umst;
priority_queue<ll,deque<ll>,greater<ll>>pq;
Pbds<ll>ost;


int main(){
    _fastio
    string s;
    cin>>s;
    if(s=="ARC") cout<<"ABC"<<en;
    else{
        cout<<"ARC"<<en;
    }





    return 0;
}


Measured memory_bytes: 3652
import math

A, B, H, M = [int(x) for x in input().strip().split(" ")]

rad_A = 0.5 * (H * 60 + M)
rad_B = 6 * M
rad = abs(rad_A - rad_B - 360)
print(math.sqrt(pow(A, 2) + pow(B, 2) - 2 * A * B * math.cos(math.radians(rad))))

Measured memory_bytes: 9572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int x;
	cin >> x;
	cout << (x? 0: 1) << endl;
}

Measured memory_bytes: 3632