akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb emplace_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005,mod=1e9+7;
struct pt{
	int x,y;
	friend bool operator < (pt a,pt b){
		return a.y==b.y?a.x>b.x:a.y<b.y;
	}
	friend bool operator == (pt a,pt b){
		return a.x==b.x&&a.y==b.y;
	}
}p[N];
int a[N],b[N],c[N],X[N],f[N];
int n,nn,m,cnt,ans=1;

#define lb(x) (x&-x)
void upd(int x,int y){
	for(;x<N;x+=lb(x))c[x]=(c[x]+y)%mod;
}
int qry(int x){
	int res=0;
	for(;x;x-=lb(x))res=(res+c[x])%mod;
	return res;
}

int main(){
	read(n),read(m);
	rep(i,1,n)read(a[i]);
	rep(i,1,m)read(b[i]);
	rep(i,1,n)if(b[1]<a[i]&&a[i]<b[m]){
		int t=lower_bound(b+1,b+m+1,a[i])-b;
		if(t<=1||t>m||a[i]==b[t])continue;
		p[++nn]=(pt){a[i]-b[t-1],b[t]-a[i]};
		X[++cnt]=p[nn].x;
	}	
	n=nn,sort(p+1,p+n+1);
	n=unique(p+1,p+n+1)-p-1;
	sort(X+1,X+cnt+1);
	cnt=unique(X+1,X+cnt+1)-X-1;
	rep(i,1,n){
		int tmp=lower_bound(X+1,X+cnt+1,p[i].x)-X;
		f[i]=qry(tmp-1)+1;
		ans=(ans+f[i])%mod;
		upd(tmp,f[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2688
/*
problem's name:
statue:
writer:Chris
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <cctype>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050208;
/*------------main part------------*/
int num[300000];
int ans[300000];
int mx[300000][2];
int dat[300000][2];
void sol(int a,int b,int c)
{
	if(c==dat[a][0] or c==dat[a][1] or c==-1)
		return ;
	if(b>mx[a][0])
	{
		mx[a][1]=mx[a][0];
		dat[a][1]=dat[a][0];
		mx[a][0]=b;
		dat[a][0]=c;
	}
	else if(b>mx[a][1])
	{
		mx[a][1]=b;
		dat[a][1]=c;
	}
}
int main()
{
	int n;
	cin>>n;
	int tmp=(1<<n);
	for(int i=0;i<tmp;i++)
	{
		cin>>num[i];
	}
	memset(dat,-1,sizeof(dat));
	for(int i=0;i<tmp;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				for(int k=0;k<2;k++)
				{
					sol(i,mx[i^(1<<j)][k],dat[i^(1<<j)][k]);
				}
			}
		}
		sol(i,num[i],i);
	}
	ans[0]=0;
	for(int i=1;i<tmp;i++)
	{
		ans[i]=max(mx[i][0]+mx[i][1],ans[i-1]);
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 9984
import sys
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


X, Y = map(int, sys.stdin.readline().split())

n = (2 * Y - X) / 3
m = (2 * X - Y) / 3

if n.is_integer() and m.is_integer():
    n = int(n)
    m = int(m)

    ans = int(cmb(n + m, n, p))
    
    print(ans)
    
else:
    print(0)

Measured memory_bytes: 122068
#include<stdio.h>
int main(){
    char c;
    while(1){
        scanf("%c",&c);
        if(c>='a' && c <= 'z'){
            printf("%c",c-32);
        }else if(c>='A' && c <= 'Z'){
            printf("%c",c+32);
        }else{
            printf("%c",c);
        }
        if(c == '\n') break;
    }
}


Measured memory_bytes: 2032
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N;

    cin >> N;

    long S = 0;

    for (int i = 1; i <= N; i++)
    {

        if (i % 3 == 0 && i % 5 == 0)
        {
            continue;
        }

        if (i % 3 == 0)
        {
            continue;
        }

        if (i % 5 == 0)
        {
            continue;
        }

        S += i;
    }

    cout << S << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int n,s,ss,i;
	scanf("%d",&n);
	s=100000;
	for(i=0;i<n;i++){
		ss=s*0.05;
		s+=ss;
		if(s%1000!=0){	
		s=s/1000;
		s=(s+1)*1000;
		}
	}
	
	printf("%d\n",s);
	return 0;
}

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

using namespace std;
int main(){
  string s;
  cin>>s;
  int sz = s.size();
  int c=0;
  for(int i=0;i<sz/2;i++){
    if(s[i] != s[sz-i-1])
        c++;
  }
  cout<<c;
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	int N;
	cin>>N;
	string S;
	cin>>S;
	int M=0;
	int x=0;
	rep(i,N){
		if(S[i]=='I') x++;
		else x--;
		if(M<x) M=x;
	}
	cout<<M<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Elhabashy ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
const int N=3000+5,mod=1e9+7;
typedef long long ll;
int n1,n2,dp[N][N];
string s1,s2;
int solve(int i=0,int j=0){
    if(i==n1 || j==n2)return 0;
    int &ret=dp[i][j];
    if(~ret)return ret;
    if(s1[i]==s2[j])return ret=1+solve(i+1,j+1);
    ret=solve(i+1,j);
    ret=max(ret,solve(i,j+1));
    return ret;

}
string ans="";
void build(int i=0,int j=0){
    if(i==n1 || j==n2)return ;
    int &ret=dp[i][j];

    if(s1[i]==s2[j]){
        ans+=s1[i];
        build(i+1,j+1);
        return ;
    }
    int ch1=solve(i+1,j);
    int ch2=solve(i,j+1);
    if(ch1==ret)
        build(i+1,j);
    else build(i,j+1);

}
int main()
{
    Elhabashy
    input();
    cin>>s1>>s2;
    n1=s1.length();n2=s2.length();
    memset(dp,-1,sizeof dp);
    int x=solve();
    build();
    cout<<ans<<endl;
}


Measured memory_bytes: 39140
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/

int main(){
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<pair<ll,ll>> b(m);
    rep(i, m){
        cin >> b[i].second >> b[i].first;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<>());
    //rep(i, m) cout << b[i].first << " " << b[i].second << endl;
    
    
    int i = 0;
    rep(j, m){
        if(i >= n) break;          
        rep(k, b[j].second){
            if(i + k >= n) break;
            if(a[i + k] < b[j].first){
                a[i + k] = b[j].first;
            }
        }
        i += b[j].second;
    }
    ll sum = 0;
    rep(i, n){
        sum += a[i];
    }
    cout << sum << endl;    
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
  string answer[3] = {"Borys", "Alice", "Draw"};
  int alice, borys, n;

  cin >> n;
  cin >> alice;
  cin >> borys;
  int num = borys - alice - 1;
  if (num <= 0) {
    num = 0;
  }
  cout << answer[num%2] << endl;

  return 0;
}


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

typedef long long ll;

int main() {
    map<string,int> m;
    int q; cin >> q;
    for(int i=0; i<q; i++){
        int query;
        cin >> query;
        if(query==0){
            string key; int x;
            cin >> key >> x;
            m[key] = x;
        }
        else if(query==1){
            string key;
            cin >> key;
            cout << m[key] << endl;
        }
        else if(query==2){
            string key;
            cin >> key;
            m.erase(key);
        }
    }
}



Measured memory_bytes: 27888
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
      
      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      String dmmy = scanner.nextLine();
      String d_all = scanner.nextLine();
      String[] d = d_all.split(" ");
      
      int r_int = 0;

      for (int i = 0;  i < n - 1 ; i ++ ) {
      for (int j = i+1;  j < n ; j ++ ) {
        r_int = r_int + (Integer.parseInt(d[i]) * Integer.parseInt(d[j]));
      }
      }
          System.out.println(r_int);

      return;
    }
  }


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

using namespace std;

bool solve() {
	long long n;
	cin >> n;

	vector<long long> a(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}

	long long ss = n * (n + 1) / 2;
	if (sum % ss != 0) return false;

	vector<long long> d(n);
	long long cnt = 0;
	for (int i = 0; i < n; i++) {
		d[i] = (a[(i + 1) % n] - a[i]);
		d[i] -= sum / ss;
		if (d[i] > 0) return false;
		if (d[i] % n == 0) cnt += -d[i] / n;
	}

	return cnt == sum / ss;
}

int main() {
	puts(solve() ? "YES" : "NO");
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int n,q;
	ll k;
	cin>>n>>k>>q;
	vector<ll>arr(n,k);
	vector<ll>dp(n,0);
	ll sum=q;
	while(q--){
		int index;
		cin>>index;
		dp[index-1]++;
	}
	for(int i=0;i<n;i++){
		if((arr[i]-(sum-dp[i]))>0){
			cout<<"Yes\n";
		}else{
			cout<<"No\n";
		}
	}
	return 0;
}


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

using namespace std;
int n,a[10005],b[10005];
long long sum1,sum2,s,t;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) 
    {
      cin>>a[i];
      sum1+=a[i];
    }
    for(int i=1;i<=n;i++) 
    {
        cin>>b[i];
        sum2+=b[i];
    }
    if(sum1>sum2) 
    {
        cout<<"No";
        return 0;
    }
    s=sum2-sum1;
    for(int i=1;i<=n;i++)
    if(b[i]>a[i])
    t+=(b[i]+1-a[i])/2;
    if(t>s) cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,t=0;cin>>n>>a>>b;
	if(a+b-1>n||(long long)a*b<n)cout<<-1;
	else{
		for(int i=0;i<a;i++)
		{
			int rem=min((n-t)-(a-i-1),b);
			for (int j=0;j<rem;j++)cout<<t+rem-j<<" ";
			t+=rem;
		}
	}
}


