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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw`(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}


ll a[200005],b[200005];
map<ll,ll> mpa,mpb;

void solve(){
  ll N; cin>>N;
  REP(i,N){
    cin >> a[i];
    ++mpa[ a[i] ];
  }
  REP(i,N){
    cin >> b[i];
    ++mpb[ b[i] ];
  }
  REP(x,N+1){
    if(mpa[x]+mpb[x]>N){
      cout << "No\n";
      return;
    }
  }
  sort(b,b+N,greater<ll>());
  REP(roop,2){
    int idx = 0;
    int temp = -1;
    int count = 0;
    REP(i,N){
      if(a[i]==b[i]){
        if(temp!=a[i]){
          idx=0;
        }
        count = 0;
        while(a[i]==b[idx]){
          idx = (idx+1)%N;
          if(idx==0){
            ++count;
            if(count>1){cout << Linn; return;}
          }
        }
        swap(b[idx],b[i]);
      }
      temp = a[i];
    }
  }
  cout << Liny;
  REP(i,N){
    if(i<N-1){
      printf("%Ld ",b[i]);
    }else{
      printf("%Ld\n",b[i]);
    }
  }
}
int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  solve();
  return 0;
}


Measured memory_bytes: 31852
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp;

fn main() {
    input!(s: chars);
    for &c in s.iter() {
        if c == '1' {
            print!("9");
        } else {
            print!("1");
        }
    }
    println!();
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>
#include <cmath>
 
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << std::fixed << std::setprecision(10);
 
	string s, t;
  	cin >> s;
  	cin >> t;
  	cout << t << s << endl;
 
	return 0;
}

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

int main(){
   int a,b,c;cin>>a>>b>>c;
   int flag=0;
   for(int i=1;i<=b;i++){
       if(i*a%b==c){flag=1;break;}
   }
   cout<<((flag)?"YES":"NO");
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
struct edge{int to,cost;};
typedef pair<int,int> P;
int N,M,K,Q;
vector<edge> G[100000];
vector<int> v,w;
int L[100000];
int R[100000];
int si[100000];
int ti[100000];
vector<int> T[100000];

int par[100000];

int find(int x){
  if(par[x]==x)return x;
  return par[x]=find(par[x]);
}
void unite(int x,int y){
  x=find(x);y=find(y);
  if(x==y)return;
  par[x]=y;
}

void search(){
  vector<int> mid(Q);
  for(int i=0;i<Q;i++){
    mid[i]=(L[i]+R[i])/2;
    T[ mid[i] ].push_back( i );
  }
  for(int i=0;i<N;i++)par[i]=i;

  vector<bool> used(N,false);
  for(int i=0;i<N;i++){
    int pos=v[i];
    used[pos]=true;
    for(int j=0;j<(int)G[pos].size();j++){
      edge e=G[pos][j];
      if(used[e.to])unite(pos,e.to);
    }
    
    for(int j=0;j<(int)T[i].size();j++){
      int k=T[i][j];
      if(find(si[k])==find(ti[k]))R[k]=mid[k];
      else L[k]=mid[k]+1;
    }
    T[i].clear();
  }
}

void dijkstra(){
  vector<int> d(N,1e9);
  priority_queue< P, vector<P>, greater<P> > Q;
  for(int i=0;i<K;i++){
    int a;
    scanf("%d",&a);
    a--;
    d[a]=0;
    Q.push(P(0,a));
  }  
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    int pos=p.second;
    int cost=p.first;
    if(cost>d[pos])continue;
    v.push_back(pos);
    w.push_back(cost);
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(cost+e.cost<d[e.to]){
        d[e.to]=cost+e.cost;
        Q.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){
  scanf("%d %d %d %d",&N,&M,&K,&Q);
  for(int i=0;i<M;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    a--,b--;
    G[a].push_back((edge){b,c});
    G[b].push_back((edge){a,c});
  }
  dijkstra();
  reverse(v.begin(),v.end());
  reverse(w.begin(),w.end());
  for(int i=0;i<Q;i++){
    scanf("%d %d",&si[i],&ti[i]);
    si[i]--;
    ti[i]--;
  }
  for(int i=0;i<N;i++){
    L[i]=0;
    R[i]=N-1;
  }
  for(int i=0;i<20;i++){
    search();
  }
  for(int i=0;i<Q;i++){
    printf("%d\n",w[ L[i] ]);
  }
  return 0;
}

Measured memory_bytes: 26304
m=1e9+7,P[3333][3333];
c,i;
f(j){
	P[i][j]=~c?*P[i-1]-P[i-1][j]:P[i-1][j];
	j<i&&f(j+1);
	P[i][j]=(1L*P[i][j]+P[i][j+1]+m)%m;
}
main()
{
	P[0][0]=1;
	for(gets(&c);c=getchar(++i)%3-1;)f(0);
	printf("%d",*P[i-1]);
}

Measured memory_bytes: 39808
#include <stdio.h>
 
#define A_MAX 1000000
#define A_MAX_HALF 500000
 
int min_factor[A_MAX + 1];
int q[A_MAX + 1];
int a[A_MAX + 1];
int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
int N;
 
int main() {
 
    for (int i = 2; i <= A_MAX_HALF; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
        }
        int j = 0;
        int min_factor_i = min_factor[i];
        for (int p = 2; ; p = primes[++j]) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor_i) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
 
    char c = getchar_unlocked();
    while (c > 47) {
        N = 10 * N + c - 48;
        c = getchar_unlocked();
    }
 
    for (int i = 0; i < N; ++i) {
        int x = 0;
        c = getchar_unlocked();
        while (c > 47) {
            x = 10 * x + c - 48;
            c = getchar_unlocked();
        }
        ++a[x];
    }
 
    int is_pairwise_coprime = 1;
    for (int n = A_MAX; n > 1; --n) {
        int an = a[n];
        if (an) {
            if (an > 1) {
                if (an == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = 0;
            }
            a[min_factor[n]] += an;
            a[q[n]] += an;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

Measured memory_bytes: 13200
#include <iostream>
using namespace std;
int bubblesort(int a[],int n){
	int sw = 0;
	bool flag = 1;
	for(int i = 0;flag;i++){
		flag=0;
		for(int j=n-1;j>=i+1;j--){
		if(a[j]<a[j-1]){
			swap(a[j],a[j-1]);
			flag=1;
			sw++;
		}
	}
}return sw;
}
int main(){
	int a[100],n,sw;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sw = bubblesort(a,n);
	for(int i=0;i<n;i++){
		if(i)cout<<" ";
		cout<<a[i];
	}
	cout << endl;
	cout << sw << endl;
	
	return 0;
}

Measured memory_bytes: 3076
//例3がオーバーフローする以外できてる

// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
//#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,n,f=0,mini=INF;
    ll sum=0,maxi=0;
    string str,sub;
    ll h,w;
    ll m,k,d;
    ll x;
    cin>>k>>a>>b;
    if(a+1>=b) cout<<k+1<<endl;
    else{
        k=k-a+1;
        sum=a;
        if(k%2) sum++;
        sum+=(b-a)*(k/2);
        //if(k==1) sum++;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();

	int x = 0;
	for (int i = 1; i <= 9; i++) {
	    if (N % i == 0) {
		x = N / i;
		if (x < 10) {
		    System.out.println("Yes");
		    break;
		}
	    }
	}
	if (x > 9)
	    System.out.println("No");
    }
}

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

# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"

using namespace std;

# 1 "../Algo/NumberTheory/modulo.h" 1
class ModuloOps {
public:
    ModuloOps(long long mod): MOD(mod) {
    }

    long long binPow(long long a, long long b) {
        if (b < 0) {
            throw "invalid op";
        }
        if (b == 0) {
            return 1;
        }
        auto prev = binPow(a, b/2);
        return mul(mul(prev, prev), b % 2 == 1 ? normalize(a) : 1);
    }

    long long inv(long long a) {
        return binPow(a, MOD - 2);
    }

    inline long long add(long long a, long long b) {
        return normalize(a + b);
    }

    inline long long sub(long long a, long long b) {
        return normalize(a - b);
    }

    inline void inc(long long &a, long long b) {
        a = add(a, b);
    }

    inline long long mul(long long a, long long b) {
        return normalize(normalize(a) * normalize(b));
    }

    inline long long div(long long a, long long b) {
        return mul(a, inv(b));
    }

private:
    long long MOD;

    inline long long normalize(long long a) {
        return (a%MOD + MOD) % MOD;
    }
};
# 5 "<stdin>" 2

ModuloOps MOD(1e9+7);

vector<long long> pw2;
vector<long long> invPw2;

long long calc(vector<int> &a) {
    auto all = 1ll;
    for (auto sz: a) {
        all = MOD.mul(all, invPw2[sz]);
    }
    auto bad = all;
    for (auto sz: a) {
        MOD.inc(bad, MOD.mul(MOD.mul(all, pw2[sz]), MOD.sub(1, invPw2[sz])));
    }
    auto res = MOD.div(MOD.sub(1, bad), 2);
    return res;
}

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

    cin >> n;
    pw2.assign(n+1, 1ll);
    for (int i = 1; i <= n; i++) {
        pw2[i] = MOD.mul(pw2[i-1], 2);
    }
    invPw2.assign(n+1, 1ll);
    for (int i = 1; i <= n; i++) {
        invPw2[i] = MOD.div(1, pw2[i]);
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < n-1; i++) {
        int u, v;
        cin >> u >> v;

        u--; v--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    long long ans = 0;
    function<int(int, int)> enter;
    enter = [&] (int v, int p) {
        vector<int> a;
        a.reserve(g[v].size());
        int tot = 1;
        for (int u: g[v]) {
            if (u != p) {
                int sz = enter(u, v);
                a.push_back(sz);
                tot += sz;
            }
        }
        if (p != -1) {
            a.push_back(n-tot);
        }
        MOD.inc(ans, calc(a));
        return tot;
    };
    enter(0, -1);
    cout << ans << endl;
}


Measured memory_bytes: 39596
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define trace(...)
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
const int mod=1e9+7;
int power(int x, unsigned int y, int p)
{
    int res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
const int INF=1e18;
signed main()
{
    fastio;
    int n;
    cin>>n;
    int h[n];
    fr(i,0,n)
    {
        cin>>h[i];

    }
    int dp[n+1];
    fr(i,0,n)
    {
        dp[i]=INF;
        //cout<<dp[i]<<" ";
    }

    dp[0]=0;

    fr(i,0,n)
    {
        if(i+1<n)
        {
            dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
            //cout<<dp[i+1]<<endl;

        }
        if(i+2<n)
        {
            dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
        }
    }
    cout<<dp[n-1]<<endl;
}


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

int main()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	int dp[k+1];
	memset(dp, 0, sizeof(dp));

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

	for(int i = a[0]; i <= k; i++)
	{
		for(int j = 0; j < n ; j++)
		{
			if(i >= a[j] && dp[i] == 0 && !dp[i - a[j]])
			{
				dp[i] = 1;
				break;
			}
		}
	}

	if(dp[k])
		cout << "First";
	else
		cout << "Second";
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  string s,t;cin>>s>>t;
  int a,b;cin>>a>>b;
  string u;cin>>u;
  if(u==s)a--;
  else b--;
  cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define INF 1e+9
using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	while(cin >> n,n){
		int mi = INF;
		vector<P> vec;
		if(n <= 3){
			cout << n << endl;
			for(int i = 0;i < n;i++) cin >> mi;
			continue;
		}
		int cnt = 1,c;
		for(int i = 0;i < n;i++){
			int a;
			cin >> a;
			if(!i) c = a;
			else if(c != a){
				vec.push_back(P(c,cnt));
				c = a;
				cnt = 1;
			}else cnt++;
		}
		vec.push_back(P(c,cnt));
		int v = vec.size();
		for(int i = 0;i < v;i++){
			int sum = 0;
			vec = vec;
			if(!i){
				if(vec[1].second == 3){
					sum = 4;
					if(v >= 3 && vec[0].second + vec[2].second >= 5 && vec[0].first == vec[2].first) sum += vec[0].second + vec[2].second - 1;
				}
			}
			else if(i == v - 1){
				if(vec[v - 2].second == 3){
					sum = 4;
					if(v >= 3 && vec[v - 1].second + vec[v - 3].second >= 5 && vec[v - 1].first == vec[v - 3].first) sum += vec[v - 1].second + vec[v - 3].second - 1;
				}
			}else{
				if(vec[i].second == 1 && vec[i - 1].first == vec[i + 1].first && vec[i - 1].second + vec[i + 1].second >= 3){
					sum = 1 + vec[i - 1].second + vec[i + 1].second;
					int l = i - 2,r = i + 2;
					while(l >= 0 && r < v){
						if(vec[l].first == vec[r].first && vec[l].second + vec[r].second >= 4){
							sum += vec[l--].second + vec[r++].second;
						}
						else break;
					}
					mi = min(mi,n - sum);
				}
				if(vec[i - 1].second == 3){
					sum = 4;
					int l = i - 2,r = i;
					vec[i].second--;
					if(vec[i].second == 0) r++;
					while(l >= 0 && r < v){
						if(vec[l].first == vec[r].first && vec[l].second + vec[r].second >= 4){
							sum += vec[l--].second + vec[r++].second;
						}
						else break;
					}
					vec[i].second++;
					mi = min(mi,n - sum);
				}
				if(vec[i + 1].second == 3){
					sum = 4;
					int l = i,r = i + 2;
					vec[i].second--;
					if(vec[i].second == 0) l--;
					while(l >= 0 && r < v){
						if(vec[l].first == vec[r].first && vec[l].second + vec[r].second >= 4){
							sum += vec[l--].second + vec[r++].second;
						}
						else break;
					}
					vec[i].second++;
					mi = min(mi,n - sum);
				}
			}
			mi = min(mi,n - sum);
		}
		cout << mi << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())), reverse=True)

ans = sorted(P[:X] + Q[:Y])

for i in range(min(C, X+Y)):
    if R[i] > ans[i]:
        ans[i] = R[i]

print(sum(ans))

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

int MAX = 100000;

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

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

  int eCount[MAX], oCount[MAX];
  for (int i=0; i<MAX; ++i) {
    eCount[i] = oCount[i] = 0;
  }
  for (int i=0; i<n; ++i) {
    if( i % 2 == 0) {
      eCount[v[i]]++;
    } else {
      oCount[v[i]]++;
    }
  }

  int e1 = 0, e2 = 0, o1 = 0, o2 = 0;
  for (int i=0; i<MAX; ++i) {
    if ( eCount[i] > eCount[e1] ) {
      e2 = e1;
      e1 = i;
    } else {
      e2 = eCount[i] > eCount[e2] ? i : e2;
    }
    if ( oCount[i] > oCount[o1] ) {
      o2 = o1;
      o1 = i;
    } else {
      o2 = oCount[i] > oCount[o2] ? i : o2;
    }
  }

  int ans;
  if (e1 != o1) {
    ans = n - eCount[e1] - oCount[o1];
  } else {
    int ans1 = n - eCount[e1] - oCount[o2];
    int ans2 = n - eCount[e2] - oCount[o1];
    ans = ans1 < ans2 ? ans1 : ans2;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define Int int64_t
#define ll long long
#define pb push_back
using namespace std;
const Int MAXN=200005;
const int ALPHA=26;

Int N,K,M;
Int X,Y,Z;Int C;
vector<Int> ID;
vector<Int> SZ;
string S;
int find(int x){
    if(ID[x]==x) return x;
    return find(ID[x]);
}
void Union(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(SZ[x]>SZ[y]){
        ID[y]=x;
        SZ[x]+=SZ[y];
    }
    else{
        ID[x]=y;
        SZ[y]+=SZ[x];
    }
    return;
}
string common_prefix(string s,string t){
    string ans="";
    for(int i=0;i<min(s.length(),t.length());++i){
        if(s[i]==t[i]) ans.pb(s[i]);
        else break;
    }
    return ans;
}
string LCP(vector<string> A,int l,int r){
    if(l>r) return "";
    if(l==r) return A[l];
    int mid=(l+r)/2;
    string left=LCP(A,l,mid);
    string right=LCP(A,mid+1,r);
    return common_prefix(left,right);
}

long long ModExpo(long long x,unsigned long long y,long long M){
    Int ans=1;
    ans=(long long)ans;
    
    while(y>0){
        if(y&1) ans=((ans%M)*(x%M))%M;
        y>>=1LL;
        x=((x%M)*(x%M))%M;
    }
    return ans%M;
}
Int LCM(Int x,Int y){
    return (x*y)/__gcd(x,y);
}

using D=long double;
vector<Int> A,B;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    t=1;
    while(t--){
    cin>>N;
    cout<<(N>=30 ? "Yes\n":"No\n");
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B; cin >> A >> B;
    if(A+B<10) cout << A+B << endl;
    else cout << "error" << endl;
    return 0;
}


Measured memory_bytes: 3564
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int n, m;
	cin >> n >> m;
	vector<int>p(n);
	for (int i = 0; i < n; i++)p[i] = i + 1;
	bool f[10][10] = {};
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		f[a][b] = 1;
		f[b][a] = 1;
	}
	int ans = 0;
	do {
		
		if (p[0] == 1) {bool r = 0;
			for (int i = 0; i < n-1; i++) {
				if (!f[p[i]][p[i + 1]])r = 1;
			}
			if (!r)ans++;
		}

	} while (next_permutation(p.begin(),p.end()));

	cout << ans << endl;
	return 0;


}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

struct Edge {
public:
	int from, to, id;
	Edge() {}
	Edge(int _from, int _to, int _id) {
		from = _from;
		to = _to;
		id = _id;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int N, M;
string S;

vvi outdeg;
vb visited;
queue<int> Q;

void bfs(Graph G) {
	while (!Q.empty()) {
		int u = Q.front	(); Q.pop();
		for (Edge e : G[u]) {
			outdeg[e.to][e.id]--;
			if ((!visited[e.to]) && outdeg[e.to][e.id] == 0) {
				Q.push(e.to);
				visited[e.to] = true;
			}
		}
	}
}


bool TSort(Graph G) {
	visited = vb(N,false);
	REP(i, N) {
		if (outdeg[i][0]*outdeg[i][1] == 0) {
			Q.push(i);
			visited[i] = true;
		}
	}
	bfs(G);

	REP(i, N) {
		if (!visited[i])return true;
	}
	return false;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> M;
	cin >> S;
	Graph G(N);
	outdeg = vvi(N, vi(2, 0)); //0 => A ,1 => B
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (S[b] == 'A') {
			outdeg[a][0]++;
			G[b].push_back(Edge(b, a, 0));
		}
		else {
			outdeg[a][1]++;
			G[b].push_back(Edge(b, a, 1));
		}
		if (S[a] == 'A') {
			outdeg[b][0]++;
			G[a].push_back(Edge(a, b, 0));
		}
		else {
			outdeg[b][1]++;
			G[a].push_back(Edge(a, b, 1));
		}
	}

	if (TSort(G))cout << "Yes" << endl;
	else cout << "No" << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 45648
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
using MaxHeap = priority_queue<T>;
template<class T>
using MinHeap = priority_queue<T,vector<T>,greater<T> >;
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
  os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
  is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
  for(int i=0;i<vec.size();i++){
    os << vec[i];
    if(i+1<vec.size())os << ' ';
  }
  return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
  for(int i=0;i<vec.size();i++)is >> vec[i];
  return is;
}
void fastio(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(20);
}
struct UnionFind{
	vector<int> par,rank,sz;
	void init(int n){
    par.resize(n);
    sz.resize(n,1);
    rank.resize(n,0);
		for(int i=0;i<n;i++){
			par[i] = i;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
    par[x] = y;
    sz[y] += sz[x];
    rank[y] += rank[x];
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
}uf;
int N;
int H,W;
struct edge{
  int f,t;
  ll c;
  edge(){}
  edge(int f,int t,int c):f(f),t(t),c(c){}
  bool operator < (const edge& a) const{
    return c > a.c;
  }
};
vector<edge> es;
int main(){
  fastio();
  cin >> N >> H >> W;
  uf.init(H+W);
  for(int i=0;i<N;i++){
    int r,c,a;
    cin >> r >> c >> a;
    r--;c--;
    c += H;
    es.pb(edge(r,c,a));
  }
  sort(all(es));
  ll ans = 0ll;
  for(int i=0;i<es.size();i++){
    edge e = es[i];
    int f = uf.find(e.f);
    int t = uf.find(e.t);
    if(f==t){
      if(uf.sz[f]>uf.rank[f]){
        ans += e.c;
        uf.rank[f]++;
      }
    }else{
      if(uf.sz[f]+uf.sz[t]>=uf.rank[f]+uf.rank[t]+1){
        ans += e.c;
        uf.unite(f,t);
        uf.rank[t]++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

long long dp[405][405];
long long a[405];
int n;
long long MAX =1e18+5;
int main(){
    cin>>n;

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

    for(int i=1;i<=n;i++)
        dp[i][i]=0;
    for(int l=2;l<=n;l++){
        for(int i=1;i+l-1<=n;i++){
            int j= i+l-1;

            dp[i][j]=MAX;
            for(int k=i;k<j  && k<n;k++)
            dp[i][j]=min(dp[i][j],(dp[i][k]+dp[k+1][j])+a[j]-a[i-1]);

        }
    }
    cout<<dp[1][n];

}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

class Main{

public static int knap(int[] wt, int[] price, int i, int w,int[][] dp){
    
   if(w < 0 || i >= price.length)
       return 0;
    int a = 0;
   if(dp[i][w] > -1){
       System.out.println("used" + i + ' ' + w);
       return dp[i][w];
   
   }
    if(w >= wt[i]){

        a = price[i] + knap(wt,price,i+1,w-wt[i],dp);

    }
    
    
    int b = knap(wt,price,i+1,w,dp);
    
    dp[i][w] = Math.max(a,b);
    return dp[i][w]; 
 }

public static int knap2(int[] wt, int[] price, int n, int w,int[][] dp){
    
   if(w == 0 || n == 0)
       return 0;
    int a = 0;
   if(dp[n-1][w] > -1){
       System.out.println("used" + n + ' ' + w);
       return dp[n][w];
   
   }
    if(w >= wt[n-1]){

        a = price[n-1] + knap2(wt,price,n-1,w-wt[n-1],dp);

    }
    
    
    int b = knap2(wt,price,n-1,w,dp);
   // return Math.max(a,b);
    dp[n-1][w] = Math.max(a,b);
    return dp[n-1][w]; 
 }


public static long knap3(int[] wt, int[] price, int n, int w){
    
  
   
   long[][] dp = new long[n+1][w+1];
   for(int i = 0; i < dp.length; i++){
       for(int j=0; j< dp[0].length; j++){
            if(j == 0 || i == 0){
                //System.out.println(i + " " + j);
                dp[i][j] = 0;
            }
            else if(j >= wt[i-1]){
                dp[i][j] = Math.max(price[i-1] + dp[i-1][j-wt[i-1]],dp[i-1][j]);
            }
            
            else
                dp[i][j] = dp[i-1][j];
       }
   }
     for(int i = 0; i < dp.length; i++){
                  //  System.out.println(Arrays.toString(dp[i]));
                }
    return dp[n][w]; 
 }


public static void main(String[] args) throws Exception{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
                String s[] = br.readLine().split(" "); 
                int n = Integer.parseInt(s[0]);
                int w = Integer.parseInt(s[1]);
                
                int[] price = new int[n];
                int[] wt = new int[n];
                 
                for(int i = 0; i < n; i++){
                    String ss[] = br.readLine().split(" "); 
                    wt[i] = Integer.parseInt(ss[0]);
                    price[i] = Integer.parseInt(ss[1]);
                //in
                    //int w =     Integer.parseInt(s[1]);
                
                }
               //System.out.println(n);
//                int val[] = {10, 20, 30}; 
////                int wt[] = {1,1,1}; 
//                int  W = 2; 
                //int[][] dp = new int[val.length][W+1];
//                for(int i = 0; i < price.length; i++){
//                    Arrays.fill(dp[i],-1);
//                }
               // int l = val[3];
    
//                System.out.println(knap2(wt,val,3,W,dp));
                    System.out.println(knap3(wt,price,n,w));
//                  for(int i = 0; i < dp.length; i++){
//                    System.out.println(Arrays.toString(dp[i]));
//                }
              
	} 
} 



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

int main() {
  int N,L,R,A;
  cin >> N;
  A = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> L >> R;
    A += R - L + 1;      
  }
  
  cout << A << endl;
  
}


Measured memory_bytes: 3592
N = int(input())

count = dict()
for _ in range(N):
    x = input()
    count[x] = count.get(x, 0) + 1

max_val = -float("infinity")
for k, v in sorted(count.items(), key=lambda x: (-x[1], x[0])):
    max_val = max(v, max_val)
    if v == max_val:
        print(k)
    else:
        break


Measured memory_bytes: 115928
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(v <= w){
        puts("NO");
    }else {
        a = abs(a-b), v = abs(v-w);
        ll x = (a+v-1)/v;
        if(x <= t) puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 3608
using System;
    using System.Collections.Generic;
	using System.Linq;
    class Program
    {
      static int n;
      static int[] a = new int[100001];
      static long sum;
      static void Main()
      {
        n = int.Parse(Console.ReadLine());
        var line = Console.ReadLine();
        var _line = line.Split(" ");
        for (int i = 0; i < n; i++)
        {
          int num = int.Parse(_line[i]);
          sum += num;
          a[num]++;
        }
        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i++)
        {
          line = Console.ReadLine();
          _line = line.Split(" ");
          int b = int.Parse(_line[0]);
          int c = int.Parse(_line[1]);
          sum += (c - b) * a[b];
          Console.WriteLine(sum);
          a[c] += a[b];
          a[b] = 0;
        }
      }
    }

Measured memory_bytes: 49652
n = int(input())
a = list(map(int, input().split()))
data = [0 for _ in range(2*10**5+1)]
for x in a:
    data[x] += 1

ans = 0
for i in range(2*10**5):
    ans += data[i]*(data[i]-1)//2

for x in a:
    print(ans - (data[x]-1))


Measured memory_bytes: 25644
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
int main()
{
   int a,b,c;
   string s,t;
   cin>>a>>b;
   cout<<(a>b?"safe":"unsafe");
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
// #define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

using Int = __int128_t;
using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}


signed main() {
    
	int n;
	cin >> n;
	int d[1000][2]={};

	for(int i = 0; i < n; i++) {
		cin >> d[i][0] >> d[i][1];
	}

	for(int i = 0; i < n - 2; i++) {
		if(d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]) {
			cout << "Yes\n";
			return 0;
		}
	}

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


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll dp[100100];
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  vl c;
  srep(i,1,8){
    c.push_back(pow(9,i));
    c.push_back(pow(6,i));
  }
  c.push_back(1);
  sort(rng(c),greater<ll>());
  fill(dp,dp+100100,1001001001);
  dp[0] = 0;
  dp[1] = 1;
  
  rep(i,n+1){
    rep(j,sz(c)){
      //show(c[j]);
      if((i+1-c[j])>=0)
      dp[i+1] = min(dp[i+1],dp[i+1-c[j]]+1);
    }
  }
  //rep(i,n+1)cout<<i<<":"<<dp[i]<<endl;;
  print(dp[n]);
  return 0;
}

Measured memory_bytes: 1152
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> P(n);
    for (int i = 0; i < n; ++i) {
        cin >> P[i];
    }
    sort(P.begin(), P.end());

    long long res = 0;
    for (int i = 0; i < k; ++i) {
        res += P[i];
    }

    cout << res << '\n';


    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision

int main() {
    long int L;
    std::cin >> L;
    double Ld = static_cast<double>(L);
    double ans = pow(Ld/3.0, 3.0);
    std::cout << std::setprecision(std::numeric_limits<long double>::digits10 + 1)
    << ans
    << std::endl;
    return 0;
}


Measured memory_bytes: 512
from collections import deque

n=int(input())
g=[[] for i in range(n+1)]
clst=[-1]*(n-1)

for i in range(n-1):
    a,b=list(map(int,input().split()))

    g[a].append([b,i])
    g[b].append([a,i])


q=deque([[1,0]])
k=0

while len(q)>0:
    u,c=deque.popleft(q)

    clr=1

    for v,i in g[u]:
        if clst[i]==c:
            continue
        if clr==c:
            clr+=1
        
        clst[i]=clr
        deque.append(q,[v,clr])

        clr+=1


    k=max(k,clr-1)

print(k)

for i in range(n-1):
    print(clst[i])


Measured memory_bytes: 46904
x, y = [int(i) for i in input().split()]

gr = [4,6,9,11]
gr2 = [1,3,5,7,8,10,12]

if (x ==2) | (y ==2):
    print("No")
    
elif (x in gr) & (y in gr):
    print("Yes")
elif (x in gr2) & (y in gr2):
    print("Yes")
else:
    print("No")
    
    

Measured memory_bytes: 3060
import fractions
def gcd_all(a):
    A = a[0]
    length = len(a)
    for i in range(1,length):
        A = fractions.gcd(A,a[i])
    return A

n,k = map(int,input().split())
a = list(map(int,input().split()))
#入力
a.sort()
if k > a[n-1]:
    print('IMPOSSIBLE')
    exit()
A = gcd_all(a)
if k%A == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

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

    if(s.size()==1){
        cout << k/2 << endl;
        return 0;
    }

    ll cnt = 0;
    for(int i=0;i<s.size()-1;i++){
        if(s.at(i)==s.at(i+1)){
            i++;
            cnt+=1;
        }
    }

    ll ans = cnt*k;
    if(s.at(0)==s.at(s.size()-1)){
        int lcnt=1;
        for(int i=1;i<s.size();i++){
            if(s.at(0)==s.at(i)) lcnt++;
            else break;
        }
        if(lcnt==s.size()){
            cout << s.size()*k/2 << endl;
            return 0;
        }

        int j =s.size()-2;
        int rcnt=1;
        for(int j=s.size()-2;j>0;j--){
            if(s.at(s.size()-1)==s.at(j)) rcnt++;
            else break;
        }
        if(lcnt%2==1 and rcnt%2==1) ans+=k-1;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int a[100010];

int32_t main()
{
    int n,q;
    cin >> n >> q;

    string s;
    cin >> s;

    for(int i=1;i<n;i++)
    {
        if(s[i] == 'C' && s[i-1] == 'A')
            a[i]++;
    }

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

    while(q--)
    {
        int x,y;
        cin >> x >> y;
        x--;
        y--;

        cout << a[y] - a[x] << endl;
    }
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	vi a(3);
	rep(i,3) cin>>a[i];
	sort(all(a));
	cout<<(a[0]==5 && a[1]==5 && a[2]==7?"YES":"NO")<<endl;
}


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

int main(){
    int x,y;
    cin >> x >> y;
    int ans;
    int count = 0;
    int max = 4*x;
    int min = 2*x;
    if (max >= y && min <= y){
        for (int i = 0; i <= x; i++){
            for (int j = 0; j <= x; j++){
                ans = 2*i + 4*j;
                if (ans == y){
                count++;
                }
            }    
        }
    }
    if (count > 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t sum,M;
int32_t A[2000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> sum >> M;
	for (int32_t i = 0; i < M; i++)
	{
		in >> A[i];
	}
	if (M == 1) {
		out << A[0] << '\n';
		if (A[0] - 1 > 0) {
			out << 2 << '\n'
				<< 1;
			out <<' '<< (A[0] - 1);
		}
		else {
			out << 1 << '\n'
				<< 1;
		}
		out << endl;
		return 0;
	}

	int odd_count = 0;
	for (int32_t i = 0; i < M; i++)
	{
		if (A[i] % 2 == 1) {
			std::swap(A[i], A[odd_count]);
			++odd_count;
			if (odd_count > 2) {
				out << "Impossible" << endl;
				return 0;
			}
		}
	}

	std::swap(A[M -1], A[1]);
	out << A[0];
	for (int32_t i = 1; i < M; i++)
	{
		out << ' ' << A[i];
	}
	out << '\n';

	std::vector<int32_t> res;
	res.reserve(M + 20);
	if (A[0] - 1 > 0) {
		res.push_back(A[0] - 1);
	}
	res.push_back(2);
	for (int32_t i = 1; i < M-1; i++)
	{
		res.push_back(A[i]);
	}
	if (A[M-1] - 1 > 0) {
		res.push_back(A[M - 1] - 1);
	}
	out << res.size() << '\n';
	out << res[0];
	for (size_t i = 1; i < res.size(); i++)
	{
		out << ' ' << res[i];
	}
	out << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<pair<int,int>> p(N);
  vector<ll> h(N);
  rep(i,N){
    cin >> p[i].first >> p[i].second >> h[i];
  }
  rep(cx,101){
    rep(cy,101){
      ll H = -1;
      ll max_H = 1e10;
      rep(i,N){
        if(h[i]==0){
          ll max_H_ = abs(p[i].first - cx) + abs(p[i].second - cy);
          max_H = min(max_H, max_H_);
          if(H != -1 && max_H < H) break;
        }
        else{
          ll H_ = h[i] + abs(p[i].first - cx) + abs(p[i].second - cy);
          if(H == -1) H = H_;
          if(H != H_) break;
        }
        if(i == N-1)cout << cx << " " << cy << " " << H << endl;
      }
    }
  }
  return 0;
}


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

fn solve(a: &Vec<i64>) -> i64 {
    let n = a.len();
    if a[0] != 0 { return -1; }
    let mut res = 0;
    let mut ex = 0;
    for i in 0..n {
        if a[n-1-i] < ex { return -1; }
        if a[n-1-i] > ex {
            res += a[n-1-i];
            ex = a[n-1-i];
        }
        ex = std::cmp::max(0, ex-1);
    }
    return res;
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let a = (0..n).map(|_| it.next().unwrap().parse::<i64>().unwrap()).collect::<Vec<_>>();
    println!("{}", solve(&a));
}


Measured memory_bytes: 8572