akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

double calc(vector<int> path[601], int N, int block)
{
    double dp[N + 1];
    dp[N] = 0.0;
    for (int i = N - 1; i >= 1; i--)
    {
        double sum = 0.0;
        double maxval = 0.0;
        int num = path[i].size();
        for (auto j : path[i])
        {
            sum += dp[j];
            if (maxval < dp[j]) maxval = dp[j];
        }
        if (i == block && num > 1)
        {
            sum -= maxval;
            num--;
        }
        dp[i] = sum / num + 1.0;
    }
    return dp[1];
}

void solve()
{
    int N, M;
    vector<int> path[601];
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int s, t;
        cin >> s >> t;
        path[s].push_back(t);
    }
    double ans = calc(path, N, 1);
    for (int i = 2; i <= N; i++)
    {
        double a = calc(path, N, i);
        if (a < ans) ans = a;
    }
    cout << fixed << setprecision(7) << ans << endl;
}

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    string s; cin >> s;
    int n = s.size();

    set<int> values;
    rep(i,n) values.insert(s[i]);

    string alpa = "abcdefghijklmnopqrstuvwxyz";
    int num = 0;
    bool flag = false;

    for(auto itr = values.begin(); itr != values.end(); ++itr) {
            if(*itr == alpa[num]){
                flag = true;
                num++;
            }
            else if(*itr != alpa[num]){
                print(alpa[num]);
                flag = false;
                break;
            }
    }

    if(flag && num == 26)print("None");
    else if(flag && num < 26)print(alpa[num]);

}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  ll S;cin >> S;
  if(S == 1e18){
    cout << 0 << ' ' <<  0  << ' ' << 1000000000 << ' ' << 0 << ' ' << 0 << ' ' << 1000000000 << endl;
    return 0; 
  }
  cout << 0 << ' ' <<  0 << ' ' << 1000000000 << ' '  << 1 << ' ' <<(ll)1e9 - S%(ll)1e9  << ' ' << (S + (ll)1e9 - S % (ll)1e9) / (ll)1e9 << endl;
}

Measured memory_bytes: 256
//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
const long long LMOD=1000000007;
/*
struct seg
{
	long long data[500001];
	long long datb[500001];
	long long init()
	{
		for(int i=0;i<500001;i++)
		{
			data[i]=0;
			datb[i]=0;
		}
	}
	long long dwn(long long k)
	{
		data[k*2]+=datb[k];
		data[k*2+1]+=datb[k];
		datb[k]=0;
	}
	long long add(long long l,long long r,long long a,long long b,long long k,long long v)
	{
		if(l>r)return 0;
		//cout<<"!";
		if(l>b||r<a)return 0;
		//cout<<"!";
		//cout<<l<<" "<<r<<endl;
		if(a<=l&&r<=b)
		{
			data[k]+=v;
		}
		else
		{
			datb[k]+=(min(b,r)-max(a,l)+1)*v;
			add(l,(l+r)/2,a,b,k*2+1,v);1
			add((l+r)/2+1,r,a,b,k*2+2,v);
			data[k]=max()
		}
	}
	long long sum(long long l,long long r,long long a,long long b,long long k)
	{
		if(l>r)return 0;
		if(l>b||r<a)return 0;
		//cout<<l<<" "<<r<<endl;
		if(a<=l&&r<=b)
		{
			return data[k]*(r-l+1)+datb[k];
		}
		else
		{
			long long res=0;
			res=(min(b,r)-max(a,l)+1)*data[k];
			res+=sum(l,(l+r)/2,a,b,k*2+1);
			res+=sum((l+r)/2+1,r,a,b,k*2+2);
			return res;
		}
	}
}cccp;
vector<pair<int,int> >vin;
vector<pair<int,int> >vout;
int n,m;
int l[200005];
int r[200005];
int v[200005];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&l[i],&r[i],&v[i]);
		vin.push_back(make_pair(l[i],i));
		vout.push_back(make_pair(r[i],i));
	}
	set<int>st;
	for(int i=1;i<=n;i++)
	return 0;
}
*/
vector<int>v[100001];
vector<int>vt[100001];
int in[100001];
queue<int>q;
int n,m;
int dp[100001];
int tp()
{
	for(int i=1;i<=n;i++)
	{
		if(in[i]==0)
		{
			q.push(i);
		}
	}
	int u=0;
	int mx=0;
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(int i=0;i<vt[u].size();i++)
		{
			dp[u]=max(dp[vt[u][i]]+1,dp[u]);
		}
		mx=max(mx,dp[u]);
		for(int i=0;i<v[u].size();i++)
		{
			//dp[i]=max(dp[v[u][i]]+1,dp[i]);
			in[v[u][i]]--;
			if(in[v[u][i]]==0)
			{
				q.push(v[u][i]);
			}
		}
	}
	return dp[u];
}
int x,y;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		in[y]++;
		v[x].push_back(y);
		vt[y].push_back(x);
	}
	printf("%d",tp());
	return 0;
}