Measured memory_bytes: 2176
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			double answer = 0;
			for(int i = 0; i < N; i++) {
				answer += 1 / sc.nextDouble();
			}
			
			System.out.printf("%.10f\n", 1 / answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21076
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, K;
double n, ans;

signed main(){
    cin >> N >> K;
    n = (double)N;
    for(int i = 1; i <= N; i++){
        int j = i;
        int cnt = 0;
        while(j < K){
            j *= 2;
            cnt++;
        }
        double po = 1.0;
        for(int k = 0; k < cnt; k++){
            po *= 0.5;
        }
        ans += (1 / n) * po;
    }
    printf("%.10lf\n", ans);

    return 0;
}
/*



*/

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = [LI() for _ in range(n)]
for i in range(n-2):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        print('Yes')
        quit()
print('No')     

Measured memory_bytes: 67212
/*
 * main.c
 *
 *  Created on: 2020/07/27
 *      Author: 113896
 */
#include <stdio.h>

void call(int n) {
	int i = 1;
	int x;
	do {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		} else {
			do {
				if (x % 10 == 3) {
					printf(" %d", i);
					x = 0;
				} else {
					x /= 10;
				}
			} while (x);
		}
	} while (++i <= n);
	printf("\n");
}

int main() {

	int n;
	scanf("%d", &n);
	call(n);

	return 0;
}







