akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define	REP(i,n) for(int i = 0;	i < (int)(n); i++)
typedef	long long ll;
typedef	pair<int, int> pint;
int main() {
  int N, M; cin>>N>>M;
  vector<pint > data(N);
  REP(i,N) {
    int	A, B; cin>>A>>B;
    data[i] = make_pair(A, B);
  }
  sort(data.begin(), data.end());

  //  REP(idx,N){                                                                                
  //    cout << data[idx].first << " " << data[idx].second << endl;                              
  //  }                                                                                          
  int idx = 0;
  ll ans = 0;
  priority_queue<int , vector<int> > q;
  for(int d = 1; d <= M; d++) {
    while(idx <	N && data[idx].first ==	d) {
      q.push(data[idx].second); idx++;
    }
    if(! q.empty()) {
      int work	= q.top(); q.pop();
      ans += work;
    }
    //    cout << d << " " << q.size() << " " << ans << endl;                                    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1660
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,m;
vi x,dif;
int res;

signed main(){

    in(n,m);
    if(n>=m){
        out(0);
        return 0;
    }
    resz(m,x);
    in(x);
    sort(all(x));
    REP(i,0,m-1){
        dif.pb(x[i+1]-x[i]);
        res+=x[i+1]-x[i];
    }
    sort(rall(dif));
    rep(i,n-1){
        res-=dif[i];
    }

    out(res);


    return 0;
}


Measured memory_bytes: 2168
n,blue = map(int,input().split())
red = n-blue
MOD = 10**9+7

def cmb(n,r):
    if (n-r)<r: r=n-r
    if r==0: return 1
    if r==1: return n

    numerator = [n-r + k+1 for k in range(r)]
    denominator = [k+1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p-1]
        if pivot>1:
            offset = (n-r)%p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def f(x,y):
  if x==0 and y==0:
    return 1
  elif y==0:
    return 0
  else:
    return cmb(x-1,y-1)

for i in range(blue):
  # 青の並べ方
  ao = f(blue,i+1)

  # 赤の並べ方
  if red<i:
    ak = 0
  elif red==i:
    ak = f(red,i)
  elif red==i+1:
    ak = f(red,i) + f(red,i+1) + f(red,i+1)
  else:
    ak = f(red,i) + f(red,i+1) + f(red,i+1) + f(red,i+2)
  
  print(ao*ak % MOD)

Measured memory_bytes: 3444
N[]={ 6, 14, 18, 10,  2,  9, 22, 15,  1, 17, 23,  7,  3,  5, 21, 19,  0, 13, 20, 11,  4,  8, 16, 12};
E[]={13, 17,  9,  5,  8, 21, 14,  1, 16, 22,  6,  0,  4, 20, 18,  2, 12, 23, 10,  3, 11, 19, 15,  7};
R_[]={ 3,  0,  1,  2,  7,  4,  5,  6, 11,  8,  9, 10, 15, 12, 13, 14, 19, 16, 17, 18, 23, 20, 21, 22};
a;
d;
T,F,R,t;
char s[9];
main(c)
{
	for(;c-48&&scanf("%s",s);a+=d/4+1)
	{
		c=*s;
		if(c<60)a&&printf("%d\n",a),a=d=0,T=1,F=2,R=3;
		if(c==78)t=T,T=F,F=7-t,d=N[d];
		if(c==83)t=F,F=T,T=7-t,d=N[N[N[d]]];
		if(c==69)t=R,R=T,T=7-t,d=E[d];
		if(c==87)t=T,T=R,R=7-t,d=E[E[E[d]]];
		if(c==82)t=F,F=R,R=7-t,d=R_[d];
		if(c==76)t=R,R=F,F=7-t,d=R_[R_[R_[d]]];

		//if ( T != d/4+1 )
		//	while(1);
	}
}

Measured memory_bytes: 0
N = int(input())
V = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
 
N = []
for i, v in enumerate(V):
    N.append(V[i]-C[i])

N.sort(reverse=True)
 
result = 0
for n in N:
    if 0<n:
        result += n
    else:
        break

print(result)

Measured memory_bytes: 3064
N,K = map(int,input().split())
L = [0 for _ in range(N+1)]
for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for j in range(len(A)):
        L[A[j]] += 1
ans = L.count(0)
print(ans-1)

Measured memory_bytes: 9192
# -*- coding: utf-8 -*-
"""
Created on Mon May 11 16:30:15 2020

@author: shinba
"""

import bisect

n,m,x = map(int,input().split())

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

a = bisect.bisect(A, x)

print(min(a,m-a))


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

using namespace std;

typedef long long ll;
typedef double long dl;
typedef pair < int , int > pii;
typedef pair < pii, pii > p2i;
const int maxn = (int) 3e5 + 1;
const int mod = (int) 1e9 + 7;
const ll inf = (ll)1e18;

#define fi first
#define se second
#define acel ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define next continue
#define getsz(x) (int) log10(x)

int n;
int a[maxn], maxx, b[maxn], mn = 1e9;

int get(int x){
    if(maxx / 2 >= x){
        return 1;
    }
    return 0;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        maxx = max(maxx, a[i]);
    }
    cout << maxx << " " ;
    sort(a + 1, a + n + 1);
    b[0] = 1e9;
    for(int i = 1; i <= n; i++){
        b[i] = abs((maxx / 2) - a[i]);
        if(b[i] > b[i - 1]){
            cout << a[i - 1];
            return 0;
        }
    }
    cout << a[1];
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
vint G[111];
int D[111][111];


int calc(vint vs){
	int n=vs.size();
	int ans=0;
	rep(i,1<<n){
		if(__builtin_popcount(i)<=1)continue;
		int score=0;
		rep(j,n)if(i>>j&1){
			int f=1001001001;
			rep(k,n)if((i>>k&1)&&j!=k)chmin(f,D[vs[j]][vs[k]]);
			score+=f;
		}
		chmax(ans,score);
	}
	return ans;
}

signed main(){
	cin>>N>>M;
	rep(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		G[a].pb(b);G[b].pb(a);
		D[a][b]=D[b][a]=c;
	}

	vint big;

	int ans=0;

	rep(i,N){
		if(G[i].size()<12){
			vector<int>lis=G[i];
			lis.pb(i);
			chmax(ans,calc(lis));
		}
		else{
			big.pb(i);
		}
	}
	chmax(ans,calc(big));

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


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

struct rest{
    string s;
    int p;
    int i;

    bool operator<(const rest &R){
        if (s == R.s) return p > R.p;
        return s < R.s;
    }
};

void solve(){
    int n;
    cin >> n;
    vector<rest> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i].s >> a[i].p;
        a[i].i = i;
    }

    sort(all(a));
    for (int i = 0; i < n; i++){
        //cout << a[i].s << ' ' << a[i].p << '\n';
        cout << a[i].i+1 << '\n';
    }
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3600
n = int(input())
a = tuple(map(int, input().split()))
reverse_a = a[::-1]


if n % 2 == 0:
    first = first = reverse_a[::2]
    second = a[::2]
else:
    first = reverse_a[::2]
    second = a[1:n:2]

print(*first+second)


Measured memory_bytes: 26308
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	
	char c;
	cin >> c;

	if(c >= 'a' && c <= 'z')
		cout << "a" << endl;
	else
		cout << "A" << endl;


	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
    char s[3];
    int i,j,t;
    scanf("%s",s);
    for(i=0;i<3;i++)
        for(j=i;j<3;j++)
            if(s[i]>s[j])
        {t=s[i];s[i]=s[j];s[j]=t;}
        if(s[0]=='a'&&s[1]=='b'&&s[2]=='c')
            printf("Yes\n");
        else
            printf("No\n");

    return 0;
}


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

const int N = 100005;
int x, y, h, w, n;
int ans[10], base = 1000000007, zero, node[N << 9], tol = 0;

signed main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w >> n;
    zero = (h - 2) * (w - 2);
    while (n--){
        cin >> x >> y;
        for (int i = 0; i < 3; i++){
			for (int j = 0; j < 3; j++){
                if (1 <= x - i && x - i <= h - 2 && 1 <= y - j && y - j <= w - 2){
                    node[tol++] = base * (x - i) + (y - j);
                }
            }
        }
    }
    sort(node, node + tol);
    int cnt = 1;
    for (int i = 0; i < tol; i++){
        if (node[i] == node[i + 1]){
			cnt++;
		}
        else{
			ans[cnt]++;
			cnt = 1;
			zero--;
		}
    }
    cout << zero << endl;
    for (int i = 1; i < 10; i++){
		cout << ans[i] << endl;
	}
    return 0;
}

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

