akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void getSuffixArray(vector<int> &res, const string &str){
	int n = str.size();
	vector< pair<int, int> > vp(n);
	vector<int> rank(n), cnt(256, 0);
	for(int i=0;i<n;i++) cnt[str[i]]++;
	for(int i=1;i<256;i++) cnt[i] += cnt[i-1];
	for(int i=0;i<n;i++){
		rank[i] = cnt[str[i]];
		vp[i] = make_pair(cnt[str[i]], i);
	}
	sort(vp.begin(), vp.end());
	for(int h=1;h<n;h*=2){
		vector< pair<int,int> >::iterator cur = vp.begin();
		while(cur != vp.end()){
			vector< pair<int,int> >::iterator end = cur;
			int key = rank[cur->second];
			while(end!=vp.end() && rank[end->second] == key){
				end->first = end->second + h < n ? rank[end->second + h] : -1;
				end++;
			}
			int s = distance(vp.begin(), cur), e = distance(vp.begin(), end);
			if(e-s>1){
				sort(cur, end);
				rank[vp[e-1].second] = key;
				for(int i=e-2;i>=s;i--){
					if(vp[i].first == vp[i+1].first) rank[vp[i].second] = rank[vp[i+1].second];
					else rank[vp[i].second] = key-(e-1-i);
				}
			}
			cur = end;
		}
	}
	res.assign(n,0);
	for(int i=0;i<n;i++) res[i] = vp[i].second;
}

// Suffix Arrayに対して高さ配列を得る
void getHeightArray(vector<int> &res, const vector<int> &SA, const string &str){
	int n = SA.size();
	vector<int> rev(n);
	for(int i=0;i<n;i++) rev[SA[i]] = i;
	res.assign(n,0);
	int prev = 0;
	for(int i=0;i<n;i++){
		int idx = rev[i];
		if(idx == n-1){ res[idx] = prev = 0; continue; }
		idx = SA[idx+1];
		int t = prev;
		while(i+t<n && idx+t<n && str[i+t]==str[idx+t]) t++;
		res[rev[i]] = t;
		prev = max(0, t-1);
	}
}

int main(){
	string s;
	while(cin >> s){
		vector<int> SA;
		getSuffixArray(SA, s);
		int res = s.size();
		int n = SA.size();
		vector<int> rev(n);
		for(int i=0;i<n;i++) rev[SA[i]] = i;
		int prev = 0;
		for(int i=0;i<n;i++){
			int idx = rev[i];
			if(idx == n-1){ prev = 0; continue; }
			idx = SA[idx+1];
			int t = prev;
			while(i+t < n && idx+t < n && s[i+t] == s[idx+t]) t++;
			res = min(res, (int)s.size() - t);
			prev = max(0, t-1);
		}
		cout << res << endl;
	}
}


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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=0; i<n; i++){
        int l, r;
        cin >> l >> r;
        ans += (r-l+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);i <= (e);(i)++)

int N;
int s[101];