Measured memory_bytes: 11904
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long 
#define ull unsigned long long
#define li long long int

int main()
{
  ul n,ct=0,ct2=0;
  cin >> n;

  for (ul i=1;i<=n;i+=2) {
    ct2=0;
    for (ul j=1;j<=i;j++) {
      ct2+=i%j==0;
      if (ct2>8)break;
    }
    ct+=ct2==8;
  }

  cout << ct<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);

int main()
{
    int k;
    unsigned ll ans = 0;
    cin >> k;
    rep(i, k  )
    {
        rep(j, k  )
        {
            rep(x, k  ) { ans += __gcd(i + 1, __gcd(j + 1, x + 1)); }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


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

using namespace std;

using int64 = long long;

vector< vector< pair< int64, int64 > > > solve(int N, int *A) {
  vector< int64 > latte(N);
  for(int i = 0; i < N; i++) {
    latte[i] = A[i];
    if(i) latte[i] += latte[i - 1];
  }
  vector< vector< pair< int64, int64 > > > chokudai(N);
  int64 add = 0;
  for(int i = 0; i < N; i++) {
    add += A[i];
    if(i > 0) {
      int ok = 0, ng = i;
      auto check = [&](int pos) {
        return latte[pos] * 2 <= add;
      };
      while(ng - ok > 1) {
        int mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
      }
      for(int j = max(0, ok - 2); j < min(ok + 3, i); j++) {
        pair< int64, int64 > p = minmax(add - latte[j], latte[j]);
        chokudai[i].emplace_back(p);
      }
    }
  }
  return chokudai;
}

int main() {
  int N, A[200000];

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  auto p = solve(N, A);
  reverse(A, A + N);
  auto q = solve(N, A);
  reverse(begin(q), end(q));

  int64 ret = 1LL << 60;
  for(int i = 1; i < N - 1; i++) {
    for(auto &s : p[i]) {
      for(auto &t : q[i + 1]) {
        auto tt = min(s.first, t.first);
        auto vv = max(s.second, t.second);
        ret = min(ret, vv - tt);
      }
    }
  }

  cout << ret << endl;
}


Measured memory_bytes: 68196
S = list(input())
n = len(S)-1
for i in range(2**n):
    op = ['-']*n
    f = S.copy()
    for j in range(n):
        if ((i >> j) & 1):
            op[j] = '+'
    
    for j, k in zip(range(n), [1,3,5]):
        f.insert(k, op[j])
    f = ''.join(f)
    if eval(f) == 7:
        print(f + '=7')
        exit()

Measured memory_bytes: 3064
n, k = map(int, input().split())
d = []
a = []
ans = [1]*n
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int, input().split())))
    for su in a[i]:
        if ans[su-1] == 1:
            ans[su-1] = 0
answer = sum(ans)
print(answer)

Measured memory_bytes: 9224
'use strict'

