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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

ll izracunajIzraz(int nekiBroj)
{
    return (ll)nekiBroj * ((ll)nekiBroj-1LL) / 2LL;
}

int main()
{
    int n;
    cin >> n;
    map<int,int> m;
    vi v(n);
    for(int i = 0; i < n; i++)
    {
        cin>>v[i];
        m[v[i]]++;
    }

    ll resenje = 0LL;

    for(map<int,int>::iterator it = m.begin(); it != m.end(); ++it)
    {
        //cout << it->fi << ' ' << it->se << '\n';
        resenje += izracunajIzraz(it->se);
    }

    for(int i = 0; i < n; i++)
    {
        cout << resenje - m[v[i]] + 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 8320
#include <stdio.h>
#include <stdlib.h>

int main (void) {
    int n;
    long int a = 0;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        a += (n - 1) / i;
    }
    printf("%ld\n", a);
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

typedef tuple<int, int> P;

int main() {
	int n;
	while ( cin >> n, n ) {
		vector<P> v;
		for (int i = 0; i < n; ++i) {
			int c; cin >> c;
			int t = 0;
			for (int i = 0; i < 4; ++i) {
				int m, s; cin >> m >> s;
				t += m * 60 + s;
			}
			v.push_back( P(c, t) );
		}
		sort(v.begin(), v.end(), [](const P& p1, const P& p2) {
			return get<1>(p1) < get<1>(p2);
		});
		cout << get<0>(v[0]) << endl;
		cout << get<0>(v[1]) << endl;
		cout << get<0>(v[n-2]) << endl;
	}
}

Measured memory_bytes: 1304
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;

const int maxn = 1000010;

int n,k,ans;
int p[maxn];

ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }

int main(){
	n=read(),k=read();
	for(int i=1;i<=n;i++) p[i]=read();
	sort(p,p+n+1);
//	for(int i=1;i<=n;i++) printf("%d ",p[i]); printf("\n"); 
	for(int i=1;i<=k;i++) ans+=p[i];
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 3760
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,l;
 	string s;
  	cin>>k>>s;
  	l = s.length();
  	//cout<<l<<endl;
  	if(k >= l){
      	cout<<s<<endl;
    }
  	else if(k < l){
      	for(int i=0; i<k; i++){
          	cout<<s[i];
        }
      	cout<<"...\n";
    }
  	return 0;
}

Measured memory_bytes: 3636
def hoge(x, y):
    return y if x >= y else y - 1

N = int(input())
H = list(map(int, input().split()))
H = list(reversed(H))

flag = 0
for i in range(N - 1):
    H[i + 1] = hoge(H[i], H[i + 1])
    if H[i] < H[i + 1]:
        flag = 1
        print("No")
        break

if flag == 0:
    print("Yes")

    

    

Measured memory_bytes: 14252
#include <cstdio>
#include <vector>
#include <iostream>
#include <cmath>
#define INF 500000+500
#define Max 0x3f3f3f3f
#define Mod 1000000007
typedef long long int ll;
using namespace std;
int arr[INF],brr[INF];
int main() 
{
	int n;
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> arr[i];
		brr[i]=i;
	}
	int cnt = 0 ;
	for(int i=1; i<=n; i++) {
		if(arr[i] != brr[i])	cnt ++;
	}
	if(cnt >= 3) {
		cout << "NO" <<endl;
	}else{
		cout << "YES" <<endl;
	}
	
	
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int x,n; cin >> x >> n; 
    int a[n];
    rep(i,n) cin >> a[i];
    bool e[102];
    rep(i,102) e[i] = false;
    int ans =0;
    rep(i,n){
        e[a[i]] = true;
    }
    int ab = 102;
    rep(i,102){
        if(!e[i]){
            if(ab > abs(i-x)){
                 ans = i;
                 ab = abs(i-x);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
map<ll,int>pm;
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    ll ans=0,cur=0;
    pm[0]++;
    while(n--){
		int x;
		scanf("%d",&x);cur+=x;
		ans+=pm[cur];pm[cur]++;
	}
	printf("%lld\n",ans);
	return 0;
}
 

Measured memory_bytes: 12800
#include "bits/stdc++.h"
using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define debug(x) cout << #x << ": " << x << endl

using ll = long long;
//#define int ll


//**********

int N;

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a[3][3];
    REP(i,3){
        REP(j,3){
            cin >> a[i][j];
        }
    }
    int ok = 1;
    
    REP(i,3){
        if(a[0][i%3]-a[0][(i+1)%3] != a[2][i%3]-a[2][(i+1)%3]) ok=0; //b
        if(a[1][i%3]-a[1][(i+1)%3] != a[0][i%3]-a[0][(i+1)%3]) ok=0; //b
        if(a[2][i%3]-a[2][(i+1)%3] != a[1][i%3]-a[1][(i+1)%3]) ok=0; //b
    }
    REP(i,3){
        if(a[i%3][1]-a[(i+1)%3][1] != a[i%3][2]-a[(i+1)%3][2]) ok=0; //a
        if(a[i%3][2]-a[(i+1)%3][2] != a[i%3][0]-a[(i+1)%3][0]) ok=0; //a
        if(a[i%3][0]-a[(i+1)%3][0] != a[i%3][1]-a[(i+1)%3][1]) ok=0; //a
    }

    if(ok==1) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 long long int i,k,n,s;
 s=0;
 cin >> k >> n;
 int a[n],b[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 for(i=0;i<(n-1);i++)
 b[i]=a[i+1]-a[i];
 b[n-1]=k+a[0]-a[n-1];
 sort(b,b+n);
 for(i=0;i<(n-1);i++)
 s+=b[i];
 cout << s;
 return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;



int main(int argc, char *argv[])
{

	//input
	string s;
	cin >> s;


	//calc
	string ans;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){
		ans = "Bad";
	}
	else{
		ans = "Good";
	}



	//ans
	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
  string s;
  cin >> s;
  for(ll i = 0; i < s.length() - 1; i++) {
    if(s.substr(i,2) == "AC") {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> P(N, "WA");
  vector<int> V(N, 0);
  int p;
  string S;
  for (int i=0; i<M; i++) {
    cin >> p >> S;
    if (P[p-1]=="WA") {
      if (S=="WA") {
        V[p-1]++;
      }
      else {
        P[p-1]=S;
      }
    }
  }
  
  int ac=0, pn=0;
  for (int i=0; i<N; i++) {
    if (P[i]=="AC") {
      ac++;
      pn+=V[i];
    }
  }
  cout << ac << " " << pn << endl;
}

Measured memory_bytes: 6616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  vector<int>s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
    sum += s.at(i);
  }
  sort(s.begin(), s.end());
  
  if (sum % 10 != 0){
    cout << sum << endl;
    return 0;
  }
  else {
    for (int i = 0; i < N; i++) {
      if (s.at(i) % 10 != 0){
        cout << sum - s.at(i) << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
}

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

using namespace std;

#define node first
#define state second

const int N = 1e5 + 5;
vector<int> adj[N];
bool vis[N][3];

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

    int n , m;
    cin >> n >> m;

    while (m--) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    int s , e;
    cin >> s >> e;

    queue<pair<int , int> > q;
    q.push({s , 0});
    vis[s][0] = 1;

    int dep = 0;
    while (q.size()) {
        int sz = q.size();
        while (sz--) {
            auto &cur = q.front();
            q.pop();

            if (cur.node == e && !cur.state) {
                cout << dep / 3;
                return 0;
            }

            for (int child : adj[cur.node]) {
                if (!vis[child][(cur.state + 1) % 3]) {
                    q.push({child , (cur.state + 1) % 3});
                    vis[child][(cur.state + 1) % 3] = 1;
                }
            }
        }
        dep++;
    }

    cout << -1;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
const int INF=999999999;

int main() {
 int A,B;
 cin>>A>>B;
 int count=0;
 for(int a=1;a<10;a++){
   for(int b=0;b<10;b++){
     for(int c=0;c<10;c++){
       int x=10001*a+1010*b+100*c;
       if(x>=A&&x<=B){count++;}
     }
   }
 }
 cout<<count<<endl;
 return 0;}

Measured memory_bytes: 256
S = input()
n = len(S)
op_cnt = n-1
answer = 0

for i in range(2 ** op_cnt):
    op = ['+']*op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[j] = ""
    op.append("")
    ans = []
    for num,plus in zip(S,op):
        ans.append(num)
        ans.append(plus)
    ans = [_ for _ in ans if _ != ""]
    ans = ''.join(ans)
    answer += eval(ans)
print(answer)

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int a,b;
    while(cin >> a >> b) {
        if(a <= 0 && 0 <= b) {
            cout << "Zero" << '\n';
        } else if(a > 0) {
            cout << "Positive" << '\n';
        } else if(b < 0) {
            int d = abs(b-a+1);
            cout << (d&1? "Negative" : "Positive") << '\n';
        } 
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int cnt=0;
	int n, m; cin >> n >> m;
	vector<int> p(n);
	rep(i,n){cin>>p[i];p[i]--;}
	vector<vector<int>> Map(n);
	//rep(i,n)cout<<p[i]<<endl;
	rep(i,m)
	{
		int foo,fooo;
		cin >> foo >> fooo;
		foo--;fooo--;
		Map[foo].push_back(fooo);
		Map[fooo].push_back(foo);
	}

	stack<int> S;
	vector<int> Ssame;
	vector<int> color(n);
	rep(i,n)color[i]=-1;
	rep(iii,n)
	{
		if(color[iii]==-1)
		{
		S.push(iii);
		Ssame.push_back(iii);
		color[iii]=iii;
		}
		//cout<<iii<<endl;
		while(!S.empty())
		{
			int v=S.top();
			
			S.pop();
			int next=-1;
			rep(i,Map[v].size())
			{
				if(color[Map[v][i]]==-1)
				{
					S.push(Map[v][i]);
					Ssame.push_back(Map[v][i]);
					color[Map[v][i]]=iii;
				}
			}
		}
		
		sort(ALL(Ssame));
		vector<int> compare;
		rep(i,Ssame.size())
		{
			compare.push_back(p[Ssame[i]]);
		}
		sort(ALL(compare));
		/*
		cout<<"  "<<iii<<endl;
		rep(i,Ssame.size())cout<<Ssame[i];cout<<endl;
		rep(j,compare.size())cout<<compare[j];cout<<endl;
		*/
		int i=0,j=0;
		for(i,j;i<Ssame.size()&&j<compare.size();)
		{
			if(Ssame[i]==compare[j])
			{
				cnt++;
				i++;
				j++;
			}
			else if(Ssame[i]<compare[j])i++;
			else j++;
		}
		Ssame.clear();
	}
	//rep(i,n)cout<<color[i]<<endl;
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 7672
// Problem : E - Sum of gcd of Tuples (Hard)
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n; i >= a; i--)
#define pb              push_back
#define lb              lower_bound		// first element >= val(itr) 
#define ub              upper_bound		// first element >  val(itr)
#define vll							vector<ll>
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))	//x can be 0 or -1

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { while (a < 0) {a += mod;} while (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { while (a < 0) {a += mod;} while (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { while (a < 0) {a += mod;} while (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

#ifdef LOCAL_TEST
#include"/home/shrey/debug.h"
#endif

const ll inf = 1e18;
const int nax = 1e5 + 5;
ll dp[nax];

ll count(ll i, ll n, ll k)
{
	if(i == k)
	{
		return 1;
	}
	
	if(dp[i] != -1)
	{
		return dp[i];
	}
	
	ll ans = 0;
	ll cnt = 1;
	for(ll j = 2*i;j<=k;j+=i)
	{
		cnt++;
		ans = add(ans,count(j,n,k));
	}
	ans = mult(-1,ans);
	ans = add(ans,mypow(cnt,n));
	
	return dp[i] = ans;
}

void SolveTestCase()
{
	ll n,k;
	cin>>n>>k;
	
	ll ans = 0;
	reset(dp,-1);
	forn(i,1,k+1)	//gcd is i
	{
		ans = add(ans,mult(i,count(i,n,k)));
	}
	cout<<ans;	
}

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	forn(i, 0, t)
	{
		SolveTestCase();
	}

	return 0;
}


Measured memory_bytes: 4436
N = int(input())
town_list = []
for _ in range(N):
    x, y = map(int,input().split())
    town_list.append((x,y))

roads = []
for i in range(N-1):
    for j in range(i+1,N):
        t1 = town_list[i]
        t2 = town_list[j]
        length = ((t1[0]-t2[0])**2 + (t1[1] - t2[1])**2)** (1/2)
        roads.append(length)

print(sum(roads) / len(roads) * (N-1))

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;

const int MAXN = 1e5;
const int INF = INT_MAX;

int num[MAXN], cost[MAXN];

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

	fill(cost, cost+MAXN, INF);
    int n, k; cin >> n >> k;
    for(int i=0; i<n; i++)
        cin >> num[i];

    cost[0] = 0;
    cost[1] = abs(num[1]-num[0]);
    for(int i=2; i<n; i++){
    	for(int j=1; j<=min(k,i); j++){
        	cost[i] = min(cost[i],cost[i-j]+abs(num[i]-num[i-j]));
        }
    }

    cout << cost[n-1] << '\n';

    return 0;
}



Measured memory_bytes: 1024
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            if(Algo.isEven(i)){
                System.out.print(s.charAt(i));
            }
        }
        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}



Measured memory_bytes: 29400
#include<bits/stdc++.h>
using namespace std;
int n,stone[200010],aff[200010],ans[200010][2];
string s;
int dp(int index,int bb)
{
	int aa=99999999;
	if(index>n)
		return 0;
	if(ans[index][bb])
		return ans[index][bb];
	if(bb==0)
	{
		if(stone[index]==0)
			aa=min(aa,dp(index+1,bb));
		else
			aa=min(aa,min(1+dp(index+1,bb),aff[index]));
	}
	return ans[index][bb]=aa;
}
int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='.')
			stone[i+1]=0;
		else
			stone[i+1]=1;
	}
	for(int i=n-1;i>=1;i--)
	{
		if(stone[i+1]==0)
			aff[i]=1+aff[i+1];
		else
			aff[i]=aff[i+1];
	}
	cout<<dp(1,0);
	return 0;
}

Measured memory_bytes: 9988
import math 

def com(n, r):
    try:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    except ValueError:
        return 0

n,k = map(int,input().split())

for i in range(k):
    ans = com(n-k+1,i+1)*com(k-1,i)
    print(ans%(10**9+7))

Measured memory_bytes: 3316
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}
template<class T> T read_val() { throw 1; }
template<> int read_val() { int tmp; scanf("%" PRId32, &tmp); return tmp; }
template<> long long read_val() { long long tmp; scanf("%" PRId64, &tmp); return tmp; }
auto read_int = read_val<int>; auto read_long = read_val<long long>;
template<class T> void scanf_vec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) vec[i] = read_val<T>(); }

