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

namespace from_ecnerwala {

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;
}
using namespace from_ecnerwala;

const int MAXN = 5010;
int N;
vector<int> adj[MAXN];

num dp[MAXN][MAXN];
num tmp[MAXN];
int sz[MAXN];

void dfs(int cur = 1, int prv = 0) {
	if (prv) {
		adj[cur].erase(find(adj[cur].begin(), adj[cur].end(), prv));
	}

	sz[cur] = 1;
	dp[cur][1] = 1;
	for (int nxt : adj[cur]) {
		dfs(nxt, cur);

		fill_n(tmp, sz[cur] + sz[nxt] + 1, 0);
		for (int i = 0; i <= sz[cur]; i++) {
			for (int j = 0; j <= sz[nxt]; j++) {
				tmp[i+j] += dp[cur][i] * dp[nxt][j];
			}
		}
		sz[cur] += sz[nxt];
		copy_n(tmp, sz[cur] + 1, dp[cur]);
	}

	// don't use parent edge
	num coef = -1;
	for (int i = 2; i <= sz[cur]; i += 2) {
		coef *= (i-1);
		dp[cur][0] += coef * dp[cur][i];
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	dfs();

	cout << -dp[1][0] << endl;

	return 0;
}


Measured memory_bytes: 99072
let to_list str =
  let rec doit i acc =
    if i < 0 then acc
    else doit (i - 1) (str.[i] :: acc)
  in doit (String.length str - 1) []

let calc_area lst =
  let doit (i, idxs, acc) = function
    | '_' -> (i + 1, idxs, acc)
    | '\\' -> (i + 1, i :: idxs, acc)
    | '/' ->
        begin match idxs with
        | [] -> (i + 1, idxs, acc)
        | j :: js -> (i + 1, js, ((j, i), i - j) :: acc)
        end
    | _ -> exit 1
  in
  List.fold_left doit (0, [], []) lst
  |> fun (_, _, t) -> t

let integrale lst =
  let rec doit acc = function
    | [] -> acc
    | [e] -> e :: acc
    | (((j1, i1), area1) as xs) :: ((((j2, i2), area2) :: tl) as ys) ->
        if j1 < j2 && i1 > i2 then doit acc (((j1, i1), area1 + area2) :: tl)
        else doit (xs :: acc) ys
  in doit [] lst

let () =
  let areas = integrale (calc_area (to_list (read_line ()))) in
  Printf.printf "%d\n" (List.fold_left (fun acc (_, n) -> acc + n) 0 areas);
  Printf.printf "%d" (List.length areas);
  List.iter (fun (_, n) -> Printf.printf " %d" n) areas;
  print_newline ()

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    int e=c-a,f=d-b;
    vector<vector<ll>> dp(e+1,vector<ll>(f+1,0));
    dp[0][0]=1;
    rep(i,e){
        ll r=0,rr=0;
        rep(j,f+1){
            ll u=b+j;
            dp[i+1][j]=(r+dp[i][j]*u%MOD)%MOD;
            r=(r+dp[i][j])%MOD;
            ll uu=a+i;
            r=r*uu%MOD;
        }
    }
    ll ans=0,h=1;
    rep(i,f+1){
        ans=(ans+dp[e][f-i]*h%MOD)%MOD;
        // cout << dp[e][f-i]*h%MOD << endl;
        h=h*c%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 73604
H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
elif H % 2 == 0:
    print(H*W//2)
else:
    if W % 2 == 0:
        print(H*W//2)
    else:
        print((H//2)*(W//2) + (H//2+1)*(W//2+1))

Measured memory_bytes: 38256
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var list = new List<List<int>>();
        for (int i = 0; i < nm[1]; i++)
        {
            var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            list.Add(line.ToList());
        }
        var hash = new int[nm[1]];
        for (int i = 0; i < nm[1]; i++)
        {
            for (int j = 1; j < list[i].Count(); j++)
            {
                hash[i] += (int)Math.Pow(2, list[i][j] - 1);
            }
        }
        var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int ans = 0;
        for (int i = 0; i < Math.Pow(2, nm[0]); i++)
        {
            for (int j = 0; j < nm[1]; j++)
            {
                var temp = i & hash[j];
                var cnt = 0;
                for (int k = 0; k < nm[0]; k++)
                {
                    if ((temp >> k & 1) == 1) cnt++;
                }
                if (cnt % 2 != p[j]) break;
                if (j == nm[1] - 1) ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

typedef unsigned long long ull;

int n;

#define TUPLE(a,b,c,d) (a | (b<<16) | ((ull)c<<32) | ((ull)d<<48))
#define UNPACK(t,a,b,c,d) int a=((t)&65535),b=(((t)>>16)&65535),c=(((t)>>32)&65535),d=(((t)>>48)&65535)

ull normalize(int a,int b,int c,int d){
  ull r = TUPLE(a,b,c,d);
  REP(_,3){
    swap(a,b);
    swap(b,c);
    swap(c,d);
    CHMIN(r,TUPLE(a,b,c,d));
  }
  return r;
}
ull normalize(ull s){
  UNPACK(s,a,b,c,d);
  return normalize(a,b,c,d);
}
void debunpack(string po,ull s){
  UNPACK(s,a,b,c,d);
  printf("%s%5d%5d%5d%5d\n",po.c_str(),a,b,c,d);
}

int main(){
  // cube, [count,multiply]
  unordered_map<ull,pii> mp;
  scanf("%d",&n);
  REP(i,n){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    set<ull> S;
    S.insert(TUPLE(a,b,c,d));
    REP(_,3){
      swap(a,b);
      swap(b,c);
      swap(c,d);
      S.insert(TUPLE(a,b,c,d));
    }
    ull s = *S.begin();
    mp[s].first += 1;
    mp[s].second = 4/S.size();
  }
  ull ans = 0;
  for(auto& _s1:mp){
    ull s1 = _s1.first;
    ull u = _s1.second.first;
    _s1.second.first--;
    UNPACK(s1,a,b,c,d);
    for(auto& _s2:mp){
      ull s2 = _s2.first;
      ull v = u * _s2.second.first;
      _s2.second.first--;
      UNPACK(s2,h,g,f,e);
      REP(_,4){
        ull add = v;
        ull s3 = normalize(b,a,e,f);
        ull s4 = normalize(c,b,f,g);
        ull s5 = normalize(d,c,g,h);
        ull s6 = normalize(a,d,h,e);
        bool ok = mp.count(s3) && mp.count(s4) && mp.count(s5) && mp.count(s6);
        if(ok){
          add *= mp[s3].first * mp[s3].second;  mp[s3].first--;
          add *= mp[s4].first * mp[s4].second;  mp[s4].first--;
          add *= mp[s5].first * mp[s5].second;  mp[s5].first--;
          add *= mp[s6].first * mp[s6].second;  mp[s6].first--;
        }else{
          add = 0;
        }
        ans += add;
        if(ok){
          mp[s3].first++;
          mp[s4].first++;
          mp[s5].first++;
          mp[s6].first++;
        }
        swap(e,f);
        swap(f,g);
        swap(g,h);
      }
      _s2.second.first++;
    }
    _s1.second.first++;
  }
  printf("%llu\n",ans/6);
  return 0;
}


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

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<int>A(N+1),B(N);
	for(int i=0;i<N+1;i++){
			cin>>A[i];
	}
	for(int i=0;i<N;i++){
			cin>>B[i];
	}
	long long int ans=0;
	for(int i=0;i<N;i++){
		if(A[i]>B[i]){
				ans+=B[i];
				continue;
		}else{
				ans+=A[i];
				B[i]-=A[i];
				if(A[i+1]<B[i]){
						ans+=A[i+1];
						A[i+1]=0;
				}else{
						ans+=B[i];
						A[i+1]-=B[i];
				}
		}
	}
	cout<<ans<<endl;

	return 0;
}



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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(12);
    string s;
    cin >> s;
    ll c = 0;
    rep(i, s.size()/2){
        if(s[i] != s[s.size()-i-1]){
            c++;
        }
    }

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int max(int,int);

int main(void)
{
	int i,j,N,T,S,A[3000],B[3000],dp[2][3001];
	
    scanf("%d%d%d",&N,&T,&S);
	for(i=0;i<=N-1;i++) scanf("%d%d",&A[i],&B[i]);
	for(i=0;i<=N;i++)
	{
	    for(j=0;j<=T;j++)
		{
			dp[0][j]=0;
		}
	}
	for(i=1;i<=N;i++)
	{
		for(j=1;j<=T;j++)
		{
				if(j<=S)
				{
			        if(B[i-1]<=j) dp[1][j]=max(dp[0][j],dp[0][j-B[i-1]]+A[i-1]);
			        else dp[1][j]=dp[0][j];
				}
				else
				{
					if(B[i-1]<=j && j-B[i-1]>=S)  dp[1][j]=max(dp[0][j],dp[0][j-B[i-1]]+A[i-1]);
					else dp[1][j]=max(dp[0][j],dp[1][j-1]);
				}
		}
		for(j=0;j<=T;j++) dp[0][j]=dp[1][j];
	}
	printf("%d\n",dp[1][T]);
	return 0;
}

int max(int a, int b)
{
	if(a>b) return a;
	else return b;
}

Measured memory_bytes: 648
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    string N;
    cin>>N;

    if(N[0]!='7'&&N[1]!='7'&&N[2]!='7'){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }


}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

const LL INF = 1e17;
const int N = 300;
vector<pair<int, int>> adj[N];
int ans[N][N];
LL dis[N][N];

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

	int n, m; LL l; cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dis[i][j] = INF;
		}
		dis[i][i] = 0;
	}
	for (int i = 0; i < m; i++) {
		int u, v, w; cin >> u >> v >> w;
		adj[u - 1].emplace_back(v - 1, w);
		adj[v - 1].emplace_back(u - 1, w);
		dis[u - 1][v - 1] = dis[v - 1][u - 1] = w;
	}
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}

	for (int s = 0; s < n; s++) {
		vector<int> jmp(n, 1e9);
		queue<int> Q;
		Q.push(s); jmp[s] = 0;
		while (!Q.empty()) {
			int u = Q.front(); Q.pop();
			for (int v = 0; v < n; v++) {
				if (dis[u][v] <= l && jmp[v] > jmp[u] + 1) {
					jmp[v] = jmp[u] + 1;
					Q.push(v);
				}
			}
		}
		for (int u = 0; u < n; u++) {
			ans[s][u] = jmp[u];
		}
	}
	

	int q; cin >> q;
	while (q--) {
		int s, t; cin >> s >> t;
		LL d = ans[s - 1][t - 1];
		if (d > n) d = -1;
		else d--;
		cout << d << '\n';
	}

	return 0;
}


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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#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 SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n, x;
    cin >> n >> x;
    VI a(n);
    REP(i, n) {
        cin >> a[i];
    }

    VI t(n, 0), b = a;
    int ans = LLONG_MAX;
    REP(k, n) {
        REP(i, n) {
            int j = (i - k < 0 ? n + i - k : i - k);
            if (b[i] > a[j]) {
                b[i] = a[j];
                t[i] = k;
            }
        }


        int maxt = 0, sumb = 0;
        REP(i, n) {
            maxt = max(maxt, t[i]);
            sumb += b[i];
        }
        ans = min(ans,maxt * x + sumb);
    }

    cout << ans << ENDL;

    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int x,a;
	cin>>x>>a;
	if(x<a)
	{
		cout<<"0";
	}
	else
	{
		cout<<"10";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1000000;
const int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  COMinit();
  long N,A,B,K;cin>>N>>A>>B>>K;
  long ans=0;
  for(long a=0;a<=N;a++){
    if((K-a*A)%B==0){
      long b=(K-a*A)/B;
      if(0<=b&&b<=N)ans=(ans+COM(N,a)*COM(N,b))%MOD;
    }
  }
  cout<<ans;
}

/*
aA+bB=K
a,b=0~N

NCa*NCb

*/

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

int main() {
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int v1=x2-x1, v2=y2-y1;
	int x3=x2-v2, y3=y2+v1;
	int x4=x1-v2, y4=y1+v1;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	ll c = a + b;

	ll d = (n / c) * a;
	ll e = n % c;

	e = (e <= a) ? e : a;
	println(d + e);
}


Measured memory_bytes: 256
class Node():
    def __init__(self):
        self.parent = -1
        self.left = -1
        self.right = -1


def preorder(id):
    print(" {}".format(id), end="")

    if Nodes[id].left != -1:
        preorder(Nodes[id].left)
    if Nodes[id].right != -1:
        preorder(Nodes[id].right)


def inorder(id):
    if Nodes[id].left != -1:
        inorder(Nodes[id].left)

    print(" {}".format(id), end="")

    if Nodes[id].right != -1:
        inorder(Nodes[id].right)


def postorder(id):
    if Nodes[id].left != -1:
        postorder(Nodes[id].left)

    if Nodes[id].right != -1:
        postorder(Nodes[id].right)

    print(" {}".format(id), end="")


def main():
    n = int(input())
    global Nodes
    Nodes = [Node() for i in range(n)]

    for i in range(n):
        id, *children = map(int, input().split())
        left = children[0]
        right = children[1]
        Nodes[id].left = left
        Nodes[id].right = right
        for child in children:
            if child != -1:
                Nodes[child].parent = id

    rootid = ""
    for i, node in enumerate(Nodes):
        if node.parent == -1:
            rootid = i

    print("Preorder")
    preorder(rootid)
    print()

    print("Inorder")
    inorder(rootid)
    print()

    print("Postorder")
    postorder(rootid)
    print()


if __name__ == '__main__':
    main()



Measured memory_bytes: 5616
N, T = map(int, input().split())
c = [0 for i in range(0,N)]
t = [0 for i in range(0,N)]
for i in range(0,N):
    c[i], t[i] = map(int, input().split())

r = min(t)
if r > T:
    print("TLE")
    exit()
else:
    m = max(c)
    for i in range(0,N):
        if t[i] <= T:
            if m > c[i]:
                m = c[i]
print(m)

Measured memory_bytes: 38384
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

vector <int> conn[100050];
vector <int> son[100050];
bool dchk[100050];
void DFS1(int n) {
	dchk[n] = true;
	for (auto it : conn[n]) {
		if (dchk[it]) continue;
		son[n].push_back(it);
		DFS1(it);
	}
}

int N;
int tus;
int dp[100050][2];
vector <int> Vu[100050];
void DFS2(int n) {
	dp[n][0] = 0;
	dp[n][1] = 0;
	Vu[n].clear();
	for (auto it : son[n]) {
		DFS2(it);
		dp[n][0] += dp[it][0];
		if (dp[it][1] >= tus) {
			dp[n][0]++;
			Vu[n].push_back(1);
		}
		else Vu[n].push_back(dp[it][1]);
	}
	sort(all(Vu[n]));

	int st = 1, en = Vu[n].size() / 2, mi, rv = 0, i;
	while (st <= en) {
		mi = (st + en) / 2;
		for (i = 0; i < mi; i++) if (Vu[n][i] + Vu[n][2 * mi - 1 - i] + 1 > tus) break;
		if (i >= mi) {
			rv = mi;
			st = mi + 1;
		}
		else en = mi - 1;
	}
	dp[n][0] += Vu[n].size() - rv;
	if (rv * 2 == Vu[n].size()) {
		dp[n][1] = 1;
		return;
	}

	dp[n][0]--;
	int st2 = 0, en2 = 2 * rv - 1, mi2, rv2 = 2 * rv;
	while (st2 <= en2) {
		mi2 = (st2 + en2) / 2;
		for (i = 0; i < rv; i++) {
			int t1 = i, t2 = 2 * rv - i - 1;
			if (t1 >= mi2) t1++;
			if (t2 >= mi2) t2++;
			if (Vu[n][t1] + Vu[n][t2] + 1 > tus) break;
		}
		if (i >= rv) {
			rv2 = mi2;
			en2 = mi2 - 1;
		}
		else st2 = mi2 + 1;
	}
	dp[n][1] = 1 + Vu[n][rv2];
}
int getv(int x) {
	tus = x;
	DFS2(1);
	return dp[1][0] + !!(dp[1][1] - 1);
}
int main() {
	int i;
	scanf("%d", &N);
	for (i = 1; i < N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		conn[t1].push_back(t2);
		conn[t2].push_back(t1);
	}
	DFS1(1);

	int st = 2, en = N-1, mi, rv = N;
	while (st <= en) {
		mi = (st + en) / 2;
		if (getv(mi) == getv(rv)) {
			rv = mi;
			en = mi - 1;
		}
		else st = mi + 1;
	}
	printf("%d %d\n", getv(rv), rv - 1);
	return 0;
}

Measured memory_bytes: 25472
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  map<int ,int> cnt;
  string ans = "YES";
  rep(i,n){
    if(cnt[a.at(i)] == 0) {
      cnt[a.at(i)] = 1;
    }else{
      ans = "NO";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
use text_io::*;
use std::cmp::*;

fn main() {
    let a: i32 = read!();
    let b: i32 = read!();
    let c: i32 = read!();
    let d: u32 = read!();
    let e: i32 = max(a,max(b,c));
    println!("{}",a+b+c-e+e*2_i32.pow(d))
}

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

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

    int n;
    cin >> n;
    if ( (n % 1000) == 0 ){
        cout << 0 << '\n';
    }else{
        cout << 1000 - (n%1000) << '\n';
    }
    return 0;
}

Measured memory_bytes: 3644
s = [0,0,0]
n,s[0],s[1],s[2] = map(int,input().split())
T = [0]*n
ABC = 'ABC'
for i in range(n):
    t = input()
    if t == 'AB':T[i] = 2
    if t == 'BC':T[i] = 0
    if t == 'AC':T[i] = 1
ans = ['' for _ in range(n)]
# if s.count(0) <= 1 and sum(s) >= 3:
#     for i,t in enumerate(T):
#         nxt = [0,1,2]
#         nxt.remove(t)
#         if s[nxt[0]] < s[nxt[1]]:
#             ans[i] = ABC[nxt[0]]
#             s[nxt[0]] += 1
#             s[nxt[1]] -= 1
#         else:
#             ans[i] = ABC[nxt[1]]
#             s[nxt[0]] -= 1
#             s[nxt[1]] += 1
#     print('Yes')
#     print('\n'.join(ans))
if sum(s) == 2:
    if s.count(0) == 1:
        now = s.index(0)
        i = 0
    else:
        if T[0] != s.index(2):
            now = T[0]
            i = 1
            nxt = [0,1,2]
            nxt.remove(T[0])
            nxt.remove(s.index(2))
            ans[0] = ABC[nxt[0]]
        else:
            print('No')
            exit(0)
    while i < n-1:
        if T[i] == T[i+1]:
            if T[i] == now:
                ans[i] = ABC[(now-1)%3]
                ans[i+1] = ABC[(now-2)%3]
            else:
                for j in range(3):
                    if j not in [T[i],now]:
                        ans[i+1] = ABC[j]
                ans[i] = ABC[now]
            i += 2
        elif T[i] == now:
            for j in range(3):
                if j not in [T[i+1],now]:ans[i] = ABC[j]
            ans[i+1] = ABC[T[i]]
            now = T[i+1]
            i += 2
        else:
            ans[i] = ABC[now]
            for j in range(3):
                if j not in [T[i],now]:
                    now = j
                    break
            i += 1
    if i == n-1:
        if T[i] == now:
            for j in range(3):
                if j not in [now,T[i]]:ans[i] = ABC[j]
        else:
            ans[i] = ABC[now]
    print('Yes')
    print('\n'.join(ans))
else:
    for i,t in enumerate(T):
        nxt = [0,1,2]
        nxt.remove(t)
        if s[nxt[0]] < s[nxt[1]]:
            ans[i] = ABC[nxt[0]]
            s[nxt[0]] += 1
            s[nxt[1]] -= 1
        else:
            ans[i] = ABC[nxt[1]]
            s[nxt[0]] -= 1
            s[nxt[1]] += 1
        if -1 in s:
            print('No')
            break
    else:
        print('Yes')
        print('\n'.join(ans))


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

const int N=3e5+5;
struct Edge{int to,nxt,dir;}e[N*4];
int n,rt1,rt2,deg[N],head[N],id[N],cntE=1;

inline void add(int u,int v) {e[++cntE]=(Edge){v,head[u],-1},head[u]=cntE,++deg[v];}

void Euler(int u)
{
    for(int &i=head[u];i;i=e[i].nxt)
    {
        if(~e[i].dir) continue;
        e[i].dir=1,e[i^1].dir=0,Euler(e[i].to);
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=1,x;i<=n;++i)
    {
        scanf("%d",&x);
        if(x==-1) rt1=i;
        else add(x,i),add(i,x);
    }
    for(int i=1,x;i<=n;++i)
    {
        scanf("%d",&x);
        if(x==-1) rt2=i+n+1;
        else add(x+n+1,i+n+1),add(i+n+1,x+n+1);
    }
    add(n+1,rt1),add(rt1,n+1),add(n+1,rt2),add(rt2,n+1);
    for(int i=1;i<=n;++i)
        if((deg[i]&1)!=(deg[i+n+1]&1))
            return puts("IMPOSSIBLE"),0;
    puts("POSSIBLE");
    for(int i=1;i<=n;++i)
        if(deg[i]&1) add(i,i+n+1),add(i+n+1,i),id[i]=cntE-1;
    for(int i=1;i<=2*n+1;++i) while(head[i]) Euler(i);
    for(int i=1;i<=n;++i)
        if(id[i]) printf(e[id[i]].dir?"1 ":"-1 ");
        else printf("0 ");
    return 0;
}

Measured memory_bytes: 22048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}

ll const mod =1e9+7;
int main() {
  int n;
  cin >> n;
  string s;
  cin >>s;
  map<char,int> c0,c1;
  for (auto i:s) c0[i]++;
  rep(i,n-1) {
    cin >> s;
    c1.clear();
    for (auto i:s) c1[i]++;
    for (auto i:"abcdefghijklmnopqrstuvwxyz") {
      chmin(c0[i],c1[i]);
    }
  }
  for (auto itr=c0.begin();itr!=c0.end();itr++) {
    cout << string(itr->second,itr->first);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
ll a,b,c;
cin>>a>>b>>c;
ll d=0;
string ans = "NO";
for(int i=0;i<256;i++){
if(d%b==c)ans="YES";
d+=a;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int tmp = N % 2;
    int tmp2 = N/2;
    if (tmp == 0)
    {
        cout << "0.5" << endl;
    }
    else
    {
        cout << setprecision(6) << (tmp2 + 1.0) / N << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7 ;

int mul (int a, int b) {
    return 1LL * a * b % mod ;
}
void minun (int &a, int b) {
    if ((a -= b) < 0) a += mod ;
}

int power (int a, int b ) {
    int res = 1;
    for (; b > 0 ; b >>= 1 , a = mul(a, a))
        if (b & 1) res = mul(res, a);
    return res;
}
int c (int n, int b) {
    int fac = 1;
    for (int i = 1 ; i <= b ; i ++)
        fac = mul (fac, i);
    fac = power(fac, mod - 2) ;
    int res = 1;
    for (int j = 0 ; j < b ; ++ j)
        res = mul(res, n - j);
    return mul(res, fac);
}

int main () {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = power(2, n);
    minun(ans, c(n, a));
    minun(ans, c(n, b));
    minun(ans, 1);
    cout  << ans << endl ;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)

def find(idx, c, arr, tb):

    if c == 0:
        return 0

    if idx <= 0 or idx < 2 * c - 1:
        return float('-inf')

    if (idx, c) in tb:
        return tb[(idx, c)]

    rs = find(idx - 2, c - 1, arr, tb) + arr[idx - 1]
    rs = max(rs, find(idx - 1, c, arr, tb))

    tb[(idx, c)] = rs
    return rs

def main():

    n = int(input())
    arr = [int(e) for e in input().split(' ')]
    print(find(n, n // 2, arr, {}))
    return 0


main()


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

int main() {
	int n;
	cin >> n;
	bool puni[n][5][2];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) {
			for (int k = 0; k < 2; k++) {
				cin >> puni[i][j][k];
			}
		}
	}
	int p[n][11];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			cin >> p[i][j];
		}
	}
	int ans = numeric_limits<int>::min();
	for (int t = 1; t < (1 << 10); t++) {
		int tmp = 0;
		for (int i = 0; i < n; i++) {
			int c = 0;
			for (int j = 0; j < 5; j++) {
				for (int k = 0; k < 2; k++) {
					if (((t >> (2 * j + k)) & 1) && puni[i][j][k]) {
						c++;
					}
				}
			}
			tmp += p[i][c];
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: i128,
        a: [i128; n as usize],
        b: [i128; m as usize],
    }

    solve(n, m, k, &a, &b);
}

fn solve(n: usize, m: usize, k: i128, a: &[i128], b: &[i128]) {
    let mut x: Vec<i128> = vec![0; n + 1];
    for i in 0..n {
        x[i + 1] = x[i] + a[i];
    }

    let mut y: Vec<i128> = vec![0; m + 1];
    for i in 0..m {
        y[i + 1] = y[i] + b[i];
    }

    let mut ans = 0;
    let mut j = m;
    for i in 0..(n + 1) {
        if x[i] > k {
            break;
        }
        while x[i] + y[j] > k {
            j -= 1;
        }
        ans = std::cmp::max(ans, i + j);
    }

    println!("{}", ans);
}


Measured memory_bytes: 18780
#-*- using:utf-8 -*-

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

money = 1000
kabu = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        #買い
        tmp = money // A[i]
        money = money - tmp*A[i]
        kabu = kabu+tmp
        #売り
        money = money + kabu*A[i+1]
        kabu = 0
print(money)

Measured memory_bytes: 9188
def insertSort(a):
    for i in range(len(a)):
        v = a[i]
        j = i - 1

        while j >= 0 and a[j] > v:
            a[j + 1] = a[j]
            j -= 1

        a[j + 1] = v

        print(" ".join([str(x) for x in a]))

if __name__ == '__main__':

    n = int(input())
    a = [int(x) for x in input().split()]

    insertSort(a)


Measured memory_bytes: 5612
keta = ["", "Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]

while True:
    m,n = [int(i) for i in input().split()]
    if m == 0 and n == 0:
        break
    
    num = m**n
    
    index = 0
    ans = [0] * 18

    while num > 0:
        ans[index] = num % 10000
        num = num // 10000
        index = index + 1
        
    index = 17
    while index >= 0:
        if(ans[index] > 0):
            print(ans[index], end="")
            print(keta[index], end="")
        index = index - 1
    print("")
    


Measured memory_bytes: 5600
#include<iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
int main(){
  int A, B, M;cin >> A >> B >> M;
  int a[A], b[B];
  int mina = INF,minb = INF;
  rep(i, A){cin >> a[i];mina = min(mina, a[i]);}
  rep(i, B){cin >> b[i];minb = min(minb, b[i]);}
  int minValue = mina + minb,x,y,c;
  rep(i, M){cin >> x >> y >> c;minValue = min(a[x-1]+b[y-1]-c,minValue);}
  cout << minValue;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int n = str.length();
    for(int i = 0; i<n/2; i++){
      char a = str.charAt(i);
      char b = str.charAt(n-1-i);
      if(a != b){
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}


Measured memory_bytes: 23764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,m; cin>>n>>m;
    vector<ll> x(m,0),dx(m-1,0);
    rep(i,m) cin>>x[i];
    if(n>=m) cout<<0<<endl;
    else{
        sort(al(x));
        rep(i,m-1) dx[i]=x[i+1]-x[i];
        sort(al(dx));
        ll ans=0;
        rep(i,m-n) ans+=dx[i];
        cout<<ans<<endl;
    }
}


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

int main(){
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll mn = min({a, b, c, d, e});

    cout << (n + mn - 1) / mn + 4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ARRAY_LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
using namespace std;
int main(void){
  std::string s;
  std::string t;
  cin >> s;
  cin >> t;
  bool flg;
  flg = true;
  int stot[26];
  int ttos[26];
  REP(i,26){
     stot[i] = -1;
     ttos[i] = -1;
  }
  REP(i,s.length()){
    int x,y;
    x = (unsigned char)s[i] - 97;
    y = (unsigned char)t[i] - 97;
    if(stot[x] < 0){
      stot[x] = y;
    }
    else if(stot[x] != y){
      flg = false;
    }

    if(ttos[y] < 0){
      ttos[y] = x;
    }
    else if(ttos[y] != x){
      flg = false;
    }

  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 776
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int main() {
  unsigned long long A;
  // double B;
  unsigned long long ba, bb;
  // cin >> A;

  scanf("%lld %lld.%lld", &A, &ba, &bb);

  
  // unsigned long long cB = B * 100;
  // // cout << cB << endl;
  // 
  // unsigned long long bresult = A * cB;
  // 
  // cout << bresult << endl;
  // 
  // unsigned long long result = bresult / 100;
  
  unsigned long long result = (A * ba * 100 + A * bb) / 100;

  cout << fixed << result << endl;

  // cout << fixed << (unsigned long long) floor(A * B) << endl;
  return 0;
}


Measured memory_bytes: 3256
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll d, c[26], s[365][26];
  cin >> d;
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < d; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < d; i++) {
    cout << i % 26 + 1 << endl;
  }
}

Measured memory_bytes: 3648
def check(a,b,c,d)
  if (a==0 && c==2 && d==1) \
    || (a==0 && b==2 && d==1) \
    || (b==2 && c==0 && d==1) \
    || (b==0 && c==1 && d==2) \
    || (b==0 && c==2 && d==1)
    return false
  else
    return true
  end
end

MOD = 10**9+7
N = gets.to_i
cnt=Array.new(N+1){Array.new(4){Array.new(4){Array.new(4){Array.new(4,0)}}}}
# A:0 C:1 G:2 T:3
4.times do |i|
  4.times do |j|
    4.times do |k|
      cnt[3][3][i][j][k] = 1
    end
  end
end
cnt[3][3][0][2][1] = 0
cnt[3][3][0][1][2] = 0
cnt[3][3][2][0][1] = 0

4.upto(N) do |n|
  4.times do |i|
    4.times do |j|
      4.times do |k|
        4.times do |l|
          if check(i,j,k,l)
            4.times do |m|
              cnt[n][i][j][k][l] += cnt[n-1][m][i][j][k]
              cnt[n][i][j][k][l] %= MOD
            end
          end
        end
      end
    end
  end
end

ans = 0
4.times do |i|
  4.times do |j|
    4.times do |k|
      4.times do |l|
        ans += cnt[N][i][j][k][l]
        ans %= MOD
      end
    end
  end
end
p ans

Measured memory_bytes: 2300
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var d = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

            var total = 0;
            for(var i = 0; i < n-1; i++){
                for(var j = i+1; j < n; j++){
                    var x = d[i];
                    var y = d[j];
                    total += (x * y);
                }
            }

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i=a; i<b; i++)
typedef long long ll;
#define SML(a, b) ((a)=min((a),(b)))
#define LAR(a, b) ((a)=max((a),(b)))
#ifdef LOCAL
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n, k, x, y;
	scanf("%d%d%d%d", &n, &k, &x, &y);
	if(n<=k){
		printf("%d\n", n*x);
	}else{
		printf("%d\n", k*x+(n-k)*y);
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
int main(int argc, char const *argv[]) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll c = n / (a + b) * a;
  if ((n % (a + b)) > a)
    c += a;
  else
    c += n % (a + b);
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 4  ;
const int MAXN = 1000*100 + 5 ;
const int INF = INT_MAX ;
int main ( ){
fast_io();


int n ;
cin >> n ;
vector<int>x(n) ;
for (int &i : x )
	{cin >>i;}
	sort(all(x));
ll res = INT_MAX ;
int k = 100;
for (int  p = 0 ; p <= k  ; ++p)
{	ll  res1 = 0 ;  
	for (int el  : x )
		res1+= ( ( el -  p  ) * (el - p ));  
	res = min ( res , res1) ;
	 
}

cout << res ;

return 0 ;
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
  int N; 
	string S; 
	cin >> N >> S; 
	long long int count[30] = {}; 
	for(int i = 0; i < S.size(); i++){
		count[S.at(i) - 'a'] ++; 
	}
	long long int ans = 1; 
	for(int i = 0; i < 26; i++){
		ans *= count[i] + 1; 
      ans = ans % 1000000007; 
	}
	cout << (ans +  1000000006) %  1000000007 << endl; 
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            var E = ReadIntArray();
            int count = E.Distinct().Count();
            Console.WriteLine(count == 2 ? "Yes" : "No");
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	
	static int n;
	static char[]c;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		n = Integer.parseInt(sc.next());
		
		c = sc.next().toCharArray();
		
		int[] r = new int [n+2];
		int[] g = new int [n+2];
		int[] b = new int [n+2];
		
		for(int i = 0 ; i < n ;i++) {
			
			if(c[i] == 'R') {
				r[i]++;
			}
			if(c[i] == 'G') {
				g[i]++;
			}
			if(c[i] == 'B') {
				b[i]++;
			}
			
			r[i+1] = r[i];
			g[i+1] = g[i];
			b[i+1] = b[i];
		}
		
		long ans = solve(r,g,b);
		System.out.println(ans);
		
	}
	
	static long solve(int []r , int []g , int[]b) {
		long temp = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = n-1 ; j >= 0; j--) {
				if(i == j) {
					break;
				}
				if(c[i] == c[j]) continue;
				
				int jdg = -1;
				boolean p = false;
				
				if((i + j)% 2 == 0) {
					jdg = (i + j)/2;
					p = true;
				}
				if(c[i] != 'R' && c[j] != 'R') {
					temp  += (long)(r[j] - r[i]);
					if(p) {
						if(c[jdg] == 'R'){
						temp--;
						}
					}
				}
				else if(c[i] != 'G' && c[j] != 'G') {
					temp  += (long)(g[j] - g[i]);
					if(p) {
					if(c[jdg] == 'G') {
						temp--;
						}
					}
				}
				else if(c[i] != 'B' && c[j] != 'B') {
					temp  +=(long)(b[j] - b[i]);
					if(p) {
					if(c[jdg] == 'B') {
						temp--;
					}
				}
			}
		}
	}
		
		return temp;

		}
}


Measured memory_bytes: 27640
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];

  vector<vector<bool>> dp(n+1, vector<bool>(100*100+5, false));
  dp[0][0] = true;

  rep(i,n) rep(j,100*100+1) if(dp[i][j]) dp[i+1][j] = dp[i+1][j+vec[i]] = true;

  for(int i=100*100+5; i>=0; i--) if(i%10!=0 && dp[n][i]){
    cout << i << endl;
    return 0;
  }
  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<(int)S.size();++i)
#define fore(i,x) for(int i = head[x] ; i ; i = e[i].next)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define lowbit(x) (x&(-x))
using namespace std;
#define maxn 200020

typedef long long ll;
typedef long double ld;

ll A,B,C,D;
int T;

ll gcd(ll x,ll y){
	if ( !y ) return x;
	return gcd(y,x % y);
}
int main(){
	cin>>T;
	while ( T-- ){
		cin>>A>>B>>C>>D;
		if ( A < B || D < B ){ printf("No\n"); continue; }
		ll d = gcd(B,D);
		A = A % B;
		ll L = floor((ld)(C - A) / d) + 1 , R = ceil((ld)(B - A) / d) - 1;
		if ( L <= R )  printf("No\n");
		else  printf("Yes\n");
	}
}


Measured memory_bytes: 512
n=input()[::-1]
n+="0"
lt=len(n)
dp=[[float('inf') for _ in range(2)] for j in range(lt+1)]
dp[0][0]=0

for i in range(0,lt):
    for j in range(2):
        x=int(n[i])
        x+=j #繰り上がり処理，あとに+11でもOK
        for num in range(0,10):
            ni = i + 1
            nj = 0
            b=num-x
            if b<0:
                b+=10
                nj=1
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+num+b)

print(dp[lt][0])

Measured memory_bytes: 216372