akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

"""
・射影平面 P^2(F_p)
・同一直線上にある点を同じ紙の上に書く
・直線は、P^2(F_p)の点でパラメタライズされる
・(a:b:1) -> a+bp, (a:1:0) -> p^2+a, (1:0:0) -> p^2+p
"""

p = 37; rng = range(p)

inv = [pow(x,p-2,p) for x in range(p)]

def coord_to_idx(x,y,z):
    x %= p; y %= p; z %= p
    if z != 0:
        x *= inv[z]; y *= inv[z]; z = 1; x%=p; y%=p
        return x+y*p+1
    if y != 0:
        x *= inv[y]; x%=p
        return p*p+x+1
    return p*p+p+1

line = []
for a,b in itertools.product(rng,repeat=2):
    # ax+by+z=0となる射影平面上の点(x:y:z)
    if a==0 and b==0:
        pts = [coord_to_idx(x,1,0) for x in rng] + [coord_to_idx(1,0,0)]
        line.append(pts)
        continue
    pts = []
    # 無限遠直線 ax+by=0 上に1つ点がある
    pts.append(coord_to_idx(b,-a,0))
    # アフィン平面上の点。ax+by+z=0 and z=1
    if b != 0:
        pts += [coord_to_idx(x,-(a*x+1)*inv[b],1) for x in rng]
    else:
        # ax+z=0
        pts += [coord_to_idx(1,x,-a) for x in rng]
    line.append(pts)
for a in rng:
    # ax+y=0
    pts = [coord_to_idx(1,-a,x) for x in rng] + [coord_to_idx(0,0,1)]
    line.append(pts)
# x=0
pts = [coord_to_idx(0,x,1) for x in rng] + [coord_to_idx(0,1,0)]
line.append(pts)

print(p*p+p+1,p+1)
for l in line:
    print(' '.join(map(str,l)))


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

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

	int n = N.size();
	long long sum = 0;
	for( int i = 0; i < n; i++ ) {
		sum += N[i] - '0';
	}
	string ans = "Yes";
	if( sum % 9 ) ans = "No";

	cout << ans << endl;
}


Measured memory_bytes: 3728
#include <cstdio>
#include <cmath>

using namespace std;


int main() {
    unsigned long long x, y;
    scanf("%llu %llu", &x, &y);
//    printf("%llu %llu", x, y);
    unsigned int i{0};

    for (; x <= y; i++) {
        x = x * 2;
    }
    printf("%u",i);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
int main(){
    int n;cin>>n;
    int guu=0; int ki=0;
    ll temp;rep(i,n){cin>>temp;if(temp%2)ki++;else guu++;}
    if(ki%2){cout<<"NO"<<endl; return 0;}
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 384
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

a1 = (a + 9) // 10 * 10
b1 = (b + 9) // 10 * 10
c1 = (c + 9) // 10 * 10
d1 = (d + 9) // 10 * 10
e1 = (e + 9) // 10 * 10

tmax = 0
if tmax < a1 -a:
    tmax = a1 -a
if tmax < b1 -b:
    tmax = b1 -b
if tmax < c1 -c:
    tmax = c1 -c
if tmax < d1 -d:
    tmax = d1 -d
if tmax < e1 -e:
    tmax = e1 -e
    
print(a1+b1+c1+d1+e1-tmax)


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

int main(){
    int n, k;
    cin >> n >> k;
    int num = 1;

    for(int i=0; i<n; i++){
        if(num * 2 >= num + k){
            num += k;
        }
        else{
            num *= 2;
        }
    }

    cout << num << endl;

}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	int x,a,b;

	cin >> x >> a >> b;

	cout << ((abs(x-a) > abs(x-b)) ? "B" : "A") << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (n); ++i )
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;


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

    int n;
    cin >> n;

    vector<int> a(n);
    bool flag = false;
    rep(i,n) cin >> a[i];
    sort( all(a) );
    rep(i,n-1) {
        if( a[i] == a[i+1] ) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1024
def selectionSort(A, N):
    cnt = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    print(*A)
    print(cnt)
N = int(input())
A = list(map(int, input().split()))
selectionSort(A, N)


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

using namespace std;
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#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(c) c.begin(),c.end()
#define in(x, a, b) a <= x && x < b
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p <<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
  int n;
  cin >> n;
  vi a(n), b(n);
  rep (i, n) {
    cin >> a[i];
  }
  rep (i, n) {
    cin >> b[i];
  }
  vi use;
  for (int k = 50; k >= 0; k--) {
    vector<set<int> > st(n);
    rep (i, n) {
      st[i].insert(a[i]);
    }
    rep (i, n) {
      rep (j, use.size()) {
	rep1 (l, 50) {
	  if (st[i].count(l)) {
	    st[i].insert(l % use[j]);
	  }
	}
      }
    }
    rep (i, n) {
      for (int j = k; j >= 1; j--) {
	rep1 (l, 50) {
	  if (st[i].count(l)) {
	    st[i].insert(l % j);
	  }
	}
      }
    }
    bool flag = true;
    rep (i, n) {
      if (!st[i].count(b[i])) {
	flag = false;
	break;
      }
    }
    if (!flag) {
      if (k == 50) {
	cout << -1 << endl;
	return 0;
      }
      else {
	use.push_back(k + 1);
      }
    }
  }
  ll ans = 0;
  rep (i, use.size()) {
    ans += pow(2LL, use[i]);
  }
  cout << ans << endl;
  return 0;
}
  


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

ll dp[10001];

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int N, W;
	cin >> N >> W;
	vector<int> v;
	vector<int> w;

	v.pb(0);
	w.pb(0);
	for(int i=0; i<N; i++){
		int tv, tw;
		cin >> tv >> tw;
		v.pb(tv);
		w.pb(tw);
	}

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

	cout << dp[W] << endl;
	
	return 0;
}