#define MOD 1000000007
#define inf 2000000000
#define FWT_SIZE 2000000
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())

vector<int> step(vector<int> vec)
{
	vector<int> ans;
	for (int i = 0; i + 1 < vec.size(); i++)
	{
		ans.push_back(abs(vec[i] - vec[i + 1]));
	}
	return ans;
}

int solve(vector<int> vec)
{
	int n = vec.size() - 1;
	vector<int> ans;
	ans.push_back(0);
	for (int j = 30; j >= 0; j--)
	{
		if ((1<<j) & n)
		{
			vector<int> newans;
			for (int jj : ans)
			{
				newans.push_back(jj);
				newans.push_back(jj + (1 << j) );
			}
			sort_all(newans);
			ans = newans;
		}
	}
	int resp = 0;
	for (int x : ans)
	{
		if (x < vec.size())
			resp ^= vec[x];
	}
	return resp;
}

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string str;
	cin >> str;
	n = str.size();
	vector<int> vec;
	bool any2 = false, any1 = false;
	for (char c : str)
	{
		vec.push_back(c - '0');
	}

	vector<int> orig_vec = vec;
	vec = step(vec);
	for (int c : vec)
	{
		if (c == 2) any2 = true;
		if (c == 1) any1 = true;
	}

	if (any1)
	{
		for (int& x : vec)
		{
			if (x == 2)x = 0;
		}
		cout << solve(vec);
	}
	else
	{
		cout << solve(vec);
	}

	return 0;
	cout << "\n";
	vec = orig_vec;
	while (vec.size() > 1)
	{
		vec = step(vec);

		cout << vec << "\n";

	}



	return 0;
}