Measured memory_bytes: 2136
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] p = new int[n];

		int i;
		for(i = 0; i < n; i++) {
			p[i] = scan.nextInt();
		}
		int ans = 0;
		for(i = 1; i < n - 1; i++) {
			if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) {
				ans++;
			}
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <math.h>

int main(void)
{
	double r, l, s;
	scanf("%lf", &r);
	
	l = 2.0f * M_PI * r;
	s = M_PI * r * r;

	printf("%lf %lf\n", s, l);

	return 0;
}



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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18+9
#define sz(a) ((int)a.size())
ll mod=1e9+7;

vector<ll> fac; 
vector<ll> ifac; 
void init_ch(int n){
  fac=vector<ll> (n); 
  ifac=vector<ll> (n); 
  vector<ll> inv(n); 
  fac[0]=1; 
  inv[0]=inv[1]=1; 
  ifac[0]=ifac[1]=1; 
  for(int i=1;i<n;i++){
    fac[i]=fac[i-1]*i%mod; 
    if(i>1){
      ll q=mod/i, r=mod%i; 
      ll ii=-1*q*inv[r]%mod; ii+=mod; ii%=mod; 
      inv[i]=ii; 
      ifac[i]=ifac[i-1]*ii%mod; 
    }
  }
}

void solve(){
  int h,w,n; cin>>h>>w>>n; 
  init_ch(h+w+10); 
  vector<pair<int,int>> walls(n); 
  for(int i=0;i<n;i++){
    int x,y; cin>>x>>y; 
    walls[i]={x,y}; 
  }
  sort(walls.begin(),walls.end()); 
  walls.push_back({h,w}); 
  vector<ll> ways(sz(walls)); 
  for(int i=0;i<sz(walls);i++){
    ll r=walls[i].first-1, c=walls[i].second-1; 
    ways[i]=fac[r+c]*ifac[r]%mod*ifac[c]%mod; 
    for(int j=i-1;j>=0;j--){
      if(walls[j].second > walls[i].second || walls[j].first > walls[i].first) continue; 
      r=walls[i].first-walls[j].first, c=walls[i].second-walls[j].second; 
      ways[i]-=ways[j]*fac[r+c]%mod*ifac[r]%mod*ifac[c]%mod; ways[i]+=mod; ways[i]%=mod; 
    }
  }
  cout<<ways.back()<<endl; 
}

