akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

template <typename X>
struct SegTree {
    using FX = function<X(X, X)>; // X•X -> X となる関数の型
    int n;
    FX fx;
    const X ex;
    vector<X> dat;
    SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }
    X get(int i) {
        i += n - 1;
        return dat[i];
    }
    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ex;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
};

auto fx = [](int x1, int x2) -> int { return max(x1, x2); };
int ex = 0;

int main() {
  int n, k;
  cin >> n >> k;
  SegTree<int> rmq(300100, fx, ex);
  rep(i,0,n) {
    int a;
    cin >> a;
    int l = max(0, a - k);
    int r = min(300100, a + k + 1);
    int q = rmq.query(l, r);
    rmq.update(a, q + 1);
  }
  cout << rmq.query(0, 300100) << endl;
  return 0;
}

Measured memory_bytes: 8020
N = int(input())
numset = [0]*100
for i in range(N):
  i +=1
  for p in range(2, N+1):
    while i%p == 0:
      numset[p] += 1
      i = i//p
    
niijo = 0
yonijo = 0
juuyonijo =0
nijuuyonijo = 0
nanajuuyonijo =0
for numbers in numset:
  if numbers >= 2: niijo+=1
  if numbers >= 4: yonijo +=1
  if numbers >= 14: juuyonijo +=1
  if numbers >= 24: nijuuyonijo +=1
  if numbers >= 74: nanajuuyonijo+=1
    