Measured memory_bytes: 21140
#include <bits/stdc++.h>
#define X first
#define Y second
#define LL long long
#define MP make_pair
#define PB push_back
#define SZ(a) (LL)(a.size())
const LL INF = 1000 * 1000 * 1000 + 47;
const LL LINF = INF * (LL)INF;
using namespace std;
const int MAXN = 55;
int idx[MAXN];
int N , x , D;
int m[MAXN];
int p[MAXN];
LL X[MAXN] , Y[MAXN] , Z[MAXN];
int am[MAXN][6];
LL dp[2][MAXN * MAXN * MAXN];
bool cmp(int i1 , int i2)
{
	return Y[i1] * X[i2] > Y[i2] * X[i1];
}
void getAm(int j)
{
	LL ye = min(Z[j] , 50LL);
	for(int i = 0; i < 5; i++)
	{
		if(ye >= (1 << i))
		{
			am[j][i] = (1 << i);
			ye -= am[j][i];
		}
	}
	am[j][5] = ye;
}
int main() 
{
	ios_base::sync_with_stdio(0);
	cin >> N >> x >> D;
	Z[0] = LINF;
	for(int i = 1; i < N; i++)
		Z[i] = D;
	for(int i = 0; i < N; i++)
		getAm(i);
	
	
	for(int i = 0; i < N; i++)
	{
		cin >> m[i];
		if(i)
			cin >> p[i];
		p[i]--;
	}
	for(int i = N - 1; i >= 0; i--)
	{
		Y[i]++;
		X[i] += m[i];
		if(i)
		{
			Y[p[i]] += Y[i];
			X[p[i]] += X[i];
		}
		//cout << i << " " << X[i] << " " << Y[i] << " " << Y[i] * 1.0 / X[i] << endl;
	}
	for(int i = 0; i < N; i++)
		idx[i] = i;
	sort(idx , idx + N , cmp);
	
	int cur = 0;
	for(int i = 0; i < 2; i++)
		for(int YY = 0; YY <= 50 * 50 * 50; YY++)
			dp[i][YY] = LINF;
	dp[0][0] = 0;
	for(int item = 0; item < N; item++)
		for(int type = 0; type < 6; type++)
		{
			for(int YY = 0; YY <= 50 * 50 * 50; YY++)
			{
				dp[cur ^ 1][YY] = min(dp[cur ^ 1][YY] , dp[cur][YY]);
				dp[cur ^ 1][YY + Y[item] * am[item][type]] = min(dp[cur ^ 1][YY + Y[item] * am[item][type]]
				 , dp[cur][YY] + X[item] * am[item][type]);
			}
			cur ^= 1;
		}
	LL ans = 0;
	for(int YY = 0; YY <= 50 * 50 * 50; YY++)
	{
		LL w = dp[cur][YY];
		//cout << YY << " " << w << endl;
		if(w > x)
			continue;
		LL she = x - w;
		LL curAns = YY;
		for(int item = 0; item < N; item++)
		{
			LL lft = max(0LL , Z[idx[item]] - 50LL);
			
			LL XX = X[idx[item]] , y = Y[idx[item]];
			LL took = min(lft , she / XX);
			she -= took * XX;
			curAns += took * y;
		}
		ans = max(ans , curAns);
	}
	cout << ans;
	
}