int main(){
	fast_io;
	clock_t beg=clock();
  int t;
  t=1;
  while(t--){
	  solve();
  }
	clock_t end=clock();
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 4992
s=[list(input()) for i in range(3)]
for i in range(3):
  s[i]=list(reversed(s[i]))
flag=True
next=0
ans=0
mem_s=["a","b","c"]
ans_s=["A","B","C"]
while(flag):
  if len(s[next]) >0:
    tmp=s[next].pop()
    next=mem_s.index(tmp)
  else:
    ans=next
    flag=False
print(ans_s[ans])

Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1 for i in range(self.n)]
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        p = self.find(x)
        q = self.find(y)
        if p == q:
            return None
        if p > q:
            p, q = q, p
        self.par[p] += self.par[q]
        self.par[q] = p
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def size(self, x):
        return -self.par[self.find(x)]
n, q = map(int, input().split())
UF = UnionFind(n)
for i in range(q):
    o, u, v = map(int, input().split())
    if o == 0:
        UF.unite(u, v)
    else:
        print(1 if UF.same(u, v) else 0)

Measured memory_bytes: 11688
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B,C;
  cin >> A >> B >> C;
  if(C-A+B>=0)
  {
  cout << C-A+B << endl;
  }
  else
  {
    cout << 0 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::max;

#[allow(non_snake_case)]
fn main() {
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  let mut S : Vec<usize> = buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
  let N = S[0];

  let mut dp1 = vec![None; N + 1];
  let mut dp2 = vec![vec![None; N + 1];N + 1];
  {
    let s = &mut S[1 ..= 2];
    s.sort();
    let (a,b) = (s[0], s[1]);
    dp1[a].get_or_insert(0);
    dp1[b].get_or_insert(0);
    dp1[0].get_or_insert(0);
    dp2[a][b].get_or_insert(0);
    dp2[b][a].get_or_insert(0);
  }

  let mut base = 0;
  let mut q = Vec::new();

  for i in 1 .. N {
    let s = &mut S[3 * i .. 3 * (i + 1)];
    s.sort();
    let (a,b,c) = (s[0],s[1],s[2]);
    
    if a == c {
      base += 1;
      continue;
    } else if a == b {
      for x in 1 ..= N {
        if let Some(v) = dp2[x][a] {
          q.push((x, c, v + 1));
        }
      }
      if let Some(v) = dp2[c][c] {
        q.push((a, a, v + 1));
      }
    } else if b == c {
      for x in 1 ..= N {
        if let Some(v) = dp2[x][c] {
          q.push((x, a, v + 1));
        }
      }
      if let Some(v) = dp2[a][a] {
        q.push((c, c, v + 1));
      }
    } else {
      if let Some(v) = dp2[a][a] {
        q.push((b, c, v + 1));
      }
      if let Some(v) = dp2[b][b] {
        q.push((a, c, v + 1));
      }
      if let Some(v) = dp2[c][c] {
        q.push((a, b, v + 1));
      }
    }
    
    q.push((a, b, dp1[0].unwrap()));
    q.push((a, c, dp1[0].unwrap()));
    q.push((b, c, dp1[0].unwrap()));
    
    for x in 1 ..= N {
      if let Some(v) = dp1[x] {
        for y in &[a,b,c] {
          if x < *y {
            q.push((x, *y, v));
          } else {
            q.push((*y, x, v));
          }
        }
      }
    }
    
    while let Some((a,b,v)) = q.pop() {
      if dp2[a][b].is_none() || dp2[a][b].unwrap() < v {
        dp2[a][b].replace(v);
        dp2[b][a].replace(v);
        for i in &[0, a, b] {
          let u = dp1[*i].get_or_insert(v);
          *u = max(*u, v);
        }
      }
    }
  }

  let s = S[S.len() - 1];
  if let Some(v) = dp2[s][s] {
    println!("{}", base + max(v + 1, dp1[0].unwrap()));
  } else {
    println!("{}", base + dp1[0].unwrap());
  }
}


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

int main(){
    string s, t ;
    cin >> s >> t ;
    int ans = 0; 
    rep(i, 3) {
        if (s[i] == t[i]){
            ans++ ;
        }
    }
    cout << ans << endl ;

}

Measured memory_bytes: 3564
n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**9
for i in range(1,n):
    if k>abs(a[0]/2-a[i]):
        k=abs(a[0]/2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])


Measured memory_bytes: 14052
import java.util.Scanner;
public class Main {