const main = (input) => {
    input = input.split(' ').map(v => Number(v))
    const a = input[0]
    const b = input[1]
    const c = input[2]

    let count = Math.floor(b / a)
    console.log(Math.min(count, c))
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
import sys
import math
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
A,B,H,M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
cA = 360*H/12 +30 * M/60
cB = 360*M/60
cC = abs(cA -cB)
if cC > 180:
    cC = 360 - cC
#cnt = 0
#cnt += 1
coscC = math.cos(math.radians(cC))
C = A**2 +B**2 - 2* A*B*coscC

#print(N)
#print(S,T)
print(C**(1/2))
#print('Yes')
#print('No')
#sin30 = math.sin(math.radians(30))

Measured memory_bytes: 9508
# coding: utf-8
S = input()
ans = 'WA'
if S[0] == 'A':
  if 'C' in S[2:-1]:
    c = 0
    for s in S:
      if ord(s) < 97:
        c += 1
    if c == 2:
      ans = 'AC'
print(ans)


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

int main() {
  string S;
  cin >> S;
  int length = S.size();
  int times = length / 2;
  int cnt = 0;
  for (int i = 0; i < times; i++){
    if (S[i] != S[length - 1 - i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <istream>
#include <algorithm>
#include <functional>
#include <unordered_map>

#ifdef _MSC_VER
#define scanf scanf_s
#define KEYWAIT getchar();getchar();
#else
#define KEYWAIT
#endif

int main()
{
    long a,b,c,ans=0;

    std::unordered_map<std::string, long> map;

    std::cin >> a;

    std::string str;

    for (int i = 0; i < a; i++) 
    {
        std::cin >> str;
        map[str]++;
    }

    std::cin >> b;

    for (int i = 0; i < b; i++)
    {
        std::cin >> str;
        map[str]--;
    }

    for (auto itr = map.begin(); itr != map.end(); ++itr) {
        if (itr->second > ans) {
            ans = itr->second;
        }
    }

    std::cout << ans << std::endl;
 

    KEYWAIT

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>

const long long INF = 1LL<<60;
const int inf = 1 << 30;
const int mod = 1e9+7;


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; }

const int MAX = 1999999;
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(){
  int x, y;
  cin >> x >> y;
  if ((x+y) % 3 != 0){
    cout << 0 << endl;
    return 0;
  }
  COMinit();
  int n = (2 * x - y) / 3;
  int m = (2 * y - x) / 3;

  cout << COM(n+m, n) << endl;
}


Measured memory_bytes: 47232
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int,int>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power( (num*num)%mod,g/2,mod);
}

int main(){
	int n;
	cin >> n;
	string s;
	set<string> st;
	FOR0(i, n) cin >> s, st.insert(s);
	cout << st.size();
}

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

int main(){
    int N, x;
    int a_i;
//    vector<int> a;
    multiset<int> ma;
    int a;
    int ans = 0;

    //input
    cin >> N >> x;
    for(int i = 0; i < N; i++){
        cin >> a_i;
        ma.insert(a_i);
    }

    while((a = *(ma.lower_bound(0))) <= x && ans < N - 1 && x != 0){
        ans++;
        x -= a;
        ma.erase(ma.lower_bound(0));
    }
    if((a = *(ma.lower_bound(0))) == x){
        ans++;
    }

    //output
    cout << ans << endl;

}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

const int N = 1e5 + 5;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    map<pair<int, int>, vector<pair<int, int>>> g;
    for (int i = 0; i < m; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      g[make_pair(a, c)].push_back(make_pair(b, c));
      g[make_pair(b, c)].push_back(make_pair(a, c));

      g[make_pair(b, -1)].push_back(make_pair(a, c));
      g[make_pair(a, -1)].push_back(make_pair(b, c));
      g[make_pair(a, c)].push_back(make_pair(b, -1));
      g[make_pair(b, c)].push_back(make_pair(a, -1));
    }

    set<pair<int, int>> vis;
    vis.insert(make_pair(0, -1));

    map<pair<int, int>, int> cost;
    cost[make_pair(0, -1)] = 0;

    deque<pair<int, int>> q;
    for (q.push_back(make_pair(0, -1)); q.size(); ) {
      pair<int, int> p = q.front();
      q.pop_front();
      each (i, g[p]) {
        if (vis.count(i)) continue;
        vis.insert(i);
        if (i.second != -1) {
          cost[i] = cost[p];
          q.push_front(i);
        } else {
          cost[i] = cost[p] + 1;
          q.push_back(i);
        }
      }
    }

    pair<int, int> p = make_pair(n - 1, -1);
    cout << (cost.count(p) ? cost[p] : -1) << endl;
  }

  return 0;
}


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

int main(){
  int N;
  int p;
  int sum;
  
  cin>>N;
  
  sum=0;
  vector<int> X(N);
  for(int i=0;i<N;i++){
    cin>>X.at(i);
    sum+=X.at(i);
  }

  int d;
  d=round(sum/(double)N);
  //cout<<d<<endl;
  
  int d2;
  d2=0;
  for(int i=0;i<N;i++){
    d2+=(X.at(i)-d)*(X.at(i)-d);
  }
  
  
  
  cout<<d2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 110;
struct edge {
  int la,b;
} con[N << 1];
int tot, fir[N];
void add_edge(int from,int to) {
  con[++tot] = (edge) {fir[from], to};
  fir[from] = tot;
}
int n, dis[N], p1, p2, rec[2][N];
void dfs(int pos,int fa) {
  for (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa) continue;
    dis[con[i].b] = dis[pos] + 1;
    dfs(con[i].b, pos);
  }
}
int dep[N], mx[N], vis[N], len;
void fsd(int pos,int fa) {
  dep[pos] = dep[fa] + 1;
  int num = 0;
  for (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa || vis[con[i].b]) continue;
    ++ num;
    fsd(con[i].b, pos);
  }
  ckmx(mx[dep[pos]], num);
}
ll calc(int p1,int p2=0) {
  ll ret = 1;
  if (p2 != 0) ret = 2;
  memset(vis, 0, sizeof vis);
  memset(mx, 0, sizeof mx);
  vis[p1] = vis[p2] = 1;
  fsd(p1, 0);
  if (p2) fsd(p2, 0);
  rep (i, 1, len/2) ret = ret * mx[i];
  return ret;
}
int main() {
  int x,y;
  ll ans = 1ll << 60;
  read(n);
  rep (i, 1, n-1) {
    read(x), read(y);
    add_edge(x, y);
    add_edge(y, x);
  }
  dis[1] = 0, dfs(1, 0);
  p1 = 1;
  rep (i, 1, n) if (dis[i] > dis[p1]) p1 = i;
  dis[p1] = 0, dfs(p1, 0);
  rep (i, 1, n) rec[0][i] = dis[i];
  p2 = 1;
  rep (i, 1, n) if (dis[i] > dis[p2]) p2 = i;
  dis[p2] = 0, dfs(p2, 0);
  rep (i, 1, n) rec[1][i] = dis[i];
  len = rec[0][p2];
  if (len % 2 == 0) {
    int rt = 1;
    rep (i, 1, n) if (rec[0][i] == len/2 && rec[1][i] == len/2)
      rt = i;
    ans = calc(rt);
    for (int i = fir[rt]; i; i = con[i].la)
      ckmn(ans, calc(rt, con[i].b));
  } else {
    int r1 = 0, r2 = 0;
    rep (i, 1, n) if (rec[0][i] == (len+1)/2 && rec[1][i] == (len-1)/2)
      r1 = i;
    rep (i, 1, n) if (rec[0][i] == (len-1)/2 && rec[1][i] == (len+1)/2)
      r2 = i;
    ans = calc(r1, r2);
  }
  cout << len/2+1 << ' ' << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxW 100005
int main()
{
	int n,W;
	scanf("%d%d",&n,&W);
	long long dp[maxW] = {};
	for(int i=0; i<n ;i++)
	{
		int w,v;
		scanf("%d%d",&w,&v);
		for(int j=W; j>=w; j--)
			dp[j] = max(dp[j],dp[j-w]+v);
	}
	printf("%lld\n",dp[W]);
	return 0;
}

Measured memory_bytes: 1532
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);
static LL P = 1000000007LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N; cin >> N;

	LL a = 1, b = 1, c = 1;
	for(int i=1; i<=N; i++){
		a *= 10;
		a %= P;
		b *= 9;
		b %= P;
		c *= 8;
		c %= P;
	}
	a %= P;
	b %= P;
	c %= P;
	LL ans = a - (b*2) + c;
	ans %= P;
	if(ans < 0){
		ans += P;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

vvec<int> G;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, M;
    cin >> N >> M;
    G.resize(N);
    vector<bool> visited(N, false);
    vector<int> ans(N);
    rep(i,M){
        int a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int> q;
    q.push(0);
    visited[0] = true;
    while(not q.empty()){
        int v = q.front();
        q.pop();
        for(auto &nv: G[v]){
            if(visited[nv])continue;
            ans[nv] = v;
            visited[nv] = true;
            q.push(nv);
        }
    }
    cout << "Yes" << endl;
    rep1(i,N){
        cout << ans[i]+1 <<endl;
    }
}

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

double floor_velo(int floor);

int main(void)
{
    double crash_velo;
    while (scanf("%lf", &crash_velo) != EOF) {
        int floor = 1;
        while (crash_velo > floor_velo(floor)) {
            floor++;
        }

        printf("%d\n", floor);
    }

    return 0;
}

double floor_velo(int floor)
{
    int height = 5 * (floor - 1);
    return (9.8 / sqrt(4.9)) * sqrt(height);
}

Measured memory_bytes: 628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+1000;
const ll INF=1e9+7;
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll n,m,p;
struct node{
    ll w;
    bool friend operator<(node a,node b)
    {
        return a.w<b.w;
    }
};
priority_queue<node>q;
int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        ll x;
        scanf("%lld",&x);
        node u;u.w=x;
        q.push(u);
    }
    while(m--)
    {
        node u=q.top();q.pop();
        node now;now.w=u.w/2;
        q.push(now);
    }
    ll sum=0;
    while(!q.empty())
    {
        sum+=q.top().w;
        q.pop();
    }
    printf("%lld\n",sum);
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll A, B, C;
    cin >> A >> B >> C;

    cout << min(C, B + A + 1) + B << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

//const int MOD=998244353;
const double PI=3.14159265359;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<int> v(n);
    for(int&i:v)cin>>i;
    
    int ans=v[0];
    for(int i=1; i<n; i++){
        if(v[i]>v[i-1]) ans+=v[i]-v[i-1];
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n+1))
        self.size = [1] * (n+1)
        
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    
    def union(self, a, b):
        a = self.find(a)
        b = self.find(b)
        
        if self.parent[a] == self.parent[b]:
            return
        if self.size[a] >= self.size[b]:
            self.parent[b] = a
            self.size[a] += self.size[b]
        else:
            self.parent[a] = b
            self.size[b] += self.size[a]
        
    def count(self, x):        
        return self.size[self.find(x)]

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