using namespace std;

const int N = 1e5 + 7;
int n;

const long long inf = (long long)1e18;

int main() {
    std :: ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    long long mul = 0;
    long double logarim = 0.0;
    for(int i = 0 ; i < n; ++i) {
        long double p;
        cin >> p;
        logarim += log10(p);
        long long f = (long long)p;
        if(i == 0) {
            mul = f;
        }
        else {
            mul *= f;
        }
    }
    long double limit = log10(1.0 * 1e18);
  //  cout << logarim << " " << limit << endl;
    if(logarim > limit) cout << -1 << endl;
    else if(logarim == limit) {
        if(mul == (long long)(1e18 + 0.0000001)) {
            cout << mul << endl;
        }
        else {
            cout << -1 << endl;
        }
    }
    else {
        cout << mul << endl;
    }
    return 0;
}


Measured memory_bytes: 3884
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
using ll = long long;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    ll n; cin >> n; //n奇数
    vector<int> v(0);
    ll a[n];
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if (i % 2 == 0){
            sum += a[i];
        } else {
            sum -= a[i];
        }
    }
    sum /= 2;
    v.push_back(sum*2);
    for(int i = 1; i < n; i++){
        ll check = a[i-1]-sum;
        v.push_back(check*2);
        sum = check;
    }
    for(int i = 0; i < n; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}
  