count = 0
count += max(0, yonijo*( yonijo-1)*(niijo - 2)//2)
count += max(0, nanajuuyonijo)
count += max(0, (niijo-1)*nijuuyonijo)
count += max(0, (yonijo-1)* juuyonijo)
print(count)

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

int main(){
  long long N;
  cin >> N;
  
  vector<long long> staff(N);
  for (long long si = 1; si < N; si++){ cin >> staff[si]; }
  
  vector<long long> res(N+1, 0);
  for (long long si = 0; si < N; si++){
    res[staff[si]]++;
  }
  
  for (long long si = 1; si <=N; si++){
    cout << res[si];
    if (si < N) cout << " ";
    else cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 6264
import math
A, B, H, M = map(int, input().split())

H_rad = (H*60+M)/(12*60)*360
M_rad = M/60*360

H_x = A*math.cos(math.radians(H_rad))
H_y = A*math.sin(math.radians(H_rad))
M_x = B*math.cos(math.radians(M_rad))
M_y = B*math.sin(math.radians(M_rad))

X = H_x - M_x
Y = H_y - M_y

print(math.sqrt(X*X+Y*Y))

Measured memory_bytes: 62552
#include<iostream>
int n,h,w,i,j,k,a,b[100][100],x;
main(){
  for(std::cin>>h>>w>>n;i++<n;){
    std::cin>>a;
    for(j=0;j++<a;++x)x/w%2?b[x/w][w-x%w-1]=i:b[x/w][x%w]=i;
  }
  for(;k<h*w;++k)std::cout<<b[k/w][k%w]<<((k+1)%w?' ':'\n');
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <stack>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int LCM(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return (a / dummy1) * (b / dummy1) * dummy1;
}

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	long long int N, M;
	cin >> N >> M;
	
	string S, T;
	cin >> S;
	cin >> T;
	
	long long int L = LCM(N, M);
	long long int G = GCD(N, M);
	
	map<long long int, char> m;
	
	long long int step = L / N;
	for(long long int i = 0; i < N; i++){
		m[i * step] = S[i];
	}
	bool flag = true;
	step = L / M;
	for(long long int i = 0; i < M; i++){
		if(m.find(i * step) != m.end() && m[i * step] != T[i]){
			flag = false;
			break;
		}
	}
	
	if(flag){
		cout << L << endl;
	}else{
		cout << "-1" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 6144
#include<stdio.h>

int main(){
  int a,b,c,max;
  
  scanf("%d",&a);
  scanf("%d",&b);
  
  max=a+b;
  
  if(max<a-b){
    max=a-b;
  }
  if(max<a*b){
    max=a*b;
  }
  
  printf("%d",max);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
const ll INF=LLONG_MAX;


int main(){
  int n,r;
  cin >> n >> r;
  if(n>=10)cout << r;
  else cout << r+100*(10-n);

  return 0;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int ret = 0;
    for (int i = 0; i < s.size(); i++) {
        if ((i % 2 == 0) != (s[i] == '0'))ret++;
    }
    cout << min(ret, (int)s.size() - ret) << endl;
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF= 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();

int main() {
	LL h, w;
	cin >> h >> w;
	VS a(h);
	REP(i, h)cin >> a[i];
	queue<PLL> que;
	int countBlack = 0;
	int ans = 0;
	int dis[1000][1000];
	memset(dis, -1, sizeof(dis));
	REP(i, h) {
		REP(j, w) {
			if (a[i][j] == '#') {
				que.push({ i, j });
				//ans = 1;
				dis[i][j] =0;
			}
		}
	}
	while (!que.empty())
	{
		auto nq = que.front(); que.pop();
		REP(i, 4) {
			int nx = nq.first + dx[i], ny = nq.second+dy[i];
			if (nx >= 0 && nx < h && ny >= 0 && ny < w && dis[nx][ny] == -1&&a[nx][ny]=='.') {
				dis[nx][ny] = dis[nq.first][nq.second]+1;
				que.push({ nx, ny });
			}
		}
	}
	REP(i, h)REP(j, w)ans = max(ans,dis[i][j]);
	COUT(ans);
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}


Measured memory_bytes: 21556
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=924844033;

ll qexp(ll b,ll p,int m){
    ll res=1;
    while (p){
        if (p&1) res=(res*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return res;
}


ll inv(ll i){
	return qexp(i,MOD-2,MOD);
}

ll fac[2005];
ll ifac[2005];

ll C(int i,int j){
	return fac[i]*ifac[j]%MOD*ifac[i-j]%MOD;
}

int n,k;
vector<int> v; //length of lines

ll way(int l,int x){
	return C(l-x+1,x);
}

ll memo[2005][2005];
ll dp(int i,int j){
	if (i==sz(v)) return (j==0);
	if (j<0) return 0;
	if (memo[i][j]!=-1) return memo[i][j];
	
	ll res=0;
	
	rep(x,0,(v[i]+1)/2+1){
		res+=dp(i+1,j-x)*way(v[i],x)%MOD;
	}
	
	return memo[i][j]=res%MOD;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	fac[0]=1;
	rep(x,1,2005) fac[x]=fac[x-1]*x%MOD;
	rep(x,0,2005) ifac[x]=inv(fac[x]);
	
	memset(memo,-1,sizeof(memo));
	
	cin>>n>>k;
	
	rep(x,1,k+1){
		if ((n-x)/k==0) break;
		
		v.push_back((n-x)/k);
		v.push_back((n-x)/k);
	}
	
	//for (auto &it:v) cout<<it<<" "; cout<<endl;
	
	ll ans=0;
	rep(x,0,n+1){
		//cout<<dp(0,x)<<" "<<fac[n-x]<<endl;
		
		if (x%2==0) ans=(ans+dp(0,x)*fac[n-x])%MOD;
		else ans=(ans-dp(0,x)*fac[n-x])%MOD;
	}
	
	cout<<(ans+MOD)%MOD<<endl;
}


Measured memory_bytes: 35180
#include <bits/stdc++.h>
#define int long long
using namespace std;
double dp[3001][3001];
double a[3001], sum;
main(){
	int n;
	
	cin>>n;
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dp[0][0] = 1.0;
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<i;j++){
			dp [i][j+1] += (a[i] * dp[i-1][j]);
			dp [i][j] += ( (1 - a[i]) * dp[i-1][j]);	
		}
			
	}
	for(int i= (n+1)/2 ;i<=n;i++)
		sum+=dp[n][i];
		
	cout<<fixed<<setprecision(10)<<sum<<endl;
	
	
}

Measured memory_bytes: 68992
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] arr = new int[n];
        boolean sol = true;
        int sum = 0;
        for (int i = 0; i< n; i++){
            arr[i] = in.nextInt();
            if (arr[i] % 2 != 0){
                sol = false;
            }
        }
        while(sol){
            for (int i = 0; i < n; i++){
                if (arr[i] % 2 == 0){
                    arr[i] = arr[i] /2;
                }
                else{
                    System.out.println(sum);
                    return;
                }
            }
            sum++;
        }
        System.out.println(sum);
    }
}

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

typedef struct
{
  vector<int> dis;
  vector<bool> dir;
} Data;

void set_d(vector<int> &dis, vector<bool> &dir, int m)
{
  int x[m], y[m];
  cin >> x[0] >> y[0];
  for(int i = 1; i < m; i++){
    cin >> x[i] >> y[i];
    dis.push_back(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]));
    if(i >= 2){
      int a, b;
      a = x[i-1]-x[i-2]+y[i-1]-y[i-2];
      b = x[i]-x[i-1]+y[i]-y[i-1];
      if(a > 0 && b > 0){
        if(x[i] == x[i-1])
          dir.push_back(true);
        else
          dir.push_back(false);
      }else if(a > 0 && b < 0){
        if(x[i] == x[i-1])
          dir.push_back(false);
        else
          dir.push_back(true);
      }else if(a < 0 && b > 0){
        if(x[i] == x[i-1])
          dir.push_back(false);
        else
          dir.push_back(true);
      }else if(a < 0 && b < 0){
        if(x[i] == x[i-1])
          dir.push_back(true);
        else
          dir.push_back(false);
      }
    }
  }
}

int main()
{
  while(1){
    int n;
    cin >> n;
    if(n == 0) break;
    int m;
    cin >> m;
    Data org1, org2;
    set_d(org1.dis, org1.dir, m);
    org2 = org1;
    reverse(org2.dis.begin(),org2.dis.end());
    reverse(org2.dir.begin(),org2.dir.end());
    for(vector<bool>::iterator ite = org2.dir.begin(); ite != org2.dir.end(); ite++)
      *ite = !(*ite);
    for(int i = 1; i <= n; i++){
      cin >> m;
      Data d;
      set_d(d.dis, d.dir, m);
      if((org1.dis == d.dis && org1.dir == d.dir) || (org2.dis == d.dis && org2.dir == d.dir))
        cout  <<  i << endl;
    }
    cout << "+++++" << endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N;
    ll res = 0;
    reps(i,1,N + 1){
        ll num = N / i;
        num = num * (num + 1) / 2;
        res += num * i;
    }
    cout<<res<<endl;
}


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

int main(){
    string s,t,u;
    cin>>s>>t>>u;
    queue<char> a,b,c,now;
    for(int i=0;i<s.size();i++) a.push(s[i]);
    for(int i=0;i<t.size();i++) b.push(t[i]);
    for(int i=0;i<u.size();i++) c.push(u[i]);
    now=a;
    a.pop();
    while(1){
        char o=now.front();
        if(o=='a'){
            if(a.empty()){
                cout<<"A"<<endl;
                return 0;
            }
            now=a;
            a.pop();
        }
        if(o=='b'){
            if(b.empty()){
                cout<<"B"<<endl;
                return 0;
            }
            now=b;
            b.pop();
        }
        if(o=='c'){
            if(c.empty()){
                cout<<"C"<<endl;
                return 0;
            }
            now=c;
            c.pop();
        }
    }
}

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

vector<long long> divisor(long long N){ //約数列挙
    vector<long long> res;
    for(long long i=1;i*i<=N;i++){
        if(N%i==0){
            res.push_back(i);
            if(i!=N/i) res.push_back(N/i);
        }
    }
    sort(res.begin(),res.end()); //約数を小さい順に列挙 
    return res;
}

int main(){
    long long N; cin >> N;
    long long ans=0;
    vector<long long> div=divisor(N-1);
    vector<long long> div2=divisor(N);
    ans+=div.size()-1;
    for(auto d:div2){
        if(d==1) continue;
        long long res=N;
        while(res%d==0){
            res/=d;
        }
        if(res%d==1){
            //cout << d << endl;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
from collections import Counter

N = int(input())
As = list(map(int, input().split()))

maxA = max(As)
minA = (maxA+1) // 2
cnt = Counter(As)

for A, num in cnt.items():
    if A < minA:
        print('Impossible')
        break
    elif A == minA:
        if (maxA % 2 and num != 2) or (maxA % 2 == 0 and num != 1):
            print('Impossible')
            break
    elif num < 2:
        print('Impossible')
        break
else:
    for A in range(minA+1, maxA+1):
        if A not in cnt:
            print('Impossible')
            break
    else:
        print('Possible')


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

void insert(int code);
void find(int code);
int getIndex(int code);

/*
A:1
C:2
G:3
T:4
 */

char dictionary[390626];
int dictLen = 0;

main(){

  int i,j,n;
  char command[7];
  char op;
  int code;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    j=0; code=0;
    while(j<=8){
      scanf("%c",&op);
      if(op=='\n') break;
      switch(op){
      case 'A':
	code+=1*pow(5,j);
	j++;
	break;
      case 'C':
	code+=2*pow(5,j);
	j++;
	break;
      case 'G':
	code+=3*pow(5,j);
	j++;
	break;
      case 'T':
	code+=4*pow(5,j);
	j++;
	break;
      default:
	break;
      }
    }
    if(command[0] == 'i'){ // insert
      insert(code);
    }else if(command[0] == 'f'){ // find
      find(code);
    }
  }

  return 0;

}

void insert(int code){

  int index = code;
  if(dictionary[index] == 0){
    dictionary[index] = 1;
  }

}

void find(int code){

  int index = code;
  if(dictionary[index] == 1){
    printf("yes\n");
  }else{
    printf("no\n");
  }

}

int getIndex(int code){

  int i;
  int tmp;
  int _code = code;
  int index = 0;

  for(i=0; i<8; i++){
    tmp = _code % 10;
    _code /= 10;
    index += pow(5,i) * tmp;
  }

  return index;

}

Measured memory_bytes: 724
#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<climits>  
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;     
int read(){     
    int f=1,x=0;char c=getchar();        
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}       
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();     
    return x*f;    
}
#define MAXN 500000
#define INF 0x3f3f3f3f
int main(){
	int n=read(),h=read(),w=read();
	cout<<(n-h+1)*(n-w+1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define rrep(i, a, b) for(ll i = b - 1; i >= a; i--)
typedef pair<ll,ll> pll;

int main(){
    ll N, X, D; cin >> N >> X >> D;
    unordered_map<ll, vector<ll>> mp;
    if(D < 0){
        D = -D;
        X = -X;
    }
    if(D == 0){
        if(X == 0){
            cout << 1 << endl;
            return 0;
        }
        cout << N + 1 << endl;
        return 0;
    }
    ll t;
    if(X >= 0) t = X % D;
    else t = (X + ((-X) / D + 1) * D) % D;
    cerr << "t " <<   t << endl;
    rep(i, 0, N + 1){
        mp[(t * i) % D].push_back(i);
    }
    //for(auto e: mp) for(auto f: e.second) cout << f << endl;
    ll ans = 0;

    for(auto e: mp){
        //l premin = 2, premax = 1;
        cerr << e.first << " ";
        for(auto f: e.second) cerr << f << " ";
        cerr << endl;
        vector<pll> section;
        for(auto f: e.second){
            ll summax = 0, summin = 0;
            if(f%2 == 0) summax = ((X + D * (N - f)) + (X + D * (N - 1))) * (f / 2);
            else summax = ((X + D * (N - f)) + (X + D * (N - 1))) / 2 * f;
            if(f%2 == 0) summin = (X + X + D  * (f - 1)) * (f / 2);
            else summin = (X + X + D  * (f - 1))/ 2 * f;
            section.push_back({summin, summax});
        }
        sort(section.begin(), section.end());
        ll premin, premax;
        rep(i, 0, section.size()){
            if(i == 0) premin = section[i].first, premax = section[i].second;
            else{
                //if(premin == section[i].first) premax = section[i].second;
                if(premax < section[i].first){
                    ans += (premax - premin) / D + 1;
                    premax = section[i].second;
                    premin = section[i].first;
                }else if(premax < section[i].second) premax = section[i].second;
            }
        }
        ans += (premax - premin) / D + 1;
        cerr << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 17864
#include <bits/stdc++.h>
using namespace std;
int main(){
	unsigned long long n;cin >> n;
	unsigned long long cnt=0;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0)cnt+=i;
	}
	cout<<cnt;
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

using Graph = vector<vint >;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  Graph graph(N);
  rep(i, N-1) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  string s;
  cin >> s;
  vint deg(N);
  vector<bool> used(N, true);
  rep(i, N) deg[i] = graph[i].size();
  queue<int> que;
  rep(i, N) {
    if(deg[i] == 1 && s[i] == 'B') {
      used[i] = false;
      que.push(i);
    }
  }
  while(!que.empty()) {
    int u = que.front(); que.pop();
    for(int v : graph[u]) {
      if(!used[v]) continue;
      --deg[v];
      if(deg[v] <= 1 && s[v] == 'B') {
	used[v] = false;
	que.push(v);
      }
    }
  }
  Graph graph2(N);
  vint cost(N);
  int root = -1;
  int cnt = 0;
  rep(i, N) {
    if(!used[i]) continue;
    if(s[i] == 'W') root = i;
    ++cnt;
    for(int v : graph[i]) {
      if(!used[v]) continue;
      graph2[i].push_back(v);
    }
    cost[i] = (graph2[i].size()%2)^(s[i]=='W');
  }
  if(root == -1) {
    cout << 0 << endl;
    return 0;
  } else if(cnt == 1) {
    cout << 1 << endl;
    return 0;
  }
  int ans = 2*(cnt-1);
  rep(i, N) ans += cost[i];
  //cout<<ans<<endl;
  function<Pi(int, int)> dfs = [&](int u, int p) {
    Pi res = Pi(cost[u], u);
    for(int v : graph2[u]) {
      if(v == p) continue;
      Pi tmp = dfs(v, u);
      tmp.first += cost[u];
      chmax(res, tmp);
    }
    return res;
  };
  Pi p = dfs(root, -1);
  Pi q = dfs(p.second, -1);
  cout << ans-2*q.first << endl;

  return 0;
}



Measured memory_bytes: 22224
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b, c = (_ for _ in input().split())
    print(a[0]+b[0]+c[0])
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
N=int(input())
txy=[list(map(int,input().split()))for _ in range(N)]

ans='Yes'
now=[0,0,0]
for t,x,y in txy:
    distance=abs(x-now[1])+abs(y-now[2])
    if distance>t-now[0] or (distance+(t-now[0]))%2>0:
        ans='No'
        break
    else:
        now=[t,x,y]

print(ans)

Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin>>s;

    vector<int>v(2019);
    v[0]=1;

    int x=0,ans=0,p=1,n=s.size();

    for (int i=n-1; i>=0; --i)
    {
        x+=(s[i]-'0')*p;
        x%=2019;
        ans+=v[x];
        v[x]++;
        p*=10;
        p%=2019;
    }
    cout<<ans;

}


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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;

int main(void)
{
	FAST
	
	int n; cin >> n;
	
	ll ans = 0;

	for(ll i = 1; i <= n; i++){
		ll x = (i*(n/i)*(1+n/i))/2;
		ans += x;
	}
			
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3556
n=int(input())
a=[int(input()) for _ in range(n)]
cnt=0
def isprime(x):
    flag=0
    for i in range(2,int(x**(1/2))+1):
        if x%i==0:
            flag=1
            break
    if flag==0:
        return True
    else:
        return False
for i in a:
    if isprime(i)==True:
        cnt+=1
print(cnt)


Measured memory_bytes: 5980
n = int(input())

u = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    if i == 0:
        ans = u[i] + sum(l)
    else:    
        ans = max(ans,sum(u[:i]) + sum(l[i-1:]))
    
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    int d = 0;
    int ans = 1;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        d += a[i];
        if(d <= x) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N, ans=0;
	int A, B;

	cin >> N >> A >> B;
	N -= A;
	ans = N % B;

	cout << ans << endl;

	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(), t.end());
  
  if(s<t){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    LL h, w;cin >> h >> w;
    LL ans = min(h, w);
    if(h%3 == 0 || w%3 == 0) ans = 0;
    for(int i=1;i<w;i++){
        vector<LL> v = {i*h, (h/2)*(w-i), (h-h/2)*(w-i)};
        sort(v.begin(), v.end());
        ans = min(ans, v[2]-v[0]);
    }
    for(int i=1;i<h;i++){
        vector<LL> v = {i*w, (w/2)*(h-i), (w-w/2)*(h-i)};
        sort(v.begin(), v.end());
        ans = min(ans, v[2]-v[0]);
    }
    cout << ans << endl;
    return 0;
}


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

#define int long long


signed main() {
    
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i=0; i<N; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());

    for(int i=0; i<N; i++){
        cerr << s[i] << endl;
    }
    
    int ans = 0;
    for(int i=0; i<N;){
        int j=i;
        while(j<N && s[i]==s[j]) j++;
        int l = j-i;
//        cerr << i << j << endl;
        ans += l*(l-1)/2;
        i=j;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int a,b,c,d,ans,num;
    cin >> num;
    a = num / 1000;
    d = num % 10;
    c = (num % 100)/10;
    b = (num % 1000)/100;

    rep(i,8){
        ans = a;
        if(i%2==0){ ans+=b;}
        else { ans-=b; }

        if((i/2)%2==0){ ans+=c;}
        else{ ans-=c; }

        if((i/4)%2==0) {ans+=d;}
        else{ ans-=d; }

        if(ans == 7){
            cout << a;
            if(i%2==0) cout << "+";
            else cout << "-";
            cout << b;
            if((i/2)%2==0) cout << "+";
            else cout << "-";
            cout << c;
            if((i/4)%2==0) cout << "+";
            else cout << "-";
cout <<d<<"=7";
            break;
        }
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int k; cin >> k;
  int x = 7 % k;
  set<int> s;
  int cnt = 1;
  while (s.count(x) == 0)
  {
    if (x == 0) {
      cout << cnt << endl;
      return 0;
    }
    s.insert(x);
    x = (x * 10 + 7) % k;
    cnt++;
  }
  cout << - 1<< endl;
  return 0;
}

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

int main () {
    int n;
    std::cin >> n;
    std::string s, t;
    std::cin >> s >> t;

    std::string ans = "";
    for (int i = 0; i < n; i++) {
        ans += s[i];
        ans += t[i];
    }

    std::cout << ans << std::endl;
}

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

using namespace std;

int main()
{
  int n, a[100][2];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i][0];
  for (int i = 0; i < n; i++)
    cin >> a[i][1];
  int sum[100][2], ans = 0;
  sum[0][0] = a[0][0];
  sum[n - 1][1] = a[n - 1][1];
  for (int i = 1; i < n; i++)
    sum[i][0] = sum[i - 1][0] + a[i][0];
  for (int i = n - 2; i > -1; i--)
    sum[i][1] = sum[i + 1][1] + a[i][1];
  for (int i = 0; i < n; i++)
    ans = max(ans, sum[i][0] + sum[i][1]);
  cout << ans << endl;

  return 0;
}


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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> o;
  vector<pair<int, int>> b(n);
  for(int i = 0; i < n; i++) scanf("%d", &b[i].first), b[i].second = i + 1;
  for(int i = 0; i < n; i++) {
    int j;
    for(j = n - 1; j >= 0; j--) {
      if(b[j].first == b[j].second) {
        o.push_back(b[j].first);
        b[j].second = -1;
        for(int k = j + 1; k < n; k++) b[k].second--;
        break;
      }
    }
    if(j == -1) {
      printf("-1\n");
      return 0;
    }
  }
  for(int i = n - 1; i >= 0; i--) printf("%d\n", o[i]);
}

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

// #define int long long

using namespace std;

int main(void) {
  int n, m; cin >> n >> m;

  int l = 1, r = n;
  for (int i = 0; i < m; ++i) {
    int _l, _r; cin >> _l >> _r;
    l = max(l, _l);
    r = min(r, _r);
  }

  cout << max(0,r - l + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

i64 gcd(i64 x, i64 y) {
  if(y == 0) return x;
  return gcd(y, x % y);
}


int main() {
  i64 a, b;
  cin >> a >> b;
  cout << a / gcd(a, b) * b << endl;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


int main() {
	
	ll n;
	cin >> n;
	ll ans = INFL;

	ll i = 1;

	for (; i * i < n; i++) {
		if (n%i == 0) {
			ans = min(ans, i - 2 + (n / i));
		}
	}
	if (i*i == n) {
		ans = min(ans, (n / i) * 2 - 2);
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
n=int(input())
m=int((n**(1/2))//1+1)
l=[]
for i in list(range(m+1))[:0:-1]:
  if n%i==0:
    l.append(max(len(str(i)),len(str(n//i))))
  if len(l)==2:
    break
print(min(l))

Measured memory_bytes: 7668
def bb
    n = gets.chomp.to_i

    o = [0, 111, 222, 333, 444, 555, 666, 777, 888, 999]
    for i in 0..(o.length-2)
        if o[i] < n and n <= o[i+1]
            puts o[i+1]
            exit
        end
    end
end

bb

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

#define rep(i,n) for(int i=0; i < n; i++)
using namespace std;

int main()
{
    int N, R, ans;
    cin >> N >> R;
    ans = R;
    if (N < 10)
    {
        ans += 100 * (10 - N);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int calc(int a,int b){
	if(a >= b) return a - b;
	else if((a - b) % 2) return (b - a) / 2 + 2;
	else return (b - a) / 2;
}

signed main(){
	int a,b,c,mi = INF;
	cin >> a >> b >> c;
	for(int i = -10;i <= 100;i++){
		int ans = calc(a,i) + calc(b,i) + calc(c,i);
		chmin(mi,ans);
	}
	cout << mi << endl;
	return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];
    int ans = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i + 1; j < n; j++){
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int x,y,z;
	cin >> x >> y >> z;
	x -= z;
	cout << x / (y + z) << endl;
}

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

ll zalgo(string & s, ll beg) {
  const ll n = s.size();
  vector<ll> len(n);
  ll j = 0;
  ll i = beg + 1;
  while (i < n) {
    while (i + j < n && s[beg+j] == s[i+j]) ++j;
    len[i] = j;
    ll k = 1;
    while (k + len[beg + k] < j) {
      len[i+k] = len[beg+k];
      ++k;
    }
    i += k;
    j = max(j - k, 0LL);
  }
  ll nolen = 0;
  for (ll i = beg + 1; i < n; ++i) {
    if (nolen < min(i - beg, len[i])) {
      nolen = min(i - beg, len[i]);
    }
  }
  return nolen;
}

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

  ll len = 0;
  for (ll i = 0; i < n - 1; ++i) {
    ll ret = zalgo(s, i);
    if (ret > len) {
      len = ret;
    }
  }

  cout << len << endl;
  return 0;
}



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

int main() {
	int a, b, card[4][13] = {};
	string mark;

	cin >> a;

	for (int i = 0; i < a; i++) {
		cin >> mark >> b;
		if (mark == "S") {
			card[0][b - 1] = 1;
		}
		else if (mark == "H") {
			card[1][b - 1] = 1;
		}
		else if (mark == "C") {
			card[2][b - 1] = 1;
		}
		else if (mark == "D") {
			card[3][b - 1] = 1;
		}
	}

	for (int k = 0; k < 4; k++) {
		for (int j = 0; j < 13 ; j++) {




			if (k==0&&card[k][j] == 0) {
					cout << "S " << j+1 << endl;
			}
			if (k==1&&card[k][j] == 0) {
				cout << "H " << j+1 << endl;
			}
			if (k==2&&card[k][j] == 0) {
				cout << "C " << j+1 << endl;
			}
			if (k==3&&card[k][j] == 0) {
				cout << "D " << j+1 << endl;

			}
		}
	
	}

 }


Measured memory_bytes: 3172
N, M = map(int, input().split())
L = 0
R = 10**5 +2
for i in range(M):
    l,r = map(int, input().split())
    if L < l:
        L = l
    if R > r:
        R = r
ans = 0
for i in range(1,N+1):
    if L <= i <= R:
        ans += 1
        
print(ans)
    

Measured memory_bytes: 3060
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    a, b = li_input()

    print(a + b) if a + b < 10 else print("error")


main()


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

from itertools import permutations

N, C = list(map(int, input().split()))

D = [list(map(int, input().split())) for i in range(C)]
# c = [list(map(int, input().split())) for i in range(N)]

colors = [[0]*C for i in range(3)]
for i in range(N):
    tmp = list(map(int, input().split()))
    for j, color in enumerate(tmp):
        num = ((i+1) + (j+1)) % 3
        colors[num][color-1] += 1
# print(colors)

data = [[0]*C for i in range(3)]


for i in range(3):
    # color[i]
    for j in range(C):
        for k in range(C):
            data[i][k] += colors[i][j] * D[j][k]
# print(data)

ans = 10**10
for iter_ in permutations(list(range(C)), 3):
    # print(iter_)
    tmp = []
    for i, j in enumerate(iter_):
        tmp.append(data[i][j])
    ans = min(ans, sum(tmp))
print(ans)


Measured memory_bytes: 9316
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007mope
#define ll long long
using namespace std;
int ka[214514],inv[214514];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
signed main(){
	int n,m;
	cin>>n>>m;
	setkaijo(114514);
	setinv(114514);
	vector<int> od;
	int cur = m;
	for(int i=2;i*i<=m;i++){
		if( cur % i == 0 ){
			int cnt = 0;
			while( cur % i == 0 ){
				cnt++;
				cur /= i;
			}
			od.pb(cnt);
		}
	}
	if(cur>1)od.pb(1);
	int ans = 1;
	for(int i=0;i<od.size();i++){
		ans *= comb( n-1+od[i], od[i] );
		ans %= inf;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2048
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
ans = 0
ab = [list(map(int, input().split())) for _ in range(M)]
for i in range(M):
    uf = UnionFind(N)
    for l in ab[:i] + ab[i + 1:]:
        uf.union(l[0] - 1, l[1] - 1)
    if uf.group_count() == 2:
        ans += 1
print(ans)


Measured memory_bytes: 5464
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        mut v: [i64; n]
    }
    v.sort();
    let mut i = 0;
    while i < n - 1 && v[i] <= 0 && v[i + 1] <= 0 {
        v[i] *= -1;
        v[i + 1] *= -1;
        i += 2;
    }
    if i < n - 1 && v[i] <= 0 && v[i + 1] > 0 && v[i] + v[i + 1] < 0 {
        v[i] *= -1;
        v[i + 1] *= -1;
    }
    println!("{}", v.iter().sum::<i64>());
}


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


int main()
{
    long long n;
    long long a[5];
    cin >> n;
    long long mi = (1ll << 60);
    int pos;
    for(int i = 0;i < 5;i++) {
        cin >> a[i];
        if(a[i] < mi)
        {
            pos = i;
            mi = a[i];
        }
    }
    long long ans = (n + mi - 1) / mi + 5 - 1   ;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256