uf = UnionFind(n)
ans = [0] * (n + 1)

for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a, b)
    ans[a] -= 1
    ans[b] -= 1
    
for _ in range(k):
    a, b = map(int, input().split())
    if uf.find(a) == uf.find(b):
        ans[a] -= 1
        ans[b] -= 1
        
for i in range(1, n+1):
    ans[i] += uf.count(i) - 1    
    
print(" ".join(map(str, ans[1:])))

Measured memory_bytes: 19000
N=int(input())
a=list(map(int,input().split()))

def gcd(a,b):
  if b>a:
    a,b=b,a
  while a%b!=0:
    a,b=b,a%b
  return b

def lcd(a,b):
  return a*b//gcd(a,b)

a_lcd=1
for i in range(len(a)):
  a_lcd=lcd(a_lcd,a[i])
  
div=a_lcd-1
ans=0
for i in range(len(a)):
  ans+=div%a[i]
print(ans)

Measured memory_bytes: 3444
for i in range(1,100000000):
    try:
        a,b,c,d,e,f=map(int,input().split())
        y=(a*f-d*c)/(e*a-b*d)
        x=(c-b*y)/a
        print(f'{x:.3f} {y:.3f}')
    except EOFError:
        break


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int a, b, c;
    cin >> a >> b >> c;

    int ans = min({a, b, c}) * (a + b + c - min({a, b, c}) - max({a, b, c})) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a;
	int b;
	
	cin >> a >> b;
	
	for(int i = 1; i <= 10000;i++){
	    if((int)(i*0.08) == a && (int)(i*0.1) == b){
	        cout << i << endl;
	        break;
	    }
	    
	    if(i == 10000){
	        cout << -1 << endl;
	    }
	}
}