Measured memory_bytes: 3228
#include <stdio.h>

int main(void) {  

int n ,ai ,i ,max ,min;          

long int sum = 0;    

scanf("%d" ,&n);    

for(i=0;i<n;i++){      

scanf("%d" ,&ai);      

sum += ai;      

if(i==0){        

max = ai;                        

min = ai;

}      

else if(ai>max){        

max = ai;      

}      

else if(ai<min){        

min = ai;       

}

          }      printf("%d %d %ld\n" ,min ,max ,sum);      return 0;     }     

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ll long long
inline int read()
{
	int x=0,y=1;
	char c=getchar();
	while(c<'0' || c>'9')
	{
		if(c=='-')
		y=-1;
		c=getchar();
	}
	while(c>='0' && c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*y;
}
using namespace std;
int main()
{
	int a,b,c,d;
	a=read();
	b=read();
	c=read();
	d=b/a;
	c=min(c,d);
	printf("%d",c);
}

Measured memory_bytes: 256
n, m, k = map(int ,input().split())

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

ans = 0
acounter = 0
bcounter = 0
ans_counter = 0

while True:
  if acounter == len(a):
    break
  if ans + a[acounter] <= k:
    ans += a[acounter]
    acounter += 1
  else:
    break
while True:
  if bcounter == len(b):
    break
  if ans+b[bcounter] <= k:
    ans += b[bcounter]
    bcounter += 1
  else:
    break
ans_counter = acounter + bcounter

while acounter > 0:
  acounter -= 1
  ans -= a[acounter]
  while True:
    if bcounter == len(b):
      break
    if ans + b[bcounter] <= k:
      ans += b[bcounter]
      bcounter += 1
    else:
      break
  
  ans_counter = max(ans_counter, bcounter+acounter)
print(ans_counter)


Measured memory_bytes: 39964
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
int N, Max;
int P[200005];
int DP[200005];
const int MOD = 1000000007;
vector <int> G[200005];
int L[200005], Level[200005];
int Power[200005], cnt;
struct State{
int x[3];
State()
{
    for(int i = 0; i < 3; i++)
        x[i] = 0;
}
};
deque <State> D[200005];
int Depth[200005];
int Pos[200005];
void Read()
{
    cin >> N;
    Power[0] = 1;
    for(int i = 1; i <= N + 1; i++)
        Power[i] = (1LL * Power[i - 1] * 2) % MOD;
    for(int i = 1; i <= N; i++)
    {
        cin >> P[i];
        G[P[i]].push_back(i);
    }
    L[0] = 1;
}

void DFS(int node, int father)
{
    if(node != 0)
    {
        Level[node] = Level[father] + 1;
        L[Level[node]]++;
        Max = max(Max, Level[node]);
    }
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];

        DFS(neighb, node);
        Depth[node] = max(Depth[node], Depth[neighb]);
    }
    ++Depth[node];
}
inline void Add(int& x, int y)
{
    x += y;
    if(x >= MOD)
        x -= MOD;
}
inline void sub(int& x, int y)
{
    x -= y;
    if( x < 0)
        x += MOD;
}
inline bool cmp(int a, int b)
{
    return Depth[a] < Depth[b];
}

void Merge(int a, int b)
{
    for(int i = 0; i < D[a].size(); i++)
    {
        State p = D[a][i], q = D[b][i], res;
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
                Add(res.x[min(j + k, 2)], (1LL * p.x[j] * q.x[k]) % MOD);
        D[b][i] = res;
    }
}