  static String str;
  static String ans;
  static long sum = 0;
  public static void main(String[] args) {

	  Scanner sc = new Scanner(System.in);
	  str = sc.next();
	  char[] charArray = str.toCharArray();

	  for(int bit = 0; bit < Math.pow(2, str.length() -1) ; bit++) {
		  ans = String.valueOf(charArray[0]);
		  for(int i = 0 ; i < str.length() - 1 ;i++) {
			  if((1 & (bit >> i)) == 1) {
				 ans += ",";
			  }
			  ans += String.valueOf(charArray[i+1]);
		  }
		  String num[] = ans.split(",");
			  for(int i = 0; i < num.length;i++) {
				  sum += Long.valueOf(num[i]);
		  }
	  }
	  System.out.println(sum);
	  sc.close();

  }

}

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

n,k = map(int, input().split())
grid = [[0]*k for i in range(k)]
black = 0
for i in range(n):
    a,b,c =input().split()
    a,b = int(a), int(b)
    f = a//k + b//k
    a %= k
    b %= k
    if (c == "W" and f%2==0) or (c == "B" and f%2==1):
        grid[a][b] += 1
    else:
        grid[a][b] -= 1
        black += 1

s = [[0]*(k+1) for i in range(k+1)]
for i in range(k):
    for j in range(k):
        s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + grid[i][j]

ans = 0
for i in range(k):
    for j in range(k):
        a = s[k][k] - s[i][k] - s[k][j] + 2*s[i][j] + black
        ans = max(ans, max(a, n-a))
print(ans)

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

int main(){
  unsigned long n, i, ans=1, c= pow(10, 9)+7;
  
  cin >> n;
  
  for (i=1; i<=n; i++) {
    ans *= i;
    ans %= c;
  }
  
  cout << ans << endl;
   
  return 0;  
}

Measured memory_bytes: 256
function Main(input) {
    var H = parseInt(input[0], 10);
    var result = 0;
    var count = 0;

    while(H !== 0) {
        result += Math.pow(2, count);
        H = Math.floor(H / 2);
        count ++;
    }

    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 7372
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int[][] d = new int[A+1][B+1];
        for(int i=1;i<=A;++i)for(int j=1;j<=B;++j)d[i][j]=scan.nextInt();

        int[][] f = new int[101][101];
        int[][] dd = new int[A+1][B+1];
        for(int[] array : dd)Arrays.fill(array, 100);
        for(int a=0;a<=100;++a)for(int b=0;b<=100;++b){
            for(int i=1;i<=A;++i)for(int j=1;j<=B;++j)f[a][b] = Math.max(f[a][b] , d[i][j] - a*i - b*j);
        }
        for(int i=1;i<=A;++i)for(int j=1;j<=B;++j){
            for(int a=0;a<101;++a)for(int b=0;b<101;++b)dd[i][j]=Math.min(dd[i][j], f[a][b] + a*i + b*j);
            if(dd[i][j]!=d[i][j]){
                System.out.println("Impossible");
                return;
            }
        }
        System.out.println("Possible");
        System.out.println(202+" "+(200 + 101*101));
        for(int a=0;a<=100;++a)for(int b=0;b<=100;++b)System.out.println((a+1)+" "+(202-b)+" "+f[a][b]);
        for(int i=0;i<100;++i)System.out.println((i+1)+" "+(i+2)+" X");
        for(int i=101;i<201;++i)System.out.println((i+1)+" "+(i+2)+" Y");
        System.out.println("1 202");

    }
}

Measured memory_bytes: 27604
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define maxn 200000+66
int main()
{
    int h,a;
    while(cin>>h>>a)
    {
        int s=0;
        for(int i=1;i<=a;i++)
        {
            int x;
            cin>>x;
            s+=x;
        }
        if(s>=h)
        {
            cout<<"Yes"<<endl;
        }else
        {
            cout<<"No"<<endl;
        }
    }
}


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

int main() {
  int N = 5;
  vector<int> X(N);
  for (int i = 0; i < N; i++) cin >> X.at(i);
  for (int i = 0; i < N; i++) {
    if (!X.at(i)) return cout << i + 1 << "\n", 0;
  }
}

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