Measured memory_bytes: 256
def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        c = a % b
        return gcd(b, c)

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

g_max = -1
l = [0] * n
r = [0] * n
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1], a[i-1])

for i in range(n-1,-1,-1):
    if i == n-1:
        r[i] = 0
    else:
        r[i] = gcd(r[i+1], a[i+1])

g_max = -1
for i in range(n):
    g = gcd(l[i], r[i])
    if g > g_max:
        g_max = g

print(g_max)


Measured memory_bytes: 63984
program prob2
    implicit none
    integer::x1, x2, x3, x4, y1, y2, y3, y4, dx, dy
    read(*,*) x1, y1, x2, y2
    dx = x2 - x1
    dy = y2 - y1
    x3 = x2 - dy
    y3 = y2 + dx
    x4 = x3 - dx
    y4 = y3 - dy
    write(*,*) x3, y3, x4, y4
    stop
end program

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.size();
    string ss = "";
    rep(i,0,N){
        if(S[i] != 'x') ss += S[i];
    }
    string tt = ss;
    reverse(tt.begin(), tt.end());
    if(ss != tt){
        print(-1);
        return 0;
    }
    ll rec_num = 0;
    ll idx = 0;
    ll pos[100010] = {};
    rep(i,0,N){
        if(S[i] != 'x'){
            rec_num++;
            pos[idx] = i;
            idx++;
        }
    }
    // printa(pos, N);
    ll x_cnt[100010] = {};
    rep(j,0,pos[0]){
        if(S[j] == 'x') x_cnt[0]++;
    }
    rep(i,0,rec_num-1){
        rep(j,pos[i], pos[i+1]){
            if(S[j] == 'x') x_cnt[i+1]++;
        }
    }
    rep(j,pos[rec_num-1], N){
        if(S[j] == 'x') x_cnt[rec_num]++;
    }
    // printa(x_cnt, N);
    ll ans = 0;
    // print(rec_num);
    rep(i,0,(rec_num+1)/2){
        ans += max(x_cnt[i], x_cnt[rec_num - i]) - min(x_cnt[i], x_cnt[rec_num - i]);
    }
    print(ans);

    // xxabxbxbaxxx
}


Measured memory_bytes: 2128
import sys
input = sys.stdin.readline
from collections import defaultdict

x = int(input())
pre = [i ** 5 for i in range(1001)] # Fuck it
for i in range(1001):
    for j in range(i + 1):
        if pre[i] - pre[j] == x: print(i, j); exit()
        elif pre[i] + pre[j] == x: print(i, -j); exit()