void DFS2(int node)
{
    sort(G[node].begin(), G[node].end(), cmp);
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        DFS2(neighb);
    }
    if(G[node].size() == 0)
    {
        ++cnt;
        int x[] = {1, 1, 0};
        State p;
        for(int i = 0; i < 3; i++)
            p.x[i] = x[i];
        D[cnt].push_back(p);
        Pos[node] = cnt;
        return;
    }
    int m = 0;
    for(int i = 1; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        Merge(Pos[G[node][i - 1]], Pos[neighb]);
        m = max(m, (int) D[Pos[G[node][i - 1]]].size());
        D[Pos[G[node][i - 1]]].clear();
    }
    Pos[node] = Pos[G[node].back()];

    for(int j = 0; j < m; j++)
    {
        Add(D[Pos[node]][j].x[0], D[Pos[node]][j].x[2]);
        D[Pos[node]][j].x[2] = 0;
    }
    int x[] = {1, 1, 0};
        State p;
        for(int i = 0; i < 3; i++)
            p.x[i] = x[i];
    D[Pos[node]].push_front(p);
}
int main()
{
    Read();
    DFS(0, -1);
    DFS2(0);
    int ans = 0;
    for(int i = 0; i < D[Pos[0]].size(); i++)
    {
        int aux = Power[N - L[i] + 1];
        Add(ans, (1LL * aux * D[Pos[0]][i].x[1]) % MOD);
    }
    cout << ans << '\n';
    return 0;
}


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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)

using namespace std;

typedef uint64_t ulint;
typedef int64_t lint;

