akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll P=1e9+7;
const int N = 2000001;  
  
// array to store inverse of 1 to N 
ll factorialNumInverse[N + 1]; 
  
// array to precompute inverse of 1! to N! 
ll naturalNumInverse[N + 1]; 
  
// array to store factorial of first N numbers 
ll fact[N + 1]; 
  
// Function to precompute inverse of numbers 
void InverseofNumber(ll p) 
{ 
    naturalNumInverse[0] = naturalNumInverse[1] = 1; 
    for (int i = 2; i <= N; i++) 
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
} 
// Function to precompute inverse of factorials 
void InverseofFactorial(ll p) 
{ 
    factorialNumInverse[0] = factorialNumInverse[1] = 1; 
  
    // precompute inverse of natural numbers 
    for (int i = 2; i <= N; i++) 
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
} 
  
// Function to calculate factorial of 1 to N 
void factorial(ll p) 
{ 
    fact[0] = 1; 
  
    // precompute factorials 
    for (int i = 1; i <= N; i++) { 
        fact[i] = (fact[i - 1] * i) % p; 
    } 
} 
  
// Function to return nCr % p in O(1) time 
ll Binomial(ll N, ll R, ll p) 
{ 
    // n C r = n!*inverse(r!)*inverse((n-r)!) 
    ll ans = ((fact[N] * factorialNumInverse[R]) 
              % p * factorialNumInverse[N - R]) 
             % p; 
    return ans; 
} 
long long int po[N],po1[N];
void power(long long int P)
{
    po[0]=1;
    po1[0]=1;
    long long int a=2,i;
    for(i=1;i<=2000000;i++)
    {
        po[i]=(po[i-1]*26)%P;
        po1[i]=(po1[i-1]*25)%P;
    }
}
int main()
{
    ll i,j,k,l,m,n,o,p,q,r,t,a[300001]={0};
    InverseofNumber(P); 
    InverseofFactorial(P); 
    factorial(P); 
    power(P);

    cin>>n;
    string s;
    cin>>s;
    l=s.length();
    n+=l;
    ll ans=0;
    ans+=po[n];

    for(i=0;i<l;i++)
    {
      k=Binomial(n,i,P);
      k=(k*po1[n-i])%P;
      ans=(ans-k+P)%P;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 83380
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int a, b;
    char c;
    cin >> a >> c >> b;
    if (c == '+') cout << a+b << endl;
    else cout << a-b << endl;
    return 0;
}


Measured memory_bytes: 3620
from itertools import permutations

def main():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    num_list = []
    for a in permutations(range(1,N+1)):
        num_list.append(a)
    num_list.sort
    b = -1
    c = -1
    for i, a in enumerate(num_list):
        if list(a) == P:
            b = i
        if list(a) == Q:
            c = i

        if b != -1 and c != -1:
            break

    print(abs(b-c))

    
            



if __name__ == "__main__":
    main()

Measured memory_bytes: 46576
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
#include<set>
#include<iterator>
#include<cstdio>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  int N;
  cin>>N;
  vector<int>a(N);
  rep(i,N){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  if(N%3!=0){
    if(a[N-1]!=0){
      cout<<"No"<<endl;
    }
    else{
      cout<<"Yes"<<endl;
    }
  }
  else if(a[0]==a[N-1]&&a[N-1]==0){
    cout<<"Yes"<<endl;
  }
  else if(a[0]==a[N/3-1]&&a[N/3-1]==0){
    if(a[N/3]==a[N-1]&&a[N/3]!=0){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  else if((a[0]^a[N/3])==a[N-1]&&a[0]==a[N/3-1]&&a[N/3]==a[N/3*2-1]&&a[N/3*2]==a[N-1]){
    if(a[0]!=a[N/3]&&a[N/3]!=a[N-1]){
    cout<<"Yes"<<endl;
    }
    else{
    cout<<"No"<<endl;
    }
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
//define MOD 1000000007000000
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

int n;
vector<vector<ll>> graph(n);
vector<ll> cost(n,0);
vector<bool> check(n);

void dfs(ll now){
    check[now]=true;
    for(ll next:graph[now]){
        if(check[next]){
            continue;
        }
        cost[next]+=cost[now];
        dfs(next);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n,q;
    cin>>n>>q;
    int a,b;
    graph.resize(n);
    cost.resize(n);
    check.resize(n);
    rep(i,n-1){
        cin>>a>>b;
        a--;
        b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    int p,x;
    rep(i,q){
        cin>>p>>x;
        p--;
        cost[p]+=x;
    }

    dfs(0);

    rep(i,n){
        cout<<cost[i]<<" ";
    }
    cout<<endl;

}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};


vector<ll>ten(10,1);
vector<ll>tmp={3,5,7};
ll n;
ll ret=0;
void dfs(ll d,ll v){
  if(d<10){
    rep(i,0,3){
      v+=tmp[i]*ten[d];
      if(v<=n){
        bool judge=true;
        ll k=v;
        vector<ll>cnt(3);
        while(k!=0){
          ll x=k%10;
          cnt[(x-3)/2]++;
          k/=10;
        }
        if(cnt[0]!=0&&cnt[1]!=0&&cnt[2]!=0)ret++;
      }
      dfs(d+1,v);
      v-=tmp[i]*ten[d];
    }
  }
}
int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  cin>>n;
  rep(i,1,10)ten[i]=ten[i-1]*10;
  dfs(0,0);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct Combination {
  vector<mint> fact, ifact;
  Combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int k; string s;
  cin >> k >> s;
  int ss = s.size();
  int n = k+ss;
  Combination c(n);
  mint ans = 0;
  for(int i=ss;i<=n;++i){
    mint t = c(i-1,ss-1);
    t *= mint(25).pow(i-ss);
    t *= mint(26).pow(n-i);
    ans += t;
  }
  cout << ans << endl;
}


Measured memory_bytes: 35636
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main(void)
{
    int n;
    cin >> n;
    int a[N];
    rep(i, n)
    {
        cin >> a[i];
    }
    int m = a[0];
    ll r = 0;
    for (int i = 1; i < n; ++i)
    {
        if (m > a[i])
        {
            r += m - a[i];
        }
        m = max(a[i], m);
    }
    cout << r << endl;
}


Measured memory_bytes: 4344
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}
/* }}} */

fn main() {
    input! {
        k: i32,
        x: i32
        
    }
    for i in (x-k+1)..(x+k) {
        print!("{} ", i);
    }
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

string s;
ll a[500001], b[500001];

int main() {
	cin >> s;
	bool f = true;
	for (char c : s) {
		if (s[0] != c) {
			f = false;
			break;
		}
	}
	if (f) {
		cout << s.size() << endl << 1 << endl;
		return 0;
	}
	b[0] = 1;
	for (int i = 0; i < s.size(); ++i) {
		a[i + 1] = (a[i] * 30 + s[i] - 'a') % mod;
		b[i + 1] = b[i] * 30 % mod;
	}
	for (int i = 2; i <= s.size() / 2; ++i) {
		if (s.size() % i == 0) {
			f = true;
			for (int j = i; j < s.size(); j += i) {
				if ((a[j + i] - a[j] * b[i] % mod + mod) % mod != (a[j] - a[j - i] * b[i] % mod + mod) % mod) {
					f = false;
					break;
				}
			}
			if (f) {
				int res;
				res = s.size() - 1;
				vector<bool>v(s.size() + 1 , false);
				for (int j = 1; j + j < s.size(); ++j) {
					for (int k = j; k + j < s.size(); k += j) {
						if (a[j] == (a[k + j] - a[k] * b[j] % mod + mod) % mod) {
							if (!v[j + k]) {
								v[j + k] = true;
								--res;
							}
						}
						else {
							break;
						}
					}
				}
				for (int j = 1; j + j < s.size(); ++j) {
					for (int k = s.size() - j; k - j >= 1; k -= j) {
						if ((a[s.size()] - a[s.size() - j] * b[j] % mod + mod) % mod == (a[k] - a[k - j] * b[j] % mod + mod) % mod) {
							if (!v[k - j]) {
								v[k - j] = true;
								--res;
							}
						}
						else {
							break;
						}
					}
				}
				cout << 2 << endl << res << endl;
				return 0;
			}
		}
	 }
	cout << 1 << endl << 1 << endl;
}

Measured memory_bytes: 8708
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef vector<string>VS;
VS ReverseLR(VS v)
{
	for(int y=0;y<v.size();++y)
		reverse(v[y].begin(),v[y].end());
	return v;
}
VS ReverseUD(VS v)
{
	reverse(v.begin(),v.end());
	return v;
}
VS RotateLeft(VS v)
{
	for(int y=0;y<2;++y)
		for(int x=0;x<3;++x)
		{
			char t=v[y][x];
			v[y][x]=v[x][4-y];
			v[x][4-y]=v[4-y][4-x];
			v[4-y][4-x]=v[4-x][y];
			v[4-x][y]=t;
		}
	return v;
}
VS RotateRight(VS v)
{
	for(int y=0;y<2;++y)
		for(int x=0;x<3;++x)
		{
			char t=v[y][x];
			v[y][x]=v[4-x][y];
			v[4-x][y]=v[4-y][4-x];
			v[4-y][4-x]=v[x][4-y];
			v[x][4-y]=t;
		}
	return v;
}
VS Make(const string&s)
{
	VS vs;
	for(int i=0;i<s.size();i+=5)
		vs.push_back(s.substr(i,5));
	return vs;
}
VS Make(char m[21][58],int x,int y)
{
	string s;
	for(int i=0; i<5; ++i)
		for(int j=0;j<5;++j)
			s+=m[y+i][x+j];
	return Make(s);
}
VS num[10]={VS(),Make(
"....."
"...*."
"....."
"...*."
"..*.."
),Make(
"..*.."
"...*."
"..*.."
".*..."
"..*.."
),Make(
"..*.."
"...*."
"..*.."
"...*."
"..*.."
),Make(
"....."
".*.*."
"..*.."
"...*."
"....."
),Make(
"..*.."
".*..."
"..*.."
"...*."
"..*.."
),Make(
"..*.."
".*..."
"..*.."
".*.*."
"..*.."
),Make(
"..*.."
"...*."
"....."
"...*."
"....."
),Make(
"..*.."
".*.*."
"..*.."
".*.*."
"..*.."
),Make(
"..*.."
".*.*."
"..*.."
"...*."
"..*.."
),};
int DiceFace(const VS &v)
{
	return find(num,num+10,v)-num;
}
vector<int> MakeDice(char m[21][58],int dx)
{
	int a[6]=
	{
		DiceFace(ReverseLR(Make(m,8+dx,1))),
		DiceFace(ReverseLR(RotateRight(Make(m,1+dx,8)))),
		DiceFace(ReverseLR(Make(m,8+dx,8))),
		DiceFace(ReverseLR(RotateLeft(Make(m,15+dx,8)))),
		DiceFace(ReverseLR(Make(m,22+dx,8))),
		DiceFace(ReverseUD(ReverseLR(Make(m,8+dx,15))))
	};
	return vector<int>(a,a+6);
}
int main()
{
	char m[21][58];
	for(;;)
	{
		for(int y=0;y<21;++y)
		{
			if(scanf("%s",m[y])-1)
				return 0;
			for(int x=0;m[y][x];++x)
				if(m[y][x]!='.')
					m[y][x]='*';
		}
		vector<int>v[2]={MakeDice(m,0),MakeDice(m,29)};
		int win=0,lose=0;
		for(int i=0;i<6;++i)
			for(int j=0;j<6;++j)
				if(v[0][i]>v[1][j])++win;
				else if(v[0][i]<v[1][j])++lose;
		puts(win>=lose?"HIGH":"LOW");
	}
}

Measured memory_bytes: 1056
#include<iostream>
using namespace std;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    if(a>b){cout<<0<<endl;return 0;}
    if(n==1){cout<<(a==b)<<endl;return 0;}
    cout<<(long)b*(n-2)+(long)a*(2-n)+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main()
{
    int n, h, t = 0, ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &h);
        if (h >= t) {++ans; t = h;}
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
dp = [0] * (M+1)
W, V = [], []
for _ in range(N):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)
for i in range(N):
    for j in range(M+1, -1, -1):
        if j + W[i] <= M:
            dp[j+W[i]] = max(dp[j + W[i]], dp[j] + V[i])
print(max(dp))

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

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

int main() {
	int n;
	cin >> n;
	int* lu[3];
	for (int i = 0; i < 3; i++) {
		lu[i] = new int[n];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> lu[j][i];
		}
	}
	int* dp[3];
	for (int i = 0; i < 3; i++) {
		dp[i] = new int[n] {};
	}
	dp[0][0] = lu[0][0];
	dp[1][0] = lu[1][0];
	dp[2][0] = lu[2][0];


	for (int i = 1; i < n; i++) {
		dp[0][i] = max(dp[1][i - 1] + lu[0][i], dp[2][i - 1] + lu[0][i]);
		dp[1][i] = max(dp[0][i - 1] + lu[1][i], dp[2][i - 1] + lu[1][i]);
		dp[2][i] = max(dp[1][i - 1] + lu[2][i], dp[0][i - 1] + lu[2][i]);
	}
	int ans = 0;
	ans = max(dp[0][n - 1], dp[1][n - 1]);
	ans = max(ans, dp[2][n - 1]);
	cout << ans << endl;

	for (int i = 0; i < 3; i++) {
		delete[] lu[i],dp[i];
	}
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
 
 int A,B;
 cin >> A >> B;

 string s;
 cin >> s;
  for(int i=0;i<s.size();i++){
    if(i==A && s.at(i)!='-' || i!=A && s.at(i)=='-'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

const long long mod=1e9+7;
int n;
vector <int> v[101000];
int fa[101000];
long long dp[2][101000];

void dfs(int x){
	for(int i=0;i!=v[x].size();++i){
		if(fa[x]==v[x][i]) continue;
		fa[v[x][i]]=x;
		dfs(v[x][i]);
	}
	return;
}

long long opt1(int x);

long long opt0(int x){
	if(dp[0][x]!=-1) return dp[0][x];
	dp[0][x]=1;
	for(int i=0;i!=v[x].size();++i){
		if(fa[x]==v[x][i]) continue;
		dp[0][x]*=(opt1(v[x][i])+opt0(v[x][i]));
		dp[0][x]%=mod;
	}
	return dp[0][x];
}

long long opt1(int x){
	if(dp[1][x]!=-1) return dp[1][x];
	dp[1][x]=1;
	for(int i=0;i!=v[x].size();++i){
		if(v[x][i]==fa[x]) continue;
		dp[1][x]*=opt0(v[x][i]);
		dp[1][x]%=mod;
	}
	return dp[1][x];
}

int main(){
	cin>>n;
	for(int i=1;i<=n-1;++i){
		int a,b;cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(1);
	memset(dp,-1,sizeof(dp));
	for(int i=2;i<=n;++i) if(v[i].size()==1) dp[0][i]=1,dp[1][i]=1;
	opt1(1);
	opt0(1);
	cout<<(dp[1][1]+dp[0][1])%mod<<"\n";
	return 0;
}

Measured memory_bytes: 13312
#include <stdio.h>
int main()
{
    long long int n=0,a,b;
    int count=0;
    while (scanf("%lld%lld",&a,&b)==2)
    {
        count = 0;
        n = 0;
        n = a+b;
        while (n!=0)
        {
            n /= 10;
            count++;
        }
        printf("%d\n",count);
    }
    return 0;
}

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

int main () {
	ll int s,c,ans;
	cin >> s >> c;

	if(2*s<c){
		ans = (c + 2*s)/4;
	}else if(2*s==c){
		ans = s;
	}else{
		ans = c/2;
	}

	cout << ans << endl;

    return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x;
    cin >> x;
    cout << (x^1) << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<vector>
#include<algorithm>
#define MAXN 100006
using namespace std;
int ans[MAXN],u,v,c[MAXN],d[MAXN],p[MAXN],maxone[MAXN],n,m,q;
vector<int> road[MAXN];
void DFS(int x,int fa,int step,int c)
{
	if(maxone[x]>=step) return;
	if(!ans[x]) ans[x]=c;
	maxone[x]=step;
	for(int i=0;i<(int)road[x].size();i++)
	{
		int nex=road[x][i];
		if(nex==fa) continue;
		DFS(nex,x,step-1,c);
	}
}
int main()
{
	//freopen("splatter.in","r",stdin);
	//freopen("splatter.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		road[u].push_back(v);
		road[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		maxone[i]=-1;
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
		scanf("%d%d%d",&p[i],&d[i],&c[i]);
	for(int i=q;i>=1;i--)
		DFS(p[i],0,d[i],c[i]);
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
}

Measured memory_bytes: 8440
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int N, D;
	int count = 0;
	scanf("%d%d", &N, &D);
	while (1) {
		N = N - (2 * D + 1);
		count++;
		if (N <= 0) {
			printf("%d", count);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc092/tasks/arc092_c

寄与を残せる要素ってどんな集合？

→少なくとも連続する2つは絶対残せない
→残せるのは、偶数番目 or 奇数番目　のみ？

→少なくとも、偶奇が違う二つの要素を同時に残す方法は見当たらない

構築→右端から構築していくのが楽？(indexが変化しないので)
後ろから見ていって、取らないと決めたindと、取ると決めたやつ+1を選んでいけばよい

全て負の時はコーナーケース
"""

import sys
N = int(input())

a = list(map(int,input().split()))

esum = 0
osum = 0

if max(a) < 0:
    #コーナーケース

    maxind = 0
    for i in range(N):
        if a[maxind] < a[i]:
            maxind = i

    rem = N
    print (a[maxind])
    print (N-1)
    for i in range(maxind):
        print (1)
        rem -= 1
    while rem != 1:
        print (rem)
        rem -= 1
    sys.exit()

eve = 0
eflag = [False] * N
epicks = []
odd = 0
oflag = [False] * N
opicks = []
for i in range(N):

    if i % 2==0 and a[i] >= 0:
        eflag[i] = True
        eve += a[i]
        epicks.append(i)
    if i % 2==1 and a[i] >= 0:
        oflag[i] = True
        odd += a[i]
        opicks.append(i)

if eve > odd:

    print (eve)
    ans = []

    for i in range(N-1,-1,-1):

        if i < epicks[0]:
            ans.append(1)
        elif i % 2 == 0 and eflag[i] == False:
            ans.append(i+1)
        elif i % 2 == 1 and eflag[i-1] == True:
            ans.append(i+1)

    print (len(ans))
    print ("\n".join(map(str,ans)))

else:

    print (odd)
    ans = []

    for i in range(N-1,-1,-1):

        if i < opicks[0]:
            ans.append(1)
        elif i % 2 == 1 and oflag[i] == False:
            ans.append(i+1)
        elif i % 2 == 0 and oflag[i-1] == True:
            ans.append(i+1)

    print (len(ans))
    print ("\n".join(map(str,ans)))
    


Measured memory_bytes: 39152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(""));

            List<Integer> numbers = new ArrayList<>();
            for (String s : input) {
                numbers.add(Integer.parseInt(s));
            }

            String result = "No";
            for (int number : numbers) {
                if (number == 7) {
                    result = "Yes";
                    break;
                }
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 25492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
const int inf=0x3f3f3f3f;

int X,Y,A,B,C;
ll p[200010],q[200010],r[200010],d[200010];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>X>>Y>>A>>B>>C;
    for(int i=0;i<A;i++) cin>>p[i];
    for(int i=0;i<B;i++) cin>>q[i];
    for(int i=0;i<C;i++) cin>>r[i];
    sort(p,p+A); sort(q,q+B); sort(r,r+C);
	reverse(p,p+A); reverse(q,q+B); reverse(r,r+C);
	for(int i=0;i<X;i++) d[i]=p[i];
	for(int i=0;i<Y;i++) d[i+X]=q[i];
	sort(d,d+X+Y);
	for(int i=1;i<X+Y;i++) d[i]+=d[i-1];
	for(int i=1;i<C;i++) r[i]+=r[i-1];
	ll ans=d[X+Y-1];
	for(int i=0;i<min(X+Y,C);i++) ans=max(ans,d[X+Y-1]-d[i]+r[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<math.h>
#include<float.h>
#include<cstdio>
using namespace std;
#define EPS (1e-10)
#define equals(a,b) fabs((a)-(b))<DBL_EPSILON*fmax(1,fmax(fabs(a),fabs(b)))
//点のクラス
class Point{
    public:
        double x,y;
        Point(double x=0,double y=0):x(x),y(y){}

        Point operator + (Point p){return Point(x+p.x,y+p.y);}
        Point operator - (Point p){return Point(x-p.x,y-p.y);}
        Point operator * (double a){return Point(a*x,a*y);}
        Point operator / (double a){return Point(x/a,y/a);}
            
        double norm(){return x*x+y*y;}
        double abs(){return sqrt(norm());}    
        
        bool operator < (const Point &p)const{
            return x!=p.x?x<p.x:y<p.y;
        }
        bool operator == (const Point &p)const{
            return equals(x,p.x)&&equals(y,p.y);
        }
};
typedef Point Vector;
//内積
double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; }
//外戚
double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; }
//ベクトルa,bの位置関係
int ccw(Point p0,Point p1,Point p2){
	Vector a=p1-p0;
	Vector b=p2-p0;
	if(cross(a,b)>EPS) return 1;//p0,p1,p2が反時計回り
	if(cross(a,b)<-EPS) return -1;//p0,p1,p2が時計回り
	if(dot(a,b)<-EPS) return 2;//p1,p0,p2の順で一直線
	if(a.norm()<b.norm()) return -2;//p0,p1,p2の順で一直線
	return 0; //p0,p2,p1の順で一直線
}
int main(){
    int q,flag;
    Point p1,p2;
    scanf("%lf %lf %lf %lf",&p1.x,&p1.y,&p2.x,&p2.y);
    cin>>q;
    Point p;
    for(int i=0;i<q;i++){
        cin>>p.x>>p.y;
        flag=ccw(p1,p2,p);
        switch (flag){
            case 1:
                cout<<"COUNTER_CLOCKWISE";
                break;
            case -1:
                cout<<"CLOCKWISE";
                break;
            case 2:
                cout<<"ONLINE_BACK";
                break;
            case -2:
                cout<<"ONLINE_FRONT";
                break;
            default:    
                cout<<"ON_SEGMENT";
                
        }
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int n, m, p;
struct edge {
    ll cost, from, to;
};
vector<edge> g;
vector<ll> d(2510, 1e18);

void bellmanford(int s) {
    d[s] = 0;
    int v = 2 * n + 2;
    for (int i = 0; i < v; i++) {
        if (i < n) {
            for (auto e : g) {
                if (d[e.from] != 1e18 && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                }
            }
        } else {
            for (auto e : g) {
                if (d[e.to] != -1e16 && d[e.from] != 1e18 &&
                    d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = -1e16;
                }
            }
        }
    }
}

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

    cin >> n >> m >> p;
    rep(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        edge e = {p - c, a, b};
        g.push_back(e);
    }
    bellmanford(1);
    if (d[n] != -1e16)
        cout << max(-d[n], 0ll) << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 576
using System;

class Program
{
    static void Main(string[] args)
    {
       // 整数の入力
            int X = int.Parse(Console.ReadLine());

        int Out = 1;
        if (X < 2100)
        {
            int res = X / 100;

            if (res == 0 || X % 100 > res * 5)
                Out = 0;

        }
     
        

            Console.WriteLine(Out);
        
    }
}


Measured memory_bytes: 11092
function main(lines) {
  const [N, M] = splitN(lines[0]);

  const map = Array(N+1).fill(0).map(() => []);
  for (let i = 1; i <= M; i++) {
    const [a, b] = splitN(lines[i]);
    map[a].push(b);
    map[b].push(a);
  }
  const res = [null];
  for (let current = [1]; true; ) {
    const next = [];
    current.forEach(c => {
      map[c].forEach(n => {
        if (res[n-1] !== undefined) return;
        res[n-1] = c;
        next.push(n);
      });
    });
    if (!next.length) break;
    current = next;
  }
  
  if (res.filter(i => i !== undefined).length === N) {
    res[0] = 'Yes';
    console.log( res.join('\n') );
  } else {
    console.log('No');
  }
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}

Measured memory_bytes: 113368
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace at_coder
{
#if TEST
    [TestClass]
#endif
    public class abc154_a
    {

#if TEST
        public void Test_Main()
#else
        public static void Main()
#endif
        {
            // S T
            // A B
            // U
            string S, T;
            int A, B;
            string U;
            readstring(out S, out T);
            readint(out A, out B);
            readstring(out U);

            if (S == U) A--;
            else B--;
            println("" + A + " " + B);
        }

        private static int readint()
        {
            String s = Console.ReadLine();
            return int.Parse(s);
        }

        private static void println(string s)
        {
            Console.WriteLine(s);
        }
        private static void readstring(out string a, out string b)
        {
            string[] ar = ReadStringArray();
            a = ar[0];
            b = ar[1];
        }
        private static void readstring(out string a)
        {
            string[] ar = ReadStringArray();
            a = ar[0];
        }
        private static string[] ReadStringArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            return ss;
        }


        private static void readint(out int a, out int b)
        {
            int[] ar = ReadIntArray();
            a = ar[0];
            b = ar[1];
        }

        private static int[] ReadIntArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int[] ar = new int[ss.Length];
            for (int i = 0; i < ss.Length; i++)
            {
                ar[i] = int.Parse(ss[i]);
            }
            return ar;
        }
#if TEST
#else
    }
}
#endif


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    ll ans = 1;
    while(N / (ans * 2) > 0){
        ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;


int main(){


	string a,b;
	int c;

	cin >> a;

	c=0;

	for(int i=0; i<3; i++ ){
		
		b=a[i];
			if(b=="1"){
			c++;
		//	cout <<a[i]<<endl;

		}
	}

	cout << c <<endl;


}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
double k,i,n,p,q,s;
int main() {
    scanf("%lf%lf", &n, &k);
    for(i=1;i<=n;i++) {
        for(p=i,q=1; p<k; p*=2) q /= 2;
        s += q;
    }
    printf("%.9lf", s/n);
    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  cout << "ABC" << n;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3492
s = input()
K = int(input())
s_dic = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, c in enumerate(s):
    s_dic[c].append(i)
substrings = set()
for indices in s_dic.values():
    for i in indices:
        for j in range(i + 1, i + K + 1):
            substrings.add(s[i:j])
print(sorted(list(substrings))[K - 1])


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

#define SIZE 200000

using namespace std;

struct Task {
  string name;
  int time;
};

struct Queue {
  Task table[SIZE];
  int tail;
  int head;

  void init() {
    head = tail = 0;
  }

  bool isEmpty() {
    return head == tail;
  }

  void enqueue(Task t) {
    table[tail] = t;
    tail++;
    tail %= SIZE;
  }

  Task dequeue() {
    Task t = table[head];
    head++;
    head %= SIZE;
    return t;
  }
};

int main(){
  int N, Q;
  Queue queue;

  cin >> N >> Q;

  queue.init();
  for(int i = 0; i < N; i++){
    Task t;
    cin >> t.name >> t.time;
    queue.enqueue(t);
  }

  int elaps = 0;

  while(!queue.isEmpty()) {
    Task t = queue.dequeue();
    if(t.time <= Q){
      elaps += t.time;
      cout<< t.name << ' ' << elaps << endl;
    }else{
      elaps += Q;
      t.time -= Q;
      queue.enqueue(t);
    }
  }

  return 0;
}


Measured memory_bytes: 8480
//IIT Kanpur FacelessMen India
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int a[26];
int main(){
  // freopen("product.in","r",stdin);
  // freopen("product.out","w",stdout);
  int n,m;
  cin>>n>>m;
  ll a1=0,a2=0;
  REP(i,n){
    int x;cin>>x;
    a1+=1ll*i*x%mod-1ll*(n-1-i)*x%mod;
    a1%=mod;
  }
  REP(i,m){
    int x;cin>>x;
    a2+=1ll*i*x%mod-1ll*(m-1-i)*x%mod;
    a2%=mod;
  }
  a1=a1*a2%mod+mod;
  a1%=mod;
  printf("%lld\n",a1);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define slowanddetermined ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x); cout<<#x<<"="<<x<<endl;
#define debug2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long
using namespace std;


int32_t main()
{

    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int>red(a+1);
    vector<int>green(b+1);
    vector<int>colorless(c+1);

    for(int i=0;i<a;i++){
        cin>>red[i];
    }
    for(int i=0;i<b;i++){
        cin>>green[i];
    }
    for(int i=0;i<c;i++){
        cin>>colorless[i];
    }
    sort(red.rbegin(),red.rend());
    sort(green.rbegin(),green.rend());
    sort(colorless.rbegin(),colorless.rend());
    int i,j,k;
    i=j=k=0;
    int cnt=0;
    int sum=0;
    int maxi;
    while(cnt<(x+y)){
        maxi=max({red[i],green[j],colorless[k]});
        //debug2(cnt,maxi);
        if((j==y)?colorless[k]<red[i]:(maxi==red[i] && i<x)){
            sum+=red[i];
            i++;
            //debug2(cnt,red[i]);
        }
        else if((i==x)?colorless[k]<green[j]:(maxi==green[j] && j<y)){
            sum+=green[j];
            j++;
           // debug2(cnt,green[j]);
        }
        else{
            sum+=colorless[k];
            //debug2(cnt,colorless[k]);
            k++;
        }

        cnt++;
    }
    cout<<sum;



    return 0;

}


Measured memory_bytes: 2560
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String x; int sum;
		while (true) {
			x = scan.next();
			sum = 0;
			if (x.equals("0")) break;
			for (int i = 0; i < x.length(); i++) {
				sum += Character.getNumericValue(x.charAt(i));
			}
			System.out.println(sum);
		}
	}

}

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

int main(void){
    string s;
    cin >> s;
    string div[4] = {"dream","dreamer","erase","eraser"};

    reverse(s.begin(),s.end());
    rep(i,4) reverse(div[i].begin(),div[i].end());

    bool can = true;
    for(int i=0;i<s.size();){
        bool can2 = false;
        rep(j,4){
            string d = div[j];
            if(s.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(can2 == false){
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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

ll N, M;
vl v, A, B;

int root(int x)
{
    if(v[x] == x) return x;
    return v[x] = root(v[x]);
}
void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    v[rx] = ry;
}

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N >> M;
    v.resize(N+1); REPS(i, N) v[i] = i;
    A.resize(M);
    B.resize(M);
    vl ans(M+1); ans[M] = N*(N-1)/2;
    vl count(N+1, 1);

    REP(i, M) cin >> A[i] >> B[i];

    for(int i = M-1; i > 0; i--)
    {
        if(!same(A[i], B[i]))
        {
            int na = count[root(A[i])], nb = count[root(B[i])];
            ans[i] = ans[i+1] - (na * nb);
            unite(A[i], B[i]);
            count[root(A[i])] += na;
        }
        else ans[i] = ans[i+1];
    }
    REPS(i, M) cout << ans[i] << endl;
}

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

using namespace std;

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

    vector<pair<int, int>> a_i(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a_i.at(i) = make_pair(i + 1, a);
    }

    sort(a_i.begin(), a_i.end(), [](const auto &x, const auto &y) {
        return x.second < y.second;
    });

    for (int i = 0; i < n - 1; i++)
        cout << a_i.at(i).first << ' ';

    cout << a_i.at(n - 1).first << endl;
}

Measured memory_bytes: 4016
import numpy as np

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

Z = V - C
Ans = 0
for i in range (N):
    if Z[i]>0:
        Ans += Z[i]

print(Ans)

Measured memory_bytes: 21000
#include <iostream>
#include <vector>

using namespace std;

int main (){
  int N;
  cin >> N;
  vector<int> A(N);
  int maxh = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    maxh = max(maxh, A[i]);
  }
  int counter = 0;
  for(int i = 1; i <= maxh; i++){
    for(int j = 0; j < N; j++){
      if(j == 0 && A[j] >= i){
        counter++;
        continue;
      }else if(j == 0 && A[j] < i){
        continue;
      }
      if(A[j - 1] < i && A[j] >=i){
        counter++;
      }
    }
  }
  cout << counter;
}


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

int main(){
  int n,X;
  cin >> n >> X;
  vector<int> x(n+1);
  x.at(0)=X;
  for(int i=1;i<=n;i++){
    cin >> x.at(i);
  }
  sort(x.begin(),x.end());
  vector<int> y(n);
  for(int i=0;i<n;i++){
    y.at(i)=x.at(i+1)-x.at(i);
  }
  sort(y.begin(),y.end());
  int z=1;
  bool frag=true;
  for(int i=y.at(0);i>=0;--i){
    for(int j=0;j<n;j++){
      if(y.at(j)%i!=0){
        frag=false;
        break;
      }
    }
    if(frag==true){
      z=i;
      break;
    }
    frag=true;
  }
  cout << z << endl;
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define azazax x1
#define azazay y1
#define azazaz prev

using namespace std;

typedef long long ll;
typedef long double ld;

const int max_n = 2e9, inf = 1000111222;

ll n, len ,d;
vector<int> beauty;

void rec(vector<int> v) {
    if (v.size() == len) {
        int b = 0;
        for (int i = 0; i + 1 < v.size(); ++i) {
            if (abs(v[i] - v[i + 1]) == d) {
                ++b;
            }
        }
        beauty.PB(b);
        return;
    }
    for (int nxt = 1; nxt <= n; ++nxt) {
        v.PB(nxt);
        rec(v);
        v.pop_back();
    }
}

ld dumb() {
    beauty.clear();
    vector<int> v;
    rec(v);
    ll sum = 0;
    for (int i = 0; i < beauty.size(); ++i) {
        sum += beauty[i];
    }
    return 1.0 * sum / beauty.size();
}

ld solve() {
    if (n == 1) {
        return (len - 1);
    }
    if (d == 0) {
        ld ch = (ld)(n) * (len - 1);
        ld zn = (ld)n * n;
        return ch / zn;
    }
    ld ch = (ld)(len - 1) * (n - d) * (2 * n - 2);
    ld zn = (ld)n * n * (n - 1);
    ld ans = ch / zn;
    return ans;
}


int main() {
    cin >> n >> len >> d;
    cout << fixed << setprecision(10);
    cout << solve() << endl;
    return 0;
    if (1) {
        for (n = 1; n < 10; ++n) {
            for (len = 2; len < 10; ++len) {
                for (d = 0; d < n; ++d) {
                    ll s = solve();
                    ll dum = dumb();
                    if (abs(s - dum) < 0.0001) continue;
                   // cout << solve() <<' '<< dumb() << endl;
                    cout << n << ' '<< len << ' ' << d << endl;
                    //return 0;
                }
            }
        }
        return 0;
    }

    //cout << dumb();
    //n = 5;
    //len = 5;
    if (0) {
        len = 2;
        d = 1;
        for (n = 1; n < 8; ++n) {
            cout << dumb() << ' ' << 1.0 * (2 * n - 2) / (n * n) << endl;
        }
        return 0;
    }
    if (0) {
        vector<ld> ans;
        for (d = 1; d <= n; ++d) {
            cout << dumb() << ' ';
        }
    } else {
        d = 0;
        for (n = 1; n <= 7; ++n) {
            for (len = 2; len <= 7; ++len) {
                cout << dumb() << ' ';
            }
            cout << endl;
        }
    }
    //cout << dumb() << endl;

    return 0;
}
/*
1 2 3 4 5 6
0.5 1 1.5 2 2.5 3
0.333333 0.666667 1 1.33333 1.66667 2
0.25 0.5 0.75 1 1.25 1.5
0.2 0.4 0.6 0.8 1 1.2
0.166667 0.333333 0.5 0.666667 0.833333 1
0.142857 0.285714 0.428571 0.571429 0.714286 0.857143
*/


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

int main() {
	ll n,sum=0;
	cin>>n;
	ll arr[n],fr[n+1]={0},z=0;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		++fr[arr[i]];
		 
	}
	for(ll i=1;i<n+1;i++)
	{
		sum=sum+(fr[i]*(fr[i]-1))/2;
	}
	for(ll i=0;i<n;i++)
	{
		ll ans=sum-((fr[arr[i]]*(fr[arr[i]]-1))/2-((fr[arr[i]]-1)*(fr[arr[i]]-2)/2));
		cout<<ans<<endl;
	}
	return 0;
}

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

unsigned short *A,*B;
int C[10000+1],n;
void CountingSort(unsigned short*,unsigned short*,int);
int main(){
  int i;

  scanf("%d",&n);
 
    A=(short *)malloc(sizeof(short)*n+1);
    B=(short *)malloc(sizeof(short)*n+1);

  for(i=0;i<n;i++) {
   
    scanf("%d",&A[i+1]);

  }

  CountingSort(A,B,10000);
  
  for(i=2;i<=n+1;i++){
    if(i>2) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  free(A);
  free(B);
  return 0;
}

void CountingSort(unsigned short *A,unsigned short *B,int k){
  int i,j;

  for(i=0;i<=k;i++){
    C[i]=0;
	   }
    
  for (j=0;j<=n;j++){ 
    C[A[j+1]]++;
	   }
  for (i=1;i<=k;i++){
    C[i] = C[i] + C[i-1];
	  }
  for (j=1;j<=n;j++){
    B[C[A[j]]] = A[j];
	  C[A[j]]--;
	  }
}

Measured memory_bytes: 8212
data class STC(val s: Int, val t: Int, val c: Int) {
    constructor(sc: List<Int>): this(sc[0] * 2 - 1, sc[1] * 2, sc[2])
}
fun main(args: Array<String>) {
    val (N, C) = listOfInt()
    val Stc = Array(N) { STC(listOfInt()) }
    val MAX = 200002
    val rec = IntArray(MAX)
    for (c in 1 .. C) {
        val tt = IntArray(MAX)
        for (stc in Stc)
            if (c == stc.c) { tt[stc.s] += 1; tt[stc.t] -= 1 }
        for (n in 1 until tt.size) tt[n] += tt[n - 1]
        for (n in 0 until tt.size) if (tt[n] > 0) rec[n] += 1
    }
//System.err.println(rec.joinToString())

    var ans = rec.max()!!
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 73612
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,x,y;
  cin >> n >> x >> y;
  ll a[n];
  rep(i,n) R a[i];
  ll c[3];
  mem(c);
  rep(i,n) {
    if(a[i]<=x) c[0]++;
    else if(a[i]<=y) c[1]++;
    else c[2]++;
  }
  sort(c,c+3);
  pr(c[0]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256