Measured memory_bytes: 66624
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

string s;
ll k;

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

	cin >> s >> k;
	ll cnt = 1;
	ll fa = 0;
	ll ans = 0;
	ll b = 0;
	while (b < s.length() - 1 && s[b] == s[b + 1]) {
		b++;
	}
	if (b == s.length() - 1) {
		cout << s.length() * k / 2;
		return 0;
	}
	for (int i = 1; i < s.length(); i++) {
		while (i < s.length() && s[i - 1] == s[i]) {
			cnt++;
			i++;
		}
		ans += cnt / 2;
		cnt = 1;
	}
	string s2;
	s2.append(s);
	s2.append(s);
	for (int i = b + 1; i <= b + s.length(); i++) {
		while (s2[i - 1] == s2[i]) {
			cnt++;
			i++;
		}
		fa += cnt / 2;
		cnt = 1;
	}
	cout << ans + fa * (k - 1);
}


Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using namespace std;
using lint = int64_t;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define repn(i, a, b) for(int i = (a); i < (b); ++i)
#define rep_inv(i, n) for (int i = (n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint Mod = 1000'000'007LL;
constexpr lint Inf = 9'000'000'000'000'000'007LL; //9e18+7
constexpr double Pi = 3.141592653589793;

template<class T> using prique     = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << ((first + 1) != last ? " " : "\n");
	}
}

bool pri(lint x) { 
	for (lint i = 2; i * i <= x; ++i) {
		if (x % i == 0) return false;
	}
	return 1 < x; 
}

lint fact[3000000];
void fact_init(lint n, lint m = Mod) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1] % m;
	}
}

lint modpow(lint x, lint n, lint m = Mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r, lint m = Mod) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], m - 2, m) % m * modpow(fact[r], m - 2, m) % m;
	return res < 0 ? res + m : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

lint k, n, ans = Inf;
lint x[55], y[55];
int main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	rep(i1, n) {
		rep(i2, n) {
			rep(i3, n) {
				rep(i4, n) {
					int cnt = 0;
					lint fx, fy, lx, ly;
					auto xs = { x[i1],x[i2],x[i3],x[i4] };
					auto ys = { y[i1],y[i2],y[i3],y[i4] };
					fx = min(xs), lx = max(xs);
					fy = min(ys), ly = max(ys);
					rep(i, n) {
						lint xi = x[i], yi = y[i];
						if (fx <= xi && xi <= lx && fy <= yi && yi <= ly) cnt++;
					}
					if (k <= cnt) ans = min(ans, (lx - fx) * (ly - fy));
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n";
using namespace std;
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> v;
    vector<int> v1;
    set<int> sets;
    vector<string> str;
    string s;
    int a, b, c, t, cnt=0, flag=0;
    cin >> t;
    for(int i=0; i<t; ++i){
    	cin >> a;
    	if(a%2!=0){
    		cout << "0" << "\n";
    		return 0;
    	}
    	v.push_back(a);
    }
 	
 	for(int i=0; ; ++i){
 		for(int j=0; j<t; ++j){
 			v[j] = v[j]/2;
 			if(v[j]%2!=0){
 				flag=1;
 				break;
 			}
 		}

 		if(flag==1){
 			break;
 		}else{
 		cnt++;
 	}
 	}

 	cout << cnt+1 << "\n";


    
   bye;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int n,k; string s; cin >> n >> k >> s;
	
	vector<int> c(n); c[0]=0;
	
	for(int i=1;i<=n;i++){
		
		c[i]=c[i-1];
		
		if(s[i-1]=='A' && s[i]=='C') c[i]++;
	}
	
	rep(i,k){
		int l,r; cin >> l >> r;
		
		cout << c[r-1]-c[l-1] << endl;
	}
	
	return 0;
}



Measured memory_bytes: 1488
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define BigInt      __int128
#define endl        '\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define sim         template < class c
#define ris         return * this
#define dor         > debug & operator <<
#define eni(x)      sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

using namespace std;

sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug 
{
	~debug() 
	{ 
		cout<<endl; 
	}
	eni(!=) cout << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) 
	{
		ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) 
	{
	  	*this << "[";
	  	for (auto it = d.b; it != d.e; ++it)
	    	*this << ", " + 2 * (it == d.b) << *it;
	  	ris << "]";
	}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin >> n;
		ll int arr[n + 1];
		ll int brr[n + 1];
		for(ll int i = 1; i <= n; i++)
		{
			cin >> arr[i];
		}
		for(ll int i = 1; i <= n; i++)
		{
			cin >> brr[i];
		}
		reverse(brr + 1, brr + 1 + n);
		int e = -1;
		for(ll int i = 1; i <= n; i++)
		{
			if(arr[i] == brr[i])
			{
				e = arr[i];
			}
		}
		if(e == -1)
		{
			cout << "Yes" << endl;
			for(ll int i = 1; i <= n; i++)
			{
				cout << brr[i] << " ";
			}
			cout << endl;
			return 0;
		}
		vi v1, v2;
		for(ll int i = 1; i <= n; i++)
		{
			if(arr[i] == e && brr[i] == e)
			{
				v1.pb(i);
			}
			if(arr[i] != e && brr[i] != e)
			{
				v2.pb(i);
			}
		}
		if(v1.size() <= v2.size())
		{
			cout << "Yes" << endl;
			for(ll int i = 0; i < v1.size(); i++)
			{
				swap(brr[v1[i]], brr[v2[i]]);
			}
			for(ll int i = 1; i <= n; i++)
			{
				cout << brr[i] << " ";
			}
			cout << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 9484
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int X, K, D;
	cin >> X >> K >> D;

	X = abs(X);
	if (X / D > K) {
		cout << X - K * D << endl;
		return 0;
	}
	Int k = K - X / D;
	Int x = X % D;
	cout << (k % 2 ? abs(x - D) : x) << "\n";

	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner stdin = new Scanner(System.in);
    int A = stdin.nextInt();
    int B = stdin.nextInt();
    int C = stdin.nextInt();

    if(A == B){
      System.out.println(C);
    }
    if(B == C){
      System.out.println(A);
    }
    if(A == C){
      System.out.println(B);
    }
  }
}


Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int[] abc = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int A = abc[0];
        int B = abc[1];
        int C = abc[2];

        Console.WriteLine(Math.Min((B / A), C));
    }
}