Measured memory_bytes: 2176
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int x, y;
	int a[7] = {1, 3, 5, 7, 8, 10, 12};
	int b[4] = {4, 6, 9, 11};
	int c[1] = {2};
	bool x_a = false;
	bool x_b = false;
	bool x_c = false;
	bool y_a = false;
	bool y_b = false;
	bool y_c = false;
	cin >> x >> y;
	for(int i = 0; i < 7; i++){
		if(a[i] == x){
			x_a = true;
		}
	}
	for(int i = 0; i < 4; i++){
		if(b[i] == x){
			x_b = true;
		}
	}
	for(int i = 0; i < 7; i++){
		if(a[i] == y){
			y_a = true;
		}
	}
	for(int i = 0; i < 4; i++){
		if(b[i] == y){
			y_b = true;
		}
	}
	for(int i = 0; i < 1; i++){
		if(c[i] == x){
			x_c = true;
		}
	}
	for(int i = 0; i < 1; i++){
		if(c[i] == y){
			y_c = true;
		}
	}
	if((x_a == true && y_a == true) || (x_b == true && y_b == true) || (x_c == true && y_c == true)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

int N, A[3][101];
vector<int> sums;

int main() {
    cin >> N;

    for (int i = 1; i <= 2; ++i) {
        for (int j = 1; j <= N; ++j) {
            cin >> A[i][j];
        }
    }

    // Accumulates A_1.
    for (int j = 2; j <= N; ++j) {
        A[1][j] += A[1][j - 1];
    }

    // Accumulates A_2 (backwards).
    for (int j = N - 1; j >= 1; --j) {
        A[2][j] += A[2][j + 1];
    }

    for (int j = 1; j <= N; ++j) {
        sums.push_back(A[1][j] + A[2][j]);
    }

    sort(sums.begin(), sums.end());
    cout << sums.back() << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var k int
	fmt.Scanf("%d", &k)

	fmt.Println(answer(k))
}

func answer(k int) int {
	gcdList := make([][]int64, 200)

	for i:=0; i<200; i++ {
		gcdList[i] = make([]int64, 200)
		for j:=0; j<200; j++ {
			gcdList[i][j] = gcd(int64(i+1), int64(j+1))
		}
	}

	res := 0

	for h:=0; h<k; h++ {
		for i:=0; i<k; i++ {
			for j:=0; j<k; j++ {
				res += int(gcdList[int(gcdList[h][i]-1)][j])
			}
		}
	}

	return res
}

func gcd(m, n int64) int64 {
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	a := new(big.Int).SetInt64(m)
	b := new(big.Int).SetInt64(n)
	return z.GCD(x, y, a, b).Int64()
}

Measured memory_bytes: 6476
#include <iostream>
#include <vector>
using namespace std;
const int N = 200005;
int n, m, L, R;
vector<int> val[N];
int lch[N << 2], rch[N << 2], Max[N << 2], lazy[N << 2];
inline void update(int x, int v) {
    lazy[x] += v; Max[x] += v;
}
inline void pushup(int x) {Max[x] = max(Max[x << 1], Max[x << 1 | 1]);}
inline void pushdown(int x) {
    if(lazy[x]) {
        update(x << 1, lazy[x]); update(x << 1 | 1, lazy[x]); lazy[x] = 0; 
    }
}
void build(int x,int l, int r) {
    lch[x] = l; rch[x] = r;
    if(l == r) {
        Max[x] = l; return;
    }
    int mid = (l + r) / 2;
    build(x << 1, l, mid); build(x << 1 | 1, mid + 1, r);
    pushup(x);
}
void update(int x, int l, int r, int v) {
    if(l <= lch[x] && rch[x] <= r) {
        update(x, v); return;
    }
    pushdown(x);
    int mid = (lch[x] + rch[x]) / 2;
    if(r <= mid) update(x << 1, l, r, v);
    else if(l > mid) update(x << 1 | 1, l, r, v);
    else update(x << 1, l, mid, v), update(x << 1 | 1, mid + 1, r, v);
    pushup(x);
}
int query(int x, int l, int r) {
    if(l <= lch[x] && rch[x] <= r) {
        return Max[x];
    }
    pushdown(x);
    int mid = (lch[x] + rch[x]) / 2;
    if(r <= mid) return query(x << 1, l, r);
    else if(l > mid) return query(x << 1 | 1, l, r);
    else return max(query(x << 1, l, mid), query(x << 1 | 1, mid + 1, r));
}
int ans = 0;
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", &L, &R); val[L].push_back(R);
    }
    build(1, 0, m + 1);
    for(int i = 0; i <= m; ++i) {
        for(int j = 0; j < val[i].size(); ++j) {
            update(1, 0, val[i][j], 1);
        }
        ans = max(ans, query(1, i + 1, m + 1) - m - i - 1);
    }
    printf("%d\n", max(ans, n - m));
    return 0;
}