int main() {
    string s;
    cin >> s;
    if(s[0] == s[2]){
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    
    cout << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e6+10;
const int inf=1e9;
ll n;
int f[N];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	int ans=0;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			f[i]++;
			n/=i;
		}
	}
	if(n>1) ans++;
	rep(i,1,N-5){
		for(int j=1;f[i]>=j;j++){
			ans++;
			f[i]-=j;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  long ans = 700;
  for (auto it: S) if (it == 'o') ans += 100;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;


main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0; 
    ans += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);
    cout << ans;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
struct node {
    char name[100];
    int t;
};
int main() {
    int n,q,t;
    scanf("%d%d",&n,&q);
    queue<node>qu;
    for(int i=0; i<n; i++) {
        node N;
        scanf("%s%d",N.name,&N.t);
        qu.push(N);
    }
    int sum=0;
    while(!qu.empty()) {
        node this_node=qu.front();
        qu.pop();
        sum+=min(this_node.t,q);
        if(this_node.t<=q) {
            printf("%s %d\n",this_node.name,sum);
        } else {
            this_node.t-=q;
            qu.push(this_node);
        }
    }
}



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
ll a[10050];
set<ll> cleared;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = N; i >= 0; i--) cin >> a[i];
    vector<ll> primes;
    ll copy = abs(a[N]);
    for(ll i = 2; i * i <= copy; i++) {
        if(copy % i == 0) {
            primes.push_back(i);
            while(copy % i == 0) copy /= i;
        }
    }
    if(copy > 1) primes.push_back(copy);
    for(int i = 0; i < primes.size(); i++) {
        ll now = primes[i];
        bool ok = true;
        for(int j = 0; j <= N; j++) {
            if(a[j] % now != 0) ok = false;
        }
        if(ok) cleared.insert(now);
    }
    for(ll i = 2; i <= 10001; i++) {
        bool ok = true;
        for(ll j = 2; j * j <= i; j++) {
            if(i % j == 0) ok = false;
        }
        if(!ok) continue;
        cerr << i << endl;
        if(a[0] % i != 0) continue;
        //cerr << i << endl;
        vector<ll> v(10002);
        for(int j = N; j >= 0; j--) {
            v[j] += a[j];
            if(j-i+1 >= 0) {
                v[j-i+1] += v[j];
            }
        }
        bool clear = true;
        for(int j = 0; j < i-1; j++) {
            //cerr << j << " " << v[j] << endl;
            if(v[j] % i != 0) clear = false;
        }
        if(clear) cleared.insert(i);
    }
    for(auto itr = cleared.begin(); itr != cleared.end(); itr++) {
        cout << *itr << endl;
    }
    return 0;
}


Measured memory_bytes: 384
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

// struct SqrtDecomposition { // sum
// private:
//     ll N, K, sqrtN;
//     vector<ll> data, bucket;

// public:
//     SqrtDecomposition(ll n){
//         N = n;
//         sqrtN = sqrt(n);
//         K = (N + sqrtN - 1) / sqrtN;
//         data.assign(n+10, 0);
//         bucket.assign(K+10, 0);
//     }

//     void add(ll x, ll y){
//         ll k = x / sqrtN;
//         data[x] += y;
//         bucket[k] += y;
//     }

//     // [x, y)
//     ll getSum(ll x, ll y){
//         ll sum = 0;
//         rep(k,0,K){
//             ll lv = k * sqrtN, rv = (k+1) * sqrtN;
//             if(rv <= x || y <= lv) continue;
//             if(x <= lv && rv <= y){
//                 sum += bucket[k];
//             }else{
//                 for(ll i = max(x, lv); i < min(y, rv); i++){
//                     sum += data[i];
//                 }
//             }
//         }
//         return sum;
//     }
// };

struct SqrtDecomposition { // min
private:
    ll N, K, sqrtN;
    vector<ll> data, bucket;

public:
    SqrtDecomposition(ll n){
        N = n;
        sqrtN = sqrt(n);
        K = (N + sqrtN - 1) / sqrtN;
        data.assign(n+10, (1LL<<31)-1);
        bucket.assign(K+10, (1LL<<31)-1);
    }

    void update(ll x, ll y){
        ll k = x / sqrtN;
        data[x] = y;
        ll min_val = y;
        for(ll i = k * sqrtN; i < (k+1) * sqrtN; i++){
            min_val = min(min_val, data[i]);
        }
        bucket[k] = min_val;
    }