Measured memory_bytes: 13396
from pprint import pprint
from collections import deque, defaultdict

n, q = list(map(int, input().strip().split(" ")))
# edges = defaultdict(set)
edges = [[] for _ in range(n)]
for _ in range(n-1):
    a_i, b_i = list(map(int, input().strip().split(" ")))
    edges[a_i-1].append(b_i-1)
    edges[b_i-1].append(a_i-1)
    # edges[a_i-1].add(b_i-1)
    # edges[b_i-1].add(a_i-1)

# p = defaultdict(int)
# counter = defaultdict(int)
counter = [0] * n
p = [0] * n
for _ in range(q):
    p_i, x_i = list(map(int, input().strip().split(" ")))
    # p[p_i-1] += x_i
    counter[p_i-1] += x_i


parents = deque()
# parents.append(0)
# parents = []
parents.append(0)
visited = set()
while parents:
    parent = parents.popleft()
    # parent = parents.pop()
    if parent in visited:
        continue
    visited.add(parent)
    # counter[parent] += p[parent]
    # print("parent")
    # print(parent, counter[parent])
    for child in edges[parent]:
        if child in visited:
            continue
        # if counter[child] != 0:
        #    continue
        counter[child] += counter[parent]
        # print("child")
        # print(child, counter[child])
        parents.append(child)
        # parents.add(child)

#print(" ".join(list(map(str, counter.values()))))
#print(" ".join(list(map(str, counter))))
print(*counter)

Measured memory_bytes: 120012
N = int(input())
S = []
dic = { "AC": 0, "WA":0, "TLE": 0, "RE": 0}
for _ in range(N):
    i = input()
    dic[i] += 1