Measured memory_bytes: 20224
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        String op = "";

        if (a < b) {
            op = "<";
        } else if (a > b) {
            op = ">";
        } else {
            op = "==";
        }


        System.out.println("a " + op + " b");
        sc.close();
    }
}


Measured memory_bytes: 26336
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int K,n;
int dis[200010];
int main(){
    //freopen("data.in","r",stdin);
    cin>>K>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",&dis[i]);
    int dis_n=dis[n];
    for(int i=n;i>1;i--) 
        dis[i]=dis[i]-dis[i-1];
    dis[1]+=K-dis_n;
    int mx=0,ans;
    for(int i=1;i<=n;i++){
        mx=max(mx,dis[i]);
        ans+=dis[i];
    }
    cout<<ans-mx<<endl;
    
}

Measured memory_bytes: 4524
import sys
input = sys.stdin.readline

N,P=map(int,input().split())
S=input().strip()

if P==2:
    L=[int(s)%2 for s in S[::-1]]

    ANS=0
    for i in range(N):
        if L[i]==0:
            ANS+=N-i
    print(ANS)

elif P==5:
    L=[int(s)%5 for s in S[::-1]]

    ANS=0
    for i in range(N):
        if L[i]==0:
            ANS+=N-i
    print(ANS)

else:   
    L=[0]
    NOW=1
    for i in range(N):
        L.append((L[-1]+int(S[N-i-1])*NOW)%P)
        NOW=NOW*10%P

    from collections import Counter
    C=Counter(L)
    ANS=0

    for i in range(N):
        ANS+=C[L[i]]-1
        C[L[i]]-=1
    print(ANS)

