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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

bool check(const vector<int>& A, int mid, int k) {
  if (mid == 0) {
    return false;
  }
  for(int a : A) {
    if (a <= mid) {
      continue;
    }
    int tmp = a/mid;
    if (a%mid == 0) {
      tmp--;
    }
    k -= tmp;
  }
  return 0 <= k;
}

signed main()
{
  int N, K; cin >> N >> K;
  vector<int> A(N);
  REP(n,N) {
    cin >> A[n];
  }

  int l = 0, r = INF_LL;
  while(r-l>1) {
    int mid = (l+r)/2;
    if (check(A, mid, K)) {
      r = mid;
    } else {
      l = mid;
    }
  }

  cout << r << endl;

  return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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 int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<int> Parent; 
 public:
  UnionFind(int N){
    Parent = vector<int>(N, -1);
  }
  
  int root(int A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  int size(int A){
    return -Parent[root(A)]; 
  }
  
  bool connect(int A, int B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(int A, int B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  vll a(n); rep(i,n) cin>>a[i], a[i]--;
  UnionFind uf(n);
  rep(i,m){
    ll x,y; cin>>x>>y; x--,y--;
    uf.connect(a[x],a[y]);
  }
  ll ans=0;
  rep(i,n){
    if(a[i]==i || uf.isSame(a[i], a[a[i]])) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1408
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N;
    long x;
    long[] a;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long count = 0;
        if(a[0] > x){
            count += a[0]-x;
            a[0] = x;
        }
        for(int i=0;i<N-1;i++){
            if(a[i]+a[i+1] > x){
                count += a[i]+a[i+1]-x;
                a[i+1] = x-a[i];
            }
        }
        sb.Append(count+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        x = Int64.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        a = new long[N];
        for(int i=0;i<N;i++){
            a[i] = Int64.Parse(str[i]);
        }
    }    
}

Measured memory_bytes: 17240
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    A = 14 if A == 1 else A
    B = 14 if B == 1 else B
    if A == B:
        print("Draw")
    elif A > B:
        print("Alice")
    else:
        print("Bob")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

//#define int long long
typedef long long ll;
const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i=0;i<N;i++) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(N+1,vector<ll>(100001,INF));
    dp[0][0] = 0;
    for (int i=0;i<N;i++){
        for (int j=0;j<=100000;j++){
            if (j+v[i]<=100000){
                dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]],dp[i][j] + w[i]);
            }
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    int ans = 0;
    for (int i=0;i<=100000;i++){
        if (dp[N][i]<=W){
            ans = i;
        }
    }
    cout << ans << "\n";
}

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

signed main(){
  int n;
  cin >> n;
  
  vector<string> s(n);
  map<string,int> map;
  rep(i,n){ 
    cin >> s[i]; 
    sort(s[i].begin(),s[i].end());
    map[ s[i] ]++;
  }
  
  int ans = 0;
  rep(i,n){
    int j = map[ s[i] ];
    ans += j*(j-1)/2;
    map[ s[i] ] = 0;
  }
 
  cout << ans << endl;
  
  return 0;
}

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

# Set max recursion limit
sys.setrecursionlimit(10000)

# 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:]

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

dp = None

def main():
    a, b = map(int, input().split())

    if a <= b:
        print(a)
    else:
        print(a-1)

main()


Measured memory_bytes: 5184
import sys
import heapq
from collections import defaultdict
import itertools
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
L = sum(A)
length = 0
mid = None
for i in range(N):
    length += A[i]
    if length >= L / 2:
        mid = i
        break
#print('mid={}, length={}'.format(mid, length))

d = min(length - L / 2, L / 2 - (length - A[mid]))
print(int(d * 2))

Measured memory_bytes: 79952
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MMAX 500000

struct Node{
  int key;
  struct Node *left;
  struct Node *right;
  struct Node *parent;
};

struct Node *root, *NIL;

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left; //　大事　//
    }else{
      x = x->right; // 大事　//
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else{
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(void){
  int m,i,x;
  char com[6];

  scanf("%d",&m);

  for(i = 0;i < m;i++){
    scanf("%s",com);
    if(strcmp(com,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }else if(strcmp(com,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}
   
		       



Measured memory_bytes: 25160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const int siz = 1e5 + 7;
vector<ll>v(siz);
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	int nax1 = 0, nax2 = 1e9;
	for (int i = 0; i < m; i++) {
		int l, r;
		cin >> l >> r;
		nax1 = max(nax1, l);
		nax2 = min(nax2, r);
	}
	int ans = nax2 - nax1 + 1 ;
	if (ans < 1)
		ans = 0;
	cout << ans << endl;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = k; i < n; i++)
    {
        if (a[i] > a[i-k])
        {
            cout << "Yes" << "\n";
        }
        else
        {
            cout << "No" << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 4420
#include <iostream>
#include <math.h>
#include <vector>
#include <iomanip>

using namespace std;

long double pow(int time)
{
	long double ret = 1.0;

	for (int i = 0; i < time; i++)
	{
		ret *= (long double)1.0 / 2.0;
	}

	return ret;
}

int check(int i, int k)
{
	int time = 0;
	for (long double j = k; ; j /= 2)
	{
		if (i >= j)
		{
			//cout << "  check " << i << " " << k << " " << time << endl;
			return time;
		}
		time++;
	}

	return time;
}

int main()
{
	int N, K;
	cin >> N >> K;

	long double ret = 0.0;

	for (int i = 1; i <= N; i++)
	{
		ret += (long double)1.0 / N * pow(check(i, K));

		//cout << i << " " << ret << endl;
	}

	cout << fixed << setprecision(10) << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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 T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}

ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}
vi a={};
void div_sum(ll n) {
    ll s = 0;
    ll k;
    for ( k = 1; k * k <= n; k++ ) { 
      if(k * k == n) a.pb(k);
      else if ( n % k == 0 ) { a.pb(k), a.pb(n / k); } 
    }
    return ;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    ll X;cin>>X;
	for(ll i = -1000; i <= 1000; i++) for(ll j= -1000; j <= 1000; j++){
		if((ll)(i*i*i*i*i - j*j*j*j*j) == X) {
			cout << i << " " << j << endl;
			return 0;
		}
		
	}
	

}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
const int N=2e8+5;
char s[N],t[N];
int n,m,xx,yy,nex[N];
void kmp_init()
{
    int i=1,k=0;
    while(i<=xx*m)
        if(k==0||t[i]==t[k]) nex[++i]=++k;
    else k=nex[k];
}
int main()
{
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1);m=strlen(t+1);
    xx=15000000/m;
    for(int j=1;j<xx;j++)
    for(int i=1;i<=m;i++)
        t[i+m*j]=t[i];
    kmp_init();
    int ans=0,p=m*xx/n;
    int now=0,pos=0;
    m*=xx;
    for(int l=1;l<=p;l++)
    {
        for(int i=1;i<=n;i++)
        {
            pos++;
            while(pos&&t[pos]!=s[i])
                pos=nex[pos];
            ans=max(ans,pos);
        }
    }
    m/=xx;
    if(ans==n*p||ans>=n*(p-1)) printf("-1\n");
    else printf("%d\n",ans/m);
}


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

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


int main(){
    int n,m;
    cin >> n >> m;
    vi a(m);
    rep(i,0,m)cin >> a[i];
    ll sum = accumulate(a.begin(), a.end(), 0);
    if(n-sum<0){cout << -1;}
    else{cout<< n-sum;}
}

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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  int a[n];
  int min_a = INF;
  for(int i=0;i<n;i++) {
    cin>>a[i];
    min_a = min(a[i], min_a);
  }

  vector<int> divisor;
  for(int i=1;i*i<min_a;i++) {
    if(min_a%i == 0) {
      divisor.push_back(i);
      if(i*i!=min_a) {
        divisor.push_back(min_a/i);
      }
    }
  }
  sort(divisor.begin(), divisor.end(), greater<int>());
  for(int d: divisor) {
    if (d == 1) {
      cout<<1<<endl;
      return 0;
    }
    bool flag = true;
    for(int i=0;i<n;i++) {
      if(a[i] % d != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout<<d<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 640
# coding: utf-8
# Your code here!
data = input()
data_list = data.split(" ")
data_list[0] = int(data_list[0])
data_list[1] = int(data_list[1])

if data_list[0] < data_list[1]:
    print(0)
else:
    print(10)
    


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

int main() {
	int n;
	long long sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%5!=0&&i%3!=0)sum+=i;
	}
	cout<<sum<<endl;
	
}

//なぜWA？


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

int main()  {
   int a, e, k, t;
  cin >> a >> t >> t >> t 
                >> e >> k; 
  // cout << a << e <<  k << endl;
 if (e - a > k) {
    cout << ":(" << endl;
} else {
   cout << "Yay!" << endl;
}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
const int mod=1e9+7;
int a[110],f[110][100010],sum[110][100010],n,k;
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=0;i<=k;i++) sum[0][i]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=k;j++)
		{
			int l=max(0,j-a[i]);
			f[i][j]=sum[i-1][j];
			if(l!=0) (f[i][j]-=sum[i-1][l-1])%=mod;
			//printf("%d %d %d\n",i,j,f[i][j]);
		}
		for(int j=0;j<=k;j++) sum[i][j]=f[i][j];
		for(int j=1;j<=k;j++) (sum[i][j]+=sum[i][j-1])%=mod;
	}
	printf("%d",(f[n][k]+mod)%mod);
}

Measured memory_bytes: 82176
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<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 MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  string u = "";
  IN3(s,t,u);
  string turn = "a";
  while(true){
    if(turn == "a" && s == "") break;
    else if(turn == "b" && t == "") break;
    else if(turn == "c" && u == "") break;
    if(turn == "a"){
      turn = gCh(s,0);
      s.erase(s.begin());
    } else if(turn == "b"){
      turn = gCh(t,0);
      t.erase(t.begin());
    } else {
      turn = gCh(u,0);
      u.erase(u.begin());
    }
  }
  OUT(toStrUp(turn));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> conn(n);
  vector<int64_t> c(n);
  rep(i,n-1){
    int s,t;
    cin >> s >> t;
    conn[s-1].push_back(t-1);
    conn[t-1].push_back(s-1);
  }
  rep(i,n){
    cin >> c[i];
  }
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  vector<int> res(n);
  vector<bool> isused(n);
  queue<int> que;
  que.push(0);
  int h=0;
  while(!que.empty()){
    int x = que.front();
    res[x] = c[h];
    isused[x] = true;
    h++;
    rep(i,conn[x].size()){
      if(!isused[conn[x][i]]){
        que.push(conn[x][i]);
      }
    }
    que.pop();
  }
  cout << accumulate(c.begin(),c.end(),0L)-c[0] << endl;
  rep(i,n){
    cout << res[i] << " ";
  }
    
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans[60],k,b[60],s;
bool t;
int main() {
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
		scanf("%lld",&ans[i]);
	k=0;
	while (1) {
		s=0;
		for (int i=1;i<=n;i++) {
			b[i]=ans[i]/n;
			s+=b[i];
		}
		k+=s;
		t=false;
		for (int i=1;i<=n;i++) {
			ans[i]-=b[i]*n;
			ans[i]+=s-b[i];
			if (ans[i]>=n)
				t=true;
		}
		if (!t)
			break;
	}
	printf("%lld\n",k);
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    auto a = readln.split.to!(int[]).sort();
    writeln(a[0] + a[1] == a[2] ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int M = 5*1e5+5;
#define pi acos(-1)
#define INF 1e10
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
int main()
{
	int f = 0;
	int n;sd(n);
	while(n)
	{
		if(n%10 == 7)
		{
			f = 1;
			break;
		}
		n /= 10;
	}
	if(f) printf("Yes\n");
	else printf("No\n");
	//system("pause");
	return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <array>
#include <stdexcept>

using namespace std;

int solve(
    const array<vector<int>, 10>& F,
    const vector<array<int, 11>>& P,
    vector<int> counts,
    int depth
) {
  if (depth == F.size()) {
    int p = 0;
    int count = 0;
    for (int i = 0; i < P.size(); ++i) {
      count += counts[i];
      p += P[i][counts[i]];
    }
    if (count == 0) throw exception();
    return p;
  }
  int p0;
  try {
    p0 = solve(F, P, counts, depth + 1);
    for (int i = 0; i < F[depth].size(); ++i) ++counts[F[depth][i]];
    int p1 = solve(F, P, counts, depth + 1);
    return max(p0, p1);
  } catch (exception& e) {
    for (int i = 0; i < F[depth].size(); ++i) ++counts[F[depth][i]];
    return solve(F, P, counts, depth + 1);
  }
}

int main()
{
  int N;
  cin >> N;
  array<vector<int>, 10> F;
  for (int n = 0; n < N; ++n) {
    for (int d = 0; d < 5; ++d) {
      for (int m = 0; m < 2; ++m) {
        int v;
        cin >> v;
        if (v == 1) F[d * 2 + m].push_back(n);
      }
    }
  }

  /*
  for (int i = 0; i < F.size(); ++i) {
    cerr << i << ":";
    for (int j = 0; j < F[i].size(); ++j) {
      cerr << " " << F[i][j];
    }
    cerr << endl;
  }
  */

  vector<array<int, 11>> P(N);
  for (int n = 0; n < N; ++n) {
    for (int c = 0; c < P[n].size(); ++c) {
      cin >> P[n][c];
    }
  }

  /*
  cerr << "P:" << endl;
  for (int i = 0; i < P.size(); ++i) {
    cerr << i << ":";
    for (int j = 0; j < P[i].size(); ++j) {
      cerr << " " << P[i][j];
    }
    cerr << endl;
  }
  */

  cout << solve(F, P, vector<int>(N), 0) << endl;
  return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    a_cost = (l[i + 1] - l[i]) * a
    if a_cost <= b:
        ans += a_cost
    else:
        ans += b
print(ans)

Measured memory_bytes: 14252
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    H=list(map(int,input().split()))
    edge=[[] for _ in range(N)]
    for i in range(M):
        a,b=map(int1,input().split())
        edge[a].append(b)
        edge[b].append(a)
    ans=0
    for v in range(N):
        for nv in edge[v]:
            if H[v]<=H[nv]:
                break
        else:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 90292
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include <wchar.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
*/

ll a,b,c,ans=0;

int main(void){
	cin>>a>>b>>c;
	if(b>=c){
		ans=b+c;
	}else{
		ans+=b*2;
		ans+=min(a+1,c-b);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	boolean a = (scan.next().charAt(0) == 'H' ? true : false);
	boolean b = (scan.next().charAt(0) == 'H' ? true : false);
	boolean status = a ? b : !b;

	System.out.println(status ? "H" : "D");
	scan.close();
    }
}


Measured memory_bytes: 21844
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
H = l.shift() * 1
N = l.shift() * 1
k = []
for (i=0;i<N;i++) {
    k.push(inp.shift().split(' ').map(x => x - 0))
}
dp = [0]
for(h=0;h<=H+1;h++) {
    if (dp[h] === undefined) {
        continue;
    }
    for(i=0;i<N;i++) {
        dp[h+k[i][0]] = (dp[h+k[i][0]] === undefined || dp[h+k[i][0]] > dp[h] + k[i][1]) ? dp[h] + k[i][1] : dp[h+k[i][0]]
    }
}
min = dp[dp.length - 1]
for(j=dp.length - 1; j >= H; j--) {
    if (dp[j] >= min || dp[j] === undefined) {
        dp[j] = min
    } else {
        min = dp[j]
    }
}
console.log(dp[H])



Measured memory_bytes: 7740
#include<stdio.h>
int main(){
	int AC=0;
	int WA=0;
	int TLE=0;
	int RE=0;
	int batas;
	scanf("%d", &batas);
	for(int i=0;i<batas;i++){
		char string[6]="";
		scanf("%s", &string);
		if(string[0]=='A') AC++;
		else if(string[0]=='W') WA++;
		else if(string[0]=='T') TLE++;
		else if(string[0]=='R') RE++;	
	}
	printf("AC x %d\n", AC);
	printf("WA x %d\n", WA);
	printf("TLE x %d\n", TLE);
	printf("RE x %d\n", RE);
	return 0;
}

Measured memory_bytes: 1736
use std::cmp::max;
use std::collections::HashSet;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let s: String = read(&mut stdin_lock, &mut buf, b'\n');
    let cs: Vec<char> = s.chars().collect();
    let mut ans = 0;
    for i in 1..n {
        let set1: HashSet<_> = cs[0..i].iter().collect();
        let set2: HashSet<_> = cs[i..n].iter().collect();
        ans = max(ans, set1.intersection(&set2).count());
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});

reader.on("close", function() {
  // A,B,C
  var numbers: number[] = lines[0].split(" ").map(x => {
    return Number(x);
  });
  if (numbers[0] + numbers[1] >= numbers[2]) {
    console.log("Yes");
  } else {
    console.log("No");
  }
});


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

struct node
{
  int key;
  node *parent=nullptr, *left=nullptr, *right=nullptr;
};

using tree = node*;

void preOrder(tree t)
{
  std::cout << " " << t->key;
  if (t->left != nullptr)
    preOrder(t->left);
  if (t->right != nullptr)
    preOrder(t->right);
}

void inOrder(tree t)
{
  if (t->left != nullptr)
    inOrder(t->left);
  std::cout << " " << t->key;
  if (t->right != nullptr)
    inOrder(t->right);
}

void insert(tree &t, int key)
{
  node *new_node = new node;
  new_node->key = key;
  if (t == nullptr)
    {
      t = new_node;
      //std::cout << "New: " << t->key << std::endl;
    }
  else
    {
      tree cur_node = t;
      auto parent = cur_node->parent;
      while (cur_node != nullptr)
        {
          parent = cur_node;
          if (key < cur_node->key)
            cur_node = cur_node->left;
          else
            cur_node = cur_node->right;
        }
      if (key < parent->key)
        {
          parent->left = new_node;
        }
      else
        {
          parent->right = new_node;
        }
      new_node->parent = parent;
    }
}

bool find(tree t, int key)
{
  tree cur_node = t;
  while (cur_node != nullptr)
    {
      if (key == cur_node->key)
        return true;
      else if (key < cur_node->key)
        cur_node = cur_node->left;
      else
        cur_node = cur_node->right;
    }
  return false;
}

int main ()
{
  int n;
  std::cin >> n;

  std::string order;
  tree root = nullptr;
  for (int i=0; i<n; ++i)
    {
      std::cin >> order;
      if (order == "insert")
        {
          int key;
          std::cin >> key;
          insert(root, key);
        }
      else if (order == "print")
        {
          inOrder(root);
          std::cout << std::endl;
          preOrder(root);
          std::cout << std::endl;
        }
      else if (order == "find")
        {
          int key;
          std::cin >> key;
          if (find(root, key))
            std::cout << "yes\n";
          else
            std::cout << "no\n";
        }
    }
}





Measured memory_bytes: 21916
import math

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

candidate = [[i] for i in range(1, N + 1)]
while len(candidate) < math.factorial(N):
    temp = []
    for c in candidate:
        for i in range(1, N + 1):
            if not i in c:
                temp.append(c + [i])
    candidate = temp

a = candidate.index(P[:-1])
b = candidate.index(Q[:-1])

print(abs(a - b))

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

#define FAST {ios::sync_with_stdio(false); cin.tie(NULL);}
#define pb push_back
#define fi first
#define se second
#define ll long long int
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007

vector<vector<int>> dp(4,vector<int>(100009));
// 1-> 'A', 2-> 'B', 3->'C'
int n,ans;
vector<int> a,b,c;

void DynamicProg(){

	dp[1][n] = a[n];
	dp[2][n] = b[n];
	dp[3][n] = c[n];

	for(int i=n-1;i>=1;i--){
		dp[1][i] = a[i] + max(dp[2][i+1], dp[3][i+1]);
		dp[2][i] = b[i] + max(dp[1][i+1], dp[3][i+1]);
		dp[3][i] = c[i] + max(dp[1][i+1], dp[2][i+1]);
	}
	ans = max(max(dp[1][1],dp[2][1]),dp[3][1]);
}

int main(){

    FAST
	
	
	cin>>n;

	a = b = c = vector<int>(n+1);

	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];

	DynamicProg();

	cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 5932
t,a[];short*p;Q(){for(p=a;*p=='=Q';p++);}main(i,s){for(;~scanf("%[^\n]\n",s);i=0)i||puts(sscanf(s,">^%[Q=]~%c%c",a,&t,a)-2||t-'~'|(Q(),*p&7|p==a)?sscanf(s,">'%[=]#%[=]%c%c",a,s,&t,a)-3||t-'~'|strcmp(a,s)?"NA":"A":"B");}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	string s,t;
	cin>>s>>t;
	ll ch1[30],ch2[30];
	for(ll i=0;i<30;i++){
		ch1[i]=ch2[i]=-1;
	}
	bool ans=true;
	for(ll i=0;i<s.size();i++){
		ll now1=s[i]-'a';
		ll now2=t[i]-'a';
		if(ch1[now1]!=-1){
			if(ch1[now1]!=now2){
				ans=false;
			}
		}
		else{
			ch1[now1]=now2;
		}
		if(ch2[now2]!=-1){
			if(ch2[now2]!=now1){
				ans=false;
			}
		}
		else{
			ch2[now2]=now1;
		}
	}
	cout << (ans?"Yes":"No");
	// your code goes here
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    int N;
    cin >> N;

    ll h = 0;
    cin >> h;

    ll s = 0;
    for(int i = 1; i < N; i++){
        ll A;
        cin >> A;
        if(h < A){
            h = A;
        }else{
            s += h - A;
        }
    }

    cout << s << endl; 
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 2e6 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

ll cost[M], pre[M], mem[(1 << 13)];
vector<int> vv[M];

int n, m;
ll solve(int mask) {
  if(__builtin_popcount(mask) == n)
    return 0;
  ll& ret = mem[mask];
  if(~ret)
    return ret;
  ret = inf;
  for (int i = 1; i <= m; ++i) {
    ret = min(ret, solve(mask | pre[i]) + cost[i]);
  }
  return ret;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int a, k;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> cost[i] >> k;
    ll mask = 0;
    for (int j = 0; j < k; ++j) {
      cin >> a;
      --a;
      mask |= (1 << a);
      vv[i].push_back(a);
    }
    pre[i] = mask;
  }
  memset(mem, -1, sizeof mem);
  ll ans = solve(0);
  if(ans == inf)
    ans = -1;
  cout << ans;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    string input; cin >> input;
    vector<int> a(4);
    rep(i,4) a[i] = input[i]-'0';
    rep(i,8) {
        int sum = a[0];
        string s;
        s += (char)('0'+a[0]);
        rep(j,3) {
            if (i & (1<<j)) {
                sum += a[j+1];
                s += '+';
                s += (char)('0'+a[j+1]);
            }
            else {
                sum -= a[j+1];
                s += '-';
                s += (char)('0'+a[j+1]);
            }
        }
        if (sum == 7) {
            cout << s << "=7" << endl;
            return 0;
        }
    }
} 

Measured memory_bytes: 3604
v, e = map(int, input().split())
p = [i for i in range(v)]
E = [list(map(int, input().split())) for _ in range(e)]

E = sorted(E, key=lambda x: x[2])

def root(x):
  if p[x]==x:
    return x
  p[x] = root(p[x])
  return p[x]

ans = 0
for edg in E:
    a, b, w = edg
    if root(a)!=root(b):
        ans += w
        p[root(a)] = root(b)

print(ans)


Measured memory_bytes: 29380
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	int n = in();
	vector<int>a(n);
	REPC(&i, a)i = in();
	int q = in();
	REP(i, q)
	{
		int k = in();
		cout << lower_bound(a.begin(), a.end(), k) - a.begin() << ' ' << upper_bound(a.begin(), a.end(), k) - a.begin() << endl;
	}
}


Measured memory_bytes: 3100
from collections import deque

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N, Q = MI()
T = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = MI()
    T[a - 1].append(b - 1)
    T[b - 1].append(a - 1)
    
plus = [0] * N

for _ in range(Q):
    p, x = MI()
    plus[p - 1] += x

queue = deque([0])
visited = [False] * N

while queue:
    u = queue.popleft()
    visited[u] = True
    
    for t in T[u]:
        if not visited[t]:
            plus[t] += plus[u]
            queue.append(t)

print(*plus)

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

int main() {

    int N;
    cin >> N;

    if (N%2 == 0) {
        cout << 0.5 << endl;
    }
    else {
        cout << setprecision(15) << (1.0 * (N/2+1) / N) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>           // printf(), scanf()
#include <vector>
#include <algorithm>        // sort()

using namespace std;
static const int MAX_E = 100000;

class disjointSet
{
public:
	vector<int> rank;
	vector<int> par;

	disjointSet() {}
	disjointSet(int size)
	{
		rank.resize(size, 0);
		par.resize(size, 0);
		for (int i = 0; i < size; ++i)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x)
	{
		if (x != par[x])
			par[x] = find(par[x]);

		return par[x];
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y)
			return;

		if (rank[x] < rank[y])
			par[x] = y;
		else
		{
			par[y] = x;
			if (rank[x] == rank[y])
				rank[x]++;
		}
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

struct edge
{
	int from, to;
	int cost;
};

edge es[MAX_E];
int V, E;

bool
cmp_func(const edge &e1, const edge &e2)
{
	return e1.cost < e2.cost;
}

int
kruskal()
{
	sort(es, es + E, cmp_func);
	disjointSet dset = disjointSet(V);
	int res = 0;

	for (int i = 0; i < E; ++i)
	{
		edge e = es[i];
		if (!dset.same(e.from, e.to))
		{
			dset.unite(e.from, e.to);
			res += e.cost;
		}
	}

	return res;
}

int
main(int argc, char** argv)
{
	edge e;
	int s, t, w;
	int i;

	scanf("%d %d", &V, &E);
	for (i = 0; i < E; ++i)
	{
		scanf("%d %d %d", &s, &t, &w);
		e.from = s;
		e.to = t;
		e.cost = w;
		es[i] = e;
	}

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

Measured memory_bytes: 2300
//at abc121d
#include <bits/stdc++.h>
#define y1 y1_
#define index index_
#define pipe pipe_
#define next next_
#define ll long long
#define Pi acos(-1.0)
#define lowbit(x) ((x&(-x)))
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;
inline ll read() {
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll a,b;
ll get(ll x) {
	if(x%4==0) return x;
	if(x%4==1) return 1;
	if(x%4==2) return x+1;
	if(x%4==3) return 0;
}
int main() {
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);/*syn加速*/
	a=read();b=read();
	cout<<(get(a-1)^get(b))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

const int N = 15, M = 1005;

int n, m, K, s[N][M], a[N], tot;

int g[N][M];


int inline get(int lx, int ly, int rx, int ry) {
	return s[rx][ry] - s[lx - 1][ry] - s[rx][ly - 1] + s[lx - 1][ly - 1];
}

bool inline check(int l, int r) {
	for (int i = 1; i < tot; i++) {
		if (get(a[i], l, a[i + 1] - 1, r) > K)
			return false;
	}
	return true;
}

// 切 x 刀行不行。
inline bool check(int x) {
	for (int i = 0; i < (1 << (n - 1)); i++) {
		tot = 0; a[++tot] = 1;
		int limit = x;
		for (int j = 0; j < n - 1; j++) 
			if (i >> j & 1) a[++tot] = j + 2, limit--;
		a[++tot] = n + 1;
		int last = 1, cnt = 0;
		for (int j = 1; j <= m; j++) {
			if (!check(last, j)) {
				if (last == j) {
					cnt = 1e9;
					break;
				}
				last = j, cnt++;
			} 
		}
		if (cnt <= limit) {
			return true;
		}
	}
	return false;
}

int main() {
	scanf("%d%d%d", &n, &m, &K);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			scanf("%1d", &g[i][j]);
			s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
			if (g[i][j] == 1) s[i][j]++; 
		}
	}
	int l = 0, r = n + m;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", r);
	return 0;
}

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

using namespace std;

int main()
{
  int values[200] = { 0 };
  string str;
  cin >> str;

  int N = str.size();

  for (int i = 0; i < N; i++)
  {
    int id = (int)str[i];
    values[id]++;
  }

  char outStr = 'a' - 1;
  for (int i = 'a'; i <= 'z'; i++)
  {
    if (values[i] == 0)
    {
      outStr = (char)i;
      break;
    }
  }

  if (outStr >= 'a')
    cout << outStr << "\n";
  else
    cout << "None\n";

  return 0;
}


Measured memory_bytes: 512
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let s = read string
    match s with
    | "Sunny" -> "Cloudy"
    | "Cloudy" -> "Rainy"
    | "Rainy" -> "Sunny"
    |> printfn "%s"
    0

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

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

const int lim = 1000000007;

int main(){
    //今回Nは奇数
    int N;
    cin >> N;
    //ダムに貯蔵されている水の量を格納
    vector<ll> a(N);
    //各山に降った雨の量を格納
    vector<ll> x(N);
    //降った雨の総量を格納
    ll sum = 0;
    rep(i, N){
        ll A;
        cin >> A;
        sum += A;
        a[i] = A;
    }

    //1-indexで偶数番目のダムの貯蔵量の和をとる
    ll elim_sum = 0;
    for(int i = 1; i <= N-2; i+=2){
        elim_sum += a[i];
    }
    //x[0]を求める
    x[0] = sum - 2*elim_sum;
    //漸化式によって、x[i]を求めていく
    for(int i = 0; i < N-1; i++){
        x[i+1] = 2 * a[i] - x[i];
    }
    rep(i, N) cout << x[i] << endl;
    return 0;
}

Measured memory_bytes: 4792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
 
using namespace std;
template <typename T> T max(T a, T b) {return a>b?a:b;}
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
#define ll long long
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))

const double eps = (double)1e-6;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool ac[maxn] = {};
int cnt[maxn] = {};

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

    int n,m; cin >> n >> m;
    int ans = 0, accnt = 0;
    int p; string s;

    for (int i = 1; i <= m; i++) {
        cin >> p >> s;
        if (s == "AC") {
            if (!ac[p]) {
                ac[p] = 1;
                ans += cnt[p];
                accnt++;
            }
        } else {
            cnt[p]++;
        }
    }

    cout << accnt << " " << ans << endl;

    
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  for (auto &e : a)
    cin >> e;
  for (auto &e : b)
    cin >> e;
  vector<int> x(M), y(M), c(M);
  for (int i = 0; i < M; ++i)
    cin >> x[i] >> y[i] >> c[i];
  vector<int> sum;
  for (int i = 0; i < M; ++i)
  {
    sum.push_back(a[x[i] - 1] + b[y[i] - 1] - c[i]);
  }
  sort(sum.begin(), sum.end());
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << min(a[0] + b[0], sum[0]) << endl;

  return 0;
}


Measured memory_bytes: 2812
import sys

class Node:
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

class BST:
    def __init__(self):
        self.root = None
    def insert(self, key):
        x, y = self.root, None
        while x != None: x, y = x.left if key < x.key else x.right, x
        if y == None: self.root = Node(key)
        elif key < y.key: y.left = Node(key)
        else: y.right = Node(key)
    def print_tree(self):
        def inorder(node):
            return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
        def preorder(node):
            return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
        print(inorder(self.root))
        print(preorder(self.root))

tree = BST()
input()
for e in sys.stdin:
    if e[0] == 'i': tree.insert(int(e[7:]))
    else: tree.print_tree()


Measured memory_bytes: 114804