int main(){
    lint h, w;
    cin >> h >> w;



    vector<string> s(h + 5);
    //2次元配列
    vector<vector<lint>> sum(h + 5, vector<lint>(w + 5, 0));

    rep0(i, h)
    {
        cin >> s[i];
        s[i] += "#";
    }
    s[h] = string(w, '#');

    rep0(i,h + 1)
    {
        lint cnt = 0;
        lint st = 0;
        rep0(j, w + 1)
        {
            if(s[i][j] == '.')cnt ++;
            else
            {
                //debug(j);
                for(lint k = st; k < j ; k ++)
                {
                    sum[i][k] += (j - st);
                }
                cnt = 0;
                st = j + 1;
                //debug(st);
            }
        }
    }

    lint ans = 0;
    rep0(j, w + 1)
    {
        lint cnt = 0;
        lint st = 0;
        rep0(i, h + 1)
        {
            if(s[i][j] == '.')cnt ++;
            else
            {
                for(lint k = st; k < i ; k ++)
                {
                    sum[k][j] += (i - st) - 1;
                    if(sum[k][j] > ans) ans = sum[k][j];
                }
                cnt = 0;
                st = i + 1;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35968
#include <stdio.h>
#define MAX 200

int main(int argc, const char * argv[]) {
    int n, m, c, i, t, k, l, w, soc=0, clr=0;
    int bsum[MAX];
    int sum[MAX][MAX];
    scanf("%d %d %d", &n, &m, &c);
    //printf("%d %d %d\n", n, m, c);
    
    for(i=0;i<m;i++){
        scanf("%d", &bsum[i]);
        //printf("bsum[0][%d]=%d\n", i, bsum[0][i]);
    }
    
    for(t=0;t<n;t++){
        for(k=0;k<m;k++){
            scanf("%d", &sum[t][k]);
            //printf("sum[%d][%d]=%d\n", t, k, sum[t][k]);
        }
    }
    for(l=0;l<n;l++){
        for(w=0;w<m;w++){
            soc = soc + sum[l][w]*bsum[w];
        }
        if(soc+c>0){
            clr++;
        }
        soc = 0;
    }
    printf("%d\n", clr);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <cmath>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

int const Q_MAX = 100;

int Q;
ll A[Q_MAX + 1], B[Q_MAX + 1];

int main() {
  scanf("%d", &Q);
  rep(i, Q) scanf("%lld %lld", &A[i], &B[i]);

  rep(i, Q) {
    ll a = min(A[i], B[i]);
    ll b = max(A[i], B[i]);

    if (b - a <= 1) {
      printf("%lld\n", 2 * a - 2);
    } else {
      ll x = a * b;
      ll y = sqrt(x);
      if (x == y * y) y--;

      if (y * (y + 1) >= x) {
        printf("%lld\n", 2 * y - 2);
      } else {
        printf("%lld\n", 2 * y - 1);
      }
    }
  }
}


Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
	/*freopen("output.txt", "w", stdout);
	freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e6 + 15;
int dx[8] = { -1, 0, 0, 1, 1, -1, 1, -1 };
int dy[8] = { 0, -1, 1, 0, 1, -1, -1, 1 };


int main()
{
	//fast();
	ll n;
	cin >> n;
	cout << ((n*(n + 1)) >> 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    typedef long long ll;
    const ll mod=998244353;
    using namespace std;
    int boom[100005];
    int a[100005];
    ll ksm(ll a,ll b)
    {
        ll ans=1;
        for(;b;b>>=1,a=a*a%mod) if(b&1) ans=ans*a%mod;
        return ans;
    }
    int main()
    {
        int n;cin>>n;
        int mx=0;
        ll sum=1;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            boom[a[i]]++;
            mx=max(mx,a[i]);
        }
        if(a[0]!=0||boom[0]!=1) cout<<0<<endl;
        else
        {
            for(int i=1;i<=mx-1;i++)
            {
                sum=sum*ksm(boom[i],boom[i+1])%mod;
            }
            cout<<sum<<endl;
        }
        
        return 0;
    }


Measured memory_bytes: 4248
#include <bits/stdc++.h>
using namespace std;
#define A 0
#define B 1
#define C 2

int main(){
  string str[3];
  for(int i=0 ; i<3 ; i++)
    cin >> str[i];
  
  int turn=A;
  while(str[turn].size()>0){
    if(str[turn][0]=='a'){
      str[turn]=str[turn].substr(1);
      turn=A;
    }else if(str[turn][0]=='b'){
      str[turn]=str[turn].substr(1);
      turn=B;
    }else if(str[turn][0]=='c'){
      str[turn]=str[turn].substr(1);
      turn=C;
    }
  }
  if(turn==A)
    cout << "A" << endl;
  else if(turn==B)
    cout << "B" << endl;
  else
    cout << "C" << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

struct Edge{
    ll dst;
    ll weight;
    Edge(ll dst, ll weight): dst(dst), weight(weight) {}
};

struct TmpDist{
    ll vertex;
    ll dist;
    TmpDist(ll vertex, ll dist): vertex(vertex), dist(dist) {}
    bool operator< (const TmpDist& right)const{
        return dist > right.dist;
    }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const ll INFLL = LLONG_MAX/3;

vector<ll> dijkstra(Graph &G, ll r){
    ll V = G.size();
    vector<ll> dist(V, INFLL);
    priority_queue<TmpDist> pq;
    vector<bool> check(V, false);
    TmpDist init(r, 0);
    pq.push(init);
    while(!pq.empty()){
        TmpDist td = pq.top();pq.pop();
        ll now = td.vertex;
        if(!check[now]){
            check[now] = true;
            dist[now] = td.dist;
            for (int i=0;i<(int)G[now].size();i++){
                if(dist[G[now][i].dst] > td.dist + G[now][i].weight){
                    TmpDist tdCandidate(G[now][i].dst, td.dist + G[now][i].weight);
                    pq.push(tdCandidate);
                }
            }
        }
    }
    return dist;
}

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

    ll N, X, Y;
    cin >> N >> X >> Y;
    X--, Y--;
    Graph G(N);
    REP(i, N-1){
    	Edge e = {i+1, 1};
    	Edge f = {i, 1};
    	G[i].push_back(e);
    	G[i+1].push_back(f);
    }
    Edge e = {Y, 1};
    Edge f = {X, 1};
    G[X].push_back(e);
    G[Y].push_back(f);

    vector<ll> res(N, 0);

    REP(i, N){
    	auto tmp = dijkstra(G, i);
    	REP(j, N){
    		if(j>i)
    		res[tmp[j]]++;
    	}
    }
    REP(i, N-1) cout << res[i+1] << endl;
    return 0;
}

Measured memory_bytes: 384
from collections import deque
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
d = [[-1] * N for _ in range(2)]
for i in range(2):
    d[i][i * (N - 1)] = 0
    q = deque([i * (N - 1)])
    while len(q) > 0:
        u = q.popleft()
        for v in edge[u]:
            if d[i][v] > -1:
                continue
            d[i][v] = d[i][u] + 1
            q.append(v)
S = 0
F = 0
for i in range(N):
    if d[0][i] > d[1][i]:
        S += 1
    else:
        F += 1
if F > S:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 29400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
#define all(a) begin(a),end(a)

#define MOD 1000000007

template <class T> T comb(T n, T r)
{
    if (n < 0 || n < r || r < 0)
        return 0;

    r = min(r, n - r);
    if (r == 0)
        return 1;

    vector<T> numer(r);
    vector<T> denom(r);

    iota(all(numer), n - r + 1);
    iota(all(denom), 1);

    for (T i = 1; i < r; i++) {
        T divisor = denom[i];
        if (divisor > 1) {
            T offset = (n - r) % (i + 1);
            for (T j = i; j < r; j += i + 1) {
                numer[j - offset] /= divisor;
                denom[j] /= divisor;
            }
        }
    }
    
    T p = 1;
    for(T i = 0; i < r; i++) {
        // p *= numer[i];
        p = p * numer[i] % MOD;
    }

    return p;
}

ll modpow(ll b, ll x, ll mod)
{
    if (x == 0)
        return 1;

    if (x & 1) {
        return modpow(b*b % mod, x/2, mod) * b % mod;
    } else {
        return modpow(b*b % mod, x/2, mod);
    }
}

int main()
{
    ll N, A, B; cin >>N>>A>>B;

    ll ans = 0;

    ll nca = 0;
    if (A <= N) {
        nca = comb(N, A);
    }
    ll ncb = 0;
    if (B <= N) {
        ncb = comb(N, B);
    }

    ll pow2 = modpow(2, N, MOD);

    ans = pow2 - 1 - nca - ncb;
    while (ans < 0) {
        ans += MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3400
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
less=[]
cnt=0
expense=0
for i in range(m):
    if ab[i][0]>=n:
        cnt+=1
    else:
        less.append(ab[i][1]-n)
if cnt<m-1:
    less.sort()
    expense=sum(less[:m-1-cnt])
print(expense)


Measured memory_bytes: 5716
import java.util.Scanner;
 
public class Main {
     public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(multipleOf2andN(n));
    }

    private static int multipleOf2andN(int n)
    {
        return n % 2 == 0 ? n : 2 * n;
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;

	vector<int32_t> H(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> H[i];
	}

	if (N == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	for (int32_t i = N - 1; i >= 1; i--) {
		if (H[i - 1] > H[i])
			H[i - 1]--;
	}

	bool res = true;
	for (int32_t i = N - 1; i >= 1; i--) {
		if (H[i - 1] > H[i]) {
			res = false;
			break;
		}
	}

	cout << (res ? "Yes" : "No") << endl;

	return 0;
}


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

void Main()
{
    int n;
    cin >> n;
    int m = 0, c = 0;
    for (int i = 0; i < n; i++)
    {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2) c++;
        else {m = max(m, c); c = 0; }
    }
    m = max(m, c);
    
    if (m >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3608
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    H,W=map(int,readline().split())
    grid=[]
    for i in range(H):
        S=readline().strip()
        grid.append(S)
    up=[[0]*W for _ in range(H)]
    down=[[0]*W for _ in range(H)]
    left=[[0]*W for _ in range(H)]
    right=[[0]*W for _ in range(H)]

    #up,left
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                if i==0:
                    up[i][j]=1
                else:
                    up[i][j]=up[i-1][j]+1
            
                if j==0:
                    left[i][j]=1
                else:
                    left[i][j]=left[i][j-1]+1

    #down,right
    for i in range(H-1,-1,-1):
        for j in range(W-1,-1,-1):
            if grid[i][j]==".":
                if i==H-1:
                    down[i][j]=1
                else:
                    down[i][j]=down[i+1][j]+1

                if j==W-1:
                    right[i][j]=1
                else:
                    right[i][j]=right[i][j+1]+1

    res=0
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                res=max(res,up[i][j]+down[i][j]+left[i][j]+right[i][j]-3)
    
    print(res)
if __name__=="__main__":
    main()

Measured memory_bytes: 176392
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

def check(y, x):
    dx = [1, 0, -1]
    dy = [1, 0, -1]
    for i in dy:
        for j in dx:
            nx = x + j
            ny = y + i
            if 0<=nx<w and 0<=ny<h:
                if  s[ny][nx] == '#':
                    s[y][x] += 1

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            s[i][j] = 0
            check(i, j)

for i in s:
    print(''.join(map(str, i)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
typedef long long ll;

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

const int mod = 998244353;
struct mint
{
  ll x; //
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
combination comb(100000);

mint H(int n, int r)
{
  return comb(n + r - 1, r);
}

int main()
{
  int N;
  cin >> N;
  vector<int> count(N, 0);

  int max_length = 0;
  rep(i, N)
  {
    int D;
    cin >> D;
    if (i == 0 && D != 0)
    {
      cout << 0 << endl;
      return 0;
    }
    count[D]++;
    max_length = max(max_length, D);
  }
  if(count[0] != 1)
  {
    cout << 0 << endl;
    return 0;
  }
  rep(i, max_length + 1)
  {
    if (count[i] == 0)
    {
      cout << 0 << endl;
      return 0;
    }
  }

  mint ans = 1;
  rep(i, max_length)
  {
    mint n = count[i];
    int r = count[i + 1];
    ans *= n.pow(r);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//入力
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int train_cost;
	int bus_cost;

	if (A < B) {
		train_cost = A;
	}
	else {
		train_cost = B;
	}

	if (C < D) {
		bus_cost = C;
	}
	else {
		bus_cost = D;
	}

	cout << train_cost + bus_cost;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

typedef unsigned long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll x;
    cin >> x;
    ll mam = 100, odp = 0;
    while (mam < x)
    {
        mam += mam / 100;
        ++odp;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int n,w,s,e;
char str[1001];
int main(void)
{
	int i;
	scanf("%s",str);
	FOR(i,0,strlen(str)){
		if(str[i]=='N') n=1;
		else if(str[i]=='W') w=1;
		else if(str[i]=='S') s=1;
		else e=1;
	}
	if((n==s)&&(w==e)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;
typedef long long int lli;
const lli mod1 = 1e9 +7, mod2 = 1e9 +21;
const lli base = 100;
 
lli power(lli n, lli p, lli mod){
    lli ret=1;
    for(int i=62; i>=0; i--){
        ret = (ret*ret)%mod;
        if((1LL<<i & p) != 0) ret = (ret*n)%mod;
    }
    return ret;
}
 
int main(){
    int n,m;
    string s;
    cin >> n >> m >> s;
     
    vector<lli> h1(n+1, 0), h2(n+1, 0);
    for(int i=0; i<n; i++){
        h1[i+1] = (h1[i]*base + s[i]-'a'+1)%mod1;
        h2[i+1] = (h2[i]*base + s[i]-'a'+1)%mod2;
    }
    int l=0, r=1;
    set<pair<lli, lli> > ans;
    for(int i=0; i<m; i++){
        string q;
        cin >> q;
        if(q=="L++") l++;
        if(q=="L--") l--;
        if(q=="R++") r++;
        if(q=="R--") r--;
        lli hash1 = (h1[r] -(h1[l]*power(base, r-l, mod1))%mod1 +mod1)%mod1;
        lli hash2 = (h2[r] -(h2[l]*power(base, r-l, mod2))%mod2 +mod2)%mod2;
        ans.insert(make_pair(hash1, hash2));
    }
    cout << ans.size() << endl;
    return 0;
}



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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll n, ans;
    ll cnt[100005];
    cin >> n;
    for(ll i = 1; i <= 100; i++) {
        for(ll j = 1; j <= 100; j++) {
            for(ll k = 1; k <= 100; k++) {
                ans = i * i + j * j + k * k + i * j + j * k + k * i;
                if(ans <= n) {
                    cnt[ans]++;
                }
            }
        }
    }

    for(ll i = 1; i <= n; i++) {
        cout << cnt[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3528
/**
 * Title: C - Traveling Salesman around Lake
 * Url: https://atcoder.jp/contests/abc160/tasks/abc160_c
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {

    int k, n; cin >> k >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int ans = k;
    for(int i=0; i<n; i++) {
        if(i==0) {
            ans = min(ans, k-a[i+1]+a[i]);
            ans = min(ans, -a[i]+a[n-1]);
        } else if (i==n-1) {
            ans = min(ans, a[i]-a[0]);
            ans = min(ans, k-a[i]+a[i-1]);
        } else {
            ans = min(ans, k-a[i+1]+a[i]);
            ans = min(ans, k-a[i]+a[i-1]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }

    long int count=0;
    for(int i=0; i<n; i++){
        while(1){
            if(a.at(i)%2) break;
            else{
                count++;
                a.at(i)/=2;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	int N, Ma, Mb; cin >> N >> Ma >> Mb;
	vector<int> a(N), b(N), c(N); rep(i, 0, N) { cin >> a[i] >> b[i] >> c[i]; }
	static int dp[410][410] = {};
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	rep(i, 0, N) {
		rrep(j, 0, 410 - a[i]) {
			rrep(k, 0, 410 - b[i]) {
				if (dp[j][k] == INF)continue;
				chmin(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
			}
		}
	}
	int ans = INF;
	rep(ma, 1, 410)rep(mb, 1, 410) {
		if (ma*Mb != Ma*mb)continue;
		chmin(ans, dp[ma][mb]);
	}
	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
void run();
signed main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13); run(); }
mt19937 rng(random_device{}());

void run() {
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;
    if (s == u)
        cout << a - 1 << " " << b << endl;
    else if (t == u)
        cout << a << " " << b - 1 << endl;
    else
        cout << a << " " << b << endl;
}



Measured memory_bytes: 256
input = gets.chomp.split
n = input[0].to_i
m = input[1].to_i

list = []
m.times do
  lr = gets.chomp.split.map!(&:to_i)
  list << lr
end
# puts "#{list}"

min, max = 0, n
for i in 0..(list.count - 1) do
  if list[i][0] > min
    min = list[i][0]
  end
  if list[i][1] < max
    max = list[i][1]
  end
end
# puts max, min

if min > max
  puts 0
else
  puts max - min + 1
end


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<double> A(N);
    for (int i = 0;i < N;i++) {
        cin >> A[i];
    }
    double ans = 0;
    for (int i = 0;i < N;i++) {
        ans+=1/A[i];
    }
    cout<<std::setprecision(20)<<1/ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

long long cnt[4005][4005];

void cntinc(int x,int xend,int y,int yend){
  cnt[x][y]++;
  cnt[xend][y]--;
  cnt[x][yend]--;
  cnt[xend][yend]++;
}

int main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int x,y;
    char cc;
    cin>>x>>y>>cc;
    if(cc == 'W') x += k;

    x %= 2*k;
    y %= 2*k;

    bool even = (x >= k) ^ (y >= k);

    x %= k;
    y %= k;

    if(even){
      cntinc(0,x+1,y+1,y+1+k);
      cntinc(x+1,x+k+1,0,y+1);
      cntinc(x+1,x+k+1,y+k+1,2*k);
      cntinc(x+k+1,2*k,y+1,y+k+1);
    } else {
      cntinc(0,x+1,0,y+1);
      cntinc(0,x+1,y+k+1,2*k);
      cntinc(x+k+1,2*k,0,y+1);
      cntinc(x+k+1,2*k,y+k+1,2*k);
      cntinc(x+1,x+k+1,y+1,y+k+1);
    }

  }


  for(int i=0;i<=2*k;i++){
    for(int j=1;j<=2*k;j++){
      cnt[i][j] += cnt[i][j-1];
    }
  }

  for(int i=0;i<=2*k;i++){
    for(int j=1;j<=2*k;j++){
      cnt[j][i] += cnt[j-1][i];
    }
  }

  /*for(int i=0;i<=k;i++){
    for(int j=0;j<=2*k;j++)cout<<cnt[i][j]<<" ";cout<<endl;
  }*/

  long long ma = 0;
  for(int i=0;i<=2*k;i++){
    for(int j=0;j<=2*k;j++){
      ma = max(ma,cnt[i][j]);
    }
  }


  cout<<ma<<endl;

}

Measured memory_bytes: 62976
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

mint dp[100005][13];

int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    dp[0][0] = mint(1);
    int now = 1;
    rep(i, s.size()) {
        bool flg = true;
        int v;
        if (s[i]=='?') flg = false;
        else {
            v = s[i] - '0';
        }
        if (flg) {
            int x = (v*now)%13;
            rep(j, 13) {
                dp[i+1][(j+x)%13] += dp[i][j];
            }
        }
        else {
            rep(k, 10) {
                int x = (k*now)%13;
                rep(j, 13){
                    dp[i+1][(j+x)%13] += dp[i][j];
                }
            }
        }
        now *= 10;
        now %= 13;
    }

    cout << dp[s.size()][5].x << endl;

    return 0;
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r, n;
    cin >> r >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    int minm = a[n-1] - a[0];
    for(int i=0;i<n-1;i++)
    {
        minm = min(minm, r - (a[i+1]-a[i]));
    }
    cout << minm << endl;
    // vector<int> f1, f2;
    // bool fs = false, fg = false;
    // for(int i=0;i<n;i++)
    // {
    //     if(a[i]>=r/2)
    //     {
    //         fg = true;
    //         f2.push_back(a[i]);
    //     }
    //     else
    //     {
    //         fs = true;
    //         f1.push_back(a[i]);
    //     }
    // }
    // sort(f1.begin(), f1.end());
    // sort(f2.begin(), f2.end());
    // if(fg && fs)
    // {
    //     cout << min(abs(f1[0]-f2[f2.size()-1]), abs(f1[f1.size()-1]-f2[0])) << endl;
    // }
    // else if(fg)
    // {
    //     cout << f2[f2.size()-1]-f2[0] << endl;
    // }
    // else
    // {
    //     cout << f1[f1.size()-1]-f1[0] << endl;
    // }
}

Measured memory_bytes: 1024
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

const long long mod = 1e9 + 7;

long long power(long long a, long long n) {
    long long ret = 1;
    while(n) {
        if(n & 1) {
            ret = ret * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

long long st(int x) {
    long long ret = 1;
    for(int i = 2; i <= x; i++) {
        ret = ret * i % mod;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> G(n + 1);
    for(int i = 1; i < n; i++) {
        int x, y; cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    vector<long long> inv(n + 1, 1), st(n + 1, 1), dp(n + 1), sz(n + 1), ans(n);
    for(long long i = 1; i <= n; i++) {
        st[i] = st[i - 1] * i % mod;
        inv[i] = power(st[i], mod - 2);
    }
    function<long long(int, int)> dfs = [&](int x, int p) {
        sz[x] = 1;
        long long ret = 1;
        for(int y : G[x]) {
            if(y == p) continue;
            ret = ret * dfs(y, x) % mod;
            ret = ret * inv[sz[y]] % mod;
            sz[x] += sz[y];
        }
        ret = ret * st[sz[x] - 1] % mod;
        return dp[x] = ret; 
    };
    function<void(int, int, long long)> DFS = [&](int x, int p, long long S) {
        for(int y : G[x]) {
            if(y == p) continue;
            S = S * dp[y] % mod;
        }
        ans[x - 1] = S * st[n - 1] % mod;
        for(int y : G[x]) {
            if(y == p) continue;
            long long tmp = S * power(dp[y], mod - 2) % mod;
            tmp = tmp * st[n - sz[y] - 1] % mod;
            tmp = tmp * inv[n - sz[y]] % mod;
            DFS(y, x, tmp);
        }
    };
    dfs(1, -1);
    for(int i = 1; i <= n; i++) {
        dp[i] = dp[i] * inv[sz[i]] % mod; 
    }
    DFS(1, -1, 1);
    for(auto x : ans) cout << x << '\n';

    return 0;
}


Measured memory_bytes: 21748
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int n, ans, G[300][300][4];
const int mv[4][2] = { {-1,0},{0,-1},{-1,-1},{-1,1} };
inline bool nextChar(void) {
	char c = getchar();
	while (c != '1'&&c != '0')c = getchar();
	return c == '1';
}
signed main(void) {
	while (scanf("%d", &n) && n) {
		memset(G, 0, sizeof(G)), ans = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++) if (nextChar())
				for (int k = 0; k < 4; k++)
					G[i][j][k] = G[i + mv[k][0]][j + mv[k][1]][k] + 1,
					ans = ans < G[i][j][k] ? G[i][j][k] : ans;
		printf("%d\n", ans);
	}
}

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

using namespace std;

#define FOR(i, a, b) for (int i=(a);i<(b);++i)
#define ROF(i, a, b) for (int i=(b)-1;i>=(a);--i)
#define REP(i, n) for (int i=0;i<(n);++i)
#define PRE(i, n) for (int i=(n)-1;i>=0;--i)
#define FOREACH(a, v) for(auto a : v)

#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cerr<<#x<<": "<<x<<endl
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)

#define INF INT_MAX/3
#define eps 1e-14

#define ll long long
using vint = vector<int>;

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a * b % 2 ? "Odd" : "Even") << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    
    if(n == 1)
    {
        cout << A[0] << '\n';
        return 0;
    }
    
    vector<ll> prefixSum(n);
    prefixSum[0] = A[0];
    for(int i = 1; i < n; i++)
    {
        prefixSum[i] = prefixSum[i-1]+A[i];
    }
    
    vector<vector<ll>> dp(n,vector<ll>(n));
    for(int i = 0; i < n; i++)
    {
        dp[i][i] = A[i];
    }
    
    for(int i = n-1; i >= 0; i--)
    {
        for(int j = i+1; j < n; j++)
        {
            ll sum1 = prefixSum[j]-prefixSum[i];
            ll sum2 = prefixSum[j-1];
            if(i > 0)
            {
                sum2 -= prefixSum[i-1];
            }
            
            dp[i][j] = max(A[i]+sum1-dp[i+1][j], A[j]+sum2-dp[i][j-1]);
        }
    }
    
    // for(int i = 0; i < n; i++)
    // {
    //     for(int j = 0; j < n; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << '\n';
    // }
    
    ll X = max(A[0]+prefixSum[n-1]-prefixSum[0]-dp[1][n-1], A[n-1]+prefixSum[n-2]-dp[0][n-2]);
    ll Y = prefixSum[n-1]-X;
    
    // cout << A[0]+prefixSum[n-1]-prefixSum[0]-dp[1][n-1] << " " << A[n-1]+prefixSum[n-2]-dp[0][n-2] << '\n';
    cout << X-Y << '\n';
    
    return 0;
}

Measured memory_bytes: 70784
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


inline int popCount(unsigned int x) {
	x = x - ((x >> 1) & 0x55555555);
	x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
	x = (x + (x >> 4)) & 0x0F0F0F0F;
	x = x + (x >> 8);
	x = x + (x >> 16);
	return x & 0x0000003F;
}


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

	int n;
	cin>>n;
	int a[10];
	rep(i, n)cin >> a[i];

	int ans=1,odd=1;
	rep(i,n)ans*=3;
	rep(i,n){
		if (a[i]&1)odd*=1;
		else odd*=2;
	}
	ans-=odd;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
int n;
long long X=0,x=0,ans=1000000000000000000LL;
cin>>n;
vector<long long> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
X+=a[i];
}
for(int i=0;i<n;i++){
x+=a[i];
if(i+1<n)ans=min(ans,abs(X-2*x));
}
cout<<ans<<endl;
}
  

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define rrep()
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    stack<string> st;
    string s;
    int ans=0;
    cin>>ans;
    while(1){
        cin>>s;
        if(s=="=")break;
        
        if(s=="+"||s=="-"||s=="*"||s=="/")st.push(s);
        else {
            string ss=st.top();
            st.pop();
            if(ss=="+"){
                ans+=stoi(s);
            }else if(ss=="-"){
                ans-=stoi(s);
            }else if(ss=="*"){
                ans*=stoi(s);
            }else if(ss=="/"){
                ans/=stoi(s);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3196