Measured memory_bytes: 12012
import java.util.*;

class Main{

    class Idle{
        String name;
        int m;
        int[] d;
        int point = 0;
        Idle(String name, int m, int[] d){
            this.name = name;
            this.m = m;
            this.d = d;
        }
    }

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            int[] cnt = new int[30];
            Arrays.fill(cnt, n+1);

            Idle[] idle = new Idle[n];
            for(int i=0; i<n; i++){
                String name = sc.next();
                int m = sc.nextInt();
                int[] d = new int[m];
                for(int j=0; j<m; j++){
                    d[j] = sc.nextInt();
                    cnt[d[j]]--;
                }
                idle[i] = new Idle(name, m, d);
            }

            for(int i=0; i<n; i++){
                int point = 0;
                for(int j=0; j<idle[i].m; j++){
                    point += cnt[idle[i].d[j]];
                }
                idle[i].point = point;
            }

            Arrays.sort(idle, new Comparator<Idle>(){
                    public int compare(Idle i1, Idle i2){
                        if(i1.point<i2.point) return -1;
                        if(i1.point>i2.point) return 1;
                        String n1 = i1.name, n2 = i2.name;
                        int len1 = n1.length(), len2 = n2.length();
                        for(int i=0; i<Math.min(len1, len2); i++){
                            if(n1.charAt(i)<n2.charAt(i)) return -1;
                            if(n1.charAt(i)>n2.charAt(i)) return 1;
                        }
                        if(len1<len2) return -1;
                        if(len1>len2) return 1;
                        return 0;
                    }
                });

            System.out.println(idle[0].point+" "+idle[0].name);
        }
    }

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

Measured memory_bytes: 30336
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    cout << max(max(a+b,a-b),a*b) << ednl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    
    int i,j;
    char s[27];
    
    scanf("%s",s);
    
    for(i=0;i<strlen(s)-1;i++){
        for(j=i+1;j<strlen(s);j++)
        if(s[i]==s[j]){
            printf("no\n");
            return 0;
        }
    }
    printf("yes\n");
    return 0;
}


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

int A=0,T=1,G=2,C=3;
const long long mod = 1e9+7;
long long dp[110][4][4][4];