vector<vector<int>> dp(101,vector<int>(10,-(1e9)));
int main(){
  cin >> N;
  rep(i,1,N) cin >> s[i];

  dp[0][0] = 0;

  rep(i,1,N){
    rep(j,0,9){
      int before = (j + 10 - (s[i] % 10)) % 10;

      dp[i][j] = max(dp[i - 1][j],dp[i - 1][before] + s[i]);
    }
  }

  int MAX = 0;

  rep(i,1,9) MAX = max(dp[N][i],MAX);
  cout << MAX << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#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 rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;
using ld=long double;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int mod = TEN(9)+7;
const int inf = TEN(18) * 3 + 10;

int Q;

signed main()
{
	cin >> Q;

	int sum = 0;
	int v = 0;

	priority_queue<int> small;
	priority_queue<int, vi, greater<int>> big;

	small.emplace(-inf);
	big.push(inf);

	int median = -1;
	int sz = 0;

	rep(_, Q) {
		int query; scanf("%lld", &query);

		if (query == 1) {
			sz++;

			int a,b;scanf("%lld%lld",&a,&b);
			sum += b;

			if (sz > 1) {
				if ((sz - 1) & 1) {
					v += abs(small.top() - a);
				} else unless (small.top() <= a and a <= big.top()) {
					v += min(abs(small.top() - a), abs(big.top() - a));
				}
			}

			if (small.top() > a) {
				small.emplace(a);
			} else {
				big.emplace(a);
			}

			if (sz & 1) {
				while (big.size() >= small.size()) {
					int tmp = big.top();
					big.pop();
					small.emplace(tmp);
				}

				while (small.size() >= big.size() + 2) {
					int tmp = small.top();
					small.pop();
					big.emplace(tmp);
				}
			} else {
				while (big.size() > small.size()) {
					int tmp = big.top();
					big.pop();
					small.emplace(tmp);
				}
				while (big.size() < small.size()) {
					int tmp = small.top();
					small.pop();
					big.emplace(tmp);
				}
			}

			//printf("a = %lld, v = %lld\n", a, v);
		} else {
			printf("%lld %lld\n", small.top(), v + sum);
		}
	}
}




Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
using vvb=vector<vector<bool>>;
using vb= vector<bool>;
ll modpow(ll a,ll b,ll p){
	if(b==0) return 1;
	if(b%2==0){
		ll t=modpow(a,b/2,p);
		return t*t%p;
	}
	return a*(modpow(a,b-1,p))%p;
} 
//cout << fixed << setprecision(桁数);
//__builtin_popcount()
signed main(){
	ll n,k; cin>>n>>k;
	vl vec(n); 
	rep(i,0,n)cin>>vec[i];
	sort(all(vec));
	ll ans=MOD;
	rep(i,0,n-k+1){
		chmin(ans,vec[i+k-1]-vec[i]);
	}
	cout<<ans<<endl;
	

	return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
char s[105];
int main () {
  stack<char> t;
  int n;
  cin >> n;
  char temp;
  int a = 0;
  for (int i =0; i< n; i++) {
    cin >> s[i];
    if (s[i] == '(') {
      t.push('(');
    } else {
      if (t.empty()) {
        a++;
      } else {
        t.pop();
      }
    }
  }
  while (a > 0) {
    cout << '(';
    a--;
  }
  for (int i =0; i< n; i++)
    cout <<s[i];
  while (!t.empty()) {
    cout <<')';
    t.pop();
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define per(i,x,y) for(in i=y;i>=(x);--i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const in maxn = 1e5 + 9;
in clifo[maxn];

int main()
{
      IOS;
      in x;
      cin >> x;
      for(in i = 2; i<maxn;++i)
      {
            if(clifo[i] == 0)
            {
                  for(in j = 2; i*j < maxn;++j)
                  {
                        clifo[i*j] = 1;
                  }
            }
      }
      rep(i,2,maxn)
      {
            if(clifo[i] == 0 and i>= x)
            {
                  cout << i << "\n";
                  break;
            }
      }
}

Measured memory_bytes: 1024
N,M=map(int,input().split()) #SがN個、cがM個
Ans=0 #答えを入れる変数
if 2*N<=M: #cc→Sを使わないとcが余る場合
  Ans+=N
  M=M-2*N
  Ans+=M//4
  print(Ans)
elif 2*N>M: #cc→Sを使わないとSが余る場合
  Ans+=M//2
  print(Ans)

Measured memory_bytes: 2940
while 1:
    n, m, a = map(int, input().split())
    if n == 0:
        break

    row = []
    for _ in range(m):
        tmp = list(map(int, input().split()))
        row.append(tmp)

    row = sorted(row, key=lambda x: -x[0])
    for r in row:
        if r[1] == a:
            a = r[2]
        elif r[2] == a:
            a = r[1]

    print(a)


Measured memory_bytes: 5628
class UnionFind():
    '''
    UnionFindでグラフの状態を管理する
    '''
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n)
        self.rnk = [0]*(n)

    def find_root(self, x):
        '''
        ルートのノードを見つける
        '''
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        '''
        ノード同士を連結する
        '''
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def is_same_group(self, x, y):
        '''
        同一のルーツを持つかどうか調査する
        '''
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]

    def get_root(self):
        return self.root

    def get_member(self, x):
        if(self.root[x] < 0):
            return -self.root[x]
        else:
            return -self.root[self.root[x]]


N, M, K = map(int, input().split())
union_find = UnionFind(N)
AB = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int,input().split())
    a, b = a-1,b-1
    AB[a].append(b)
    AB[b].append(a)
    union_find.unite(a, b)

CD = [[] for _ in range(N)]
for _ in range(K):
    c, d = map(int,input().split())
    c, d = c-1,d-1
    CD[c].append(d)
    CD[d].append(c)

ret = [-1] * N
for i in range(N):
    union_find.find_root(i)
    ret[i] += union_find.get_member(i)

for i in range(N):
    for a in AB[i]:
        if union_find.is_same_group(i, a):
            ret[i] -= 1
    for c in CD[i]:
        if union_find.is_same_group(i, c):
            ret[i] -= 1

print(*ret, sep=" ")


Measured memory_bytes: 124832
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a+b>=10){
      System.out.println("error");
    }else{
      System.out.println(a+b);
    }
  }
}

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