    // [x, y)
    ll find(ll x, ll y){
        ll min_val = INF;
        rep(k,0,K){
            ll lv = k * sqrtN, rv = (k+1) * sqrtN;
            if(rv <= x || y <= lv) continue;
            if(x <= lv && rv <= y){
                min_val = min(min_val, bucket[k]);
            }else{
                for(ll i = max(x, lv); i < min(y, rv); i++){
                    min_val = min(min_val, data[i]);
                }
            }
        }
        return min_val;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Q;
    cin >> N >> Q;
    SqrtDecomposition sd(100010);
    while(Q--){
        ll c,x,y;
        cin >> c >> x >> y;
        if(c == 0){
            sd.update(x, y);
        }else{
            print(sd.find(x, y+1));
        }
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
const double EPS = 1e-8;
#define Scan(a) int a;scanf("%d", &a);
#define ScanS(a) char a[500];scanf("%s", a);
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {
	int n;
	cin >> n;
	map<ll, int> m;
	int a;
	ll cur = 0;
	int ans = 0;
	m[0] = -1;
	REP(i, n){
		scnaf("%d", &a);
		cur += a;
		if(!m.count(cur))
			m[cur] = i;
		else {
			ans = max(ans, i - m[cur]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15708
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,m;
ll a[1000005],ans;
int main(){
	in(n);in(m);
    for(int i=1;i<=n;i++)in(a[i]);
    sort(a+1,a+1+n);
    for(int i=1;i<=n-m;i++)ans+=a[i];
    printf("%lld\n",ans);
	return 0;
}


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


using namespace std;


int euclid( int a, int b )
{
    int temp;

    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}

int main()
{
	long long int a,b,c,d,x,y;
	long long int e,f,g,h,i,j,ans;
	
	
	cin >> a >> b >> c >> d;
	
	x = euclid(c,d);
	y = (c/x)*d;
	
	e = (a-1)/c;
	f = b/c;
	g = (a-1)/d;
	h = b/d;
	i = (a-1)/y;
	j = b/y;
	
	ans = b - a + 1 + e - f + g - h - i + j;
	
	cout << ans << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S, T = sys.stdin.buffer.readline().decode().rstrip().split()
A, B = list(map(int, sys.stdin.buffer.readline().split()))
U = sys.stdin.buffer.readline().decode().rstrip()

cnt = {}
cnt[S] = A
cnt[T] = B
cnt[U] -= 1
print(cnt[S], cnt[T])
   


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

string S,T;

int main(){
    cin>>S>>T;
    
    int ans=0;
    for(int i=0;i<3;i++){
        if(S[i]==T[i]) ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

class UnionFind {
public:
	vector<int> par;

	UnionFind(int n) {
		par = vector<int>(n, -1);
	}

	int root(int a) {
		if (par[a] < 0) {
			return a;
		}
		else {
			return par[a] = root(par[a]);
		}
	}

	int size(int a) {
		return -par[root(a)];
	}

	bool connect(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}
		if (size(a) < size(b)) {
			swap(a, b);
		}
		par[a] += par[b];
		par[b] = a;
		return true;
	}

};

int main(){
	int n, m; cin >> n >> m;
	vector<P> g;
	rep(i, 0, m) {
		int p1, p2; cin >> p1 >> p2;
		p1--; p2--; g.push_back({ p1,p2 });
	}
	int ans=0;
	rep(i, 0, m) {
		UnionFind uni(n);
		rep(j, 0, m) {
			if (i == j) continue;
			uni.connect(g[j].first, g[j].second);
		}
		rep(j, 0, n)rep(k, 0, n) {
			if (uni.root(j) != uni.root(k)) {
				ans++;
				j += n; k += n;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M;
  cin>>N>>M;
  vector<vector<int> > d={
    {1,1,1},
    {1,1,-1},
    {1,-1,1},
    {-1,1,1},
    {1,-1,-1},
    {-1,1,-1},
    {-1,-1,1},
    {-1,-1,-1}
  };
  vector<ll> x(N),y(N),z(N),sum(N);
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i]>>z[i];
  }

  ll ans=0ll;
  for(auto e : d){
    for(int i=0;i<N;i++){
      sum[i]=e[0]*x[i]+e[1]*y[i]+e[2]*z[i];
    }
    sort(rALL(sum));
    ans=max(ans,accumulate(sum.begin(),sum.begin()+M,0ll));
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
C - Divide the Problems
https://atcoder.jp/contests/abc132/tasks/abc132_c

"""
import sys
from bisect import bisect_left, bisect_right

def solve(n, problems):
    lb, ub = 0, n
    while ub - lb > 1:
        mid = (lb + ub) // 2
        i = bisect_left(problems, problems[mid])
        if i < n // 2:
            lb = mid
        else:
            ub = mid
    return problems[ub] - problems[lb] if lb + 1 == n // 2 else 0


def main(args):
    n = int(input())
    problems = sorted([int(x) for x in  input().split()])
    ans = solve(n, problems)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const ll INF = pow(10,10);

ll cnt = 0;

void merge(vector<int> &A, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<ll> L(n1+1);
    vector<ll> R(n2+1);
    rep(i,n1) L[i] = A[left+i];
    rep(i,n2) R[i] = A[mid+i];
    L[n1] = R[n2] = INF;
    int i=0, j=0;
    for(int k=left; k<right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            cnt += j;
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(vector<int> &A, int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main()
{
    int n; cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    mergeSort(A, 0, n);
    //rep(i,n) cout << A[i] << " ";
    //cout << endl;
    cout << cnt << endl;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll x1, y1, x2, y2;
  scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);

  ll wx = (x2 - x1);
  ll wy = (y2 - y1);

  ll x3 = x2 - wy;
  ll y3 = y2 + wx;
  ll x4 = x1 - wy;
  ll y4 = y1 + wx;

  cout << (x3) << " " << (y3) << " " << (x4) << " " << (y4) << endl;
}


Measured memory_bytes: 3756
/** 
 *  Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    if((b-1)%(a-1) == 0)    cout<<(b-1)/(a-1);
    else    cout<<(b-1)/(a-1) + 1;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	int V[21], C[21];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> V[i];
	for (int i = 0; i < N; i++) cin >> C[i];
	int ans = 0;
	int num = -mod;
	for (int i = 0; i < N; i++) {
		ans += max(0, V[i] - C[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


struct Segtree {
	int size = 1;
	vector<int>dat, lazy;
	Segtree(int x,int y) {
		while (size < x)size *= 2;
		dat.resize(2 * size - 1, y);
		lazy.resize(2 * size - 1, 0);
	}
	void eval(int k, int l, int r) {
		dat[k] -= lazy[k];
		if (r - l > 1) {
			lazy[k * 2 + 1] += lazy[k];
			lazy[k * 2 + 2] += lazy[k];
		}
		lazy[k] = 0;
	}
	void update(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r == -1)r = size;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l && r <= b) {
			lazy[k]++;
			eval(k, l, r);
			return;
		}
		update(a, b, k * 2 + 1, l, (l + r) / 2);
		update(a, b, k * 2 + 2, (l + r) / 2, r);
	}
	void query(int a, int k = 0, int l = 0, int r = -1) {
		if (r == -1)r = size;
		eval(k, l, r);
		if (r - l == 1) {
			if (dat[k] <= 0)cout << "No" << endl;
			else cout << "Yes" << endl;
			return;
		}
		if (a < (l + r) / 2) {
			query(a, k * 2 + 1, l, (l + r) / 2);
		}
		else {
			query(a, k * 2 + 2, (l + r) / 2, r);
		}
	}
};
int n, k, q;
signed main() {
	cin >> n >> k >> q;
	Segtree S(n, k);
	while (q--) {
		int a; cin >> a; a--;
		if (a)S.update(0, a);
		if (a < n - 1)S.update(a + 1, S.size);
	}
	rep(i, n) {
		S.query(i);
	}
}

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
    static int[][] data;
    static boolean[][] check;

    static int W,H;
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            W = sc.nextInt();
            H = sc.nextInt();
            if(W==0&&H==0) return;
            data = new int[H][W];
            check = new boolean[H][W];
            int count = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++) {
                    data[i][j] = sc.nextInt();
                    check[i][j] = false;
                }
            }
            for(int h=0;h<H;h++)
            {
                for(int w=0;w<W;w++)
                {
                    if(!check[h][w])
                    {
                        if(checkAround(h,w))
                            count++;
                    }
                }
            }
            System.out.println(count);
        }

    }

    static boolean checkAround(int x,int y)
    {
        if(data[x][y]==0||check[x][y]) return false;
        check[x][y] = true;
        if(x!=0) checkAround(x-1,y);
        if(y!=0)checkAround(x,y-1);
        if(x!=H-1)checkAround(x+1,y);
        if(y!=W-1)checkAround(x,y+1);
        if(x!=0&&y!=0)checkAround(x-1,y-1);
        if(x!=0&&y!=W-1)checkAround(x-1,y+1);
        if(x!=H-1&&y!=0)checkAround(x+1,y-1);
        if(x!=H-1&&y!=W-1)checkAround(x+1,y+1);
        return true;
    }
}

Measured memory_bytes: 47896