int main(){
    int N;
    cin>>N;
    for(int p3=0;p3<4;p3++){
        for(int p2=0;p2<4;p2++){
            for(int p1=0;p1<4;p1++){
                if(p3==A&&p2==G&&p1==C)continue;
                if(p3==G&&p2==A&&p1==C)continue;
                if(p3==A&&p2==C&&p1==G)continue;
                dp[3][p3][p2][p1]=1;
            }
        }
    }
    for(int i=3;i<N;i++){
        for(int p4=0;p4<4;p4++){
            for(int p3=0;p3<4;p3++){
                for(int p2=0;p2<4;p2++){
                    for(int p1=0;p1<4;p1++){
                        if(p3==A&&p2==G&&p1==C)continue;
                        if(p3==G&&p2==A&&p1==C)continue;
                        if(p3==A&&p2==C&&p1==G)continue;
                        if(p4==A&&p2==G&&p1==C)continue;
                        if(p4==A&&p3==G&&p1==C)continue;
                        dp[i+1][p3][p2][p1] += dp[i][p4][p3][p2];
                        dp[i+1][p3][p2][p1] %= mod;
                    }
                }
            }
        }
    }
    long long ans=0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                ans+=dp[N][i][j][k];
            }
        }
    }
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 256
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int k,a,b;
    scanf("%d%d%d",&k,&a,&b);
    int x = a / k;
    int y = x * k;
    if (y <= b && y >= a) printf("OK\n");
    else {
        y = (x + 1) * k;
        if (y <= b && y >= a) printf("OK\n");
        else printf("NG\n");
    }
    
    
    return 0;
}


Measured memory_bytes: 3164
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int ret = min(B / A, C);

    cout << ret << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 256
/*
    Created by vasu090 on 19 Apr, 2020
*/
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int r; cin >> r;
    cout << M_PI * 2 * r << "\n";

    return 0;
}

Measured memory_bytes: 3188
use std::io::{self, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut v: Vec<i32> = Vec::new();
    for _ in 0..n {
        let x: i32 = read();
        v.push(x);
    }
    v.sort();
    println!("{}", v[n / 2] - v[n / 2 - 1]);
}

Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        int n = Integer.parseInt(br.readLine().trim());
        int a[] = new int[3];
        int ans[] = new int[n+1];
        a[0]=a[1]=a[2]=1;
        
        
        int i=1,j=1,k=1;
        L1:
        for(i=1;i<=n;i++){
            if(val(i,j,k)>n) continue;
            L2:
            for(j=1;j<=n;j++){
                if(val(i,j,k)>n) {j=1;continue L1;}
                L3:
                for(k=1;k<=n;k++){
                    long f = val(i,j,k);
//                    out.println("f: "+f+' '+i+" "+j+" "+k);
                    if(f > n) {k=1;continue L2;}
                    ans[(int)f]++;
                }
            }
        }
        for(i=1;i<=n;i++) out.println(ans[i]);
        br.close();out.flush();out.close();
    }
    public static long val(long x, long y, long z){
        long ans = x*x;
        ans += y*y;
        ans += z*z;
        ans += x*y;
        ans += y*z;
        ans += z*x;
        return ans;
    }
}

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

