akhauriyash/Code-Regression huggingface dataset:
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 24, 2019
 * 
 */

#include <bits/stdc++.h>

//#define MORE_THAN_ONE_TESTCASE // COMMENT IT
#define mod 1000000007
#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;

vector<bool> broken(100009,false);
vector<bint> dp(100009 , -1);

bint count(bint n){
    if(broken[n]){
        dp[n] = 0;
        return dp[n]%mod;
    }

    if(dp[n]!=-1){
        return dp[n]%mod;
    }
    else{
        
        dp[n] = (count(n-1)%mod + count(n-2)%mod)%mod;

    }
    return dp[n]%mod;
}



auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 


    int n , b;
    cin>>n>>b;
    while(b--){
        int temp;
        cin>>temp;
        broken[temp]=true;
    }
    
    cout<<count(n)<<endl;

    return ;
}




int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#ifdef MY_LOCAL_PROJECT
    freopen("cin","r",stdin);
    freopen("cout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    dp[0] = 1;
    dp[1] = 1;
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
const LL MOD = (LL)1e9 + 7;
LL fac[MAXN], inv[MAXN];
int visit[MAXN];

void init() {
     inv[0] = fac[1] = inv[1] = 1;
     for (int i = 2; i < MAXN; i++) {
         LL tmp = (-(MOD / i) * inv[MOD % i]) % MOD;
         tmp += (tmp / MOD + 1) * MOD;
         inv[i] = tmp;
     }
     for (int i = 2; i < MAXN; i++) inv[i] = (inv[i - 1] * inv[i]) % MOD;
     for (int i = 2; i < MAXN; i++) fac[i] = (fac[i - 1] * i) % MOD;
}

LL C(int n, int m) {
   if (!m || !n) return 1;
   LL ans = fac[n];
   ans = (fac[n] * inv[n - m]) % MOD;
   return (ans * inv[m]) % MOD;
}

int main() {
    int N;
    init();
    scanf("%d", &N);
    int tg, fs;
    for (int i = 1; i <= N + 1; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (visit[tmp]) {
           fs = visit[tmp];
           tg = i;
        } else visit[tmp] = i;
    }
    LL cnt = (fs - 1) + (N + 1 - tg);
    for (int i = 1; i <= N + 1; i++) {
        LL ans = C(N + 1, i);
        if (i - 1 <= cnt) {
           LL tmp = C(cnt, i - 1);
           ans -= tmp;
        }
        ans = (ans + MOD) % MOD;
        printf("%lld\n", ans);
    }
    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A=in();

    int B=in();
    int C=in();
  	int ans;ans=C-(A-B);
  	if(ans<0)ans=0;
    cout<<ans<<endl;
    //cout<<fixed;
    return 0;
}

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

int main(){
  unsigned long long N, K;
  cin >> N;
  cin >> K;
  
  vector<bool> arr;
  for (int i = 0; i < N; ++i) {
    char hin;
    cin >> hin;

    bool l;
    if (hin == 'L') {
      l = true;
    } else {
      l = false;
    }
    
    arr.push_back(l);
  }

  int score = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (arr[i] == arr[i+1]) {
      ++score;
    }
  }

  // cerr << "init score =" << score << endl;
  
  int max_score = arr.size() - 1;

  int cur_iter = 0;


  
  while (K > cur_iter) {
    if (max_score - score >= 2) {
      score += 2;
    } else if (max_score - score > 0) {
      score += 1;
    } else {
      // Do nothing.
      break;
    }
    cur_iter++;
  }
  cout << score;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n, k, a1, a2, a3, ans = 1e18;
	cin >> n >> k;
	a1 = n% k;
	a2 = k - a1;
	a3 = k - a2;
	ans = min(ans, a1);
	ans = min(ans, a2);
	ans = min(ans, a3);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

vp prime_factorize(int n){
    vp ret;
    for(int p=2; p*p<=n; p++){
        if(n%p!=0) continue;
        int num=0;
        while(n%p==0){
            num++;
            n/=p;
        }
        ret.PB(MP(p,num));
    }
    if(n!=1) ret.PB(MP(n,1));
    return ret;
}

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

    int n,p; cin >> n >> p;
    vp pf=prime_factorize(p);
    int res=1;
    
    for(auto p:pf){
        rep(j,p.S/n) res*=p.F;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3652
$hist = Hash.new

def add_to_hist(key)
    if $hist.has_key?(key)
        $hist[key] += 1
    else
        $hist[key] = 1
    end
end

def twotwo?
    return false unless $hist.length == 2
    $hist.each_pair {|*a| return false unless a[0][1] == 2}
    return true
end

def za
    a,b,c,d = gets.chomp.scan(/./)
#    puts a, b, c, d

    add_to_hist(a)
    add_to_hist(b)
    add_to_hist(c)
    add_to_hist(d)

#    p $hist
    puts twotwo? ? 'Yes' : 'No'
end

za


Measured memory_bytes: 1788
h[4],c[4],C,Y,a[4],U[]={50,10,5,1},f;F(y,j,s,i){for(i=!~j?y<1?s+=y/50+y%50/10+y%10/5+y%5,s>C|s==C&y>Y?C=s,Y=y,memcpy(a,c,16):0:0,-1:h[j];~i;i--)c[j]=i,F(y-i*U[j],j-1,s+i);}main(i,y){for(;scanf("%d%d%d%d%d",&y,h+3,h+2,h+1,h)*y;)for(C=Y=-1e9,F(y/10,3,0),f&&puts(""),i=4;i--;f=1)a[i]&&printf("%d0 %d\n",U[i],a[i]);}

Measured memory_bytes: 412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#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 fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    vector<int> A(n);
    rep(i, n) {
        cin >> A[i];
        sum += A[i];
    }
    int x = 0;
    rep(i, n) {
        if (4 * m * A[i] >= sum) x++;
    }
    cout << (x >= m ? "Yes" : "No") << endl;
    return;
}

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

#define int long long

signed main(){
    int A, B; cin >> A >> B;
    int res = 0;
    int loops = 0;
    while(B/pow(2, loops++)>1);
    loops++;
    auto f = [](int n,int m){
        return (int)(n/(int)pow(2,m+1) * pow(2,m) + max(0.0,n%(int)pow(2,m+1)-pow(2,m)+1));
    };
    for(int i=0; i<loops; i++){
        bool temp = (f(B,i)-f(A-1,i))%2;
        if(temp) res += pow(2,i);
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int main()
{
	cin.tie(0);ios::sync_with_stdio(false);
	/* ====================================== */
	int N;
	cin >> N;
	vector<int> L(N);
	for(int i = 0; i < N; i++){
		cin >> L[i];
	}
	string s = "No";
	int max = 0;
	int sum = 0;
	for(int i = 0; i < N; i++){
		sum += L[i];
		if(L[i] > max) max = L[i];
	}
	if(sum - max > max) s = "Yes";


	cout << s;
	/* ====================================== */
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef string str;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	int n;
	cin >> n;
	int q = n % 10;
	if(n % 10 == 3){
		cout << "bon";
	}
	else if(q == 0 || q == 1 || q == 6 || q == 8){
		cout << "pon";
	}
	else{
		cout << "hon";
	}


}


Measured memory_bytes: 3592
def f(x):
    if x%2:
        return 3*x + 1
    else:
        return x/2
s = int(input())
a = [s]
for i in range(1,10**6+2):
    if f(a[i-1]) in a:
        print(i+1)
        break
    a.append(f(a[i-1]))


Measured memory_bytes: 9128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

double dist(double dx, double dy) {
  return sqrt(dx*dx+dy*dy);
}

int main() {
  
  int n;
  cin >> n;
  
  vector<pair<double,double>> vdd;
  
  while (n--) {
    double x, y;
    cin >> x >> y;
    
    vdd.pb(mp(x, y));
  }
  
  
  double sumEdges = 0.0;
  
  for (int i = 0; i < vdd.size(); ++i) {
    for (int j = i+1; j < vdd.size(); ++j) {
      double x1, x2, y1, y2;
      
      x1 = vdd.at(i).first;
      y1 = vdd.at(i).second;
      
      x2 = vdd.at(j).first;
      y2 = vdd.at(j).second;
      
      sumEdges += dist(x1-x2, y1-y2);
    }
  }
  
  cout << fixed << 2*sumEdges/vdd.size() << endl;
  
  return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    if(a > b) {
        cout << 0 << endl;
        return 0;
    }

    if(n == 1) {
        if(a == b) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }

    ll shita = a * (n-1) + b;
    ll ue = b * (n-1) + a;

    cout << ue - shita + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    for i in 0..n + 1 {
        if (i as f64 * 1.08).floor() as usize == n {
            println!("{}", i);
            return;
        }
    }
    println!(":(");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 1e5+5;

int n;
ll h[N],dp[N];


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];

    for(int i=2;i<=n;i++)dp[i]=1LL*N*N;

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

    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1792
import itertools
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
N, M, R = map(int, input().split())
r = [int(i) for i in input().split()]

G = [[10**8]*(N+1) for _ in range(N+1)]
for _ in range(M):
    A, B, C = map(int, input().split())
    G[A][B] = C
    G[B][A] = C

DG = csgraph_from_dense(G, null_value=10**8)
d = floyd_warshall(DG)

ans = 10**8
for route in itertools.permutations(r):
    c = 0
    for i in range(len(route)-1):
        c += d[route[i]][route[i+1]]
    ans = min(ans, c)
print(int(ans))


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

signed main(){
	int m,d,cnt=0;
	cin >> m >> d;
	for (int i=10; i<=d; ++i){
		int fi = i;
		int a = fi%10;
		fi /= 10;
		int b = fi%10;
		if (i%10 > 1 and b > 1 and a*b <= m){
			++cnt;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = sum(B)
pa = -1
for a in A:
    if a - pa == 1:
        ans += C[pa-1]
    pa = a
print(ans)


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

int main(int argc, const char * argv[]) {
    double d1,d2,d3,d4;
    int i,n;
    double x[1000] = {0};
    double y[1000] = {0};
    double o,p,q,max;
    max = -1;
    o=0;
    p=0;
    q=0;
    d1 = 0;
    d2 = 0;
    d3 = 0;
    d4 = 0;
    
    scanf("%d",&n);
    
    for(i=0; i<n; i++) {
        scanf("%lf",&x[i]);
    }
    
    for(i=0; i<n; i++) {
        scanf("%lf",&y[i]);
    }
    
    for(i=0; i<n;i++) {
        
        o = (x[i] - y[i]) * (x[i] - y[i]);
        p = (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
        p = p*p;
        p = sqrt(p);
        
        d3 = d3 + p;
        d2 = d2+o;
        d1 = d1 + sqrt(o);
        
        if(max < sqrt(o)) {
            max = sqrt(o);
        }
        
        
    }
    
    d2 = pow(d2,1.0/2);
    d3 = pow(d3,1.0/3);
    d4 = max;
    
    printf("%lf\n%lf\n%lf\n%lf\n" ,d1,d2,d3,d4);
    
    return 0;
    
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n,m; scanf("%d%d",&n,&m);
   int a[310][310];
   rep(i,0,n)rep(j,0,m){
      scanf("%d",&a[i][j]);
      a[i][j]--;
   }
   int ans=n;
   int cnt[310],idx[310]; bool used[310];
   rep(i,0,n)cnt[a[i][0]]++;
   rep(i,0,m-1){
      int ma=0,idx2=-1;
      rep(j,0,m)if(chmax(ma,cnt[j]))idx2=j;
      chmin(ans,ma); used[idx2]=1;
      rep(j,0,m)cnt[j]=0;
      rep(j,0,n){
         while(idx[j]<m&&used[a[j][idx[j]]])idx[j]++;
         cnt[a[j][idx[j]]]++;
      }
   } printf("%d\n",ans);
   return 0;
}

Measured memory_bytes: 640
import collections
N=int(input())
a=list(map(int,input().split()))
count=0
count_in=0
for i in a:
  while(True):
    if i%2==0:
      count_in+=1
      i//=2
    else:
      break
  count+=count_in
  count_in=0
print(count)

Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
const int N = 100050;
int n,m,k,a[N],b[N],mna,mnb,ans;
int main(){
	int i,j;
	read(n),read(m),read(k); 
	mna = 1000000,mnb = mna;
	for (i = 1; i <= n; ++i) read(a[i]),mna = min(mna,a[i]);
	for (i = 1; i <= m; ++i) read(b[i]),mnb = min(mnb,b[i]);
	ans = mna + mnb;
	int x,y,c;
	for (i = 1; i <= k; ++i){
		read(x),read(y),read(c);
		ans = min(ans,a[x]+b[y]-c);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = Integer.parseInt(sc.next());

		int ure = 0;

		while(X >= 500) {
			ure += (X / 500)*1000;
			X %= 500;

		}

		while(X >= 5) {
			ure += (X / 5)*5;
			X %= 5;

		}



		System.out.println(ure);

	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int dp[100005];
int path(int i,vector <int> *g){
	if(dp[i]!=-1)
		return dp[i];
	if(g[i].size()==0){
		dp[i]=0;
		return 0;
	}
	int mx=0;
	for(int j=0;j<g[i].size();j++){
		mx=max(mx,path(g[i][j],g));
	}
	dp[i]=mx+1;
	return dp[i];
}
int main(){
	int n,m;
	cin >> n >> m;
	memset(dp,-1,sizeof(dp));
	vector <int> g[n+1];
	for(int i=0;i<m;i++){
		int x,y;
		cin >> x >> y;
		g[x].push_back(y);
	}
	int mx=0;
	for(int i=1;i<=n;i++){
		mx=max(mx,path(i,g));
	}
	cout << mx << endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) (x).begin(),(x).end()
#define Ceil(x, n) (((((x))+((n)-1))/n))
#define CeilN(x, n) (((((x))+((n)-1))/n)*n)

#define INF 2e7
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V 5000000000000000000

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

bool isIn(int x, int y){
    if(0<= x && x <= n-1 && 0<= y && y <= n-1) {
        return true;
    }
    return false;
}

int main(){
    cin >> n;
    int seat_num = n * n;

    vector<int> kaisu(seat_num);
    vector<bool> visit(seat_num, false);
    REP(i, seat_num) {
        int j = i / n, k = i % n;
        int tmp = min(j, n - 1 - j);
        tmp = min(tmp, k);
        tmp = min(tmp, n - 1 - k);
        kaisu[i] = tmp;
    }

    int ans = 0;

    REP(i, seat_num) {
        int tmp;
        cin >> tmp;
        tmp--;
        queue<int> que;
        que.push(tmp);
        ans += kaisu[tmp]; 
        visit[tmp] = true;
        while(que.size() > 0) {
            int loop = que.size();
            REP(j, loop) {
                int idx = que.front();
                que.pop();
                int x = idx / n;
                int y = idx % n;
                REP(k, 4) {
                    int a = x + dx[k];
                    int b = y + dy[k];
                    if(isIn(a, b)) {
                        int pos = a*n + b;
                        if(visit[idx]) {
                            if(kaisu[pos] > kaisu[idx]) {
                                kaisu[pos] = kaisu[idx];
                                que.push(pos);
                            }
                        } else {
                            if(kaisu[pos] > kaisu[idx]+1) {
                                kaisu[pos] = kaisu[idx]+1;
                                que.push(pos);
                            }
                        }

                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4296
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;
int main(){
    ll K,N;
    cin >> K >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }
    vector<ll> B(N);
    for(int i=0; i<N-1; i++){
        B.at(i)=A.at(i+1)-A.at(i);
    }
    B.at(N-1)=A.at(0)+K-A.at(N-1);
    ll max=B.at(0);
    for(int i=0; i<N-1; i++){
        if(B.at(i+1) > max) max = B.at(i+1);
    }
    cout <<  K-max << endl;
    return 0;
}

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


int main() {
	map<pair<int, int>, int> m;
	int n;
	pair<int, int> p[50];
	cin >> n;
	int M = 0;
	for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; }

	for (int a = 0; a < n; a++) {
		for (int b = 0; b < n; b++) {
			if (a == b)continue;
			if (m.count(make_pair(
				p[a].first - p[b].first,
				p[a].second - p[b].second
			)))
				m[make_pair(
					p[a].first - p[b].first,
					p[a].second - p[b].second
				)]++;
			else
				m[make_pair(
					p[a].first - p[b].first,
					p[a].second - p[b].second
				)] = 1;
			M = max(M, m[make_pair(
				p[a].first - p[b].first,
				p[a].second - p[b].second
			)]);
		}
	}

	cout << n - M << endl;

	return 0;
}


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

int main() {
    int i,j,n,w;
    cin>>n>>w;
    ll val[n],wt[n],dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    for(i=0;i<n;i++) cin>>wt[i]>>val[i];
    for(i=0;i<=n;i++){
        for(j=0;j<=w;j++){
            if(i==0 || j==0) continue;
            if(wt[i-1]>j) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);
        }
    }
    cout<<dp[n][w];
}

Measured memory_bytes: 82436
/*
   Author : tarang
*/
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with(false); cin.tie(0);cout.tie(0);
const int MOD = 1000000007;
#define PI = acos(-1)
using namespace std ;
int a[106];
int main(){
     int a , b , c ; cin >> a >> b >> c ;
     if(a+b+c >= 22)
     cout << "bust";
     else cout << "win";
}



Measured memory_bytes: 3620
// https://atcoder.jp/contests/dp/tasks/dp_q

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
// struct FLW {
//   int h, i;
//   bool operator < (const FLW &f) const {
//     if (h != f.h) return h < f.h;
//     return i < f.i;
//   }
// };

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%lld%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 2*1e5;
const int A_I_MAX = 1e9;

//------------------------------------------------------------------------------
#define SZ      (sz * 2 - 1)
#define LF(i)   (i + sz - 1)
#define PA(k)   ((k - 1) / 2)
#define LC(k)   (k * 2 + 1)
#define RC(k)   (k * 2 + 2)
#define M(l,r)  ((l + r) / 2)

const int ST_SIZE = 1 << 19;    // N_MAX * 2 - 1

int sz;
ll dat[ST_SIZE];

void rmq_init(int n) {
  sz = 1;
  while (sz < n) sz <<= 1;
  REP(i, SZ) dat[i] = 0;
}

void update(int i, ll a) {
  int k = LF(i);
  dat[k] = a;
  while (k > 0) {
    k = PA(k);
    dat[k] = max(dat[LC(k)], dat[RC(k)]);
  }
}

ll query_sub(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) return dat[k];
  else {
    ll vl = query_sub(a, b, LC(k), l, M(l, r));
    ll vr = query_sub(a, b, RC(k), M(l, r), r);
    return max(vl, vr);
  }
}

ll query(int a, int b) {
  return query_sub(a, b, 0, 0, sz);
}

//------------------------------------------------------------------------------
int N;
int h[N_MAX];
int a[N_MAX];

void solve() {
  ll ans = 0;
  rmq_init(N);
  REP(i, N) {
    ll v = query(0, h[i]);
    ll v2 = v + a[i];
    update(h[i] - 1, v2);
    ans = max(ans, v2);
    // printf("i:%d, h:%d, a:%d, v:%lld, v2:%lld\n", i, h[i], a[i], v, v2);
    // DUMP(dat, SZ);
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", h + i);
  REP(i, N) scanf("%d", a + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 5888
#include<stdio.h>
int main(void){
	long long n,a,b,r;
	scanf("%lld%lld%lld",&n,&a,&b);
	r=n%(a+b)<a?n%(a+b):a;
	n/=(a+b);
	printf("%lld",n*a+r);
	return 0;
}

Measured memory_bytes: 1736
#include<stdio.h>

int main(void){

  int n,q,cnt=0,a[10001],b[501],i,j;

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

  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&b[i]);

  for(i=0;i<q;i++)
    for(j=0;j<n;j++)
      if(a[j]==b[i]){cnt++;break;}
    
  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
typedef long long ll;
ll h[30],n;
const ll inf=1e18;
ll solve(int l,int r,ll a,ll b) {
    if(r-l<=1)return 0;
    ll ans=inf;
    for(int i=l+1;i<=r-1;i++) {
        ans=min(ans,solve(l,i,a,a+b)+solve(i,r,a+b,b)+h[i]*(a+b));
    }
    return ans;
    
}
int main() {
    cin>>n;for(int i=1;i<=n;i++)cin>>h[i];
    cout<<solve(1,n,1,1)+h[1]+h[n];
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct bellman_fold{//1-origin
	vector<ll> min_dst;
	vector<vector<ll>> edge;
	ll ans;
	bellman_fold(ll n){
		min_dst.resize(n);
	}

	void append(ll u, ll v, ll cost){edge.push_back({u-1, v-1, cost});}
	
	void run(ll s){
		fill(min_dst.begin(), min_dst.end(), 1e18);
		min_dst[s-1] = 0;
		
		for(ll ite = 1; ite < min_dst.size(); ite++){
			for(ll j = 0; j < edge.size(); j++){
				if(min_dst[edge[j][0]] != 1e18 && min_dst[edge[j][0]]+edge[j][2] < min_dst[edge[j][1]]){
					min_dst[edge[j][1]] = min_dst[edge[j][0]] + edge[j][2];
				}
			}
		}
	}
	
	ll get(ll at){return min_dst[at-1];}
	
	bool loop(){
		for(ll ite = 1; ite <= min_dst.size(); ite++){
			for(ll j = 0; j < edge.size(); j++){
				if(min_dst[edge[j][0]] != 1e18 && min_dst[edge[j][0]]+edge[j][2] < min_dst[edge[j][1]]){
					min_dst[edge[j][1]] = -1e18;
				}
			}
		}
		if(min_dst[min_dst.size()-1] <= -1e18){
			return true;
		}
		else{
			return false;
		}
	}
};

ll n, m, p, a, b, c;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m >> p;
	bellman_fold bf(n);
	rep(i, 1, m){
		cin >> a >> b >> c;
		bf.append(a, b, -c+p);
	}
	bf.run(1);
	
	if(bf.loop()){
		print(-1)
	}
	else{
		print(max(-bf.get(n), 0LL))
	}
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	ArrayList<ArrayList<Integer>> pass;
	int ans;
	
	private void dfs(ArrayList<Integer> cards){
		ans = Math.min(ans, cards.size());
		if(ans == 0) return;
		boolean [][] used = new boolean[20][20];
		for(int i=0; i < cards.size();i++){
			for(int j = 0; j < pass.get(i).size();j++){
				int ind = pass.get(i).get(j);
				if(used[i][ind]) continue;
				used[i][ind] = true;
				used[ind][i] = true;
				if(ind >= cards.size()) continue;
				int ind2;
				if(ind < i){
					ind2 = i;
				}
				else{
					ind2 = ind;
					ind = i;
				}
				int cand1 = cards.get(ind) , cand2 = cards.get(ind2);
				if(cand1 != cand2) continue;
				ArrayList<Integer> next = new ArrayList<Integer>();
				next.addAll(cards);
				next.remove(ind2);
				next.remove(ind);
				dfs(next);
				next.add(ind, cand1);
				next.add(ind2, cand2);
				
			}
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		pass = new ArrayList<ArrayList<Integer>>();
		passCreate();
		while(n-- > 0){
			ans = 20;
			ArrayList<Integer>cards = new ArrayList<Integer>();
			for(int i=0; i < 20; i++){
				cards.add(sc.nextInt());
			}
			dfs(cards);
			System.out.println(ans);
		}
	}
	
	private void passCreate(){
		for(int i=0; i < 20; i++){
			ArrayList<Integer> now = new ArrayList<Integer>();
			if((i - 4) >= 0){
				if(i% 4 != 0){
					now.add(i-5);
				}
				now.add(i-4);
				if((i + 1) % 4 != 0){
					now.add(i-3);
				}
			}
			if(i% 4 != 0){
				now.add(i-1);
			}
			if((i + 1) % 4 != 0){
				now.add(i+1);
			}
			if(i + 4 < 20){
				if(i% 4 != 0){
					now.add(i+3);
				}
				now.add(i+4);
				if((i + 1) % 4 != 0){
					now.add(i+5);
				}
			}
			pass.add(now);
		}
//		for(int i=0; i < pass.size(); i++){
//			System.out.println("i= " + i);
//			System.out.println(pass.get(i).toString());
//		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  size_t N;
  std::cin >> N;
  u64 A, B;
  std::cin >> A >> B;
  u64 X = 0, Y = A + B;
  for ([[maybe_unused]] auto i: range(2, N)) {
    u64 x;
    std::cin >> x;
    X ^= x;
  }
  if (Y < X || (Y - X) % 2 == 1) {
    std::cout << "-1\n";
    return 0;
  } 
  u64 Z = (Y - X) / 2;
  if ((X & Z) != 0 || A < Z) {
    std::cout << "-1\n";
    return 0;
  }
  u64 border = A - Z;
  u64 cur = Z;
  for (auto digit: revrange(0, 40)) {
    u64 num = u64(1) << digit;
    if ((X >> digit & 1) && num <= border) {
      cur += num;
      border -= num;
    }
  }
  if (cur == 0) {
    std::cout << "-1\n";
    return 0;
  }
  std::cout << A - cur << '\n';
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  int c=0;
  vector<int>a;
  cin>>n;
  cin>>k;
  for(int i=0;i<n;i++){
    int c;
    cin>>c;
    a.push_back(c);
  }
  for(int i=0;i<n;i++){
    if(a[i]>=k)
      c++;
  }
  cout<<c;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(void) {
	int H, W;
	char a[100][100],b[102][102];
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < H+2; i++)
		for (int j = 0; j < W+2; j++)
			b[i][j] = '#';
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			b[i+1][j+1] = a[i][j];
		}
	}
	for (int i = 0; i < H+2; i++) {
		for (int j = 0; j < W+2; j++)
			cout << b[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
typedef long long ll;
using namespace std;

int main() {
	int N;
	string S;
	string T;
	cin >> N >> S >> T;
	string A;
	int j = 0;
	for (int i = 0; i < N; i++) {
		A += S[i];
	
		A += T[i];
	
	}
	cout << A << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[3];
  for(auto &X : a)
    	cin >> X;
 	sort(a,a+3);
  	if(a[0]==5 && a[1]==5 && a[2]==7)
      	cout << "YES";
  	else
      	cout << "NO";
}

Measured memory_bytes: 256
// AOL Q.0042
// YAMADA Terushige 2013.2.13.

#include<iostream>
#include<algorithm>

using namespace std;

int main(){

  int W,N;
  int nloop=0;
  while(cin >> W >> N){
    if (W == 0) break;
    nloop++;

    int v[N],w[N];
    char c;
    for (int i = 0;i < N;i++)
      cin >> v[i] >> c >> w[i];

    int dp[1001]={0};
    for(int i=0;i<N;i++)
      for(int k=W;k>=w[i];k--)
	dp[k] = max( dp[k] , dp[k-w[i]] + v[i] );

    int k=0;
    while( dp[k] < dp[W] ){
      k++;
    }

    cout << "Case " << nloop << ':' << endl << dp[W] << endl << k << endl;
  }
  return 0;
}


Measured memory_bytes: 1168
n = int(input())
stop = 0
num_list = []
while stop == 0:
	if n in num_list:
		stop = 1
		print(num_list.index(n)+4)
	else:
		num_list.append(n)
		if n % 2 == 0:
			n //= 2
		else:
			n = 3 * n + 1

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
 int k,n;
  cin>>k>>n;
  set<int> st;
  int a[n],min=INT_MAX,res;
  if(n==0){
   cout<<k;
    return 0;
  }
  for(int i=0;i<n;i++){
   cin>>a[i];
    st.insert(a[i]);
    if(abs(a[i]-k)<min){
    	min  = abs(a[i]-k);
       res = a[i];
    }
  }
  int i=res+1,j=res-1;
  while(true){
  	if(st.find(j)==st.end()){
      cout<< j ;
      break;
    }
    else if(st.find(i)==st.end()){
      cout<<i;
      break;
    }
    i++,j--;
  }
  
  
  
}


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

#define int long long 

const int INF = 1e18;

signed main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i=0;i<n;++i)cin >> h[i];
	
	
	vector<int> dp(n,INF);
	
	dp[0] = 0;
	
	dp[1] = abs(h[0]-h[1]);
	
	for(int i=2;i<n;++i)
	{
		dp[i] = min(dp[i],dp[i-1] + abs(h[i]-h[i-1]));
		dp[i] = min(dp[i],dp[i-2] + abs(h[i]-h[i-2]));
	}
	
	cout << dp[n-1];
}



Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <iostream>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N_ = 100500;

int N;
int A[N_];
vector<int> tree[N_];

ll remaining (int u, int p = -1) {
	vector<ll> children;
	for(auto v : tree[u]) if(v != p) {
		children.push_back(remaining(v, u));
	}
	ll tot = children.empty() ? 0 : accumulate(children.begin(), children.end(), 0ll);
	if(tot > 0) {
		if(tot < A[u] || tot > 2 * A[u]) throw 0;
		ll mx = *max_element(children.begin(), children.end());
		if(children.size() == 1) {
			if(mx != 2 * A[u] - tot) throw 0;
		}else {
			if(mx > A[u]) throw 0;
		}
		return 2 * A[u] - tot;
	}else {
		return A[u];
	}
}

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
	}
	for(int i = 1; i < N; i++) {
		int u, v; scanf("%d%d", &u, &v);
		tree[u].push_back(v);
		tree[v].push_back(u);
	}

	if(N == 2) {
		puts(A[1] == A[2] ? "YES" : "NO");
		return 0;
	}

	for(int u = 1; u <= N; u++) {
		if(tree[u].size() >= 2) { // internal
			try {
				return 0 & puts(remaining(u) ? "NO" : "YES");
			}catch(int e) {
				puts("NO");
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 14208
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		ArrayList<Character> text = new ArrayList<Character>();
		for(int i=0;i<s.length();i++){
			if(s.charAt(i) == 'B'){
				if(!(text.isEmpty())){
					text.remove(text.size()-1);
				}
			}else{
				text.add(s.charAt(i));
			}
		}
		for(int i=0;i<text.size();i++){
			System.out.print(text.get(i));
		}
		System.out.println();
	}

}


Measured memory_bytes: 20948
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

int solve(void);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

int solve(void)
{
	ll N, m;
	cin >> N >> m;

	// 尺取り法
	vector<ll>  v(N+2, 0);
	vector<pll> cd(N);

	for(auto& p: cd) {
		cin >> p.first >> p.second;
		v[p.first] ++;
		v[p.second] --;
	}
	
	for (int i = 0; i < v.size() - 1; i++)
	{
		v[i + 1] += v[i];
	}

	pll segment;
	vector<pll> seg;
	for (int i = 1; i < v.size() - 1; i++)
	{
		if (v[i - 1] == 0 && v[i] > 0)
		{
			segment.first = i;
		}
		if (v[i] > 0 && v[i + 1] == 0)
		{
			segment.second = i + 1;
			seg.push_back(segment);
		}
	}

	ll ans = N + 1;
	for (const auto s : seg)
	{
		ans += abs(s.first - s.second) * 2;
	}

	cout << ans << endl;

	return 0;
}


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

int gcd(int a, int b) {
    while(b)
        swap(a %= b, b);
    return a;
}
long inv(int a, int m) {
    long i = 1, j = 0;
    for(int b = m; a > 1; swap(i, j), swap(a, b)) {
        j = (j + b / a * (m - i)) % m;
        b %= a;
    }
    return i;
}
long po(long a, int n, int m) {
    long r = 1;
    for(; n; n >>= 1, (a *= a) %= m)
        if(n & 1)
            (r *= a) %= m;
    return r;
}
void fa(int m, map<int, int> &f) {
    for(int p = 2; p * p <= m; p++) {
        if(m % p)
            continue;
        f[p] = 1;
        while(m % p == 0)
            m /= p, f[p] *= p;
    }
    if(m > 1)
        f[m] = m;
}
long tet(long a, int m) {
    if(m < 2)
        return 0;
    map<int, int> f;
    fa(m, f);
    int n = 1, ph = 1;
    for(auto i : f) {
        int p, q;
        tie(p, q) = i;
        if(a % p)
            m /= q, n *= q, ph *= q / p * (p - 1);
    }
    return po(a, tet(a, ph), n) * inv(m, n) % n * m;
}
int main() {
    int Q;
    cin >> Q;
    for(int j = 0; j < Q; j++) {
        int a, m;
        cin >> a >> m;
        map<int, int> f;
        fa(m, f);
        int n = 1, ph = 1;
        long l = m;
        for(auto i : f) {
            int p, q;
            tie(p, q) = i;
            if(a % p)
                m /= q, n *= q, ph *= q / p * (p - 1);
        }
        auto t = tet(a, ph);
        auto s = po(a, t, n) * inv(m, n) % n * m;
        int x = 1;
        for(auto i : f) {
            int q = i.second;
            if(ph % q)
                x *= q;
        }
        l *= ph / gcd(l, ph);
        int y = l / x;
        cout << (s * inv(y, x) % x * y + t * inv(x, y) % y * x) % l + l << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int next[n+2][26],tmp[26];
    fill(tmp,tmp+26,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<26;j++){
            next[i+1][j]=tmp[j];
        }
        tmp[s[i]-'a']=i+1;
    }
    for(int i=0;i<26;i++){
        next[n+1][i]=tmp[i];
    }
    int dp[n+2];
    int par[n+2],c[n+2];
    fill(dp,dp+n+2,INF);
    dp[n+1]=0;
    for(int i=n+1;i>=1;i--){
        for(int j=0;j<26;j++){
            int to=next[i][j];
            if(dp[to]>dp[i]+1){
                dp[to]=dp[i]+1;
                par[to]=i;
                c[to]=j;
            }
            else if(dp[to]==dp[i]+1){
                if(to==0){
                    if(c[to]>j){
                        par[to]=i;
                        c[to]=j;
                    }
                    else if(c[to]==j&&c[par[to]]>c[i]){
                        par[to]=i;
                        c[to]=j;
                    }
                }
                if(c[par[to]]>c[i]){
                    par[to]=i;
                    c[to]=j;
                }
            }
        }
    }
    int now=0;
    while(now<n+1){
        cout<<char('a'+c[now]);
        now=par[now];
    }
    cout<<endl;
}


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


int main(){
 int n;
  cin>>n;
  vector<int> p(n),q(n);
  for(int i=0;i<n;i++) cin>>p[i];
  for(int i=0;i<n;i++) cin>>q[i];
  vector<int> a(n);
  for(int i=0;i<n;i++) a[i]=i+1;
  map<vector<int>,int> b;
  do{
    b[a]=b.size();
  }while(next_permutation(a.begin(),a.end()));
  cout<<abs(b[p]-b[q])<<endl;
}

Measured memory_bytes: 8624
n = int(input())
S = list(map(int, input().split()))
q = int(input())

def binary(l, key):
    left = 0
    right = len(l)
    while left < right:
        center = (left+right) // 2
        if l[center] == key:
            return True
        elif l[center] < key:
            left = center + 1
        else:
            right = center
    return False
    
ans = 0
for num in map(int, input().split()):
    if binary(S, num):
        ans += 1
        
print(ans)


Measured memory_bytes: 16716
#1行目を読み取る
line1 = input()
#スペースで区切る
splitLine1 = line1.split()

#それぞれをintに変換してn, kに代入する
#n, k = map(int, splitLine1)を分解
n = int(splitLine1[0])
k = int(splitLine1[1])

#2行目を読み取る
line2 = input()
#スペースで区切る
splitLine2 = line2.split()

#それぞれをintに変換してリストとして持つ
lengthList = []
for i in range(n):
  eachLengthNum = int(splitLine2[i])
  lengthList.append(eachLengthNum)

#lengthListを数字の小さい順にソートする
lengthList.sort()
#順番に取り出すために、大きい順に並べ替える
#reverseを使うと、listの順番をひっくり返す
lengthList.reverse()

#頭からkまでの数字を合計していく
resultLengthSum = 0
for i in range(k):
  resultLengthSum += lengthList[i]

#答えを出力
print(resultLengthSum)


Measured memory_bytes: 3060
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(args){
    var input = args.split('\n');
    var N = parseInt(input[0], 10);
    var a = input[1].split(' ').map(a => parseInt(a, 10))
    a.sort( (a,b) => (a<b ? -1 : 1) );
    var Alice = 0;
    var Bob = 0;
    var diff = 0;

    for(var i=0; i<N; i++){
        (i%2===0)?(Alice+=a.pop()):(Bob+=a.pop());
    }

    console.log(Alice-Bob);
}

Measured memory_bytes: 7500
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m>>s1;
    l(i,0,n)
    {
        if(i==m-1)
        {
            cout<<char(s1[i]+32);
        }
        else
        {
            cout<<s1[i];
        }
    }


        cout<<endl;




}











Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>

using namespace std;

const long long int MAX_N = 100;

int main(int argc, char const *argv[]) {
  long long int n, a[MAX_N];
  cin >> n;
  for (size_t i = 0; i < n; i++) cin >> a[i];
  sort(a,a+n);
  cout << a[n-1] - a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();

        long ans = 0;

        if (n % 2 == 0) {
            for (long i = 10; i <= n ; i *= 5) {
                ans += n / i;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 22612
#include <stdio.h>

int main(){
	int x;
	scanf("%d", &x);
	
	if(x % 1000 == 0){
		printf("0");
	} else if (x < 1000){
		printf("%d", 1000 - x);
	} else if (x >= 1000 && x <= 2000){
		printf("%d", 2000 - x);
	} else if (x >= 2000 && x <= 3000){
		printf("%d", 3000 - x);
	} else if (x >= 3000 && x <= 4000){
		printf("%d", 4000 - x);
	} else if (x >= 4000 && x <= 5000){
		printf("%d", 5000 - x);
	} else if (x >= 5000 && x <= 6000){
		printf("%d", 6000 - x);
	} else if (x >= 6000 && x <= 7000){
		printf("%d", 7000 - x);
	} else if (x >= 7000 && x <= 8000){
		printf("%d", 8000 - x);
	} else if (x >= 8000 && x <= 9000){
		printf("%d", 9000 - x);
	} else if (9000 <= x && x <= 10000){
		printf("%d", 10000 - x);
	}
	
	
	return 0;
}

Measured memory_bytes: 1732