print(f"AC x {dic['AC']}")
print(f"WA x {dic['WA']}")
print(f"TLE x {dic['TLE']}")
print(f"RE x {dic['RE']}")


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m,k;
	cin >> n >> m >> k;
	vi a(n+1),b(m+1);
	rep(i,1,n+1)cin >> a[i];
	rep(i,1,m+1)cin >> b[i];
	int lp = m;
	ll bsum = accumulate(all(b), 0LL);
	ll asum = 0; 
	int ans = 0;
	rep(i,0,n+1){
		asum += a[i];
		while(lp > 0 && asum + bsum > k){
			bsum -= b[lp];
			--lp;
		}
		if(asum + bsum <= k){
			gmax(ans, i + lp);
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 4700
#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;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define endl "\n"
#define pii pair<int,int>
#define mii map<int,int>
#define int long long int
#define fbo find_by_order
#define ook order_of_key
#define in insert
#define F first
#define S second
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a) for(auto ws: a)cout<<ws<<" "; cout<<endl
#define print1(a,b) for(int ws=0;ws<b;ws++) {cout<<a[ws]<<" ";} cout<<endl
#define all(a) a.begin(), a.end()
#define si set<int>
#define print2(a) for(auto ws: a)cout<<"("<<ws.F<<","<<ws.S<<") "; cout<<endl

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
int mod = 1000000007;
int power(int x, unsigned int y)
{
	int res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (x * res) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	return res;
}
int n, m;
char a[1001][1001];
void read()
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
}
void solve()
{
	cin >> n >> m;
	read();
	int dp[n][m];
	dp[0][0] = 1;
	for (int i = 1; i < n; ++i)
	{
		if (dp[i - 1][0] && a[i][0] == '.')dp[i][0] = 1;
		else dp[i][0] = 0;
	}
	for (int i = 1; i < m; ++i)
	{
		if (dp[0][i - 1] && a[0][i] == '.')dp[0][i] = 1;
		else dp[0][i] = 0;
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < m; j++)
		{
			if (a[i][j] == '.')dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			else dp[i][j] = 0;
			dp[i][j] %= mod;
		}
	}
	cout << dp[n - 1][m - 1] << endl;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << setprecision(9) << fixed;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 12360
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var j = 0;
while (j < lines.length - 1) {
  var str = lines[j];
  var nums = str.split('').map(Number);
  var next;
  while (nums.length > 1) {
    next = [];
    for (var i = 0; i < nums.length - 1; i++) {
      next[i] = (nums[i] + nums[i + 1]) % 10;
    }
    nums = next;
  }
  console.log(nums[0]);
  j++;
}

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

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef unordered_set<int> USI;
typedef long long int llint;

// Display Map
//~for (auto const& pair: m) {
//~std::cout << "{" << pair.first << ": " << pair.second << "}\n";
//~}

// Extract word(w) from sentence(s)
//~stringstream str(s);
//~string w;
//~while(str >> w){
//~// w is your word
//~}

//Memset Syntax
// memset(array, value,sizeof(array)) val is 0,-1 or bool only

// To get accurate precision
//~cout.precision(20);

// Concatinate Vectors
//~

int main() {
    fast_io;
	int n;
	cin >> n;
	int p = n % 1000;
	if(p) cout << 1000 - p << endl;
	else cout << 0 << endl;
}


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

int main(){
	int h,w;
	cin >> h >> w;
	vector<vector<char>> mp(h, vector<char>(w));
	vector<bool> skip_row(h,false), skip_col(w,false);
	rep(i,h){
		bool all_w(true);
		rep(j,w){
			cin >> mp[i][j];
			if(mp[i][j] == '#') all_w = false;
		}
		if(all_w) skip_row[i] = true;
	}
	rep(i,w){
		bool all_w(true);
		rep(j,h){
			if(mp[j][i] == '#') all_w = false;
		}
		if(all_w) skip_col[i] = true;
	}
	rep(i,h){
		if(skip_row[i] == true) continue;
		rep(j,w){
			if(skip_col[j] == true) continue;
			cout << mp[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

#define PI 3.1415926535

int main(){
    string s;   //stringで読み込む
    cin >> s;

    string ans;    //答え用のstring
    for (int i = 0;i<s.size();i++){
        if(s.at(i)=='B'){   //Bのとき
            if(!ans.empty()){   //ansがから出ないなら
                ans.pop_back(); //最後の要素を削除
            }
        }else{
            ans += s.at(i);//普通に文字を追加
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int N=100005;

int n,l,t;
int a[N],x[N],w[N];

int main(){
	int i,j=0;
	scanf("%d%d%d",&n,&l,&t);
	for (i=0;i<n;i++){
		scanf("%d%d",&x[i],&w[i]);
		if (w[i]==1){
			a[i]=(x[i]+t)%l;
			j+=(x[i]+t)/l;
		}
		else{
			a[i]=(x[i]-t)%l;
			j-=(t-x[i])/l;
			if (a[i]<0) a[i]+=l,j--;
		}
		j=(j%n+n)%n;
	}
	sort(a,a+n);
	for (i=j;i<n;i++) printf("%d\n",a[i]);
	for (i=0;i<j;i++) printf("%d\n",a[i]);
	return 0;
} 

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main() {
	int n, a, b; cin >> n >> a >> b;
	int aa, ab;
	n %= 12;
	if (n % 6 == 0) {
		aa = a; ab = b;
	}
	if (n % 6 == 1) {
		aa = a - b; ab = b;
	}
	if (n % 6 == 2) {
		aa = a - b, ab = a;
	}
	if (n % 6 == 3) {
		aa = -b; ab = a;
	}
	if (n % 6 == 4) {
		aa = -b; ab = a - b;
	}
	if (n % 6 == 5) {
		aa = -a; ab = a - b;
	}
	if (n >= 6) {
		aa *= -1; ab *= -1;
	}
	cout << aa << ' ' << ab << endl;
}


Measured memory_bytes: 3108