akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()
#define VT(T) vector<T>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;
 
ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
 
ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}
 
ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}
 
ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

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

	int n, m;
	cin>>n>>m;
	vector<int> sub[n+1];
	for(int i=0; i<m; i++){
		int p;
		string s;
		cin>>p>>s;
		if(s[0]=='A') sub[p].pb(1);
		else sub[p].pb(0);
	}

	int c=0, w=0;
	for(int i=1; i<=n; i++){
		bool f=false;
		for(auto x : sub[i]){
			if(x==1){
				f=true;
				break;
			}
			w++;
		}
		if(f) c++;
		else w-=sub[i].size();
	}

	cout<<c<<" "<<w<<endl;
}

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

using namespace std;

int main(){
	long long N, H, W, ans = 0; cin >> N >> H >> W;
	long long A[N], B[N];
	for(long long i = 0; i < N; ++i){
		cin >> A[i] >> B[i];
	}
	for(long long i = 0; i < N; ++i){
		if(A[i] >= H && B[i] >= W) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <vector>
#include <string>
#include <cctype>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef stringstream strstm;
#define pb push_back
#define PI acos(-1.0)
#define CLR(a) MST(a,0);
#define E 2.718281829459
#define lowbit(x) (x & (-x))
#define DBG(x) cout << (x) << " ";
#define MST(a,b) memset(a,b,sizeof(a));
#define _for(i,a,b) for(int i = (a); i < (b); ++i)
#define _rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define _ech(x,z) for(auto x = z.begin(); x != z.end(); ++x)

const string str[2] = {"Alice","Borys"};

int main(int argc, char const *argv[])
{
  int n,a,b; cin >> n >> a >> b;
  if(n == 2 && a == 1 && b == 2) cout << str[1] << endl;
  else{
    if((b-a)%2) cout << str[1] << endl;
    else cout << str[0] << endl;
  }

  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  long X,Y,A,B,C;cin>>X>>Y>>A>>B>>C;
  vector<long>P(A),Q(B),R(C);
  for(long i=0;i<A;i++)cin>>P[i];
  for(long i=0;i<B;i++)cin>>Q[i];
  for(long i=0;i<C;i++)cin>>R[i];
  
  
  
  sort(P.begin(),P.end(),greater<long>());
  sort(Q.begin(),Q.end(),greater<long>());
  sort(R.begin(),R.end(),greater<long>());
  //累積和
  vector<long>SP(A+1,0);for(long i=0;i<A;i++)SP[i+1]=SP[i]+P[i];
  vector<long>SQ(B+1,0);for(long i=0;i<B;i++)SQ[i+1]=SQ[i]+Q[i];
  vector<long>SR(C+1,0);for(long i=0;i<C;i++)SR[i+1]=SR[i]+R[i];
  
  //まずPから0個の時
  long tmp=SR[min(X,C)]+SP[max(0L,X-C)];//X>Cで問題
  long iq=0,ir=min(X,C);
  for(long i=0;i<Y;i++){
    if(ir>=C||(iq<B&&Q[iq]>R[ir])){tmp+=Q[iq];iq++;}
    else{tmp+=R[ir];ir++;}
  }
  long ans=tmp;
  for(long x=max(0L,X-C);x<X;x++){
    tmp+=P[x];
    if(ir-1<0||(iq-1>=0&&Q[iq-1]<R[ir-1])){tmp-=Q[iq-1];iq--;}
    else {tmp-=R[ir-1];ir--;} 
    ans=max(ans,tmp);
    //if(ir<0&&iq<0)break;
  }
  cout<<ans;
  
}


/*

SR[X]


*/



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

// macros
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define INT_IN(a) int a; cin >> a
#define STR_IN(s) string s; cin >> s
#define PRINTLN(s) cout << s << endl
#define PRINTDOUBLELN(s) cout << setprecision(12) << (s) << endl;

// util functions
template<class T> inline T sqr(T x) {return x*x;}

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T>inline T max(vector<T> v){T max=v[0]; FOR(i, 1, v.size())max=MAX(v[i], max); return max;}
template <typename T>inline T min(vector<T> v){T min=v[0]; FOR(i, 1, v.size())min=MIN(v[i], min); return min;}
template <typename T>inline vector<T> concat(vector<T> a, vector<T> b){vector<T> ab; ab.reserve(a.size()+b.size());ab.insert(ab.end(),a.begin(),a.end());ab.insert(ab.end(),b.begin(),b.end());return ab;}

// types
typedef long long LL;

// consts
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//debug
#define dump(x)  #x << " = " << (x) << endl
#define debug(x) #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl


int main(){
    STR_IN(s);
    int N = s.size();
    vector<bool> tcd(N, false);
    REP(i, N){
        if(s[i] == 'p')tcd[i] = true;
    }

    vector<bool> acd(N, false);
    vector<int> paperStock(N, 0);
    int pS = 0;

    // try getting as much same choice as possible
    REP(i, N){
        if(tcd[i] and pS){
            pS--;
            acd[i] = true;
        }else{
            pS++;
        }
        paperStock[i] = pS;
    }

    vector<int> infPS(N);
    int min = paperStock[N - 1];
    REP(i, N){
        if(paperStock[N - 1 - i] < min) min = paperStock[N - 1 - i];
        infPS[N - 1 - i] = min;
    }

    int usedPaperOffset = 0;
    REP(i, N){
        if(!tcd[i] and !acd[i] and infPS[i] > usedPaperOffset + 1){
            acd[i] = true;
            usedPaperOffset += 2;
        }
    }

    int aScore = 0;
    REP(i, N){
        if(tcd[i] and !acd[i]) aScore--;
        else if(!tcd[i] and acd[i]) aScore++;
    }
//    REP(i, N){
//        cout << infPS[i];
//    }
//    cout << endl;
    PRINTLN(aScore);
    return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
int n;
ll a[N];
ll ans;

inline void solve()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    ll now = 0;
    for (int i = 1; i <= n; ++i)
    {
        if(now <= a[i])
        {
            now = a[i];
        }
        else
        {
            ans += -a[i] + now;
        }
    }
    cout << ans << endl;
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
        solve();
    TIME__END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int n,k,c; cin>>n>>k>>c;
  string s; cin>>s;
  unordered_map<int,int> m;
  for(int i = n-1;i>=0;i--){
    if(s[i]=='o'){
      m[i] = k--;
      i-=c;
    }
  }
  int x(0);
  for(int i=0;i<n;i++){
    if(s[i]=='o'){
      if(m[i]==++x) cout<<i+1<<endl;
      i+=c;
    }
  }
  
  return 0;
}



Measured memory_bytes: 9948
#include<bits/stdc++.h>
using namespace std;
long long N,Q,S,A,B,C;
map<int,int>m;
int main(){
    cin>>N;
    
    for(int i=0;i<N;i++){
        cin>>A;
        m[A]++;
        S+=A;
    }
    cin>>Q;
    for(int i=0;i<Q;i++){
        cin>>B>>C;
        S-=B*m[B];
        S+=C*m[B];
        m[C]+=m[B];
        m[B]=0;
        cout<<S<<endl;
    }
    return 0;
}

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

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<int> H(N);

    for(int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    
    int max = H[0];
    int can_viewing = 0;

    for (int i = 0; i < N; i++){
        if(max <= H[i]){
            max = H[i];
            can_viewing = can_viewing + 1;
        }
    }

    cout << can_viewing << endl;

    return 0;
}

Measured memory_bytes: 256
# https://beta.atcoder.jp/contests/arc070/submissions/2980516
from bisect import bisect_left

N, K = map(int, input().split())
A = sorted(map(int, input().split()))
A = A[:bisect_left(A, K)]
dp = [False] * K
dp[0] = True
curr_max = 0
ans = len(A)
for i, a in reversed(list(enumerate(A))):
    # a[i - 1]を使ってa[i]が必要ならa[i - 1]も必要
    # a[i]より大きな値を使って判定すればいい
    if curr_max + a >= K:
        ans = i

    f = True
    for j in range(min(curr_max, K - a - 1), -1, -1):
        if dp[j]:
            dp[j + a] = True
            if f:
                curr_max = max(curr_max, j + a)
                f = False
print(ans)

Measured memory_bytes: 42732
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	string S;
	cin >> N;
	cin >> S;
	vector<int> e(N),w(N);
	for(int i=0;i<N;i++){
		if(S[i]=='E')e[i]++;
		else w[i]++;
	}
	for(int i=1;i<N;i++){
		e[i] += e[i-1];
		w[i] += w[i-1];
	}
	// i 番目の人をリーダーとした場合
	int ans = N;
	for(int i=0;i<N;i++){
		int t = 0;
		//iより左のWの数を数える
		//iより右のEの数を数える
		t += ((i-1>=0)?w[i-1]:0);
		t += e[N-1] - e[i];
		ans = min(ans,t);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2964
A = int(input())
B = int(input())

if ( A == 1 or A == 2 ) and ( B == 1 or B == 2) :
    print('3')
elif ( A == 1 or A == 3 ) and ( B == 1 or B == 3) :
    print('2')
elif ( A == 2 or A == 3 ) and ( B == 2 or B == 3) :
    print('1')


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n, t, l, b; cin >> n >> t >> l >> b, n;){
        vi loseTurn(n + 1);
        rep(i, l){
            int a; cin >> a;
            loseTurn[a] = true;
        }

        vi goBack(n + 1);
        rep(i, b){
            int a; cin >> a;
            goBack[a] = true;
        }

        vector< vector<double> > dp(t + 1, vector<double>(n + 1));
        dp[0][0] = 1.;
        double p = 1./6;

        rep(i, t){
            rep(j, n){
                if(dp[i][j] == 0.) continue;

                range(k, 1, 7){
                    int next = j + k;
                    if(n < next) next -= 2 * (next - n);

                    if(goBack[next]) next = 0;

                    if(!loseTurn[next]){
                        dp[i + 1][next] += dp[i][j] * p;
                    }
                    else{
                        if(i + 2 <= t){
                            dp[i + 2][next] += dp[i][j] * p;
                        }
                    }
                }
            }
        }

        double res = 0.;
        rep(i, t + 1){
            res += dp[i][n];
        }
        printf("%.6f\n", res);
    }

	return 0;
}

Measured memory_bytes: 1324
/*input
3
28 27 24

*/

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

int main() { 
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(auto i : a) {
		if(i & 1) continue;
		if(i % 3 == 0 or i % 5 == 0) continue;
		cout << "DENIED\n";
		return 0;
	}
	cout << "APPROVED\n";

	return 0; 
} 

Measured memory_bytes: 256
while line = gets
  a, b, c, d, e, f = line.split.map(&:to_f)
  x = (c * e - b * f) / (a * e - b * d)
  y = (a * f - c * d) / (a * e - b * d)
  puts format('%.3f', x.round(3) + 0) + "\s" + format('%.3f', y.round(3) + 0)
end

Measured memory_bytes: 8784
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;


int n,m;
int k;
int a;
int coun[100];
int main(){
	scanf("%d %d", &n, &m);
	for (int i=0;i<n;i++){
		scanf("%d", &k);
		for (int j=0;j<k;j++){
			scanf("%d", &a);
			coun[a]++;
		}
	}
	int res = 0;
	for (int i=0;i<=m;i++){
		if (coun[i] == n){
			res++;
		}
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 128
s,t,a,b,x,y=map(int,open(0).read().split())
if a*s+b*t==x*s+y*t:
  print('infinity')
  exit()
if a<x:a,b,x,y=x,y,a,b
if a*s+b*t>x*s+y*t:
  print(0)
  exit()
n=(a*s-x*s)/(x*s+y*t-(a*s+b*t))
m=int(n)
print(m*2+(n>m))

Measured memory_bytes: 3064
def main(n, t, c_t):
    cost = 10000

    for c, _t in c_t:
        if t >= _t:
            if c < cost:
                cost = c

    if cost == 10000:
        print('TLE')
        return

    print(cost)


if __name__ == "__main__":
    n, t = map(int, input().split(' '))
    c_t = list()
    for _ in range(n):
        c_t.append(map(int, input().split(' ')))

    main(n, t, c_t)


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}
 
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

void solve(int A, int B, int C, int D) {
	int L = (max(A, B) + min(A, B)) / (min(A, B) + 1);
	//dump(L);
	int lo = 0, hi = A + B + 1;
	while (hi - lo > 1) {
		int m = (lo + hi) / 2;
		int lb = max(0, (m - 1) / L);
		int ra = A - m, rb = B - lb;
		if (rb <= (ll)(ra + 1) * L) {
			lo = m;
		} else {
			hi = m;
		}
	}
	int la = lo, lb = max(0, (lo - 1) / L);

	string s;

	for (int i = C; i <= D; ++i) {
		if (la + lb >= i) {
			if (i % (L + 1) == 0) {
				s.pb('B');
			} else {
				s.pb('A');
			}
		} else {
			int i2 = A + B + 1 - i;
			if (i2 % (L + 1) == 0) {
				s.pb('A');
			} else {
				s.pb('B');
			}
		}
	}
	cout << s << endl;
}

int main() {
	int Q; cin >> Q;
	rep(tt, Q) {
		int A, B, C, D;
		cin >> A >> B >> C >> D;
		solve(A, B, C, D);
	}

	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

#define N 55

int ind[N], ma[N][N];

int main() {
    int n, m;
    while (scanf("%d%d", &n, &m) != EOF) {
        memset(ind, 0, sizeof(ind));
        memset(ma, 0, sizeof(ma));
        for (int i = 0; i < m; ++i) {
            int u, v; scanf("%d%d", &u, &v);
            //if (!ma[u][v]) {
                ind[u]++; ind[v]++;
                //ma[u][v] = ma[v][u] = 1;
           // }
        }
        for (int i = 1; i <= n; ++i) printf("%d\n", ind[i]);
    }
    return 0;
}


Measured memory_bytes: 256
from heapq import *

N, M = list(map(int, input().split()))
sushi = []
for _ in range(N):
    t, d = list(map(int, input().split()))
    sushi.append([t, d])
sushi.sort(key=lambda x: x[1], reverse=True)

num_sushi = {}
tmp = 0
f = [0] * (N+1)
h = []
for i in range(M):
    s = sushi[i]
    if s[0] in num_sushi:
        num_sushi[s[0]] += 1
    else:
        num_sushi[s[0]] = 1
    heappush(h, (s[1], s[0]))
    tmp += s[1]

f[len(num_sushi)] = tmp

for i in range(M, N):
    if sushi[i][0] in num_sushi:
        continue
    while len(h) > 0:
        s = heappop(h)
        if num_sushi[s[1]] >= 2:
            num_sushi[s[1]] -= 1
            heappush(h, (sushi[i][1], sushi[i][0]))
            num_sushi[sushi[i][0]] = 1
            f[len(num_sushi)] = f[len(num_sushi)-1] + sushi[i][1] - s[0]
            break

ans = 0
for i, g in enumerate(f):
    if g <= 0: continue
    if g + i*i > ans:
        ans = g + i*i
print(ans)


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
template <typename T>
ll SIZEOF(T a){return (ll)a.size();}
ll xlcm(ll a, ll b){return (a/__gcd(a, b))*b;}

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


const int N = 100005;


void SOLVE(){
    ll n, x, t;
    cin >> n >> x >> t;
    ll z = (n+x-1)/x;
    cout << z*t << '\n';
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif

    ll TC = 1;
    // cin >> TC;
    for(ll tc1=1; tc1<=TC; tc1++){
        // cout << "Case #" << tc1 << ": ";
        SOLVE();
    }
    printclock;
}

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

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

    int a[n];
    for(int i=0;i<n;i++){
        cin >> x;
        a[i] = x;
    }
    for(int i=n-1;i>=0;i--){
        cout << a[i];
        if(i!=0)cout << " ";
    }
    cout << endl;
}


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


void solve(long long X, long long K, long long D){
    X = abs(X);
    long long ans = X / D;
    if (ans >= K) {
        X -= D * K;
        cout << X << endl;
        return;
    }

    X -= D * ans;
    K -= ans;
    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long K;
    scanf("%lld",&K);
    long long D;
    scanf("%lld",&D);
    solve(X, K, D);
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
 int main() {
  int a, b;
   std::cin >> a >> b;

     if (a > b) {
      std::cout << "a > b" <<std::endl;
     } else if (a < b) {
      std::cout << "a < b" <<std::endl;
     } else if (a == b) {
      std::cout << "a == b" <<std::endl;
     }



 return 0;




}
 
      


Measured memory_bytes: 3084
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n, m;
	cin >> n >> m;
	cout << (n == m ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n; cin >> n;
	int ans=n*800;
	ans-=(n/15)*200;
	cout << ans << endl;
}


Measured memory_bytes: 3592
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

//abbreviations
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vector<int>>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int H, N;
    cin >> H >> N;
    vi A(N);
    rep(i, N)cin>>A[i];
    int sum=0;
    rep(i, N)sum += A[i];
    if(sum >= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
import java.lang.Math;
import java.lang.StringBuilder;
import java.util.regex.Pattern;

    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            
            int D = sc.nextInt();
            switch(25%D){
                case 0:
                    System.out.println("Christmas");
                    break;
                case 1:
                    System.out.println("Christmas Eve");
                    break;
                case 2:
                    System.out.println("Christmas Eve Eve");
                    break;
                case 3:
                    System.out.println("Christmas Eve Eve Eve");
                    break;
            }
        }
    }


Measured memory_bytes: 23636
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0 };
const int dy[] = { 1, 0, 0, -1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(ll base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(2);
	
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, nn;
	cin >> n;
	nn = n;
	int re, c = 0;
	while (n)
	{
		re = n % 10;
		n /= 10;
		c += re;
	}
	if (nn % c == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <stack>
using namespace std;

void Main() {
    // input
    string S;
    cin >> S;



    // translate
    bool isReverse = false;
    u_int32_t Q;
    cin >> Q;
    string front;
    string back;
    for (u_int32_t i = 0; i < Q; i++) {
        int T, F;
        char C;
        cin >> T;
        if (T == 1) {
            isReverse = !isReverse;
        } else if (T == 2) {
            cin >> F >> C;
            if (F == 1) {
                if (isReverse) {
                    back.push_back(C);
                } else {
                    front.push_back(C);
                }
            } else if (F == 2) {
                if (isReverse) {
                    front.push_back(C);
                } else {
                    back.push_back(C);
                }
            } else {
                cout << "Error" << endl;
            }

        } else {
            cout << "Error" << endl;
        }
    }



    // output
    if (!isReverse) {
        reverse(front.begin(), front.end());
        cout << front << S << back << endl;;
    } else {
        reverse(back.begin(), back.end());
        reverse(S.begin(), S.end());
        cout << back << S << front << endl;;
    }


}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a <= b && b<=c) {
    if (c-b == b-a) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  else if (a > b && b > c) {
    if (a-b == b-c) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  else cout << "NO" << endl;
}

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

int main() {
    ll n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    //mazu +
    // i ga guusuu -> r > 0 kisuu -> r < 0 ni suru
    ll r = 0;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        r += a[i];
        if (i % 2 == 0) {
            if (r <= 0) {
                sum += abs(1 - r);
                r = 1;
            }
        } else {
            if (r >= 0) {
                sum += abs(-1 - r);
                r = -1;
            }
        }
    }
    ll ans = sum;
    r = 0;
    sum = 0;
    for (int i = 0; i < n; ++i) {
        r += a[i];
        if (i % 2 != 0) {
            if (r <= 0) {
                sum += abs(1 - r);
                r = 1;
            }
        } else {
            if (r >= 0) {
                sum += abs(-1 - r);
                r = -1;
            }
        }
    }
    ans = min(sum , ans);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int culc(ll a)
{
  int res = 0;
  while (a) {
    res++;
    a /= 10;
  }
  return res;
}
    

int main()
{
  ll a = 1;
  ll n;
  cin >> n;
  int res;
  while (true) {
    res = culc(n/a);
    a++;
    while (a * a <= n && n % a) a++;
    if (a * a > n) break;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;

public class Main{	
	public static void main(String[] arts){
		Scanner sc = new Scanner(System.in);
		Set<String> set = new HashSet<String>();
		String command,str;
		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			command = sc.next();
			str = sc.next();
			if(command.equals("insert"))
				set.add(str);
			else{
				if(set.contains(str))
					System.out.println("yes");
				else
					System.out.println("no");
			}
		}
	}
}


Measured memory_bytes: 254116
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<algorithm>
 */
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)

int h, w;
bool c[50][50];
int cnt;
int reached[50][50];
void dfs(int y, int x) {
    rep3(i, -1, 2) rep3(j, -1, 2) {
        if ((i | j) == 0) continue;
        int ny = y + i;
        int nx = x + j;
        if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
        if (reached[ny][nx] == 1 || c[ny][nx] == 0) continue;
        reached[ny][nx] = 1;
        dfs(ny, nx);
    }
}
int main() {
    while (cin >> w && w) {
        cin >> h;
        fill_n(*reached, 50 * 50, 0);
        rep(i, h) rep(j, w) cin >> c[i][j];
        cnt = 0;
        rep(i, h) rep(j, w) {
            if (c[i][j] == 0 || reached[i][j] == 1) continue;
            reached[i][j] = 1;
            cnt++;
            dfs(i, j);
            // rep(k, h) { rep(l, w) cout << reached[k][l] << " "; cout << endl; }
        }
        out(cnt);
    }
}



Measured memory_bytes: 3268
n=int(input())
a = list(map(int,input().split()))

from collections import Counter

c = Counter(a)

cnt=0
for i in c.items():
    if i[0]==i[1]:
        continue
    elif i[0]>i[1]:
        cnt+=i[1]
    elif i[0]<i[1]:
        cnt+=(i[1]-i[0])

print(cnt)

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

using Edges=vector<int>;
using Graph=vector<Edges>;
using ll=long long;
const int INF=1e9;

void make_dist(int v,vector<int> &d,const Graph &g){
    d[v]=0;
    queue<int> que;
    que.push(v);
    while(!que.empty()){
        int ver=que.front(); que.pop();
        for(int i=0;i<g[ver].size();i++){
            int to=g[ver][i];
            if(d[ver]+1<d[to]){
                d[to]=d[ver]+1;
                que.push(to);
            }
        }
    }
}
int main(){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--,t--;
    Graph g(n);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<int> ds(n,INF);
    make_dist(s,ds,g);
    vector<int> dt(n,INF);
    make_dist(t,dt,g);

    map<int,ll> cnts;
    map<int,ll> cntt;
    for(int i=0;i<n;i++){
        cnts[ds[i]]++;
        cntt[dt[i]]++;
    }

    int dist=ds[t];
    ll res=0;
    for(auto &e:cnts){
        res+=e.second*cntt[dist-e.first-2];
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 10212
/////////////////////////   _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 5005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;
int a[N];

long long dp[N][N][2];
long long d[N][2];

int order[N];
vector <int> g[N];

void dfs(int v,int p){
    order[v] = 1;
    dp[v][0][0] = a[v];
    dp[v][0][1] = (a[v] > 0);
    for(int i=0;i<(int)g[v].size();i++){
        int to = g[v][i];
        if(to == p)continue;
        dfs(to , v);
        for(int j=0;j<order[v];j++){
            for(int h=0;h<order[to];h++){
                /// edge does not pick
                if(dp[to][h][0] < 0 || dp[to][h][1]){
                    d[j + h + 1][0] = min(d[j + h + 1][0] , dp[v][j][0]);
                    d[j + h + 1][1] |= dp[v][j][1];
                }
                /// edge pick
                d[j + h][0] = min(d[j + h][0] , dp[v][j][0] + dp[to][h][0]);
                d[j + h][1] |= (dp[v][j][1] & dp[to][h][1]);

            }
        }
        order[v] += order[to];
        for(int j=0;j<order[v];j++){
            dp[v][j][0] = d[j][0];
            dp[v][j][1] = d[j][1];
            ///
            d[j][0] = inf * 1ll * inf;
            d[j][1] = 0;
        }
    }
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<n;i++){
        int a , b;
        scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<=n;i++){
        d[i][0] = inf * 1ll * inf;
        d[i][1] = 0;
    }
    dfs(1 , -1);
    for(int i=0;i<n;i++){
        if(dp[1][i][0] < 0 || dp[1][i][1]){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 391296
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)

count = 0

for i in range (0, N-2):
    for j in range (i+1, N-1):
        for k in range (j+1, N):
            if L[i]!=L[j] and L[j]!=L[k] and L[i]+L[j] >L[k]:
                count+=1

print(count)

Measured memory_bytes: 9188
open System.Linq
open System.Text.RegularExpressions

let input() = stdin.ReadLine()
let inputs() = input().Split()

let YN b = printfn "%s" (if b then "Yes" else "No")
let print x = printfn "%A" x
let printS (s: string) = printfn "%s" s


let N = int (input())

[ 1 .. N ]
|> Seq.sumBy (fun x -> string(x).Length % 2)
|> print


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};


int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a.rbegin(),a.rend());
  
  int num=0;
  ll tyo=-1,tan=-1;

  for(int i=1;i<N;i++){
    if(a[i]==a[i-1]) num++;
    else num=0;
    if(num==1){
      if(tyo>=0) {
        tan=a[i];
        break;
      }else{
        tyo=a[i];
      }
    }
    if(num==3){
      tyo=a[i];
      tan=a[i];
      break;
    }

  }

  if(tan<0) cout<<0<<endl;
  else cout<<tyo*tan<<endl;

  return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int* heights = (int*)malloc(sizeof(int)*n);
    int* costs = (int*)malloc(sizeof(int)*n);
    for(int i=0;i<n;i++){
        cin>>heights[i];
    }
    costs[0] = 0;
    for(int i=1;i<n;i++){
        costs[i] = costs[i-1]+abs(heights[i]-heights[i-1]);
        for(int j=2;j<=k;j++){
            if(i-j < 0)break;
            else{
                costs[i] = min(costs[i],costs[i-j]+abs(heights[i]-heights[i-j]));
            }
        }
    }
    cout<<costs[n-1]<<'\n';
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
ll Min(ll a,ll b){return a<b?a:b;}
ll Abs(ll a){return a>0?a:-a;}
inline ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
ll n,k,a[100005],l,ans=9999999999999999;
int main()
{
	n=read();k=read();
	for(ll i=1;i<=n;i++) a[i]=read();
	l=n+1;
	a[l]=1;
	for(ll i=1;i<=n;i++) if(a[i]>=0){l=i;break;}
	if(n-l+1>=k) ans=a[l+k-1];
	for(ll i=l-1,r=n;i>=1;i--)
	{
		if(n-i+1<k) continue;
		if(l-i+(a[l]==0)==k)
		{
			ans=Min(ans,Abs(a[i]));
			break;
		}
		while(r-i+1>k) r--;
		//printf("%d %d %lld\n",i,r,a[r]+Abs(a[i])+Min(Abs(a[i]),a[r]));
		ans=Min(ans,a[r]+Abs(a[i])+Min(Abs(a[i]),a[r]));
	}
	printf("%lld",ans);
}

Measured memory_bytes: 896
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S, T;
    cin >> S >> T;
    REP(i, 3) {
        if (S[i] != T[2 - i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

public class Dice
{
	private int[] labels;
	public const int TOP = 0;
	public const int FRONT = 1;
	public const int RIGHT = 2;
	public const int LEFT = 3;
	public const int BACK = 4;
	public const int BOTTOM = 5;
	public Dice( int[] labels )
	{
		this.labels = labels;
	}
	public void roll( string cmds )
	{
		int t;
		for( int i=0; i<cmds.Length; i++ ) {
			if( 'E' == cmds[i] ) {
			t = this.labels[TOP];
				this.labels[TOP] = this.labels[LEFT];
				this.labels[LEFT] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[RIGHT];
				this.labels[RIGHT] = t;
			} else if( 'S' == cmds[i] ) {
				t = this.labels[TOP];
				this.labels[TOP] = this.labels[BACK];
				this.labels[BACK] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[FRONT];
				this.labels[FRONT] = t;
			} else if( 'W' == cmds[i] ) {
				t = this.labels[TOP];
				this.labels[TOP] = this.labels[RIGHT];
				this.labels[RIGHT] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[LEFT];
				this.labels[LEFT] = t;
			} else if( 'N' == cmds[i] ) {
				t = this.labels[TOP];
				this.labels[TOP] = this.labels[FRONT];
				this.labels[FRONT] = this.labels[BOTTOM];
				this.labels[BOTTOM] = this.labels[BACK];
				this.labels[BACK] = t;        
			}		
		}
	}
	public int getLabel( int face )
	{
		return this.labels[face];
	}
}

public class Test
{
	public static void Main( )
	{

		int[] labels = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
		string cmds = Console.ReadLine();
				
		Dice dice = new Dice( labels );
		dice.roll( cmds );
		
		Console.WriteLine( dice.getLabel( Dice.TOP ) );
	}
}

Measured memory_bytes: 9220
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

#define INF 1<<30

ll H, W, c[10][10];

int main()
{
    cin >> H >> W;
    for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cin >> c[i][j];

    int A[H][W];
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> A[i][j];

    // ll cc[10][10] = {};
    // for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cc[i][j] = INF;

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] < 0 or A[i][j] == 1) continue;
            ans += c[A[i][j]][1];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
a[4],b[4],m[16];main(n,i,j){for(;scanf("%d",&n),n;){for(;n--;printf("%d %d %d %d\n",m[0]-m[5]-m[10]-m[15],m[1]+m[4]-m[11]+m[14],m[2]+m[7]+m[8]-m[13],m[3]-m[6]+m[9]+m[12]))for(scanf("%d%d%d%d%d%d%d%d",a,a+1,a+2,a+3,b,b+1,b+2,b+3),i=0;i<4;i++)for(j=0;j<4;j++)m[i+j*4]=a[i]*b[j];}exit(0);}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4e2+7;
char s[N], t[N] = "keyence", ch[N];
int check(int n)
{
	if(n!=7)
	{
		return false;
	}
	for(int i = 0; i < 7; i++)
	{
		if(ch[i]!=t[i])
		{
			return false;
		}
	}
	return true;
}
int main()
{
	int n;
	scanf("%s", s);
	n = strlen(s);
	memcpy(ch, s, sizeof(s));
	if(check(n))
	{
		puts("YES");
		return 0;
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = i; j < n; j++)
		{
			int tot = 0;
			for(int k = 0; k < n; k++)
			{
				if(k<i||k>j)
				{
					ch[tot++] = s[k];
				}
			}
			if(check(tot))
			{
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
s = sys.stdin.readlines()

n, q = map(int, s[0].split())

tree = [[] for _ in range(n+1)]
for ab in s[1:n]:
    a, b = map(int, ab.split())
    tree[a].append(b)
    tree[b].append(a)

counter = [0] * (n+1)
for px in s[n:]:
    p, x = map(int, px.split())
    counter[p] += x

# pop, appendまたはQueueライブラリだと間に合わない
queue = deque([[0,1]])
while queue:
    parent, node = queue.popleft()
    for leaf in tree[node]:
        if leaf == parent:
            continue
        counter[leaf] += counter[node]
        queue.append([node, leaf])

print(*counter[1:])


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  string a, b, c; cin >> a >> b >> c;
  int ans = 0;
  REP(i, n) {
    if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
      ans += 2;
    } else if(a[i] == b[i] && b[i] == c[i]) {
      ans += 0;
    } else {
      ans += 1;
    }
  }
  cout << ans << endl;
}


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

const int N = 3e5 + 9;

long long sum[N], ans[N];
vector<int> g[N]; int a[N], sz[N];
inline long long nc2(long long n) {
	return n * (n + 1) / 2;
}
void dfs(int u, int p = 0) {
	sz[u] = 1;
	int c = a[u];
	long long tot = 0;
	for (auto v: g[u]) if (v != p) {
		long long last = sum[c];
		dfs(v, u);
		ans[c] += nc2(sz[v] - (sum[c] - last));
		tot += sum[c] - last;
		sz[u] += sz[v];
	}
	sum[c] -= tot; sum[c] += sz[u];
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    for (int i = 1; i <= n; i++) ans[i] += nc2(n - sum[i]);
   	for (int i = 1; i <= n; i++) ans[i] = nc2(n) - ans[i];
   	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 40304
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const ll mod=998244353;

int main()
{
    ll n,pre,ans=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        ll x;
        cin>>x;
        if(i==1)
            pre=x;
        if(x<=pre)
            ans+=(pre-x);
        else pre=x;
    }
    cout<<ans;
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<int>>;

int main(){
  int N; cin>>N;
  vector<int> A(N),B(N);
  map<pair<int,int>,int> Edge;
  Graph G(N+1);
  rep(i,N-1){
    cin>>A.at(i)>>B.at(i);
    Edge[make_pair(A.at(i),B.at(i))] = -1;
    Edge[make_pair(B.at(i),A.at(i))] = -1;
    G.at(A.at(i)).insert(B.at(i));
    G.at(B.at(i)).insert(A.at(i));
  }

  int Colors = 1;
  rep1(i,N+1)Colors = max(Colors,(int)G.at(i).size());
  cout<<Colors<<endl;

  vector<bool> seen(N+1,false);
  queue<int> Q;
  Q.push(1);
  map<int,int> par;
  while(!Q.empty()){
    int v = Q.front();
    Q.pop();
    seen.at(v)=true;
    queue<int> CV;
    int banned_num = -1;
    if(v!=1){
      banned_num = Edge[make_pair(v,par[v])];
    }
    rep1(i,(int)G.at(v).size()+1){
      if(i!=banned_num)CV.push(i);
    }
    for(auto nv: G.at(v)){
      if(seen.at(nv))continue;
      int edge_color = CV.front();
      CV.pop();
      Edge[make_pair(v,nv)]=edge_color;
      Edge[make_pair(nv,v)]=edge_color;
      par[nv]=v;
      Q.push(nv);
    }
  }
  rep(i,N-1)cout<<Edge[make_pair(A.at(i),B.at(i))]<<endl;
}


Measured memory_bytes: 32512