Measured memory_bytes: 2680
S=input()
chars = []
moves1 = 0
moves2 = 0
n = 0
for c in S:
    n += 1
    if c == '0':
        if n % 2 == 0:
            moves1 += 1
        else:
            moves2 += 1
    else:
        if n % 2 == 0:
            moves2 += 1
        else:
            moves1 += 1

print(min(moves1,moves2))



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

int main(){
    int S;
    cin >> S;
    
    int h,m,s;
    m = S / 60 ;
    s = S % 60 ;
    
    h = m / 60 ;
    m = m % 60 ;
    
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r);for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
int main(){
  ll sx,sy,X,Y,i;cin>>sx>>sy>>X>>Y;
  X-=sx;Y-=sy
  REP(i,X)cout<<'R';
  REP(i,Y)cout<<'U';
  REP(i,X)cout<<'L';
  REP(i,Y+1)cout<<'D';
  REP(i,X+1)cout<<'R';
  REP(i,Y+1)cout<<'U';
  cout<<"LU";
  REP(i,X+1)cout<<'L';
  REP(i,Y+1)cout<<'D';
  cout<<'R'<<endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
P=list(map(int,input().split()))
from itertools import accumulate
acc=[0]
acc.extend(accumulate(P))
ans=0
for i in range(N-K+1):
  exp=(acc[K+i]-acc[i]+K)/2
  ans=max(exp,ans)
print(ans)

Measured memory_bytes: 32032
#include<iostream>
using namespace std;
#define MAX 100000
#define NILL -1

struct Node {int id,k,p;
    int *rootlist;
};
Node T[MAX];
int n;

int depth(int u){
    int d=0;
    while(T[u].p!=NILL){
        d+=1;
        u=T[u].p;
    } 
    return d;
}
void print(int u){
    int i;
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"depth = "<<depth(u)<<", ";
    
    if(T[u].p==NILL) cout<<"root, ";
    else if(T[u].k==0) cout<<"leaf, ";
    else cout<<"internal node, ";
    
    cout<<"[";
    
    if(T[u].k==0) cout<<"]"<<endl;
    else {
        for(i=0;T[u].rootlist[i]!=NILL;i++){
            if(i) cout<<", ";
            cout<<T[u].rootlist[i];
        }cout<<"]"<<endl;
    }
}




int main(){
    int m,b,h;
    cin>>n;
    for(int i=0;i<n;i++){
        T[i].p=NILL;
    }
    for(int i=0;i<n;i++){
        cin>>m>>b;
        T[m].id=m;
        T[m].k=b;
        T[m].rootlist=new int[b+1];
        for(int j=0;j<b;j++){
            cin>>h;
            T[m].rootlist[j]=h;
            T[T[m].rootlist[j]].p=m;
        }
        T[m].rootlist[b]=NILL;
        
    }

    

       
    
    for (int i=0;i<n;i++){
        print(i);
    }
    return 0;
}


Measured memory_bytes: 8980
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(void)
{
    int n;
    cin >> n;
    rep(i,10)
    {
        rep(j,10)
        {
            if(n == i*j)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    
    return 0;

}

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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L


typedef long long ll;

const ll MOD =1e9+7;

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

    int n;
    cin>>n;
    map<ll,ll> m;
    for(ll i=1;i<=n;++i){
        ll t=i;
        for(ll j =2;j*j<=t;++j){
            while(t%j==0){
                m[j]++;
                t/=j;
            }
        }
        if(t!=1)m[t]++;
    }

    ll ans=1;
    for(auto u:m) (ans*=(u.second+1))%=MOD;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=sorted(Counter(A).items(),key=lambda x:x[0],reverse=True)
m=len(C)
for i in range(m):
    if C[i][1]>=4:
        print(C[i][0]**2)
        exit()
    elif C[i][1]>=2:
        a=C[i][0]
        for j in range(i+1,m):
            if C[j][1]>=2:
                print(a*C[j][0])
                exit()
print(0)

Measured memory_bytes: 72344
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n,m;
    cin >> n >> m;
    ll a;
    rep(i,0,m){
        cin >> a;
        n -= a;
        if(n < 0) {cout << -1 << endl; return 0;}
    }

    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3688
#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;
    vector<string> s(n);
    vector<ll> t(n);
    rep(i, 0, n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    ll ans = 0;
    bool f = false;
    rep(i, 0, n) {
        if(f) ans += t[i];
        if(s[i] == x) f = true;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

int main() {
    int n;
    cin >> n;
    int x[n];
    std::vector<int> v;
    // int xx[n];
    // std::vector<int> vv;
    // int sum = 0;
    rep(i, n) {
        cin >> x[i];
        v.push_back(x[i]);
        // xx[i] = pow(x[i], 2);
        // vv.push_back(xx[i]);
        // sum += x[i];
    }
    // int ave = sum/n;
    std::vector<int> vv;
    for (ll i = 1; i <= *max_element(ALL(v)); ++i) {
        int sum = 0;
        rep(j, n) {
            sum += pow((x[j]-i), 2);
        }
        vv.push_back(sum);
    }

    cout << *min_element(ALL(vv)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

#define INF (1<<29)
#define max_n 10000

using namespace std;

struct node_t{

  node_t *pp,*lp,*rp;
  int id,val,mini,minId,lazy;
  bool rev;

  node_t(int id,int v):id(id),val(v){
    pp=lp=rp=NULL;
    rev=false; 
    lazy=0; 
    update();
  }
   
  inline void update(){
    mini=val,minId=id;
    if(lp && mini>lp->mini)mini=lp->mini,minId=lp->minId;
    if(rp && mini>=rp->mini)mini=rp->mini,minId=rp->minId;
  }
   
  inline void apply(int v){ lazy+=v, val+=v, mini+=v; }
   
  inline void push(){
    if(rev){
      rev=false;
      swap(lp,rp);
      if(lp)lp->rev^=true;
      if(rp)rp->rev^=true;
    }
    if(lp)lp->apply(lazy);
    if(rp)rp->apply(lazy);
    lazy=0;
  }
 
  bool is_root(){
    return !pp || (pp->lp != this && pp->rp != this);
  }
  
  void rotr(){
    node_t *q=pp,*r=q->pp;
    q->push(),push();
    if((q->lp=rp))rp->pp=q;
    rp=q;q->pp=this;
    if((pp=r)){
      if(r->lp==q)r->lp=this;
      if(r->rp==q)r->rp=this;
    }
    q->update();
  }

  void rotl(){
    node_t *q=pp,*r=q->pp;
    q->push(),push();
    if((q->rp=lp))lp->pp=q;
    lp=q;q->pp=this;
    if((pp=r)){
      if(r->lp==q)r->lp=this;
      if(r->rp==q)r->rp=this;
    }
    q->update();
  }

  void splay(){
    while(!is_root()){
      node_t *q=pp;
      if(q->is_root()){
	if(q->lp==this)rotr();
	else rotl();
      } else {
	node_t *r=q->pp;
	if(r->lp==q){
	  if(q->lp==this){q->rotr();rotr();}
	  else {rotl();rotr();}
	} else {
	  if(q->rp==this){q->rotl();rotl();}
	  else {rotr();rotl();}
	}
      }
    }
    push();
    update();
  }
};

node_t *expose(node_t *x){
  node_t *rp=NULL;
  for(node_t *p=x;p;p=p->pp){
    p->splay();
    p->rp=rp;
    p->update();
    rp=p;
  }
  x->splay();
  return rp;
}

node_t *find_root(node_t *x){
  expose(x);
  while(x->lp)x=x->lp;
  return x;
}

void cut(node_t *c){
  expose(c);
  node_t *p=c->lp;
  c->lp=NULL;
  p->pp=NULL;
  c->val=INF;
}

void link(node_t *c,node_t *p){
  expose(c);
  expose(p);
  c->pp=p;
  p->rp=c;
  c->update();
}

void evert(node_t *p){
  expose(p);
  p->rev^=true;
}

int minId(node_t *x){expose(x); return x->minId;}
void add(node_t *x,int val){ expose(x); x->apply(val); }

node_t *LCA(node_t *x,node_t* y){
  expose(x);
  return expose(y);
}

node_t *node[100001];

int main(void){
  int n;
  cin >> n;
  
  for(int i=0;i<n;i++)node[i]=new node_t(i,0);
  for(int i=0;i<n;i++){
    int k,t;
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> t;
      link(node[t],node[i]);
    }
  }

  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int u,v;
    cin >> u >> v;
    cout << LCA(node[u],node[v])->id << endl;
  }
  
  return 0;
}

Measured memory_bytes: 8220
def bs_left(list, target):
    low = 0
    high = len(list)

    while low < high:
        mid = (low + high) // 2
        if target > list[mid]:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(list, target):
    low = 0
    high = len(list)
    while low < high:
        mid = (low + high) // 2
        if target < list[mid]:
            high = mid
        else:
            low = mid + 1
    return low

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()

ans = 0
for b in B:
    ans += (bs_left(A, b) * (n - bs_right(C, b)))
print(ans)



Measured memory_bytes: 29216
#include <iostream>
int main(){
  int cost[] = {0, 6000, 4000, 3000, 2000};
  int t,n;
  for(int i=0; i<4; i++){
    std::cin >> t >> n;
    std::cout << cost[t]*n << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'
 
int main()
{
    fastio;
    lli a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a="RUD";
    string b="LUD";
    bool flag1=true;
    bool flag2=true;
    int i=0;
    string s;
    cin >>s;
    for (i=0;i<s.length();i++)
    {
        if (i%2==0)
        {
            if (find(a.begin(), a.end(), s[i])==a.end()) 
            {
                flag1=false;
            }
        }
        if (i%2!=0)
        {
            if (find(b.begin(), b.end(), s[i])==b.end())
            {
                flag2=false;
            }
        }
    }
    if (flag1==true && flag2==true)
    {
        cout<<"Yes";
    }
    else 
    {
        cout<<"No";
    }
    
    return 0;
}

Measured memory_bytes: 256
/**

   Author : sea_26

**/


#pragma GCC optimize("03")
#include <bits/stdc++.h>

using namespace std;

const int M = 1000000007;
const double PI = acos(-1.0);

// const double pi = atan2(0, -1);
// const double PI = 4 * atan(1);
// const double pi = 2*cos(0.0);

typedef long long ll;
typedef long double ld;

const int iinf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ln(x) (int)x.size()

#define bp(n)  __builtin_popcount(n)
#define bclz(n) __builtin_clzll(n)
#define bctz(n) __builtin_ctzll(n)
#define bip(n) __builtin_parity(n)

#define vsort(v) sort(v.begin(),v.end())
#define rvsort(v) sort(v.begin(),v.end(),greater<int>())

#define rep(n) for(int i=0; i<n; i++)
#define rrep(n) for(int i=n; i>=1; i--)
#define lrep(p,q) for(int i=p; i<=q; i++)
#define prep(n) for(int i=1; i*i<=n; i++)
#define it(a, x)  for(auto &a : x)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

priority_queue<int> pq;

#define fs   ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

template< typename T> inline T lcm(T a, T b){ return (a / gcd(a,b)) * b; }
template< typename T> inline T MAX(T a, T b){ return a ^ ((a ^ b) & -(a < b)); }
template< typename T> inline T MIN(T a, T b){ return b ^ ((a ^ b) & -(a < b)); }
template< typename T> void tpns(T n){ rrep(30){ if(n & (1 << i)) pq.push(1 << i); } }
template< typename T> void SWAP(T &a, T &b){ a = ((a) ^= (b)),  b = ((b) ^= (a)),  a = ((a) ^= (b)); }
template< typename T> inline T ABS(T a){ int x = a >> sizeof(int) * CHAR_BIT - 1; return (a + x) ^ x; }
template< typename T> inline T mod(T a, T b){ return a >= b ? a % b : a; }
template< typename T> inline T gcd(T a, T b){ while (b) b ^= a ^= b ^= a %= b; return a; }

ll gcdextd(ll a, ll b, ll& x, ll& y) {
    if (!a) { x = 0; y = 1; return b; }
    ll y1,d;
    d = gcdextd(b % a, a, y, y1);
    x = y1 - (b / a) * y;
    return d;
}



double WT() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void ReT(){

	cout << "\nTime = " << fixed << setprecision(3) << WT()  << " Sec"<< endl;

exit(0);
}




int l[100005], r[100005], a[100005];
int n,mx;

int main(){

        fs;
        cin >> n;
        lrep(1,n){
            cin >> a[i];
            l[i] = gcd(a[i], l[i-1]);
        }

        rrep(n)
            r[i] = gcd(r[i+1], a[i]);

        lrep(1,n){
            mx = max(mx, gcd(l[i-1], r[i+1]));
        }

        cout << mx << endl;

     //   ReT();

}


Measured memory_bytes: 1408
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		d = (int)Math.pow(100,d);
		if(n==100){
			System.out.println(d*(n+1));
		}else{
			System.out.println(d*n);
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main()
{
  int n,l[400000];
  char s[400000];
  cin >> n;
  rep(i,n)cin >> s[i];
  l[0]=0;
  rep(i,n-1){if(s[i+1]=='E')l[0]++;
            }
  FOR(i,1,n){if(s[i-1]=='E'&&s[i]=='E')l[i]=l[i-1]-1;
             else if(s[i-1]=='W'&&s[i]=='W')l[i]=l[i-1]+1;
             else l[i]=l[i-1];
            }
  sort(l,l+n);
  printf("%d",l[0]);
}

Measured memory_bytes: 1664
n=int(input())
A=list(map(int,input().split()))
numbers=list(range(1,n+1))              #出席番号のリスト

D=dict(zip(A,numbers))                  #出席番号と到着順を関連付けるための辞書
for a in sorted(A):
    print(D[a],end=" ")

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

int main(){
  int N,T,A;
  cin >>N>>T>>A;
  int x;
  double temp,mi,d;
  mi = 1000;
  int ans = 0;
  for(int i=0;i<N;i++){
    cin >>x;
    temp = T-0.006*x;
    d = abs(A-temp);
    if(d < mi){
      mi = d;
      ans = i;
    }
  }
  cout << ans+1 <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

 
using namespace std;
 
bool cmp(int a, int b)
{
    return abs(a) < abs(b);
}


int main()
{
    int n, l;
    cin >> n >> l;
    int taste[n] = {0};
    for (int i = 0; i < n; i++)
    {
        taste[i] = l+i;
    }
    sort(taste,taste+n, cmp);
    int sum = 0;
    for (int i = 1; i < n; i++)
    {
        sum += taste[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int n,m;
    cin>>n>>m;
    vi a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    vpii v(n);
    rep(i,n)v[i]=mp(a[i],b[i]);
    Sort(v);
    priority_queue<int> pq;
    vll dp(m+1,0);

    int day=0;
    for(int i=1;i<=m;i++){
        while(day<n&&v[day].first<=i){
            pq.push(v[day].second);
            day++;
        }
        if(!pq.empty()){
            dp[i]=dp[i-1]+pq.top();
            pq.pop();
        }
        else dp[i]=dp[i-1];
        
    }
    fin(dp[m]);

    

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 3324
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int n;
  cin >> n;
  vector<int> v(n), c(n);
  REP(i, n) cin >> v[i];
  REP(i, n) cin >> c[i];

  int x=0, y=0;
  REP(i, n){    
    if(v[i] < c[i]) continue;
    x += v[i];
    y += c[i];
  }
  cout << x-y << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)


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

int main(){
  stack<int> car;
  int n,cou=0,i=0,ans[1111];
  while(cin >> n){
    if(n == 0){
      cout << car.top() << endl;
      car.pop();
    }
    else{
      car.push(n);
    }
  }
}

Measured memory_bytes: 1204
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> p;

double GetArea(p a, p b, p c){
	double la, lb, lc, lz;
	la = abs(b-a);
	lb = abs(c-b);
	lc = abs(a-c);
	lz = (la+lb+lc)/2;

	return sqrt(lz*(lz-la)*(lz-lb)*(lz-lc));
}

int main(){
	double x, y;
	vector<p> pv;

	while(~scanf("%lf,%lf", &x, &y)){
		pv.push_back(p(x, y));
	}

	double s = 0.0;
	for(int i = 0; i+1 < pv.size(); i++){
		s += GetArea(pv[0], pv[i], pv[i+1]);
	}

	printf("%lf", s);

	return 0;
}

Measured memory_bytes: 1252
use std::io;


fn main() {
    let (a, b, c) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    let mut flg = false;
    for i in 0..b {
        if a * (i + 1) % b == c { flg = true; }
    }
    if flg { println!("YES"); }
    else { println!("NO"); }
}



#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int a,b,c,d;cin>>a>>b>>c>>d;
    int t=(c-1)/b+1,k=(a-1)/d+1;
    if(t<=k)cout<<"Yes";
    else cout<<"No";
    
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
string a, b;

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

	cin >> a >> b;

	if (a.length() > b.length()) { cout << "GREATER\n"; return 0; }
	if (a.length() < b.length()) { cout << "LESS\n"; return 0; }
	
	for (int i = 0; i < a.length(); i++) {
		if ((int)a[i] > (int)b[i]) {
			cout << "GREATER\n";
			return 0;
		}
		else if ((int)a[i] < (int)b[i]) {
			cout << "LESS\n";
			return 0;
		}
	}
	cout << "EQUAL\n";
	
	
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define fo(i, n) for(int i = 1; i <= n; ++i)
#define rep(i, a, b) for(int (i) = (a); (i) < (b); ++(i))

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

const int N = 200200;
const int mod = 1e9 + 7;
const ll INF = 1e18;

int cnt[51][26];
string s;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	fo(i, n)
	{
		cin >> s;
		for(int j = 0; j < s.length(); ++j)
		cnt[i][s[j] - 'a']++;
	}
	string res;
	for(int i = 0; i < 26; ++i)
	{
		int mx = 51;
		fo(j, n)
			mx = min(mx, cnt[j][i]);
		fo(j, mx)
			res += char(i + 'a');
	}
	cout << res;
	return 0;	
}

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

using namespace std;
int CE[300001];
int CW[300001];
signed main(){
    int n; cin >> n;
    string S; cin >> S;
    for(int i=0; i<S.size(); ++i){
        if(S[i] == 'E'){
            CE[i+1] = CE[i] + 1;
            CW[i+1] = CW[i];
        }
        if(S[i] == 'W'){
            CE[i+1] = CE[i];
            CW[i+1] = CW[i] + 1;
        }
    } 
    //for(int i=0; i<=n; ++i) cout << CE[i];
    //cout << "\n";
    //for(int i=0; i<=n; ++i) cout << CW[i];
    //cout << "\n";
    int cost = 1 << 28;
    int loc = 0;
    for(int i=0; i<n; ++i){
        if(cost > CW[i] + CE[n]-CE[i+1]){
            cost = CW[i] + CE[n]-CE[i+1];
            loc = i;
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <cstdio>
#define maxn 10000
#define NIL -1
#include <iostream>
using namespace std;

struct Node{
	int parent,left,right;
}T[maxn];


int n, D[maxn], H[maxn];

void setDepth(int u,int d){
	if(u==NIL) return;
	D[u]=d;
	setDepth(T[u].left,d+1);
	setDepth(T[u].right,d+1);
}

int setHeight(int u){
	int h1=0,h2=0;
	if(T[u].left!=NIL)
		h1=setHeight(T[u].left)+1;
	if(T[u].right!=NIL)
		h2=setHeight(T[u].right)+1;
	return H[u]=max(h1,h2);
}


int getSibling(int u){
	if(T[u].parent==NIL) return NIL;
	if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL)
		return T[T[u].parent].left;
	if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL)
		return T[T[u].parent].right;
	return NIL; //leaf node
}

void print(int u){
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u));
	int deg=0;
	if(T[u].left!=NIL) deg++;
	if(T[u].right!=NIL) deg++;

	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);

	if(T[u].parent==NIL)
		printf("root\n");
	else if(T[u].left==NIL && T[u].right==NIL)
		printf("leaf\n");
	else printf("internal node\n");
}


int main(){
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	int v,l,r,root=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) T[i].parent=NIL;

	for(int i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].left=l;
		T[v].right=r;
		if(l!=NIL) T[l].parent=v;
		if(r!=NIL) T[r].parent=v;
	}

	for(int i=0;i<n;i++) if(T[i].parent==NIL) root=i;

	setDepth(root,0);
	setHeight(root);

	for(int i=0;i<n;i++) print(i);

	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define ll long long 
using namespace std;
ll dp[3001][3001][2];
ll solve(vector<int>& v,int i,int j,int turn)
{
    if(i>j)
    {
        return 0;
    }
    if(dp[i][j][turn]!=-1)
    {
        return dp[i][j][turn];
    }
    if(turn ==1)
    {
        return dp[i][j][turn]=max(v[i]+solve(v,i+1,j,0),v[j]+solve(v,i,j-1,0));
    }
     return dp[i][j][turn]=min(solve(v,i+1,j,1),solve(v,i,j-1,1));
    
}

int main() {
    int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    vector<int> v(n+1);
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        sum=sum+v[i];
    }
    ll scoreX=solve(v,1,n,1);
    ll scoreY=sum-scoreX;
    cout<<scoreX-scoreY;
}


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

const int N = 20;

char s[N + 5];
int dp[N + 5][2];

int main()
{
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	
	scanf("%s", s + 1);
	int n = strlen(s + 1);

	dp[0][0] = -1e9;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < s[i]-'0'; ++j){
			dp[i][0] = std::max(dp[i][0], std::max(dp[i-1][0] + j, dp[i-1][0] + j));
			dp[i][0] = std::max(dp[i][0], std::max(dp[i-1][1] + j, dp[i-1][1] + j));
		}
		for(int j = 0; j < 10; ++j){
			dp[i][0] = std::max(dp[i][0], std::max(dp[i-1][0] + j, dp[i-1][0] + j));
		}
		dp[i][1] = std::max(dp[i][1], dp[i-1][1] + s[i]-'0');
		dp[i][1] = std::max(dp[i][1], dp[i-1][1] + s[i]-'0');
	}

	printf("%d\n", std::max(dp[n][1], dp[n][0]));

	return 0;
}

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

using namespace std;

int main() {//B問題
	int N;
	int *a;

	int Alice_Point = 0;
	int Bob_Point = 0;

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

	sort(a, a + N);

	for (int j = N - 1; j >= 0; j--) {
		int Alice_Turn = (N-1) % 2;

		if (j%2==Alice_Turn) {
			Alice_Point += a[j];
			//cout << "A," << j << "," << a[j];
		}
		else {
			Bob_Point += a[j];
			//cout << "B," << j << "," << a[j];
		}
	}

	cout << Alice_Point - Bob_Point << endl;
	
	return 0;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
x = list(map(int, input().split()))
ans = 10 ** 9
for l in range(n - k + 1):
	ans = min(ans, min(abs(x[l]) + abs(x[l + k - 1] - x[l]), abs(x[l + k - 1]) + abs(x[l + k - 1] - x[l])))
print(ans)

Measured memory_bytes: 14392
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int T = sc.nextInt();
		solve(N, X, T);
	}

	private static void solve(int n, int x, int t) {
		// TODO Auto-generated method stub
		if (x == 1 || n == 1) System.out.println(n * t);
		else {
			int r = (n  + x - 1) / x;
			System.out.println(r * t);
		}
	}

}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

ll calc(ll x){
	if(x == 0) return 0;
	int max_dig = 61;
	while(!((x >> max_dig) & 1)) max_dig--;
	// cout << max_dig << endl;

	ll ans = 0;
	for(int a = 0; a <= max_dig; a++){
		if(a == 0){
			if(x % 4 == 1 || x % 4 == 2){
				ans ^= 1;
			}
			continue;
		}

		if(a == 1){
			if(x % 4 == 2){
				ans ^= 2;
			}
			continue;
		}

		ll b = 1LL << a;
		ll c = x % (b * 2);
		if(c < b) continue;
		// cout << a << "," << (c - (b - 1)) % 2 <<"," <<  ((c - (b - 1)) % 2 << a) << endl;
		ans ^= (c - (b - 1)) % 2 << a;
	}

	return ans;
}

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

	ll A, B;
	cin >> A >> B;
	// cout << calc(A-1) << endl;
	// cout << calc(B) << endl;
	if(A == 0){
		cout << calc(B) << endl;
	}else{
		cout << (calc(A-1) ^ calc(B)) << endl;
	}
}


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

int main(){
    char s[4];
    bool goodflag = true;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            goodflag = false;
            break;
        }
    }
    if(goodflag){
        cout << "Good" << endl;
    }
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define pb push_back
#define ALL(v) v.begin(),v.end()
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }
using Graph = vector<vector<int>>;
int main()
{
    int X, N;
    cin >> X >> N;
    set<int> s;
    int max = 0;
    int min = INT_MAX;
    if(N == 0)
    {
        cout << X << endl;
        return 0;
    }
    rep(i, N)
    {
        int a;
        cin >> a;
        s.insert(a);
        chmax(max, abs(a-X));
    }
    int ans = -1;
    rep2(i, 0, 105)
    {
        int cand = X-i;
        int cand2 = X+i;
        if(s.find(cand) == s.end())
        {
            ans = cand; break;
        }
        if(s.find(cand2) == s.end())
        {
            ans = cand2; break;
        }
    }    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	long long a,b,x,a5,b5,c,d,bb;
	int flg;
	scanf("%lld",&x);
	a=1;	b=0;	bb=0;
	while(1)	{
		flg=1;
		while(1)	{
			d=a*a*a*a+a*a*a*b+a*a*b*b+
				a*b*b*b+b*b*b*b;
			if(d>x)	{
				flg=0;
				break;
			}
			a5=a*a*a*a*a;
			b5=b*b*b*b*b;
			c=a5-b5;
			if(c==x)	break;
			else if(c<x)	a++;
			else b++;
		}
		if(flg==1)	break;
		else {
			bb--;
			a=bb-1;	b=bb;
		}
	}
	printf("%lld %lld\n",a,b);
	return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,a,b,p[maxn],l,Q;
int f[maxn][35];
int main()
{
    scanf("%d",&n);
    for (int i=1; i<=n; i++) scanf("%d",&p[i]);
    scanf("%d",&l);
    for (int i=1;i<=n;i++)
     {
        int idx=upper_bound(p+1,p+1+n,p[i]+l)-p-1;
        if(p[i]+l>=p[n]) f[i][0]=n;
        else f[i][0]=idx;
    }
    for (int j=1; j<=30; j++)
        for (int i=1;i<=n;i++)
            f[i][j]=f[f[i][j-1]][j-1];
    scanf("%d",&Q);
    while(Q--)
    {
        scanf("%d%d",&a,&b);
        if(a>b) swap(a,b);
        int cur=a,ans=0;
        for (int i=30; i>=0; i--)
        {
            if(f[cur][i]<b)
            {
                ans+=(1<<i);
                cur = f[cur][i];
            }
        }
        printf("%d\n",ans+1);
    }
    return 0;
}

Measured memory_bytes: 14848
#include<stdio.h>

int main(void){
  int n = 0;
  int m = 0;
  scanf("%d", &n);
  int i = 0;
  int buka[n-1];
  int r = 0;
  for(i=0;i<n-1;i++){
    buka[i] = 0;
  }
  for(i=0;i<n-1;i++){
    scanf("%d", &r);
    buka[r-1]=buka[r-1]+1;
  }
  for(i=0;i<n-1;i++){
    printf("%d\n", buka[i]);
  }
  printf("0");
}

Measured memory_bytes: 2508
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

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

int check ( int q, vector<int> vec, vector<int> a, vector<int> b, vector<int> c, vector<int> d ) {
    int sum = 0;
    rep(i, q) {
        if ( vec[b[i]] - vec[a[i]] == c[i] ) {
            sum += d[i];
        }
    }
//    for ( auto u : vec ) {
//        cout << u << " ";
//    }
//    cout << sum << endl;
    return sum;
}

void dfs ( int n, int m, int q, int pre_num, vector<int> vec, vector<int> a, vector<int> b, vector<int> c, vector<int> d, int &ans ) {
    if ( vec.size() == n ) {
        ans = max(ans, check(q, vec, a, b, c, d));
        return;
    }
    vec.push_back(1);
    for ( int i = pre_num; i <= m; ++i ) {
        vec[vec.size()-1] = i; 
        dfs(n, m, q, i, vec, a, b, c, d, ans);
    }
}

int main(){
    int n, m, q;
    int ans = 0;
    cin >> n >> m >> q;
    vector<int> a(q);
    vector<int> b(q);
    vector<int> c(q);
    vector<int> d(q);
    rep(i, q) {
        int tmp_a, tmp_b;
        cin >> tmp_a >> tmp_b >> c[i] >> d[i];
        --tmp_a, --tmp_b;
        a[i] = tmp_a;
        b[i] = tmp_b;
    }
    vector<int> vec;
    dfs(n, m, q, 1, vec, a, b, c, d, ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
n = int(input())
s = str(input())
Answer = 0

for val in range(n-2):
	if s[val] != 'A' :
		continue
	elif s[val +1] != 'B' :
		continue
	elif s[val +2] != 'C' :
		continue
	else :
		Answer += 1

print(Answer)

Measured memory_bytes: 2940