struct UnionFind {
  unordered_map<int, int> parent, siz;
  UnionFind(int n) {
    for (int i = 0; i < n; i++) {
      parent[i]=i;
      siz[i]=1;
    }
  }
  int find (int x){
    if (parent[x]==x) return x;
    return find(parent[x]);
  }
  void unite(int x, int y){
    int routeX = find(x);
    int routeY = find(y);
    if (routeX == routeY) return;
    
    if (siz[routeX] < siz[routeY]) swap(routeX,routeY);
    parent[routeY] = routeX;
    siz[routeX] += siz[routeY];
  }
  int size(int x) {return siz[find(x)];}
  bool same(int x, int y) {return find(x)==find(y);}
};

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  
  UnionFind uf(N);
  unordered_map<int, int> friendsOrBlocks;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    uf.unite(A, B);
    friendsOrBlocks[A]++;
    friendsOrBlocks[B]++;
  }
  
  for (int i = 0; i < K; i++) {
    int C, D;
    cin >> C >> D;
    C--;
    D--;
    
    if (uf.same(C,D)) {
      friendsOrBlocks[C]++;
      friendsOrBlocks[D]++;
    }
  }
    
  for (int i = 0; i < N; i++) {
    cout << uf.size(i) - friendsOrBlocks[i] - 1 << " ";
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 13256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;


int main()
{
   int i,j,k,n,m; cin>>n>>k;
   bool f=false;
   vector<int> a;
   for(i=0;i<n;i++)
   {
       int b;cin>>b;
       if(b>0 && !f)
       {
           a.push_back(0);
           j=i;
           f=true;
       }
       a.push_back(abs(b));
   }
   if(!f){a.push_back(0);j=n;}
   m=INT_MAX;
   for(i=1;i<=k;i++)
   {
       if(j>=k-i && j+i<=n) m=min(m,i==k ? a[j+i] : 2*a[j+i]+a[j-(k-i)]);
       if(j-i>=0 && (j+k-i)<=n) m=min(m,i==k ? a[j-i] : 2*a[j-i]+a[j+k-i]);

   }
   cout<<m<<endl;
}


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

ll dp[N][N];

int b[N];

ll solve(int l, int r) {
	if (l == r) return 0;
	if (dp[l][r]) return dp[l][r];
	dp[l][r] = INF;
	for (int mid = l; mid < r; mid++) dp[l][r] = min(dp[l][r], solve(l, mid) + solve(mid + 1, r));
	for (int i = l; i <= r; i++) dp[l][r] += b[i];
	return dp[l][r];
}

int main() {
	FREOPEN();
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) scanf("%d ", &b[i]);
	printf("%lld", solve(1, n));
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double PI=3.14159265358979323846;

int main(){
  int a,b;
  cin >> a >> b;
  int p = 1;
  int ans = 0;
  while(p < b){
    ans++;
    p += a -1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;



int main() {

    int n,k;
    cin>>n>>k;
    vi v(n);
    vi imos(n+1,0);
    rep(i,n)cin>>v[i];
    while(k--){
        rep(i,n){
            imos[max(0,(int)i-v[i])]++;
            imos[min(n,(int)i+v[i]+1)]--;
        }
        int sum=0;
        bool isbreak=1;
        rep(i,n){
            sum+=imos[i];
            v[i]=sum;
            if(v[i]!=n)isbreak=0;
            imos[i]=0;
        }
        imos[n]=0;
        if(isbreak)break;
    }
    dump(v);
}


Measured memory_bytes: 4844
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2000+10;
const ll inf=1e15;
int n;
int w[maxn],b[maxn];
ll dp[maxn][maxn],W[maxn][maxn],B[maxn][maxn];

inline void file() {
	freopen("ARC097E.in","r",stdin);
	freopen("ARC097E.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,(n<<1)) {
		char s[10]; scanf("%s",s);
		int x=read();
		if (s[0]=='W') w[x]=i;
		if (s[0]=='B') b[x]=i;
	}
//	For (i,1,n) cout << w[i] << " " ; cout << endl;
//	For (i,1,n) cout << b[i] << " " ; cout << endl;
	For (i,1,n) For (j,1,i-1) if (w[j]>w[i]) ++W[i][0];
	For (i,1,n) For (j,1,n) if (b[j]>w[i]) ++W[i][j];
	For (i,1,n) For (j,1,i-1) if (b[j]>b[i]) ++B[0][i];
	For (i,1,n) For (j,1,n) if (w[i]>b[j]) ++B[i][j];
	For (i,1,n) For (j,1,n) W[i][j]+=W[i][j-1];
	For (i,1,n) For (j,1,n) B[i][j]+=B[i-1][j];
/*	For (i,0,n) For (j,0,n) {
		if (i) For (k,1,i-1) if (w[k]>w[i]) ++W[i][j];
		if (i) For (k,1,j) if (b[k]>w[i]) ++W[i][j];
		if (j) For (k,1,j-1) if (b[k]>b[j]) ++B[i][j];
		if (j) For (k,1,i) if (w[k]>b[j]) ++B[i][j];
	}*/
/*	For (i,0,n) {
		For (j,0,n) cout << B[i][j] << " ";
		cout << endl;
	}*/
	For (i,0,n) For (j,0,n) dp[i][j]=inf;
	dp[0][0]=0;
	For (i,0,n) For (j,0,n) {
		if (i) chkmin(dp[i][j],dp[i-1][j]+W[i][j]);
		if (j) chkmin(dp[i][j],dp[i][j-1]+B[i][j]);
	}
	printf("%lld\n",dp[n][n]);
	return 0;
}

Measured memory_bytes: 94848
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;

int main() {
	int n;
	cin >> n;
	map<string, ll> m;
	vector<string> a;
	rep(i, n) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		m[s]++;
		if (m[s] == 1) a.push_back(s);
	}
	ll ans = 0;
	rep(i, a.size()) {
		ll ni = m[a[i]];
		ans += ni * (ni - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 14136
/*
 * Problem Description: Heaps - Maximum Heap
 * Category:
 * Author: Khan
 * Date: 17th October, 2017
 */

#include <iostream>
using namespace std;
#define MAXN 2000000

int H, A[MAXN + 1];

void maxHeapify(int i)
{
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;

    if(l <= H && A[l] > A[i])
        largest = l;
    else
        largest = i;
    if(r <= H && A[r] > A[largest])
        largest = r;

    if(largest != i)
    {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    cin >> H;
    for (int i = 1; i <= H; ++i)
        cin >> A[i];
    for (int i = H / 2; i >= 1; --i)
    {
        maxHeapify(i);
    }
    for (int i = 1; i <= H; ++i)
    {
        cout << " " << A[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5012