akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <time.h> 
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

VI e[100000];
int a[100000], mi[100000], ma[100000], isodd[100000];
bool f = 1;

void dfs(int now, int past, int dist, int num){
    if (dist > 0){
        int sm = num - dist, la = num + dist;
        int t = la % 2;
        if (a[now] > 0){
            if (a[now] % 2 != t || a[now] < sm || a[now] > la) f = 0;
            return;
        }
        if (isodd[now] >= 0 && isodd[now] != t){
            f = 0;
            return;
        }
        isodd[now] = t;
        mi[now] = max(mi[now], sm);
        ma[now] = max(ma[now], la);
    }
    REP(i,e[now].size()){
        int next = e[now][i];
        if (past == next) continue;
        dfs(next, now, dist+1, num);
    }
}

int main() {
    clock_t start = clock();
    int n, k;
    cin >> n;
    REP(i,n){
        isodd[i] = -1;
        mi[i] = -1e9;
        ma[i] = 1e9;
    }
    REP(i,n-1){
        int a, b;
        scanf("%d %d", &a, &b);
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    cin >> k;
    VI s(k);
    REP(i,k){
        int v, p;
        scanf("%d %d", &v, &p);
        v--;
        a[v] = p;
        mi[v] = p;
        ma[v] = p;
        s[i] = v;
    }

    REP(i,k){
        dfs(s[i], -1, 0, a[s[i]]);
        clock_t end = clock();
        double tm = (double)(end-start)/CLOCKS_PER_SEC;
        if (tm > 1.9) break;
    }

    REP(i,n){
        if (mi[i] > ma[i]) f = 0;
    }

    if (f){
        cout << "Yes" << endl;
        REP(i,n) printf("%d\n", mi[i]);
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    int64_t n;
    cin >> n;
    
    vector<int64_t> vec(n);
    for(int64_t i = 0; i < n; i++){
        cin >> vec[i];
    }
    
    int64_t sum = 0;
    for(int64_t i = 0; i < n - 1; i++){
        if(vec[i+1] < vec[i]){
            int64_t humidai = vec[i] - vec[i+1];
            sum += humidai;
            vec[i+1] += humidai;
        }
    }
    
    cout << sum << endl;
    
}

Measured memory_bytes: 4840
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string str1;
string str2;
int main(){
	while(cin>>str1>>str2){
		int ans = 0;
		for(int i = 0;i <str1.length();i++){
			for(int j=0;j <str1.length();j++){
				if(i>0&&j>0&&str1[i-1]==str2[j-1])continue;
				int tmp = 0;
				for(int k = 0;k+i<str1.length()&&k+j<str2.length();k++){
					if(str1[i+k]!=str2[j+k]){
						break;
					}
					tmp++;
				}
				ans =max(ans,tmp);
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
# -*- coding: utf-8 -*-
k, s = map(int,input().split())
count = 0
if k == s/3:
  print(1)
  exit()
for x in range(k+1):
  for y in range(k+1):
    z = s - x -y
    if (z >= 0 and z <= k):
      #print(x,y,z)
      count += 1
print(count)


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

using namespace std;

typedef pair<int, int> P;

typedef long long ll;

#define INF 1000000000000LL

ll max(ll a, ll b) { return a > b ? a : b; }

struct Bit {
	int bitSize;
	vector<ll> bit;
	void init(int n, ll v) {
		bitSize = n;
		bit = vector<ll>(n+1, 0);
	}
	void add(int n, ll v) {
		++n;
		while (n <= bitSize) {
			bit[n] = max(bit[n], v);
			n += n & -n;
		}
	}
	ll sum(int r) {
		ll ret = 0;

		while (r) {
			ret = max(ret, bit[r]);
			r -= r & -r;
		}

		return ret;
	}
};

Bit bit;

int main() {
	int N; cin >> N;
	vector<P> v;
	for (int i = 0; i < N; ++i) {
		int x; cin >> x;
		v.push_back( P(x, i) );
	}

	sort( v.begin(), v.end() );

	ll sum = (ll)N*(N+1)/2;

	bit.init(N, 0);
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		ll val = bit.sum(v[i].second+1) + v[i].first;
		ans = max(ans, val);
		bit.add(v[i].second, val);
//		cout << bit.sum(v[i].second+1) << endl;
	}
	ans = sum-ans;
	cout << ans << endl;
}

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

#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r

const int MAXN=300010;
int tr[MAXN<<3];

void push_up(int rt)
{
    tr[rt]=max(tr[rt<<1],tr[rt<<1|1]);
}

void build(int rt,int l,int r)
{
    if (l==r) {
        tr[rt]=0;
        return;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
    push_up(rt);
}

void update(int rt,int l,int r,int x,int y)
{
    if (l==r) {
        tr[rt]=y;
        return;
    }
    int m=(l+r)>>1;
    if (x<=m) update(lson,x,y);
    else update(rson,x,y);
    push_up(rt);
}

int query(int rt,int l,int r,int L,int R)
{
    if (L<=l&&r<=R) {
        return tr[rt];
    }
    int m=(l+r)>>1;
    int res=-1;
    if (L<=m) res=max(res,query(lson,L,R));
    if (m<R) res=max(res,query(rson,L,R));
    return res;
}

const int inf=1<<28;
int a[MAXN],dp[MAXN];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int mn=inf,mx=-inf;
    for (int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
    }
    int m = (mx+k)-(mn-k)+1;
    int offset = -(mn-k)+1;
    build(1,1,m);
    int ans = 0;
    for (int i=1;i<=n;i++) {
        dp[i] = query(1,1,m,offset+a[i]-k,offset+a[i]+k)+1;
        update(1,1,m,offset+a[i],dp[i]);
        ans=max(ans,dp[i]);
    }
    printf("%d\n",ans);
    return 0;
}

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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int) 1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

int main()
{
    i64 n;
    cin >> n;
    i64 ans = 1;
    for(int i = 0; i < n; i++) {
        ans *= 10;
        ans %= mod;
    }
    i64 x = 1;
    for(int i = 0; i < n; i++) {
        x *= 9;
        x %= mod;
    }
    i64 y = 1;
    for(int i = 0; i < n; i++) {
        y *= 8;
        y %= mod;
    }
    ans -= 2*x;
    ans += y;
    ans = (ans + mod) % mod;
    ans = (ans + mod) % mod;
    ans = (ans + mod) % mod;
    ans = (ans + mod) % mod;
    printf("%lld\n", ans);
}


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

long long MOD = pow(10,9) + 7;
long long fact[1100000];
long long invfact[1100000];

long long nCr(int n, int r){
    long long ans = (fact[n] * invfact[r] % MOD) * invfact[n-r] % MOD; 
    return ans;
}

long long nPr(int n, int r){
    long long ans = fact[n] * invfact[n-r] % MOD;
    return ans;
}

long long power(long long a, long long b){
    long long res = 1;

    while(b > 0){
        if(b&1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main(void)
{
    long long N, M;
    cin >> N >> M;

    fact[0] = 1;
    for(int i = 1; i < 1100000; i++){
        fact[i] = fact[i-1] * i % MOD; 
    }

    invfact[1100000-1] = power(fact[1100000-1], MOD-2);
    for(int i = 1100000-1; i > 0; i--){
        invfact[i-1] = invfact[i] * i % MOD; 
    }

    long long pNG=0;
    //少なくとも一つが一致してしまう
    for(long long k = 0; k <= N; k++ ){
        long long temp = (((nPr(M,k) * nCr(N,k)) % MOD) * (nPr(M-k, N-k) * nPr(M-k, N-k) % MOD)) % MOD;
        if( k % 2 == 0) pNG += temp;
        else pNG -= temp;
        pNG %= MOD;
        if(pNG < 0) pNG += MOD;
    }
    
    cout << pNG << endl;
}


Measured memory_bytes: 20796
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    string s;
    cin >>  N >> s;
    int r, b;
    r =0;
    b = 0;
    rep(i, N){
        if(s[i] == 'R') r ++;
        else b ++;
    }
    if(r > b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();i++)
	{
		sum+=s[i]-'0';
	}
	if(sum%9==0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    string s(w + 2, '#');
    cout << s << endl;
    for (int i = 0; i < h; i++) {
        cout << '#';
        string t;
        cin >> t;
        cout << t;
        cout << '#' << endl;
    }
    cout << s << endl;
    return 0;
}

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

using namespace std;

int main()
{
	string s;
  	int len;
  	int count;
  	cin >> s;
  	len = s.length();
  	count = 0;
  	for (int i = 0; i < len/2; i++)
    {
    	if (s.at(i) != s.at(len - (i + 1)))
          count++;
    }
 	cout << count<< endl;
}

Measured memory_bytes: 256
// AOJ 2435: Zero Division Checker
// 2017.9.26 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define NUM 1
#define VAR 2

typedef struct { char nm[22]; int l, u; } T;
T var[102]; int m;

typedef struct { int id, n; char v[256]; } Q;	// n: ?????°??¨???v: ?????°??¨
Q q[102]; int top;

int main()
{
	int n, i, j, k;
	Q a, b, c;
	char bf[25];

	scanf("%d", &m);
	for (i = 0; i < m; i++)	scanf("%s%d%d", var[i].nm, &var[i].l, &var[i].u);

	scanf("%d", &n);
	top = 0;					// ????????????????????\??¬????????§???
	while (n-- > 0) {
		scanf("%s", bf);

		if (*bf == '+' || *bf == '-' || *bf == '*' || *bf == '/') {
			int a1, a2, b1, b2;
			if (top < 2) goto ERR;
			b = q[--top], a = q[--top];
			if (a.id == NUM) a1 = a2 = a.n, a.v[a1] = 1;
			else             a1 = 0, a2 = 255;
			if (b.id == NUM) b1 = b2 = b.n, b.v[b1] = 1;
			else             b1 = 0, b2 = 255;
			memset(c.v, 0, sizeof(c.v));

			for (i = a1; i <= a2; i++) if (a.v[i]) for (j = b1; j <= b2; j++) if (b.v[j]) {

				if      (*bf == '+') k = i + j;
				else if (*bf == '-') k = 256 + i - j;
				else if (*bf == '*') k = i * j;
				else { if (j == 0) goto ERR;		// '/'
									 k = i / j;
				}
				c.v[k & 0xff] = 1;
			}
			c.id = VAR;
			q[top++] = c;
		} else if (isdigit(*bf)) {
			q[top].id = NUM, q[top].n = atoi(bf) & 0xff;
			top++;
		} else {
			for (i = 0; i < m; i++)
				if (!strcmp(bf, var[i].nm)) break;
			if (i >= m) goto ERR;
			q[top].id = VAR;
			memset(q[top].v, 0, sizeof(q[top].v));
			for (j = var[i].l; j <= var[i].u; j++) q[top].v[j] = 1;
			top++;
		}
	}
	if (top == 1) puts("correct");
	else {
ERR:	puts("error");
	}
	return 0;
}

Measured memory_bytes: 1816
def get_input():
    data_list = input().split()
    for i in range(len(data_list)):
        data_list[i] = int(data_list[i])
    return data_list

def make_dict(day_dict, data_list):
    candidate_num =data_list[0] + 1
    for i in range(1, candidate_num):
        data = data_list[i]
        if data in day_dict:
            day_dict[data] += 1
        else:
            day_dict[data] = 1
    return day_dict

def decide_open_day(day_dict, quorum):
    max_num = max(day_dict.values())
    if max_num < quorum:
        return 0
    max_k_list = [kv[0] for kv in day_dict.items() if kv[1] == max_num]
    open_day = min(max_k_list)
    return open_day


if __name__ == "__main__":
    while True:
        member_num, quorum = get_input()
        if member_num == 0:
            break
        day_dict = dict()
        for i in range(member_num):
            data_list = get_input()
            day_dict = make_dict(day_dict, data_list)
        if day_dict == {}: # remove candidate_day is None
            print(0)
        else:
            open_day = decide_open_day(day_dict, quorum)
            print(open_day)




Measured memory_bytes: 5624
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System. in);
		int c = 0;
		int a = sc.nextInt();
		String s = sc.next();
		int b = sc.nextInt();
		if(s.equals("+")) {
			c = a + b;
		}else if(s.equals("-")) {
			c = a - b;
		}
		System.out.print(c);
	}
}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n;
  cin>>n;
  vector<ll> l(n);
  ll sum=0;

  rep(i,n){
    cin>>l[i];
    sum+=l[i];
  }
  rep(i,n){
    if( sum - l[i] <= l[i] ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <iomanip>
using namespace std;
long Nchoose2(long n){
    return n*(n-1)/2;
}
int main(){
  string s;
  cin >> s;
  string ans = "No";
  //vector<int> a(n);
  if(s[2] == s[3] && s[4] == s[5]){
      ans = "Yes";
  }
  
      cout << ans << endl;   
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define FAILURE 0
#define SUCCESS 1

int isprime(int);

int main(void){

	int n,num,i,flag=0;

	scanf("%d\n",&n);

	for(i = 0; i < n; i++){
		scanf("%d",&num);
		if(isprime(num) == 1){
			flag++;
		}
	}

	printf("%d\n",flag);
	return 0;
}


int isprime(int x){

	int i=3;

	if(x == 2) return SUCCESS;
	else if(x < 2 || x%2 == 0) return FAILURE;

	while( i <= sqrt((double)x)){		
		if(x % i == 0) return FAILURE;
		i += 2;
	}
	return SUCCESS;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n=s.size();
	int ans=1000000000;
	char bef;
	bef=s[0];
	int count=0;
	for(int i=1;i<n;i++)
	{
		if(bef!=s[i])
		{
			count++;
			bef=s[i];
		}
	}
	cout << count << endl;



	
}

Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a, b = map(int, input().split())
    print(max(a+b, a-b, a*b))

if __name__ == '__main__':
    main()

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

int main(){
    int N,M;
    scanf("%d",&N);
    scanf("%d",&M);
    int A[N];
    double sum=0;
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
        sum +=A[i];
    }
    int count=0;
    double B = 1.0/(4*M)*sum;

    for(int j=0;j<N;j++){
        if(A[j]>=B){
            count++;
        }

    }

    if(count>=M){
        printf("Yes");
    }else{
        printf("No");
    }



    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

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

    int  time = T + 0.5;

    int ans = time / A * B;

    cout << ans;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    while(true){
        ll n,x; cin>>n>>x;
        if(n==0&&x==0) break;
        ll ans=0;
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x) ++ans;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define per(i,x,y) for (int i=(x);i>=(y);i--)
#define ll long long
#define inf 1000000001
using namespace std;
ll read(){
	char ch=getchar();ll x=0;int op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 130
#define mod 1000000007
int n,a[N],f[N][N][N],ans;
void upd(int &x,int y){x+=y;x-=x>=mod?mod:0;}
int main(){
	n=read();
	rep (i,1,2*n-1) a[i]=read();
	sort(&a[1],&a[2*n]);
	f[n][a[n]!=a[n-1]][a[n]!=a[n+1]]=1;
	per (i,n,2){
		int L=a[i-1]!=a[i-2],R=a[2*n-i+1]!=a[2*n-i+2];
		rep (j,0,(n-i+1)*2+1) rep (k,0,(n-i+1)*2+1){
			int now=f[i][j][k];if (!now) continue;
			upd(f[i-1][j+L][k+R],now);
			rep (l,0,j-1) upd(f[i-1][l+L][k+R+1],now);
			rep (l,0,k-1) upd(f[i-1][j+L+1][l+R],now);
		}
	}
	rep (i,0,2*n-1) rep (j,0,2*n-1) upd(ans,f[1][i][j]);
	cout<<ans<<'\n';
	return 0;
}

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

n,u,v= map(int, input().split())
a= [list(map(int, input().split())) for i in range(n-1)]
b = [[] for i in range(n)]

for x,y in a:
    b[x-1].append(y-1)
    b[y-1].append(x-1)

import collections
from collections import deque
def tree(s):

    INF=-10**9
    dis = [INF for i in range(n)]
    dis[s]=0
    def bfs():
        d = deque()
        d.append(s)

        while len(d):
            x = d.popleft()

            for i in range(len(b[x])):
                y=b[x][i]
                if dis[y] == INF:
                    d.append(y)
                    dis[y]=dis[x]+1


        return dis
    return bfs()

# q1:高橋くんからの最短距離、q2:青木君からの最短距離
q1=tree(u-1)
q2=tree(v-1)
ans=0

for i in range(n):
    if q2[i]>q1[i]:
        ans=max(q2[i],ans)
print(ans-1)


Measured memory_bytes: 79836
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    int N; cin >> N;
    vector<string> S(N); rep(i,N) cin >> S[i];
    int BA = 0, A = 0, B = 0;
    int ans = 0;

    rep(i,N){
        if(S[i][0] == 'B') B++;
        if(S[i][(int)S[i].size()-1] == 'A') A++;
        if(S[i][0] == 'B' && S[i][(int)S[i].size()-1] == 'A') BA++;
        rep(j,(int)S[i].size()-1){
            if(S[i].substr(j,2) == "AB") ans++;
        }
    }

    if(BA > 0){
        A -= BA; B -= BA;
        ans += BA-1;
        if(A > 0) {ans++; A--;}
        if(B > 0) {ans++; B--;}
    }
    ans += min(A,B);
    

    cout << ans;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {

	ll n,ans=0;
	std::cin >> n;
	vll a(n + 1);
	rep(i, 1, n + 1) {
		std::cin >> a[i];
		if (a[i] > 0 && a[i-1] > 0) {
			ans++;
			a[i]--;
		}
		ans += a[i] / 2;
		if (a[i] % 2 == 0) {
			a[i] = 0;
		}
		else {
			a[i] = 1;
		}
	}

	outn(ans);
	
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
  char s[17];
  char a[17] = {"CODEFESTIVAL2016"};
  scanf("%s",&s);
  int i;
  i = 0;
  int counter;
  counter = 0;
  while (s[i])
  {
    if (s[i] != a[i])
      counter++;
    i++;
  }
  printf("%d",counter);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int sum1=0;
        int sum2=0;
        for (int i = 0; i < n; i++) {
            String[] lines=br.readLine().split(" ");
            int result=lines[0].compareToIgnoreCase(lines[1]);
            sum1+=result==0?1:result>0?3:0;
            sum2+=result==0?1:result<0?3:0;
        }
        System.out.println(sum1+" "+sum2);
    }
}

Measured memory_bytes: 25652
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  string S;
  cin >> S;
  for (ll i = 0; i < S.length(); i++) {
    S[i] = 'x';
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int r;
    cin >> r;
    
    if (1200 > r)
    {
        cout << "ABC" << endl;
    }
    else if (2800 > r)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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; }
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;

    string a,b;
    cin>>a>>b;

    REP(i, N){
        cout << a[i];
        cout << b[i];
    }
    cout  << endl;
    
    return 0;
}

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

int main(){
	int n,x,a[101] = {},minj,count = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x;
		a[i] = x;
	}

	for(int i = 0;i < n;i++){
		minj = i;
		for(int j = i;j < n;j++){
			if(a[j] < a[minj]){
				minj = j;
			}
		}
		swap(a[i],a[minj]);
		if(i != minj){
			count++;
		}
	}

	for(int i = 0;i < n;i++){
		if(i != n-1)cout << a[i] << " ";
		else cout << a[i] <<endl;
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;

#define int long long

void solve() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector <vector <int> > dp(n + 1, vector <int> (2 + n % 2, -1e18));
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        //cout << i << endl;
        if (i - 2 < 0) dp[i][0] = max(dp[i][0], a[i - 1]);
        else {
            dp[i][0] = max(dp[i - 2][0] + a[i - 1], dp[i][0]);
            dp[i][1] = max(dp[i - 2][1] + a[i - 1], dp[i][1]);
            if (n % 2) dp[i][2] = max(dp[i - 2][2] + a[i - 1], dp[i][2]);
        }
        if (i - 3 >= 0) {
            dp[i][1] = max(dp[i][1], dp[i - 3][0] + a[i - 1]);
            if (n % 2) dp[i][2] = max(dp[i][2], dp[i - 3][1] + a[i - 1]);
        }
        if (i - 4 > 0 && n % 2) {
            dp[i][2] = max(dp[i][2], dp[i - 4][0] + a[i - 1]);
        }
    }
    //for (int i = 0; i <= n; ++i) for (int j = 0; j < 2 + n % 2; ++j) cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
    int ans = dp[n][1];
    if (n % 2 == 0) ans = max(ans, dp[n][0]);
    if (n % 2) ans = max(ans, dp[n][2]);
    ans = max(ans, dp[n - 1][0]);
    if (n % 2) ans = max(ans, dp[n - 1][1]);
    if (n % 2) {
        ans = max(ans, dp[n - 2][0]);
    }
    cout << ans;
    /*if (n % 2 == 0) {
        int od = 0, ev = 0;
        for (int i = 0; i < n; ++i) {
            if (i % 2) od += a[i];
            else ev += a[i];
        }
        int ans = max(od, ev);
        int odl = 0, odr = 0, evl = 0, evr = 0;
        for (int i = 0; i < n; ++i) {
            if (i % 2) odr += a[i];
            else evr += a[i];
        }
        for (int i = 0; i < n - 1; ++i) {
            if (i % 2) {
                odr -= a[i];
                ans = max(ans, evl + odr);
                odl += a[i];
            }
            else {
                evr -= a[i];
                ans = max(ans, odl + evr);
                evl += a[i];
            }
        }
        cout << ans;
        return;
    }
    int odl = 0, odr = 0, evl = 0, evr = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2) odr += a[i];
        else evr += a[i];
    }
    int ans = -1e18;
    for (int i = 0; i < n - 1; ++i) {
        if (i % 2) {
            odr -= a[i];
            ans = max(ans, evl + odr);
            odl += a[i];
        }
        else {
            evr -= a[i];
            ans = max(ans, odl + evr);
            evl += a[i];
        }
    }
    cout << ans;*/
}

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


Measured memory_bytes: 15556
#include<iostream>
using namespace std;
void printArray(int p[],int n){
    for(int i=0;i<n-1;i++)
      cout<<p[i]<<' ';
      cout<<p[n-1]<<endl;
}
void insertionSort(int p[],int n){
    int t;
    for(int i=1;i<n;i++){
        t=p[i];
        int j=i-1;
        for(;j>=0;j--){
            if(p[j]>t)
                p[j+1]=p[j];
            else
                break;
        }
        p[j+1]=t;
      printArray(p,n);
        
    }
   
}
int main(){
    int n;
    cin>>n;
    int *p=new int[n];
    for(int i=0;i<n;i++) cin>>p[i];
    printArray(p,n);
    insertionSort(p,n);
    
    return 0;
}


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

int main(){
  for(int i = 0; i<3000; i++){
    int a, b;
    cin >> a >> b;
    if(a == 0 && b == 0) break;
    if(a>=b) cout << b << " " << a << endl;
    else cout << a << " " << b << endl;
  }
}


Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>

const int MAXN = 101;

int rem[MAXN][2][4];

int dfs(int p, int limit, int pre, const std::string& s, int k) {
  if (p == -1) return pre == k;
  if (rem[p][limit][pre] != -1) return rem[p][limit][pre];
  int ans = 0;
  int n = s[p] - '0';
  for (int i = 0; i <= 9; ++i) {
    if (limit && i > n) break;
    int cur = pre + (i > 0);
    if (cur > k) break;
      ans += dfs(p - 1, limit && (i == n), cur, s, k);
  }
  rem[p][limit][pre] = ans;
  return ans;
}

int solve(const std::string& s, int k) {
  memset(rem, -1, sizeof(rem));
  return dfs((int)s.length() - 1, 1, 0, s, k);
}

int main() {
  std::string s;
  int k;
  std::cin >> s >> k;
  std::reverse(s.begin(), s.end());
  std::cout << solve(s, k) << std::endl;
  return 0;
}


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

using namespace std;

struct cake
{
    int w, d;
    cake(int _w, int _d) : w(_w), d(_d) {}
};

pair<cake, cake> cut(cake c, int s)
{
    s %= 2 * c.w + 2 * c.d;
    int f = 0;
    if (s > 0 && s < c.w)
    {
        cake c1 = cake(s, c.d), c2 = cake(c.w - s, c.d);
        if (s > c.w - s)
            swap(c1, c2);
        return make_pair(c1, c2);
    }
    else if (s > c.w && s < c.w + c.d)
    {
        s -= c.w;
        cake c1 = cake(c.w, s), c2 = cake(c.w, c.d - s);
        if (s > c.d - s)
            swap(c1, c2);
        return make_pair(c1, c2);
    }
    else if (s > c.w + c.d && s < 2 * c.w + c.d)
    {
        s -= c.w + c.d;
        cake c1 = cake(s, c.d), c2 = cake(c.w - s, c.d);
        if (s > c.w - s)
            swap(c1, c2);
        return make_pair(c1, c2);
    }
    else
    {
        s -= 2 * c.w + c.d;
        cake c1 = cake(c.w, s),
             c2 = cake(c.w, c.d - s);
        if (s > c.d - s)
            swap(c1, c2);
        return make_pair(c1, c2);
    }
}

int main()
{
    int N, W, D;
    while (cin >> N >> W >> D, N | W | D)
    {
        vector<cake> cakes;
        cakes.push_back(cake(W, D));
        for (int i = 0; i < N; i++)
        {
            int p, s;
            cin >> p >> s;
            p--;
            int sz = cakes.size() + 1;
            vector<cake> next(sz, cake(0, 0));
            auto x = cut(cakes[p], s);
            for (int j = 0; j < p; j++)
            {
                next[j] = cakes[j];
            }
            for (int j = p + 1; j < sz - 1; j++)
            {
                next[j - 1] = cakes[j];
            }
            next[sz - 2] = x.first;
            next[sz - 1] = x.second;
            cakes = next;
        }
        vector<int> res(N + 1);
        for (int i = 0; i < N + 1; i++)
        {
            res[i] = cakes[i].w * cakes[i].d;
        }
        sort(res.begin(), res.end());
        for (int i = 0; i < N + 1; i++)
        {
            cout << res[i] << (i == N ? '\n' : ' ');
        }
    }
}


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    int sum=0;
    for(int i=0;i<m;++i){
        int a;
        cin>>a;
        sum+=a;
    }
    cout<<(n>=sum?n-sum:-1)<<endl;
}


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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h, w, m;
	cin>>h>>w>>m;
	pair<int, int> t[m];
	int ih[h+1] = {0};
	int iw[w+1] = {0};
	vector<int> rows[h+1];
	for(int i=0; i<m; i++) {
		cin>>t[i].first>>t[i].second;
		ih[t[i].first]++;
		iw[t[i].second]++;
		rows[t[i].first].push_back(i);
	}
	int maksih = 0;
	for(int i=1; i<=h; i++) {
		maksih = max(maksih, ih[i]);
	}
	int maska[w+1] = {0};
	int liczbamaksow = 0;
	for(int i=1; i<=h; i++) {
		if(ih[i] == maksih) {
			liczbamaksow++;
			for(int j=0; j<rows[i].size(); j++)
				maska[t[rows[i][j]].second]++;
		}
	}
	int wynik = 0;
	for(int i=1; i<=w; i++) {
		wynik = max(wynik, (maksih+iw[i]-(maska[i]==liczbamaksow?1:0)));
	}
	cout<<wynik;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e5 + 5;

vector<vi> AdjList;

int dp[maxn];

int solve(int idx) {
	int i,j;
	if(dp[idx] != -1){return dp[idx];}
	int ans = 1;
	for(i=0;i<AdjList[idx].size();i++){
		int v = AdjList[idx][i];
		ans = max(ans, 1 + solve(v));
	}
	return dp[idx] = ans;
}

int main(){
	AdjList.assign(maxn, vi());
	int n,m,i,j;
	scanf("%d %d",&n,&m);
	int indeg[maxn];
	memset(indeg, 0, sizeof indeg);
	for(i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		AdjList[a].pb(b);
		indeg[b]++;
	}
	int ans = 0;
	memset(dp, -1, sizeof dp);
	for(i=1;i<=n;i++){
		if(indeg[i] == 0){
			ans = max(ans, solve(i));
		}
	}

	// for(i=1;i<=n;i++){
	// 	printf("dp[%d]: %d\n",i,dp[i]);
	// }

	printf("%d\n",ans-1);
	return 0;
};

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

class LazySegmentTree{
public:
	int n = 1;
	vector<int> node[3], lazy[2];
	void init(int N){
		while(n < N)n *= 2;
		rep(i,3)node[i].resize(2*n-1);
		rep(i,2)lazy[i].resize(2*n-1);
	}
	void lazy_evaluate(int k){
		rep(i,3)node[i][k] += lazy[i/2][k];
		if(k < n-1){
			rrep(i,2)lazy[0][2*k+i] += lazy[0][k];
			rrep(i,2)lazy[1][2*k+i] += lazy[1][k]/2;
		}
		rep(i,2)lazy[i][k] = 0;
	}
	void update(int a, int b, int x, int k, int l, int r){
		lazy_evaluate(k);
		if(r <= a || b <= l)return;
		if(a <= l && r <= b){
			lazy[0][k] += x;
			lazy[1][k] += (r-l)*x;
			lazy_evaluate(k);
			return;
		}
		update(a, b, x, k*2+1, l, (l+r)/2);
		update(a, b, x, k*2+2, (l+r)/2, r);
		node[0][k] = max(node[0][k*2+1], node[0][k*2+2]);
		node[1][k] = min(node[1][k*2+1], node[1][k*2+2]);
		node[2][k] = node[2][k*2+1]+node[2][k*2+2];
	}
	int calc(int a, int b, int k, int l, int r, int f){
		lazy_evaluate(k);
		if(r <= a || b <= l)return !f ? -INF : f==1 ? INF : 0;
		if(a <= l && r <= b)return node[f][k];
		int vl = calc(a, b, k*2+1, l, (l+r)/2, f);
		int vr = calc(a, b, k*2+2, (l+r)/2, r, f);
		return !f ? max(vl, vr) : f==1 ? min(vl, vr) : vl+vr;
	}
	void add(int a, int b, int x){update(a, b, x, 0, 0, n);}
	int get_max(int a, int b){return calc(a, b, 0, 0, n, 0);}
	int get_min(int a, int b){return calc(a, b, 0, 0, n, 1);}
	int get_sum(int a, int b){return calc(a, b, 0, 0, n, 2);}
};

signed main(){
	int n, q, MAX = (1LL<<31)-1;
	scanf("%lld%lld", &n, &q);
	LazySegmentTree seg;
	seg.init(n+1);
	//rep(i,n)seg.replace(i, i+1, MAX);
	
	rrep(i,q){
		int c, s, t, x;
		scanf("%lld",&c);
		if(c == 0){
			scanf("%lld%lld%lld", &s, &t, &x);
			seg.add(s, t+1, x);
		}else{
			scanf("%lld%lld", &s, &t);
			printf("%lld\n", seg.get_min(s, t+1));
		}
	}
	return 0;
}








Measured memory_bytes: 13156
/***                    *waterhyacinth*

            এই খেদ মোর মনে,
                        ভালবেসে মিটল না আশ,কুলাল না এ জীবনে।
            হায়!জীবন এত ছোট কেনে,
                        এ ভুবনে?

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

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define D double

int main()
{
    int a,b;
    cin >> a >> b;
    int c;
    c=2*b;
    if(a>c)
        cout << a-c << endl;
    else
        cout << "0" << endl;

    return 0;

}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 1e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll mul(ll a, ll b){
	return (a * b) % Mod;
}
ll bin_pow(ll b, ll p){
	ll res = 1;
	for(ll j = 1, pw = b; j <= p; j <<= 1, pw = mul(pw, pw))
		if(p & j)
			res = mul(res, pw);
	return res;
}
ll inv(ll x){
	return bin_pow(x, Mod - 2);
}
ll f[N], iv[N];
ll a[20];

ll nCr(ll n, ll r){
	if((r < 0) || (n < r)) return 0;
	return mul(mul(iv[r], iv[n - r]), f[n]);
}

ll dp[18][(1<<16)];
ll cnt[N];
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	f[0] = 1;
	for(int i = 1; i < N; i++) f[i] = mul(f[i - 1], i);
	iv[0] = 1;
	for(int i = 1; i < N; i++) iv[i] = inv(f[i]);
	//cerr << nCr(10, 3) << '\n';
	ll n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i];
	dp[m + 1][0] = 1;
	ll al = (1 << n);
	for(int i = m; i >= 1; i--){
		for(int mk = 0; mk < al; mk ++){
			dp[i][mk] = dp[i + 1][mk];
			for(int j = 0; j < n; j++){
				if(mk & (1 << j)){
					dp[i][mk] += mul(dp[i + 1][mk ^ (1 << j)], mul(nCr((1 << n) - a[i] - (mk ^ (1 << j)), (1<<j) - 1), f[1<<j]) );
				}
			}
			dp[i][mk] %= Mod;
		}
	}
	for(int mk = 0; mk < al; mk ++){
		cnt[__builtin_popcount(mk)] += mul(f[(1 << n) - 1 - mk], dp[1][mk]);
		cnt[__builtin_popcount(mk)] %= Mod;
	}
	
	for(int i = n; i >= 0; i--){
		for(int j = i + 1; j <= n; j++){
			cnt[i] -= mul(cnt[j], nCr(j, i));
		}
		cnt[i] %= Mod;
	}

	cout << mul((cnt[0] + Mod) % Mod, (1 << n)) << '\n';
	return 0;
}


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

using namespace std;

/*void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
//void __print(vector<bool> x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
//void _print() {cerr << "]\n";}

#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif

template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}

template<typename... T>
void writ(T&&... args) {
	((cout << args << " "), ...);
}*/
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define EPS 1e-9
/*
	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    No, nothing good starts in a getaway car
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
vector<vector<ll>> adj;
vector<bool> vis;
vector<ll> i_D;
void DFS(ll source,vector<ll> &dp){
	stack<ll> s;
	s.push(source);
	vis[source]=true;
	while(!s.empty()){
		ll temp=s.top();
		s.pop();
		for(auto i: adj[temp]){
			//ANTHRO(i,dp[temp]+1,dp[i]);
			dp[i]=max(dp[temp]+1,dp[i]);
			--i_D[i];
			if(!vis[i] && !i_D[i]){
				s.push(i);
				vis[i]=true;
			}
		}
	}
	//ANTHRO(dp);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m; cin>>n>>m;
    adj.resize(n);
    i_D.resize(n,0);
    for(ll i=0,x,y;i<m;i++){
		cin>>x>>y;
		adj[--x].push_back(--y);
		i_D[y]++;
	}
	vector<ll> dp(n,0);
	vis.resize(n,false);
	for(ll i=0;i<n;i++){
		if(!vis[i] && !i_D[i]){
			DFS(i,dp);
		}
	}
	ll ma=0;
	for(auto i: dp){
		ma=max(ma,i);
	}
	cout<<ma;
    return 0;
}


Measured memory_bytes: 7296
package main

import (
	"fmt"
	"math"
)

func main() {
	N := read()
	X := readArray(N)
	Min, Max, Result := min(X...), max(X...), 200000000

	for p := Min; p <= Max; p++ {
		lResult := 0
		for _, r := range X {
			lResult += (r - p) * (r - p)
		}
		if lResult < Result {
			Result = lResult
		}
	}

	fmt.Println(Result)

}

func read() int {
	var v int
	fmt.Scan(&v)
	return v
}

func readArray(length int) []int {
	result := make([]int, length)
	for i := 0; i < length; i++ {
		result[i] = read()
	}

	return result
}

func min(a ...int) int {
	result := float64(a[0])

	for _, i := range a {
		result = math.Min(float64(i), result)
	}

	return int(result)
}

func max(a ...int) int {
	result := float64(a[0])

	for _, i := range a {
		result = math.Max(float64(i), result)
	}

	return int(result)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
string s;
signed main()
{
    cin>>s;
    sort(s.begin(),s.end());
    if(s=="abc") puts("Yes");
    else puts("No");
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }

  vector<map<int, int>> cnt(2);
  for (int i = 0; i < N; i++) {
    cnt[i & 1][V[i]]++;
  }

  vector<vector<pair<int, int>>> cand(2);
  for (int i = 0; i < 2; i++) {
    for (auto itr = cnt[i].begin(); itr != cnt[i].end(); itr++) {
      cand[i].emplace_back(make_pair(itr->second, itr->first));
    }
    sort(cand[i].begin(), cand[i].end(),
         [](pair<int, int> a, pair<int, int> b) { return a.first > b.first; });
  }

  int res = 0;
  if (cand[0][0].second != cand[1][0].second) {
    res = N - cand[0][0].first - cand[1][0].first;
  } else {
    res = N - max(cand[0][0].first + cand[1][1].first,
                  cand[0][1].first + cand[1][0].first);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 6524
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#define MAX 200000
#define INFTY 1<<30
using namespace std;
typedef long long llong;


template <typename T>
class Array
{
private:
  llong merge(int l, int m, int r)
  {
    llong cnt = 0;
    int n1 = m - l;
    int n2 = r - m;
    vector<T> L, R;
    L.resize(n1+1);
    R.resize(n2+1);
    for(int i = 0; i < n1; i++) L[i] = A[l+i];
    for(int i = 0; i < n2; i++) R[i] = A[m+i];
    L[n1] = INFTY;
    R[n2] = INFTY;
    int a = 0;
    int b = 0;
    for(int i = l; i < r; i++)
    {
      if(L[a] <= R[b])
      {
        A[i] = L[a];
        a++;
      }
      else
      {
        A[i] = R[b];
        b++;
        cnt += n1 - a;  // mid + a - b - 1
      }
    }
    //cerr << cnt << endl;
    return cnt;
  }
  int partition(int p, int r)
  {
    T x = A[r];
    int i = p-1;
    T tmp;
    for(int j = p; j < r; j++)
    {
      if(A[j] <= x)
      {
        i++;
        tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;
    return i+1;
  }
public:
  Array();
  Array(vector<T> &arr){A = arr;}
  vector<T> A;
  T operator [] (int x)
  {
    return A[x];
  }
  void dispArr()
  {
    for(int i = 0; i < A.size()-1 ; i++) cout << A[i] << " ";
    cout << A[A.size()-1] << endl;
  }
  void swap(int i, int j)
  {
    T tmp = A[i];
    A[i] = A[j];
    A[j] = tmp;
  }
  /*
  l : ?????????index
  r : (?????????index + 1) or (?????° + ?????????index)
  */
  llong mergeSort(int l, int r)
  {
    llong v1, v2, v3;
    if(l + 1 < r){
      int m = (l + r) / 2;
      v1 = mergeSort(l, m);
      v2 = mergeSort(m, r);
      v3 = merge(l, m ,r);
      return v1 + v2 + v3;
    }
    else return 0;
  }
  /*
  l : ?????????index
  r : ?????????index
  */
  void quicksort(int p, int r)
  {
    if(p < r)
    {
      int q = partition(p,r);
      quicksort(p, q-1);
      quicksort(q+1, r);
    }
  }
};


int main()
{
  int n; cin >> n;
  vector<int> v;
  v.resize(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  Array<int> T(v);
  cout << T.mergeSort(0, n) << endl;
  //T.dispArr();
  return 0;
}

Measured memory_bytes: 3380
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>
using namespace std;

int main() {
	char c[3][3];
    for(int i = 0;i<3;i++){
        cin >> c[i][0] >> c[i][1] >> c[i][2];
    }
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
	return 0;
}

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



int main(){
  long long N, M, i, Sum = 0;
  cin >> N >> M;
  vector<long long> A(M);
  
  for(i = 0; i < M; i++) cin >> A.at(i);
  
  for(i = 0; i < M; i++){
    Sum += A.at(i);
  }
  
  if(N - Sum < 0){
    cout << -1 << endl;
  }else{
    cout << N - Sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3676
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	_ = nextInt()
	K := nextInt()
	S := nextString()
	for i, s := range S {
		if i+1 == K {
			fmt.Print(strings.ToLower(string(s)))
			continue
		}
		fmt.Printf(string(s))
	}

	fmt.Println()
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
using namespace std;
int a[101][101];
int main()
{
	int i,j,n,m,b[101],g[101]={0};
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	for(i=0;i<m;i++)
	{
		cin>>b[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			g[i]=a[i][j]*b[j]+g[i];
		}
	}
	for(i=0;i<n;i++)
	{
		cout<<g[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3120