int main(){
  long long H,W,sum;
  cin >> H >> W;
  if(H>1 && W>1){
  	cout << (H/2)*(W/2)+((H+1)/2)*((W+1)/2) << endl;
  }else{
    cout << 1 << endl;
  }
  return 0;
}

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

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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  if(n*a>b)cout << b << endl;
  else cout << n*a << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()

struct str{
	ll L1, L2, L3;
};

char A[15];
ll d1[15][150];
map <ll, str> M1[15][150];
int n;
ll powten[15];

void solve(int tc){
	scanf("%s", A);
	n = (int)strlen(A);
	int s = 0;
	for(int i=0;A[i];i++)s += A[i] - '0';
	ll mul = 1;
	for(int i=0;A[i];i++)mul *= (A[i] - '0' + 1);
	
	d1[0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<=s-j;k++){
				d1[i][k+j] += d1[i-1][k];
			}
		}
	}
	ll ans = 0;
	for(int i=0;i<s;i++)ans += d1[n][i];
	
	for(int i=0;i<A[0]-'0';i++)M1[1][i][i+1] = str{1, 0, 0};
	M1[1][A[0]-'0'][A[0]-'0'+1] = str{0, 1, 0};
	for(int i=A[0]-'0'+1;i<10;i++)M1[1][i][i+1] = str{0, 0, 1};
	powten[0] = 1;
	for(int i=1;i<=14;i++)powten[i] = powten[i-1] * 10;
	
	for(int i=2;i<=n;i++){
		for(int j=0;j<10;j++){
			for(int u=0;u<=s-j;u++){
				for(map<ll, str>::iterator k=M1[i-1][u].begin(); k!=M1[i-1][u].end(); ++k){
					if(k->Fi * (j+1) > mul)break;
					if(k->Fi * (j+1) * powten[n-i] < mul){
					//	ans += (k->Se.L1 + k->Se.L2 + k->Se.L3) * d1[n-i][s-u-j];
					//	continue;
					}
					
					str x = M1[i-1][u][k->Fi];
					M1[i][u+j][(j+1)*k->Fi].L1 += x.L1;
					M1[i][u+j][(j+1)*k->Fi].L3 += x.L3;
					if(j < A[i-1]-'0')M1[i][u+j][(j+1)*k->Fi].L1 += x.L2;
					else if(j == A[i-1]-'0')M1[i][u+j][(j+1)*k->Fi].L2 += x.L2;
					else M1[i][u+j][(j+1)*k->Fi].L3 += x.L2;
				}
			}
		}
		for(int j=0;j<=s;j++)M1[i-1][j].clear();
	}
	for(map<ll, str>::iterator k=M1[n][s].begin();k!=M1[n][s].end() && k->Fi < mul;++k)ans += k->Se.L1 + k->Se.L2 + k->Se.L3;
	ans += M1[n][s][mul].L1;
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1;// scanf("%d",&Tc);
	for(int i=1;i<=Tc;i++){
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 29300
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <stdbool.h>
#include<ctime>

#include <cstring>

#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf ",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define MOD  ( int)(1e9 + 7)
#define MAXN (ll) ((1e6+5))
#define K 25
#define  ALPHABET_SIZE  26
//#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int, int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph;




signed main(){
	IOS;

	ll n, k; 
	cin >> n >> k;
	vi g (1000 ,1 );
	for (int a ,  i = 0; i < k; i++){
		cin >> a;

		for (int t,  j = 0; j < a; j++){
			cin >> t;
			g[t]=0;
		}
	}
	ll res = 0;
	for (int i = 1; i <= n; i++){
		if (g[i])res++;
	}
	cout << res;
	getchar();
	getchar();

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> P;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = A; i < B + 1; i++) {
        if (i <= A + K - 1 || B - K + 1 <= i) {
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int n,k; cin >> n >> k;
    vint d(k);
    vector<bool> snuke(n,true);


    rep(i,k){
        cin >> d[i];
        rep(j,d[i]){
            int a_; cin >> a_;
            --a_;
            snuke[a_] = false;
        }
    }
    



    int ans = 0;

    rep(i,n) if(snuke[i]) ans++;

    cout << ans << endl;

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    int n, K;
    cin >> n >> K;

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

    ll ret = 0;
    for (int i = 0; i < 30; i++) {
        int k = 0;

        if (i) {
            if (!(K & 1 << i)) continue;
            for (int j = i + 1; j < 30; j++) if (K & (1 << j)) k += (1 << j);
            for (int j = 0; j < i; j++) k += (1 << j);
        } else {
            k = K;
        }

        ll ans = 0;
        for (int j = 0; j < n; j++) {
            bool flag = true;
            for (int l = 0; l < 30; l++) {
                if ((a[j] & 1 << l) && !(k & 1 << l)) flag = false;
            }

            if (flag) ans += b[j];
        }

        ret = max(ret, ans);
    }

    cout << ret << '\n';
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
int n,u,v;
int a[100001],b[100001],edgenum[100001],data[200001],parent[100001],
    depth[100001],vdepth[100001];
int *con[100001];


void find_next_node(int currentnode, int currentdepth){
    int k,curedgenum,nextnode;
    //printf("find_next_node(%d,%d)\n",currentnode,currentdepth);
    curedgenum=edgenum[currentnode];
    if(currentdepth>n){
        printf("Error: depth=%d\n",currentdepth);
        return;
    };
    for(k=0;k<curedgenum;k++){
        nextnode=con[currentnode][k];
        if(nextnode!=parent[currentnode]){
            parent[nextnode]=currentnode;
            depth[nextnode]=currentdepth+1;
            find_next_node(nextnode,currentdepth+1);
        };
    };
};    

void make_connection_list(void){
    int i,k;
    int edgefound[100001];
    for(i=0;i<n;i++){
        edgenum[i]=edgefound[i]=0;
    };
    for(i=0;i<n-1;i++){
        edgenum[a[i]]++;
        edgenum[b[i]]++;
    };
    con[0]=data;
    for(i=1;i<n;i++){
        con[i]=con[i-1]+edgenum[i-1];
    };
    for(i=0;i<n-1;i++){
        con[a[i]][edgefound[a[i]]]=b[i];
        edgefound[a[i]]++;
        con[b[i]][edgefound[b[i]]]=a[i];
        edgefound[b[i]]++;
    };
    /*for(i=0;i<n;i++){
        printf("con[%d]={",i);
        for(k=0;k<edgenum[i];k++){
            printf("%d",con[i][k]);
            if(k==edgenum[i]-1){
                printf("}\n");
            }
            else{
                printf(", ");
            };
        };
    };*/
};


int main(void){
    int i, longestrun=0;
    scanf("%d %d %d",&n,&u,&v);
    u--;v--;
    //printf("%d %d %d \n",n,u,v);
    for(i=0;i<n-1;i++){
        scanf("%d %d",&a[i],&b[i]);
        a[i]--;b[i]--;
        //printf("vertex %d: (%d,%d)\n",i, a[i],b[i]);
    };
    make_connection_list();
    
    depth[v]=0;
    parent[v]=-1;
    find_next_node(v,depth[v]);
    
    //copying the depths of nodes to vdepth
    vdepth[v]=0;
    for(i=0;i<n;i++){
        //printf("from v, terminal node %d: %d, depth=%d\n",i+1,terminal[i],depth[terminal[i]]);
        vdepth[i]=depth[i];
    }
    
    // 初期化は省略
    depth[u]=0;
    parent[u]=-1;
    find_next_node(u,depth[u]);
    for(i=0;i<n;i++){
        //printf("from u, terminal node %d: %d, depth=%d\n",i+1,terminal[i],depth[terminal[i]]);
        if(edgenum[i]==1){
            if(vdepth[i]>depth[i]){
                if(longestrun<vdepth[i]-1){
                    longestrun=vdepth[i]-1;
                };
                
            };
        };
    } ;
    printf("%d",longestrun);
    return 0;
};


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

using namespace std;

const int N = 1e5 + 5;
int a[103], dp[N][2];
int n, k;

int go(int rem, int turn){
	int &ans = dp[rem][turn];
	if(ans != -1)
		return ans;
	ans = 0;

	int mark = 0;
	for(int i = 1; i <= n; i++){
		if(rem - a[i] == 0)
			mark = 1;
		if(rem - a[i] > 0){
			if(go(rem - a[i], turn ^ 1) == 0)
				mark = 1;
		}
	}

	return ans = mark;
}

int main()
{
	memset(dp, -1, sizeof(dp));
	cin >> n >> k;

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

	if(go(k, 0))
		cout << "First\n";
	else
		cout << "Second\n";
}

Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		
		System.out.println(x*x*x);
		

	}

}

Measured memory_bytes: 17156
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

void solve() {
	vector<int> v;
	v.resize(5);
	for(int i = 0; i < v.size(); i++) cin >> v[i];
	int ret = 643;
	mt19937 g1;
	for(int qq = 0; qq < 1000; qq++) {
		shuffle(v.begin(), v.end(), g1);
		int curr = 0;
		for(int out: v) {
			if(curr%10) {
				curr += 10;
				curr -= curr % 10;
			}
			curr += out;
		}
		ret = min(ret, curr);
	}
	cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
using pii = pair<int, int>;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

struct UnionFind {
  vector<int> parent; // parent[root] is the negative of the size.
  UnionFind(int n) : parent(n, -1) { };
  bool unite(int u, int v) {
    u = root(u); v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v]; parent[v] = u;
    return true;
  }
  bool find(int u, int v) { return root(u) == root(v); }
  int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
  // ランク
  int size(int u) { return -parent[root(u)]; }
};

signed main()
{
    int N;
    cin >> N;

    vector<pii> xs(N);
    vector<pii> ys(N);

    UnionFind uf(N);
    rep(i, N){
        int x, y;
        cin >> x >> y;
        xs[i] = make_pair(x, i);
        ys[i] = make_pair(y, i);
    }

    sort(be(xs));
    sort(be(ys));

    struct edge {
        int from, to, cost;
    };
    vector<edge> edges;
    rep(i, N-1){
        int cost = xs[i + 1].first - xs[i].first;
        edges.push_back({xs[i].second, xs[i + 1].second, cost});
    }

    rep(i, N-1){
        int cost = ys[i + 1].first - ys[i].first;
        edges.push_back({ys[i].second, ys[i + 1].second, cost});
    }

    sort(be(edges), [](const edge& l, const edge& r) { return l.cost < r.cost; });
    ll ans = 0;
    for(auto e : edges){
        if(!uf.find(e.from, e.to)){
            ans += e.cost;
            uf.unite(e.from, e.to);
        }
    }
    cout << ans << nl;
}


Measured memory_bytes: 6900
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
    long long a, b, c, k, sum = 0;
    cin >> a >> b >> c >> k;
    if (k < a) {
        sum += k;
        k = 0;
    }
    else {
        sum += a;
        k -= a;
        if (k < b) {
            k = 0;
        }
        else {
            k -= b;
            sum += k * -1;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>
#include <algorithm>

using namespace std;

#define MAXN 100000

int main() {
    int N;
    long long A[MAXN + 1], sum[MAXN + 1];
    int i;
    
    scanf("%d", &N);
    for(i = 1; i <= N; i++) scanf("%lld", &A[i]);
    
    sort(A + 1, A + N + 1);
    sum[0] = 0;
    for(i = 1; i <= N; i++) sum[i] = sum[i - 1] + A[i];
    
    for(i = N - 1; i > 0; i--) if(sum[i] * 2 < A[i + 1]) break;
    printf("%d", N - i);
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
using namespace std;
struct node {
	int a, b;
	bool operator<(const node& q) const{
		return a < q.a;
	}
};
int n;
node a[100010];
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].a;
		a[i].b = i;
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) {
		cout << a[i].b <<" ";
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  ll A, B;
  cin >> A >> B;
  if (A >= 13)
    cout << B;
  else if (A >= 6) {
    cout << B / 2;
  } else
    cout << 0;

  return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
set<P>S;
int h,w,n;
ll ans[10];
vector<P>vec;
int main(){
	cin >> h >> w >> n;
	for(int i=0;i<n;i++){
		int a,b; scanf("%d%d",&a,&b);
		S.insert(mp(a,b));
		for(int x=0;x<=2;x++){
			for(int y=0;y<=2;y++){
				if(a-x>=1 && a-x+2<=h && b-y>=1 && b-y+2<=w){
					vec.pb(mp(a-x,b-y));
				}
			}
		}
	}
	sort(vec.begin(),vec.end());
	ERASE(vec);
	for(int i=0;i<vec.size();i++){
		int p = vec[i].fi,q = vec[i].sc; int cnt = 0;
		for(int j=p;j<=p+2;j++){
			for(int k=q;k<=q+2;k++){
				cnt += (S.find(mp(j,k)) != S.end());
			}
		}
		ans[cnt]++;
	}
	ans[0] += 1LL*(h-2)*(w-2)-vec.size();
	for(int i=0;i<=9;i++) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 12008
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e5;
LL enter_count[N+1];
LL exit_count[N+1];
LL exit_len[N+1];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	memset(enter_count,0,sizeof enter_count);
	memset(exit_count,0,sizeof exit_count);
	memset(exit_len,0,sizeof exit_len);

	int n, m; cin >> n >> m;
	int u; cin >> u;
	LL honest = 0;

	LL curr_count = 0, curr_len = 0;
	for(int i = 0; i < n-1; i++)
	{
		int v; cin >> v;
		enter_count[u]++;
		exit_count[v]++;
		LL len = (v-u+m)%m;
		exit_len[v] += len;
		honest += len;

		if(u > v) //initialize curr_count to when favorite is placed at 1
		{
			curr_count++;
			curr_len += m-u+1;
		}
		u = v;
	}

	LL savings = curr_len-curr_count;
	for(int i = 2; i <= m; i++)
	{
		curr_count += enter_count[i-1]; //all guys who begin at i-1 begin getting bonuses now
		curr_count -= exit_count[i-1];  //all guys who end at i-1 stop getting bonuses now
		curr_len -= exit_len[i-1];      //remove the bonuses from the guys we killed
		curr_len += curr_count;  	    //everyone alive gets a +1 bonus as we move from i-1 to i
		savings = max(savings,curr_len-curr_count);
	}
	cout<<honest-savings<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//
//using namespace __gnu_pbds;
using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)
/*
tree<
       int,
     null_type,
     less<int>,
     rb_tree_tag,
     tree_order_statistics_node_update>t;
*/

int main()
{
    fast_in_out

   ll n, k;
   cin>>n>>k;

   if(n<k) cout<<min(n, k-n)<<endl;
   else
   {
       ll md=n%k;
       cout<<min(md, k-md)<<endl;

   }

    return 0;
}



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

#define st first
#define nd second
#define pb push_back
#define mp make_pair
typedef pair< int ,int > pii;
typedef vector< pii > vii;
typedef long long ll;
typedef map<int,int> mii;
typedef set<pii> sii;
typedef set<int> si;
typedef vector< int > vi;

const ll MOD = 119 << 23 | 1;

ll gcd(ll x, ll y){
    if(!y)
        return x;
    return gcd(y,x%y);
}

ll inv(ll x) {
    ll r = 1ll, t = x, k = MOD - 2ll;
    while (k) {
        if (k & 1ll) r = (long long) r * t % MOD;
        t = (long long) t * t % MOD;
        k >>= 1;
    }
    return r;
}

const int nax = 2e5+13;

void read(){

}

void solve(){
    int x,res=0;
    cin >> x;
    res=1000*(x/500);
    x%=500;
    res+=(5*(x/5));
    cout << res;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int t=1;
    //cin >> t;
    while(t--){
        read();
        solve();
    }

    return 0;
}


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

#define int long long
using namespace std;

int X, Y, x, y;

signed main()
{
	cin >> X >> Y >> x >> y;
	cout << (X - x)*(Y - y) << endl;

	//system("pause");

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int maxn = 1e6+5;
vector<int> g[maxn];
int vis[maxn];

void dfs(int p)
{
	vis[p] = 1;
	int len = g[p].size();
	for(int i=0; i<len; i++) {
		int u = g[p][i];
		if(!vis[u]) dfs(u);
	}
}

int main()
{
	memset(vis, 0, sizeof vis);
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans = 0;
	for(int i=1; i<=n; i++) {
		if(!vis[i]) {
			dfs(i);
			ans++;
		}
	}
	cout << ans-1 << endl;
	return 0;
}

Measured memory_bytes: 35012
#include <iostream>
#include <algorithm>
#include <limits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <cmath>

using namespace std;
const int mod = 998244353;
int n, k;

int main() {
    scanf("%d %d", &n, &k);
    vector<pair<int, int>> s;
    for (int i = 0; i < k; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);
        s.push_back({l, r});
    }

    vector<long long> dp(n + 1, 0);
    vector<long long> preSum(n + 1, 0);
    dp[1] = 1;
    preSum[1] = 1;
    for (int i = 2; i <= n; ++i) {
        for (int j = 0; j < k; ++j) {
            int l = i - s[j].second;
            int r = i - s[j].first;
            if (r < 0) continue;
            l = max(1, l);
            dp[i] += preSum[r] - preSum[l - 1];
            dp[i] %= mod;
        }
        preSum[i] = preSum[i - 1] + dp[i];
    }
    printf("%lld\n", dp[n]);
    return 0;


    sort(s.begin(), s.end());
    // cnt[i] := the number of possible ways to reach ith cell
    // cnt[i] = sum{cnt[i-k] | k in S}
    vector<long long> cnt(n + 1, 0);
    cnt[1] = 1;
    for (int i = 2; i <= n; ++i) {
        for (auto it : s) {
            for (int k = it.first; k <= it.second; ++k) {
                if (i - k <= 0) {
                    break;
                }
                cnt[i] += cnt[i - k];
            }
            cnt[i] %= mod;
        }
    }
    printf("%lld\n", cnt[n]);
    return 0;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  if(B-A+1>=K) cout << "OK" << endl;
  else{
    if(A % K == 0) cout << "OK" << endl;
    else if(A + K - (A % K) <= B) cout << "OK" << endl;
    else  cout << "NG" << endl;
  }
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
# input = sys.stdin.r/eadline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N = INT()
    A = LI()

    last = A[0]
    is_increase = None
    answer = 0
    for i in range(1,N):
        if last == A[i]:
            continue
        if is_increase == None:
            is_increase = last<=A[i]
            last = A[i]
            continue

        if is_increase and last<=A[i]:
            last = A[i]
            continue
        
        if not is_increase and last>=A[i]:
            last = A[i]
            continue

        if (is_increase and last>A[i]) or (not is_increase and last<A[i]):
            is_increase = None
            last = A[i]
            answer += 1

    answer += 1
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14480
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n,S,i;cin>>n>>S;
	llint dp[3001]={};
	dp[0]=1;
	while(n--){
		int a;cin>>a;
		for(i=S;i>=0;i--){
			dp[i]=dp[i]*2;
			if(i>=a){dp[i]+=dp[i-a];}
			dp[i]%=mod;
		}
	}
	cout<<dp[S]<<endl;
	return 0;
}


Measured memory_bytes: 3192
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants ---------- */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    ll a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll ret = 0;
    for (int i = 0; i < N; i++) {
        ll elem = a[i];
        while (elem % 2 == 0) {
            ret++;
            elem /= 2;
        }
    }

    cout << ret << endl;

    return 0;
}

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

using namespace std;

int main() {
	int64_t a, b, r, x,tmp;
	cin >> a >> b;
	x = a * b;

	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	cout << x / b << endl;

}

Measured memory_bytes: 256
program sample
    implicit none
  
    integer(8) :: i,j,m,n,b
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n
    allocate(a(n))
    do i=1,n
        read(*,*)a(i)
    end do
    call msort(a)
    b=0
    m=0
    do i=1,n-1
        if(a(i)==a(i+1))then
            a(i)=0
            a(i+1)=0
        
        else if(a(i)==0)then
            cycle
        else
            m=m+1
        end if
    end do
    if (a(n)/=0)then
        m=m+1
    end if
    
    write(*,*)m
    stop
    contains

    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program sample
  



Measured memory_bytes: 4384
from sys import stdin
import math
inp = lambda : stdin.readline().strip()

n = int(inp())
ans = 0
for i in range(1,n):
    l = 0
    h = n + 1
    while l < h:
        m = (h+l)//2
        if i * m >= n:
            h = m
        else:
            l = m + 1
    ans += (l-1)
print(ans)

Measured memory_bytes: 67488
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll A, B, N; std::cin >> A >> B >> N;

  auto func = [A,B](ll x) -> ll { return std::floor( (double)A*x/B ) - std::floor( (double)x/B )*A; };

  if ( B == N ) {
    int x = func(B);
    int z = func(B-1);
    std::cout << std::max( x,z ) << std::endl;
  }
  else if ( B < N ) {
    int x = func(B);
    int y = func(B+1);
    int z = func(B-1);
    std::cout << std::max( {x,y,z} ) << std::endl;
  }
  else std::cout << func(N) << std::endl;
  return 0;
}



Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, X;
	cin >> N >> X;
	int L[100];
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	int k = 0;
	int s = 0;
	while (k<N && s + L[k] <= X) {
		s += L[k];
		k++;
	}
	cout << k + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

int A[50], n;

int solve (int i, int m) {
  if (m == 0) return 1;
  if (i >= n) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main(){
  int q, M;
  cin >> n;
  REP(i, n) {
    cin >> A[i];
  }
  cin >> q;
  REP(i, q) {
    cin >> M;
    if (solve(0, M)) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <complex>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;

//#define _DEBUG_ 3
void run() {
	int fst[3];
	for (int& p : fst) cin >> p;

	int tmp[3];
	for (int i = 0; i < 3; i++) tmp[i] = fst[i];

	int ans = 0;
	for (int i = 0;; i++) {
		bool odd = false;
		for (int i = 0; i < 3; i++) if (tmp[i] % 2 != 0) {
			odd = true;
		}
		if (odd) break;

		ans++;
		int a = tmp[0], b = tmp[1],c = tmp[2];

		tmp[0] = (b / 2 + c / 2);
		tmp[1] = (a / 2 + c / 2);
		tmp[2] = (b / 2 + a / 2);

		bool roop = true;
		for (int i = 0; i < 3; i++) if (tmp[i] != fst[i]) {
			roop = false;
		}
		if (roop) {
			cout << "-1" << endl;
			return;
		}
	}
	
	cout << ans << endl;
}

int main() {
#ifdef _DEBUG_
	using std::chrono::system_clock;
	using std::chrono::duration_cast;
	system_clock::time_point  start, end;
	std::ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
	for (int i = 0; i < _DEBUG_; i++) {
		cout << "-------------------------- (cnt:" << i << ")" << endl;
		start = system_clock::now();
		run();
		end = system_clock::now();
		int elapsed = duration_cast<std::chrono::milliseconds>(end - start).count();
		cout << "-------------------------- (time:" << elapsed << "ms)" << endl << endl;
	}
#else
	run();
#endif
	return 0;
}

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

int main()
{
  int hen[4];

  for(int i = 0;i < 4;i++)
    {
      cin >> hen[i];
    }

  if(hen[0]==hen[2]&&hen[1]==hen[3])
    {
      cout << "yes" << endl;
    }
  else if(hen[0]==hen[1]&&hen[2]==hen[3])
    {
      cout << "yes" << endl;
    }
  else if(hen[0]==hen[3]&&hen[1]==hen[2])
    {
      cout << "yes" << endl;
    }
  else
    {
      cout << "no" << endl;
    }
}



Measured memory_bytes: 3080
from collections import defaultdict
n = int(input())
A = defaultdict(lambda:0)
B = list(map(int,input().split()))
S = sum(B)
for i in B:
    A[i] += 1
q = int(input())
for _ in range(q):
    b,c = map(int,input().split())
    if A[b] > 0:
        S += (c-b)*A[b]
        A[c] += A[b]
        A[b] = 0
    print(S)

Measured memory_bytes: 22420
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long  double
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define mp(p) make_pair(p)
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz(v) ((int)v.size())
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cout << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846
const int N  = 105;
ll n, aa[N],bb[N], m, x, y,z,ts,a,b,c,d,t[N][N],q,l,r,k,p,h ;
map<int, int > mii,mii2 ;
map<pair<ll,ll>, ll > mpp ;
bool prime[N];
vector <int> ans ;
vector <int> v;
queue <int> q1,q2 ;
set<int>s ;
stack<int> ss;
int freq[N];
string ch ;
pair<ll  , ll > pl[N] ;
ll res[N];

ll get(ll x){

    //cout<<d<<endl ;

   ll sum = 0 ;
   for(int i = 0 ;i<n ; i++){
      for (int j = 0 ; j< m ; j ++){
            if (t[i][j]>x){
                if (((t[i][j]-x) % d )!= 0 )
                    return 1e9 ;
                sum+=(t[i][j]-x) / d;

            }
            else {
                if (((x-t[i][j])%d )!= 0 )
                    return 1e9 ;
                sum+=(x-t[i][j]) / d ;

            }

        }

   }

   return sum ;
}



int main(){

    FASTIO;
    int tab[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
    cin>>n ;
    cout<<tab[n-1];
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long n, a, b;

int main()
{
	scanf("%lld%lld%lld", &n, &a, &b);
	
	long long dist;
	if (a > b)
	{
		long long temp = b;
		b = a;
		a = temp;
	}
	
	dist = b - a;
		
	if (dist % 2 == 0)
	{
		long long ans = dist / 2;
		printf("%lld\n", ans);
		return 0;
	}
	
	long long toLeft = b - 1;
	long long toRight = n - a;
	
	long long curMin = toLeft;
	
	if (curMin > toRight)
		curMin = toRight;
		
	long long newDist = a + (dist - 1) / 2;
	if (curMin > newDist)
		curMin = newDist;
		
	newDist = n - b + 1 + (dist - 1) / 2;
	if (curMin > newDist)
		curMin = newDist;
	
	printf("%lld\n", curMin);
	

	return 0;
}


Measured memory_bytes: 128