akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;

int main (){
    int n, x, sum = 0, aux, count = 1;
    cin >> n >> x;

    for (int i=0; i<n; i++){
        cin >> aux;
        sum += aux;
        if (sum <= x) count++;
        else break;
    }
    cout << count << endl;
    return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,res,i,j;
int main()
{   cin>>n;
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    long long dp[n][3];
    dp[0][0]=a[0];dp[0][1]=a[1];dp[0][2]=a[2];

    for(i=1;i<n;i++)
    {   cin>>a[0]>>a[1]>>a[2];
        dp[i][0]=max(dp[i-1][1]+a[0],dp[i-1][2]+a[0]);
        dp[i][1]=max(dp[i-1][0]+a[1],dp[i-1][2]+a[1]);
        dp[i][2]=max(dp[i-1][0]+a[2],dp[i-1][1]+a[2]);
    }

    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
    return 0;
}


Measured memory_bytes: 2560
M=[0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(int(M[K]))

Measured memory_bytes: 3060
import scala.io.StdIn.{readLine,readInt}
 
object Main extends App {
  def getDigit(x:Int) = if (x>=10) (x-10,1) else (x,0)

  def getSum(s:String,t:String):String = {
    if(s.length > 80 || t.length > 80) "overflow"
    else {
      val (x,y) = if(s.length>t.length) (s,t) else (t,s)
      val f = (i:Int,j:Int) => if(j<0) x(i).asDigit else x(i).asDigit + y(j).asDigit
      def loop(i:Int,j:Int,sum:List[Int],carry:Int):List[Int] =  {
        if(i<0) { if(carry > 0) carry::sum else sum }
        else {
          val (d,c) = getDigit(f(i,j)+carry)
          loop(i-1, j-1, d::sum, c)
        }
      }
      val r = loop(x.length-1,y.length-1,Nil,0).mkString
      if(r.length > 80) "overflow" else r
    }
  }
 
  for(i<-1 to readInt) println(getSum(readLine,readLine))
}

Measured memory_bytes: 43796
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int a[35][100005];

int main(void) {
    int N, C;
    cin >> N >> C;
    rep(i, 0, N) {
        int s, t, c;
        scanf("%d %d %d", &s, &t, &c);
        a[c][s] += 1; 
        a[c][t+1] += -1;
    }

    rep(i, 1, C+1) rep(j, 1, 100005) {
        a[i][j] += a[i][j-1]; 
    }

    int ans = -1; 
    rep(i, 1, 100005) {
        int t = 0;
        rep(j, 1, C+1) if (a[j][i]>=1) t++; 
        ans = max(ans, t);
    }

    printf("%d\n", ans);

	return 0;
}


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


main(){
    int n[10];
    int i,j,temp;
    int k,l;
    for(i=0;i<10;i++){

        scanf("%d",&n[i]);
    }
    for(l=0;l<10;l++){
        for(j=l+1;j<10;j++){
            if(n[l]>n[j]){
                temp = n[l];
                n[l] = n[j];
                n[j] = temp;
            }
        }
    }
    for(k=9;k>=7;k--){

        printf("%d\n",n[k]);
    }
return 0;

}

Measured memory_bytes: 600
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#include<iostream>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;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;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=100005;
const int mod=1e9+7;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
char ch[MAXN];
int val[MAXN],pres[MAXN],pos[5];
int f[MAXN],S[4][MAXN],R[MAXN],L[MAXN];
int li[MAXN],hd,tl;
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	#ifdef Rose
		double BeginJudgeTime=clock();
	#endif
	scanf("%s",ch+1);int len=strlen(ch+1);
	for(int i=1;i<=len;i++)val[i]=ch[i]-'a'+1;
	memset(pos,-1,sizeof(pos));pos[0]=0;
	for(int i=1,S=0,v=0;i<=len;i++)
	{
		while(S>1)S-=(val[v]==val[v+1]),++v;
		while(S==1&&val[v]!=val[v+1])++v;
		R[i]=v-1;S+=(val[i+1]==val[i]);
		pres[i]=(pres[i-1]+val[i])%3;
		L[i]=pos[pres[i]]+1;pos[pres[i]]=i;
	}
	if(R[len]==-1)return pr2(1),0;
	f[0]=S[0][0]=S[3][0]=1;
	for(int i=1;i<=len;i++)
	{
		if(R[i]>=L[i]-1)f[i]=(S[3][R[i]]-S[3][L[i]-1]+mod)%mod;
		ad(f[i],f[i-1]);
		for(int j=0;j<=3;j++)S[j][i]=S[j][i-1];
		ad(S[pres[i]][i],f[i]);ad(S[3][i],f[i]);
	}int ans=0;
	for(int i=1;i<=len;i++)if(pres[len]==pres[i])ad(ans,f[i]);
	pr2(ans);
//	pr2(f[len]);
	#ifdef Rose
		double EndJudgeTime=clock();
		cerr<<"JudgeTime is"<<" ";
		cerr<<(EndJudgeTime-BeginJudgeTime)/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
#define ALL(a)  (a).begin(),(a).end()
ll n;


int main(){
    cin>>n;
    vector<ll>a(n),b(n),c(n);
    rep(i,n)cin>>a[i];rep(i,n)cin>>b[i];rep(i,n)cin>>c[i];
    sort(ALL(a));sort(ALL(c));
    ll ans=0;
    rep(i,n){
        ll A=lower_bound(ALL(a),b[i])-a.begin();
        ll C=c.end()-upper_bound(ALL(c),b[i]);
        ans+=A*C;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,i;
	cin>>a>>b;
	for(i=1;i<=1200;i++)
		if(i*2/25==a&&i/10==b)
		{
			cout<<i<<endl;
			return 0;
		}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

string alph = "bdpq";
signed main() {
    string s; cin >> s;
    string s2 = "";
    rep(i,0,s.length()) {
        int t = alph.find(s[i]) ^ 1;
        s2 += alph[t];
    }
    reverse(s2.begin(), s2.end());
    if(s2 == s) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int SIZE = 1009;

int h, w;
char field[SIZE][SIZE];
int cost[SIZE][SIZE];
P dir[4] = {P(-1, 0), P(0, -1), P(1, 0), P(0, 1)};

int main() {
    cin >> h >> w;
    fill(field[0], field[SIZE], '#');
    fill(cost[0], cost[SIZE], 0);

    queue<P> q;
    for(int y = 1; y <= h; y++) {
        for(int x = 1; x <= w; x++) {
            char c;
            cin >> c;
            field[x][y]= c;
            if(c == '#')    q.push(P(x, y));
        }
    }

    while(!q.empty()) {
        int cx, cy;
        tie(cx, cy) = q.front(); q.pop();
        for(auto d : dir) {
            int nx, ny;
            tie(nx, ny) = d;
            nx += cx; ny += cy;
            if(field[nx][ny] == '#')    continue;
            field[nx][ny] = '#';
            q.push(P(nx, ny));
            cost[nx][ny] = cost[cx][cy] + 1;
        }
    }
    cout << *max_element(cost[0], cost[SIZE]) << endl;
}

Measured memory_bytes: 13456
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
using namespace std;

typedef long long ll;

const int MAX_N = 3000;
int dp[MAX_N+1][MAX_N+1];

int main(){
   int N, T;
   cin >> N >> T;
   vector<pair<int, int>> a(N);
   for(int i = 0; i <= N-1; i++){
       int A, B;
       cin >> A >> B;
       a[i]= make_pair(A, B);
   }
   sort(a.begin(), a.end());
   
   for(int i = 0; i < N; i++){
        for(int j = 1; j < T; j++){
            if(j >= a[i].first ){
                dp[i+1][j] = max(max(dp[i][j], dp[i+1][j-1]), a[i].second+dp[i][j-a[i].first]);
            } else
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-1]);
        }
        dp[i+1][T] = max(dp[i+1][T-1], dp[i][T-1]+a[i].second);
   }
   int ans = 0;
   for(int i = 1; i <= N; i++) ans = max(ans, dp[i][T]);
   cout << ans << endl;
}



Measured memory_bytes: 35456
N = int(input())
Ln = list(map(int,input().split(' ')))
max_num = 0
sum_num = 0
for l in Ln:
    sum_num += l
    max_num = max(max_num,l)
if sum_num - max_num > max_num:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main(){
	ll n;
	cin>>n;
	ll x,sum=0;
	for(int i=0;i<n;i++){
		cin>>x;
		sum+=x;
	}
	cout<<sum-n;;
}

Measured memory_bytes: 256
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int n,m,k,cnt,tot,ans=1,fac[210],invfac[210],low[60],dfn[60],head[60],to[210],nxt[210],a[60];
bool vis[60];
stack<int>Stack;
int C(int n,int m){
	return 1ll*fac[n]*invfac[m]%mod*invfac[n-m]%mod;
}
void add_edge(int u,int v){
	nxt[++tot]=head[u];
	to[tot]=v;
	head[u]=tot;
	return;
}
int qpow(int x,int n){
	int ret=1;
	while(n){
		if(n&1)
			ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		n>>=1;
	}
	return ret;
}
void init_fac(int n){
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%mod;
	invfac[n]=qpow(fac[n],mod-2);
	for(int i=n-1;~i;i--)
		invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	return;
}
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int polya(int n){
	int sum=0;
	for(int i=1;i<=n;i++){
		sum+=qpow(k,gcd(i,n));
		if(sum>=mod)
			sum-=mod;
	}
	return 1ll*sum*qpow(n,mod-2)%mod;
}
void InitInput(){
	memset(head,-1,sizeof(head));
	scanf("%d%d%d",&n,&m,&k);
	init_fac(m+k);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	return;
}
void tarjan(int u,int fa){
	dfn[u]=low[u]=++cnt;
	Stack.push(u);
	for(int i=head[u];~i;i=nxt[i]){
		int v=to[i];
		if(v==fa)
			continue;
		if(!dfn[v]){
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
			if(low[v]>=dfn[u]){
				int tot1=0,tot2=0,x;
				do{
					x=Stack.top();
					Stack.pop();
					a[++tot1]=x;
				}while(x!=v);
				a[++tot1]=u;
				for(int j=1;j<=tot1;j++)
					vis[a[j]]=1;
				for(int j=1;j<=tot1;j++)
					for(int k=head[a[j]];~k;k=nxt[k])
						if(vis[to[k]])
							++tot2;
				tot2>>=1;
				if(tot2<tot1)
					ans=1ll*ans*k%mod;
				if(tot2==tot1)
					ans=1ll*ans*polya(tot1)%mod;
				if(tot2>tot1)
					ans=1ll*ans*C(tot2+k-1,k-1)%mod;
				for(int j=1;j<=tot1;j++)
					vis[a[j]]=0;
			}
		}
		else low[u]=min(low[u],dfn[v]);
	}
	return;
}
int getans(){
	for(int i=1;i<=n;i++)
		if(!dfn[i])
			tarjan(i,0);
	return ans;
}
int main(){
	InitInput();
	printf("%d",getans());
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"bufio"
	"math"
)

var sc = bufio.NewScanner(os.Stdin)
var buf = make([]byte, 1000)

func inputLine() string{
	sc.Scan()
	return sc.Text()
}

func scanInt() int {
	out, e := strconv.Atoi(inputLine())
	if e != nil {
        panic(e)
    }
	return int(out)
}

func scanIntArray(n int) []float64 {
	out := make([]float64, n)
	for i, v := range(strings.Split(inputLine(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = float64(num)
	}
	return out
}
//  template end

func main() {
	sc.Buffer(buf, 10000)
	N := scanInt()
	ta := scanIntArray(2)
	T, A := ta[0], ta[1]
	H := scanIntArray(N)
	var min float64 = 100000.0
	min_i := -1
	for i:=0; i<N; i++ {
		d :=math.Abs(A - (T - H[i]*0.006))
		if d < min {
			min = d
			min_i = i
		}
	}
	fmt.Println(min_i+1)
}

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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <pair <int, int> > t[n];
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            t[i].push_back({x, y});
        }
    }
    int ans = 0;
    for (int msk = 0; msk < (1 << n); msk++) {
        bool bad = false;
        vector <int> honest(n, false);
        for (int j = 0; j < n; j++) {
            if (msk & (1 << j)) {
                honest[j] = true;
            }
        }
        for (int i = 0; i < n; i++) {
            for (auto p : t[i]) {
                int x = p.first;
                int y = p.second;
                if (honest[i]) {
                    if (y != honest[x]) {
                        bad = true;
                    }
                }
            }
        }
        if (!bad) {
            ans = max(ans, __builtin_popcount(msk));
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> sum(n+1, 0);
    rep(i,n){
        cin >> a[i];
        a[i]--;
        sum[i+1] = (sum[i] + a[i]) % k;
    }

    map<int, int> dp;
    queue<int> q;
    ll ans = 0;
    for(int i=0; i <= n; ++i){
        int s = sum[i];
        ans += dp[s];
        dp[s]++;
        q.push(s);
        if(q.size() == k){
            dp[q.front()]--;
            q.pop();
        }
    }

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


Measured memory_bytes: 12032
N,M = map(int,(input().split()))
if N %2 == 1:
    for i in range(M):
        print(i+1,N-i)
else:
    for i in range(min(M,N//4)):
        print(i+1,N-i)
    for i in range(max(0,M-N//4)):
        print(N//4+i+1,N-N//4-i-1)

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

typedef std::pair<int, int> ipair;
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k;i--)
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define mp make_pair

const int mod = 1000000007;
const ld pi = acos(-1);
const int maxn = 2001;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
#define IOS  std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int32_t main(){
  int n;  cin>>n;
  vector<int>A(n),B(n-1); fr(i,0,n-1) cin>>B[i];
  int sum = 0;
  A[0] = B[0];
  fr(i,0,n-1){
    A[i] = min(A[i],B[i]);
    sum += A[i];
    A[i+1] = B[i];
  }
  sum += A[n-1];
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    for(int i=0;i<n;i++) cin >> t[i];
    sort(t.begin(), t.end());

    int j = 0, ans = 1;
    for(int i=0;i<n;i++) {
        if(t[i] > t[j] + k || i == j + c) {
            ans++;
            j = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        String s[] = new String[3];
        char c[][] = new char[3][3];
        for(int i=0;i<3;i++){
          s[i] = sc.next();
        }
        for(int i=0;i<3;i++){
          for(int j=0;j<3;j++){
            c[i][j] = s[i].charAt(j);
          }
        }
        for(int i=0;i<3;i++){
          s[i] = String.valueOf(c[i][i]);
        }
      
        System.out.println(s[0]+s[1]+s[2]);  
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  struct node *right,*left,*parent;
};
struct node *root,*NIL;
struct node * find(struct node *u,int k){
  while(u!=NIL &&k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}
void insert(int k){
  struct node *y =NIL;
  struct node *x =root;
  struct node *z;

  z = (struct node*)malloc(sizeof(struct node));
  z->key =k;
  z->left =NIL;
  z->right =NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key < y->key)y->left=z;
  else y->right=z;
}
void inorder(struct node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(struct node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      struct node *t = find(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
}



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

bool f[25][61];

int main()
{
	for (int i = 0; i < 2; i++){
		int n;
		scanf("%d", &n);
		for (int j = 0; j < n; j++){
			int h, m;
			scanf("%d %d", &h, &m);
			f[h][m] = true;
		}
	}
	
	bool f2 = false;
	for (int h = 0; h < 24; h++){
		for (int m = 0; m < 60; m++){
			if (f[h][m]){
				if (f2) printf(" ");
				f2 = true;
				printf("%d:%02d", h, m);
			}
		}
	}
	puts("");
	
	return 0;
}

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

bool is_prime(long long _Num){
    if(_Num < 2)return false;
    if(_Num % 2 == 0){
        if(_Num == 2)return true;
        else return false;
    }
    bool prime = true;
    for(long long i = 3; i <= sqrt(_Num); i += 2){
        if(_Num % i == 0){
            prime = false;
            break;
        }
    }
    return prime;
}

int main(){
    long long A, B;
    cin >> A >> B;
    if(A < B)swap(A, B);//A >= B
    
    set<long long> ans;
    ans.insert(1);
    for(long long i = 2; i <= sqrt(A); i++){
        if(A % i == 0){
            long long j = A / i;
            if(B % i == 0 && is_prime(i))ans.insert(i);
            if(B % j == 0 && is_prime(j))ans.insert(j);
        }
        if(B % i == 0){
            long long j = B / i;
            if(A % i == 0 && is_prime(i))ans.insert(i);
            if(A % j == 0 && is_prime(j))ans.insert(j);
        }
    }
    if(A == B && is_prime(A))ans.insert(A);
    
    cout << ans.size() << endl;
    return 0;
}

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

using namespace std;
long long c[30][200020],d[30][200020];
int main(){
	long long i,j,n,a,b,e,x,ans=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a;
		x = 1;
		for(j=1;j<30;j++){
			x *= 2;
			c[j][i] = a%x;
		}
	}
	for(i=0;i<n;i++){
		cin >> b;
		x = 1;
		for(j=1;j<30;j++){
			x *= 2;
			d[j][i] = b%x;
		}
	}
	for(j=1;j<30;j++){
		sort(c[j],c[j]+n);
		sort(d[j],d[j]+n);
	}
	x = 1;
	for(j=1;j<30;j++){
		e = 0;
		for(i=0;i<n;i++){
			e += lower_bound(d[j],d[j]+n,2*x-c[j][i])-lower_bound(d[j],d[j]+n,x-c[j][i])+lower_bound(d[j],d[j]+n,4*x-c[j][i])-lower_bound(d[j],d[j]+n,3*x-c[j][i]);
		}
		ans += x*(e%2);
		x *= 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 92416
#include<bits/stdc++.h>
using namespace std;
int h,w,m;
//struct pos{
//	int x,y;
//	friend bool operator < (pos a,pos b){
//		if(a.x==b.x)return a.y<b.y;
//		return a.x<b.x;
//	}
////	pos(){}
////	pos(int a,int b):x(a),y(b){}
////	bool operator < (const pos &o) const{
////		return key<o.x||y<o.y;
////	}
//};
struct kkk
{
	int num,sum;
};
kkk lie[300005],hang[300005];
kkk ly[300005],hy[300005];
bool cmp(kkk a,kkk b)
{
	return a.sum>b.sum;
}
int xx[300005],yy[300005];
//map<pos,int> p;

int main()
{
	scanf("%d%d%d",&h,&w,&m);
	for(int i=1; i<=h; i++)
		hang[i].num=i;
	for(int i=1; i<=w; i++)
		lie[i].num=i;
	for(int i=1; i<=m; i++)
	{
		scanf("%d%d",&xx[i],&yy[i]);
		lie[yy[i]].sum++;
		hang[xx[i]].sum++;
	}
	for(int i=1; i<=h; i++)
	{
		hy[i].sum=hang[i].sum;
	}
	for(int i=1; i<=w; i++)
	{
		ly[i].sum=lie[i].sum;
	}
	//从大到小排序 
	sort(hang+1,hang+h+1,cmp);
	sort(lie+1,lie+w+1,cmp);
	// 
	int maxn=hang[1].sum+lie[1].sum;
	long long cnt=0;
	//枚举所有 点 
	//有几种相同的情况 
	for(int i=1; i<=m; i++)
		if(hy[xx[i]].sum+ly[yy[i]].sum==maxn)
			cnt++;
	
	long long ch=0,cl=0;
	for(int i=1; i<=h; i++)
		if(hang[i].sum==hang[1].sum)
			ch++;
	for(int i=1; i<=w; i++)
		if(lie[i].sum==lie[1].sum)
			cl++;
	if(ch*cl-cnt>0)
		printf("%d",hang[1].sum+lie[1].sum);
	else 
		printf("%d",hang[1].sum+lie[1].sum-1);
	return 0;
}


Measured memory_bytes: 15492
import java.util.*;

public class Main {
	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());//ボタンの数
		int CNT = 1;//入力終了を判定するフラグ
		int i=1;//ボタンi
		int[] NextButton = new int[N+1];//次に光るボタンを格納する配列
		while(CNT <= N){
			NextButton[CNT] = Integer.parseInt(scan.next());
			CNT++;
		}
		scan.close();
		CNT = 1;
		while(true){
			if(CNT > N){//不可能な場合
				System.out.println("-1");
				break;
			}
			if(NextButton[i] == 2){//2だった場合
				System.out.println(CNT);
				break;
			}
			else {
				i = NextButton[i];
			}

			CNT++;
		}
}
}

Measured memory_bytes: 48932
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define fi first
#define se second

using namespace std;

const int N=200010;

typedef long long ll;

int n,m,cnt,a[N];
struct stp{
  int fi,se,lk;
  stp(int x=0,int y=0,int z=0):fi(x),se(y),lk(z){}
  friend bool operator <(stp a,stp b){
    return a.fi>b.fi;
  }
}p[N];

priority_queue<stp> Q;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

inline void rea(int &x){
  char c=nc(); x=0;
  for(;c>'9'||c<'0';c=nc());for(;c>='0'&&c<='9';x=x*10+c-'0',c=nc());
}

inline int cmp(stp a,stp b){ return a.fi<b.fi; }

int main(){
  rea(n); rea(m);
  for(int i=1;i<=n;i++) rea(a[i]);
  for(int i=1;i<n;i++){
    if(a[i]<a[i+1]) p[++cnt]=stp(a[i],a[i+1]);
    else p[++cnt]=stp(a[i],m),p[++cnt]=stp(0,a[i+1],m-a[i]);
  }
  ll ans=1LL<<60,cur=0;
  for(int i=1;i<=cnt;i++) cur+=p[i].se-p[i].fi;
  sort(p+1,p+1+cnt,cmp); int q=1;
  for(int i=1;i<=m;i++){
    while(!Q.empty()&&Q.top().fi<i)
      cur+=Q.top().fi-Q.top().se-1+Q.top().lk,Q.pop();
    cur-=Q.size();
    while(q<=cnt&&p[q].fi<i)
      cur-=i-p[q].fi+p[q].lk-1,Q.push(stp(p[q].se,p[q].fi,p[q].lk)),q++;
    if(cur<ans) ans=cur;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4728
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] box=new int[n];
		int[] can=new int[n];
		can[0]=1;
		Arrays.fill(box,1);
		for(int i = 0; i<m; i++){
			int x=sc.nextInt()-1;
			int y=sc.nextInt()-1;
			if(can[x]==1 && box[x]>1){
				can[y]=1;
			}
			if(can[x]==1 && box[x]==1){
				can[x]=0;
				can[y]=1;
			}
			box[x]--;
			box[y]++;
		}
		int ans=0;
		for(int i = 0; i<n; i++){
			if(can[i]==1){
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 76564
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
int calc(char c);
int play(int dealer, string *data);

char mark;

signed main()
{
    while ( cin >> mark, mark != '#' ) {
        string input[13][4];
        rep(i, 4) {
            rep(j, 13) {
                cin >> input[j][i];
            }
        }
        //cout << "input finished." << endl;
        int ns = 0, ew = 0;
        int dealer = 3;
        rep(turn, 13) {
            dealer = play(dealer, input[turn]);
            //cout << dealer << endl;
            if (dealer % 2) {
                ew++;
            } else {
                ns++;
            }
        }
        cout << ((ns < ew) ? "EW" : "NS" ) << " " <<
            max(ns, ew) - 6 << endl;
    }
    return 0;
}
        
int play(int dealer, string *data)
{
    char start = data[dealer][1];
    int max = 0, ret = dealer;
    //cout << start << " ";
    rep(i, 4) {
        //cout << data[i] << " " ;
        if (data[i][1] == mark) {
            int tmp = calc(data[i][0]) + 100;
            //cout << tmp << " ";
            if (tmp > max) {
                ret = i;
                max = tmp;
            }
        } else if (data[i][1] == start) {
            int tmp = calc(data[i][0]);
            //cout << tmp << " ";
            if (tmp > max) {
                max = tmp;
                ret = i;
            }
        }
    }
    //cout << endl;
    return ret;
}

int calc(char c)
{
    if ( '2' <= c && c <= '9') {
        return c - '0';
    } else if (c == 'T') {
        return 10;
    } else if (c == 'J') { 
        return 11;
    } else if (c == 'Q') { 
        return 12;
    } else if (c == 'K') { 
        return 13;
    } else if (c == 'A') { 
        return 14;
    } else {
        return 0;
    }
}

Measured memory_bytes: 3108
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in reversed(sorted(list(W))):
  for sgr in reversed(sorted(list(S))):
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
      if anssgr*(100+E)==E*(answtr+anssgr):
        print("{} {}".format(answtr+anssgr, anssgr))
        exit()
print("{} {}".format(answtr+anssgr, anssgr))

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

bool checkPrime(int num){
    bool isPrime = true;
    for(int i = 2; i <= num/2; i++){
        if(num % i == 0){
            isPrime = false;
            break;
        }
    }
    return isPrime;
}

int main(){
    int x, ans = 0;
    cin >> x;
    ans = x;
    while(checkPrime(x++) == false){
        ans = x;
    }
    cout << ans << endl;
        
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);

    int a,b,c;
    VI v(3);
    rep(i,3){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    if(v[0] == 5 && v[1] == 5 && v[2] == 7){
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;

    return 0;
}


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


int main()
{	
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b&&b<c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

#define int long long

int32_t main() {
  /*int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int ans = 0;
  for (int i = n - 1; i > 0; i--) {
    int a = arr[i], b = arr[i - 1];
    if (a + b == 5) {
      cout << "Infinite" << endl;
      return 0;
    } else ans += a + b;
  }
  cout << "Finite" << endl;
  cout << ans << endl;*/
  int n;
  cin >> n;
  int arr[5], b[5];
  for (int i = 0; i < 5; i++) {
    cin >> arr[i];
    b[i] = (n + arr[i] - 1) / arr[i];
  }
  int ans = 0;
  for (int i = 0; i < 5; i++) {
    if (i == 0) {
      ans += b[i];
    } else {
      b[i] = max(b[i], b[i - 1]);
      ans += b[i] - (b[i - 1] - 1);
    }
    //cout << i << " " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ws = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var sum = new int[ws.Length + 1];
        for (int i = 1; i < sum.Length; i++)
        {
            sum[i] = sum[i - 1] + ws[i - 1];
        }

        var d = int.MaxValue;
        int j = 1;
        for (int t = 1; t < n; t++)
        {
            while (j < ws.Length && j <= t)
            {
                j++;
            }
            
            d = Math.Min(d, Math.Abs(sum.Last() - sum[j] * 2));
        }
        Console.WriteLine(d);
    }
}


Measured memory_bytes: 13396
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,m,i;cin>>n>>m;
	vector<vector<int>>road(n);
	for(i=0;i<m;i++){
		int a,b;cin>>a>>b;
		a--;b--;
		road[a].pub(b);
		road[b].pub(a);
	}
	for(i=0;i<n;i++){
		if(road[i].size()%2==1){cout<<"No"<<endl;return 0;}
	}
	if(n+2>m){cout<<"No"<<endl;return 0;}
	if(n+2<m){cout<<"Yes"<<endl;return 0;}
	
	//�����P�[�X�����킢
	int yyyy=-1;
	for(i=0;i<n;i++){
		if(road[i].size()>=6){cout<<"Yes"<<endl;return 0;}
		if(road[i].size()==4){yyyy=i;break;}
	}
	//�݂�
	for(auto it:road[yyyy]){
		int mae=yyyy;
		int gen=it;
		while(road[gen].size()!=4){
			int qqq=mae;
			mae=gen;
			gen=road[gen][0]+road[gen][1]-qqq;
		}
		if(gen==yyyy){cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;
	return 0;
}
/*
5 7
1 2
1 3
1 4
1 5
2 3
2 4
2 5

7 9
4 2
4 3
2 3
1 4
1 5
4 5
1 6
1 7
6 7
*/

Measured memory_bytes: 5760
#include<stdio.h>
 
int main(){
   long int a,b,k;
   scanf("%lld %lld %lld",&a,&b,&k);
 
   if(a>=k){
      a-=k;
   }else if(a+b>=k){
      k-=a;
      a=0;
      b-=k;
   }else{
      a=0;
      b=0;
   }
      printf("%lld %lld",a,b);
   return 0;
   
}

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

int main(){
    int A, B, C, K;
    std::cin >> A >> B >> C >> K;
    long long maxVal = std::max({A, B, C});
    long long sum = A + B + C - maxVal;
    // greedy
    for(int i = 0; i < K; i++){
        maxVal *= 2;
    }
    sum += maxVal;
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main(){
    string s;
    cin>>s;
    if(s[s.length()-1]=='s')
        s+="es";
    else
        s+="s";
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3640
import math
     
n, D = map(int, input().split())
     
point = []
for _ in range(n):
	x = list(map(int, input().split()))
	point.append(x)
     
cnt = 0
for i in range(n-1):
	for j in range(i+1, n):
		dist = 0
		for d in range(D):
			dist += (point[i][d] - point[j][d])**2
     
		dist = math.sqrt(dist)
		if int(dist) == dist:
			cnt += 1
     
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 5005;
typedef long long ll;
const int mod = 1e9 + 7;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n;
struct T {
	int to, nxt;
} way[maxn << 1];
int h[maxn], num;
int fac[maxn], ifac[maxn], inv[maxn];
inline void link(int x,int y) {
	way[++num] = {y, h[x]}, h[x] = num;
	way[++num] = {x, h[y]}, h[y] = num;
}
int size[maxn];
int root, min;
inline void dfs0(int x,int fa = 0) {
	size[x] = 1;
	for(int i = h[x];i;i = way[i].nxt) if(way[i].to != fa) {
		dfs0(way[i].to, x);
		size[x] += size[way[i].to];
	}
}
inline void dfs1(int x,int fa = 0) {
	int max = n - size[x];
	for(int i = h[x];i;i = way[i].nxt) if(way[i].to != fa) {
		dfs1(way[i].to, x);
		max = std::max(max, size[way[i].to]);
	}
	if(max < min) {
		min = max;
		root = x;
	}
}
int g[maxn][maxn];
inline int C(int x,int y) {
	return (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
inline int A(int x,int y) {
	return (ll) fac[x] * ifac[x - y] % mod;
}
inline int solve(std::vector<int> v) {
	g[0][0] = 1; int s = 0, c = 0;
	for(int i : v) {
		++ c;
		rep(k, 0, s) rep(j, 0, i) {
			g[c][k + j] = (g[c][k + j] + (ll) g[c - 1][k] * C(i, j) % mod * A(i, j)) % mod;
		}
		s += i;
	}
	int ans = 0;
	rep(i, 0, n) {
		ans = (ans + ll(i & 1 ? mod - g[c][i] : g[c][i]) * fac[n - i]) % mod;
	}
	return ans;
}
int main() {
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2;i < maxn;++i) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 2, n) {
		int x, y;
		cin >> x >> y;
		link(x, y);
	}
	dfs0(1);
	min = 1e9;
	dfs1(1);
	if(min + min == n) {
		cout << (ll) fac[min] * fac[min] % mod << '\n';
		return 0;
	}
	std::vector<int> v;
	for(int i = h[root];i;i = way[i].nxt) if(size[way[i].to] < size[root])
		v.push_back(size[way[i].to]);
	if(root != 1) v.push_back(n - size[root]);
	cout << solve(v) << '\n';
}


Measured memory_bytes: 96640
from collections import defaultdict, deque

N, M = map(int, input().split())
ab = []
for _ in range(N + M - 1):
    a, b = map(int, input().split())
    ab.append((a, b))

in_cnt = defaultdict(int)
rev = defaultdict(list)
outs = defaultdict(list)

for a, b in ab:
    in_cnt[b - 1] += 1
    rev[b - 1].append(a - 1)
    outs[a - 1].append(b - 1)

queue = deque([i for i in range(N) if in_cnt[i] == 0])
sorted_ans = []

while len(queue) != 0:
    v1 = queue.popleft()
    sorted_ans.append(v1)
    for v2 in outs[v1]:
        in_cnt[v2] -= 1
        if in_cnt[v2] == 0:
            queue.append(v2)

order = [i for i, v in sorted(enumerate(sorted_ans), key=lambda x: x[1])]

ans = [0] * N
ans[sorted_ans[0]] = 0
for v in sorted_ans[:0:-1]:
    ans[v] = max([(order[v2], v2) for v2 in rev[v]])[1] + 1

for a in ans:
    print(a)


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

int N;
vector<int> A(100);

void input() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];
}

int main() {
    input();
    int alice = 0;
    int bob = 0;
    int max;
    size_t index;
    std::vector<int>::iterator iter;

    for(int i = 0;i < N; i++){
        iter = max_element(A.begin(), A.end());
        max = *max_element(A.begin(), A.end());
        index = distance(A.begin(), iter);
        A.erase(A.begin() + index);

        if(i % 2 == 0){
            alice += max;
        } else{
            bob += max;
        }
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define maxn 100005
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pp;
const long long inf = 2e18;
int A,B,n,ans[maxn];
main(){
	//ios::sync_with_stdio(false); cin.tie(0);
	//freopen(".inp","r",stdin); freopen(".out","w",stdout);
	//freopen("inp.txt","r",stdin);
	cin>>A>>B; n=A+B; int i,j,k;
	if (A<=B){
		cout<<"Impossible"; return 0;
	}
	stack<int> st; st.push(0);
	char c;
	for (i=1;i<n;i++){
		if (!st.empty()){
			cout<<"? "<<st.top()<<' '<<i<<endl;
			cin>>c;
			if (c=='Y'){
				st.push(i);
			}
			else st.pop();
		}
		else st.push(i);
	}
	int ops=st.top(); ans[ops]=1;
	for (i=0;i<n;i++){
		if (i!=ops){
			cout<<"? "<<ops<<' '<<i<<endl;
			cin>>c;
			if (c=='Y') ans[i]=1;
			else ans[i]=0;
		}
	}
	cout<<"! ";
	for (i=0;i<n;i++) cout<<ans[i];
	
}

Measured memory_bytes: 724
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;
using System.Collections;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            return (long)N * (N - 1) / 2;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }
#pragma warning disable
    public class ConsoleReader
    {
        private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = ReadLineSplit();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader : IEnumerable<ConsoleReader>
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }

            public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator();
            IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

int n,len;
int head[MAXN],in[MAXN];
deque<pii> q;

int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    memset(head,-1,sizeof(head));
	scanf("%d",&n);
	q.push_back(make_pair(1,1));
	while(!q.empty()){
		pii u = q.front();
		q.pop_front();
		if(in[u.first])
		    continue;
		if(u.first == 0){
			printf("%d\n",u.second);
			return 0;
		}
		in[u.first] = 1;
		q.push_front(make_pair((u.first * 10) % n,u.second));
		q.push_back(make_pair((u.first + 1) % n,u.second + 1));
	}
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    std::deque<int> deq(10,0);
    deq[a]=1;
    deq[b]=1;
    deq[c]=1;
    deq[d]=1;
    if (deq[1]==1&&deq[9]==1&&deq[7]==1&&deq[4]==1) {
        cout<<"YES"<<endl;
    } else {
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._500problems
{
    class CF2017FinalC
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            int[] cnts = new int[13];
            for (int i = 0; i < n; i++)
            {
                cnts[array[i]]++;
            }
            if (cnts[0] > 0 || cnts[12] >= 2)
            {
                WriteLine(0);
                return;
            }

            bool[] on = new bool[25];
            on[0] = true;
            on[24] = true;
            List<int> vals = new List<int>();
            for (int i = 1; i <= 12; i++)
            {
                if (cnts[i] >= 3)
                {
                    WriteLine(0);
                    return;
                }
                if (cnts[i] == 2)
                {
                    on[i] = true;
                    on[24 - i] = true;
                }
                if (cnts[i] == 1)
                {
                    vals.Add(i);
                }
            }
            int allPat = 1 << vals.Count;
            int res = 0;
            for(int i = 0; i < allPat; i++)
            {
                bool[] onTemp = new bool[25];
                for(int j = 0; j <= 24; j++)
                {
                    onTemp[j] = on[j];
                }
                for(int j = 0; j < vals.Count; j++)
                {
                    if ((i & (1 << j)) > 0)
                    {
                        onTemp[vals[j]] = true;
                    }
                    else
                    {
                        onTemp[24 - vals[j]] = true;
                    }
                }
                int tmp = 0;
                int min = 24;
                for (int j = 1; j <= 24; j++)
                {
                    if (onTemp[j])
                    {
                        min = Min(min, j - tmp);
                        tmp = j;
                    }
                }
                res = Max(res, min);
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268