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

int main()
{
  int64_t N, K, s = 0;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  s = accumulate(A.begin(), A.end(), 0);
  set<int64_t> candidates;
  for (int64_t i = 1; i * i <= s; i++)
  {
    if (s % i == 0)
    {
      candidates.insert(i);
      candidates.insert(s / i);
    }
  }
  int64_t ans = 1;
  for (int64_t x : candidates)
  {
    int64_t need;
    {
      vector<int64_t> R(N);
      for (int i = 0; i < N; i++)
      {
        R[i] = A.at(i) % x;
      }
      sort(R.begin(), R.end());
      int64_t lsum = accumulate(R.begin(), R.end(), 0), rsum = 0;
      need = (1LL << 62);
      for (int i = N - 1; i >= 0; i--)
      {
        lsum -= R.at(i);
        rsum += x - R.at(i);
        need = min(need, max(lsum, rsum));
      }
    }
    if (need <= K)
      ans = max(ans, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3652
A=int(input())
B=int(input())
C=int(input())
X=int(input())
#x=X
n=0
for a in range(A+1):
    X1=X-500*a #
    for b in range(B+1):
        X2=X1-100*b
        for c in range(C+1):
            X3=X2-50*c
            if X3==0:
                n+=1
print(n)

Measured memory_bytes: 3060
/* DELAPAN.3gp */
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;

#ifdef DEBUG
	#define debug(...) printf(__VA_ARGS__)
	#define GetTime() fprintf(stderr,"Running time: %.3lf second\n",((double)clock())/CLOCKS_PER_SEC)
#else
	#define debug(...) 
	#define GetTime() 
#endif

//type definitions
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vint;

//abbreviations
#define A first
#define B second
#define MP make_pair
#define PB push_back

//macros
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n)-1; 0 <= i; --i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for (int i = (a); (b) <= i; --i)
#define FORIT(it,c) for (__typeof ((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define RESET(a,x) memset(a,x,sizeof(a))
#define EXIST(a,s) ((s).find(a) != (s).end())
#define MX(a,b) a = max((a),(b));
#define MN(a,b) a = min((a),(b));

inline void OPEN(const string &s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

/* -------------- end of DELAPAN.3gp's template -------------- */

char s[111];

int main(){
	scanf("%s", s);
	int n = strlen(s);
	ll x;
	sscanf(s, "%lld", &x);

	ll ans = 0;
	for (int mask = 0; mask < (1 << (n - 1)); ++mask) {
		ll temp = s[0] - '0';
		ll sum = 0;
		for (int i = 1; i < n; ++i) {
			if (mask & 1 << (i - 1)) {
				sum += temp;
				temp = 0;
			}
			temp = temp * 10 + (s[i] - '0');
		}
		sum += temp;
		ans += sum;
	}

	printf("%lld\n", ans);
	
	return 0;
}


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

int main(){
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;

  return 0;
}

Measured memory_bytes: 3580
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	long INF = (long) (1e19);
	PrintWriter pw = new PrintWriter(System.out);

	void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			long[] k = new long[n];
			for (int i = 0; i < n; ++i) {
				k[i] = sc.nextLong();
			}
			solve(n, k);
		}
		pw.close();
	}

	void solve(int n, long[] k) {
		ArrayList<List<Long>> lis = new ArrayList<>();
		int ans = 0;
		out: for (long w = k[0] * 2 - 1; w <= 2 * k[0] + 1; ++w) {
			long A = 0, B = 0;
			for (int i = n - 1; i >= 0; --i) {
				if (k[i] == w) {
					B += 1L << i;
					if (i > 0)
						continue;
				} else if (k[i] == 0) {
					if (i > 0)
						continue;
				} else {
					if (i == 0) {
						B += k[0];
					} else {
						B += k[i] + (1L << i) - 1;
					}
				}
				A = B - w + 1;
				if (check(A, B, k, n)) {
					++ans;
					lis.add(Arrays.asList(A, B));
				}
				continue out;
			}
		}
		if (ans == 0) {
			pw.println("None");
		} else if (ans == 1) {
			pw.println(lis.get(0).get(0) + " " + lis.get(0).get(1));
		} else {
			pw.println("Many");
		}
	}

	boolean check(long A, long B, long[] k, int n) {
		if ((1L << n) <= A || A <= 0 || (long) (1e18) < A)
			return false;
		if ((1L << n) <= B || B <= 0 || (long) (1e18) < B)
			return false;
		for (int i = n - 1; i >= 0; --i) {
			if (g(A, B, i) != k[i])
				return false;
		}
		return true;
	}

	long g(long A, long B, int i) {
		return f(B, i) - f(A - 1, i);
	}

	long f(long a, int i) {
		if (a <= 0)
			return 0;
		if (i == 0) {
			return (a + 1) / 2;
		}
		if ((1L << i) > a)
			return 0;

		int l = 0;
		while (1L << (l + 1) <= a) {
			++l;
		}
		if (i == l) {
			return a - (1L << i) + 1;
		}
		long d = a - ((1L << l) - 1);
		if (i == l) {
			return (1L << (l - 1)) + d;
		} else {
			return (1L << (l - 1)) + f(d - 1, i);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 132404
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N, M;
    void solve()
    {
        N = cin.nextint;
        M = cin.nextint;
        var G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray();
        for (int i = 0; i < M; i++)
        {
            int a = cin.nextint - 1;
            int b = cin.nextint - 1;
            G[a].Add(b);
            G[b].Add(a);
        }

        var Q = new Queue<int>();
        var C = new int[N];
        for (int i = 0; i < N; i++)
        {
            if (C[i] == 0)
            {
                C[i] = 1;
                Q.Enqueue(i);
                while (Q.Any())
                {
                    int u = Q.Dequeue();
                    foreach (var v in G[u])
                    {
                        if (C[v] == C[u])
                        {
                            WriteLine((long)N * (N - 1) / 2 - M);
                            return;
                        }
                        if(C[v] == 0)
                        {
                            C[v] = -C[u];
                            Q.Enqueue(v);
                        }
                    }
                }
            }
        }
        WriteLine((long)C.Count(i => i == 1) * C.Count(i => i == -1) - M);

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 31900
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

const ll MOD=1e9+7;
signed main() {
    ll n;
    cin>>n;
    vl t(n),a(n),m(n);
    cin>>t>>a;
    if(t[n-1]!=a[0]) {
        cout<<0<<endl;
        return 0;
    }
    if(n==1) {
        cout<<1<<endl;
        return 0;
    }
    if(n==2) {
        if(a[0]==a[1] || t[0]==t[1]) cout<<1<<endl;
        else cout<<0<<endl;
        return 0;
    }

    ll M=0;
    REP(i,n) {
        m[i]=min(t[i],a[i]);
        M=max(M,m[i]);
    }
    if(M!=a[0]) {
        cout<<0<<endl;
        return 0;
    }

    ll ans=1;
    FOR(i,1,n-1) {
        if(m[i-1]<m[i] || m[i]>m[i+1]) continue;
        ans*=m[i];
        ans%=MOD;
    }
    cout<<(ans%MOD)<<endl;
    return 0;
}


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

bool check(int a,int b,int c, int d){
  if(a+d==b+c)
    return true;
  else
    return false;
}

int main() {
  vector<vector<int>> data(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  if(!check(data.at(0).at(0),data.at(0).at(1),data.at(1).at(0),data.at(1).at(1)))
  cout << "No" << endl;
  else if(!check(data.at(0).at(1),data.at(0).at(2),data.at(1).at(1),data.at(1).at(2)))
  cout << "No" << endl;
  else if(!check(data.at(1).at(0),data.at(1).at(1),data.at(2).at(0),data.at(2).at(1)))
  cout << "No" << endl;
  else if(!check(data.at(1).at(1),data.at(1).at(2),data.at(2).at(1),data.at(2).at(2)))
  cout << "No" << endl;
  else
  cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;


int n,m;
int a[200000];
int b[200000];
map <int,int> mp;
int ans;
signed main(){
  cin >> n >> m;
  REP(i,n) cin >> a[i];
  int k = 0;
  REP(i,n){
    k += a[i];
    b[i] = k;
  }
  REP(i,n){
    mp[b[i]%m] ++;
  }
  mp[0] ++;
  for(map<int,int>::iterator it = mp.begin(),end = mp.end();it!=end;++it){
    int now = it->second;
    ans += max(now * (now-1) / 2 , (int)0);
    //dump(ans);
    //dump(it->first);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n, d, c = 0;
  cin >> n >> d;
  int x[n][d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      double l2 = 0.0;
      for (int k = 0; k < d; k++) {
        l2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      double l = sqrt(l2);
      if (l - int(l) == 0.0) {
        c++;
      }
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

static const int INF = 30;  // what's this

int main() {
    string s;
    cin >> s;
    int n = s.size(), x;
    bool alphabet[26] = { false };
    for (int i = 0; i < n; i++) {
        x = s[i] - 'a';
        alphabet[x] = true;
    }
    ll t = INF;
    for (int i = 0; i < 26; i++) {
        if (!alphabet[i]) {
            t = i;
            break;
        }
    }
    if (t == INF) cout << "None" << endl;
    else {
        char ans = t + 'a';
        cout << ans << endl;
    }
}

Measured memory_bytes: 512
def main():
    n = input()
    aa = []
    for _ in xrange(n):
        aa.append(input())
    bb = sorted(aa)
    b0, b1 = bb[-1], bb[-2]
    for a in aa:
        if a < b0:
            print b0
        else:
            print b1
 
 
if __name__ == '__main__':
    main()

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

int H, W, h, w;

void abc121a() {
  cout << (H - h) * (W - w) << '\n';
  return;
}

int main() {
  cin >> H >> W >> h >> w;
  abc121a();
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);

  for(int i = 0;i < n;i++)cin >> p[i];
  for(int i = 0;i < n;i++)cin >> q[i];

  int cnt_p = 0;
  int cnt_q = 0;
  vector<int> arr;
  for(int i = 1;i <= n;i++)arr.push_back(i);
  int now = 0;
  do{
    bool flag1 = true;
    bool flag2 = true;
    for(int i = 0;i < n;i++){
      if(arr[i] != p[i])flag1 = false;
      if(arr[i] != q[i])flag2 = false;
    }
      if(flag1)cnt_p = now;
      if(flag2)cnt_q = now;
      now++;
  }while(next_permutation(arr.begin(),arr.end()));

    cout << abs(cnt_q - cnt_p) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int n = 0;
		int max = 0;
		for(int k = 0; k < a; k++){
			int n2 = sc.nextInt();
			n += n2;
			if(max < n2){
				max = n2;
			}
		}
		n -= max/2;
		System.out.print(n);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 1e6 + 5;
const int oo = 1e9 + 5;
const LL ooll = 1e18 + 5;
const int MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng)

void solve() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i=0;i<3;++i) {
        int cnt = 1;
        while(i+1 < 3 && s[i+1] == s[i]) {
            ++cnt;
            ++i;
        }
        if (s[i] == 'R') ans = max(ans, cnt);
    }
    cout << ans << '\n';
}

int main() {
    FASTIO;
    int T = 1;
    // cin >> T;
    while(T--) {
        solve();
    }
    // cerr << fixed << setprecision(10);
    // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n';
    return 0;
} 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
const int mod = 1e9 + 7;
int main(void) {

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

    vi ans(n + 1, 0);
    for (int i = n; i >= 1; i--) {
        int cnt = 0;
        int now = i;
        while (now <= n) {
            cnt += ans[now];
            now += i;
        }
        if (cnt % 2 != a[i]) ans[i]++;
    
    }
    
    int cnt = 0;
    rrep (i, n) {
        if (ans[i]) cnt++;
    }
    
    cout << cnt << endl;
    rrep (i, n) {
        if (ans[i]) cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

template <typename T = int>
T in();

int main() {
    string S(in<string>());
    int count[2] = {0, 0};
    for (int i = 0; i < S.size(); i++) {
        int ind = S[i] - '0';
        count[ind]++;
    }
    cout << min(count[0], count[1]) * 2 << endl;

    return 0;
}

template <typename T = int>
T in() {
    T temp;
    cin >> temp;
    return temp;
}



Measured memory_bytes: 512
s = input()

n = int(len(s))
s_1 = s[:(n-1)//2]
s_2 = s[((n+3)//2-1):n]
ok,ok_1,ok_2 = False,False,False
#print(s_1,s_2)
if s == s[::-1]:
    ok = True
if s_1 == s_1[::-1]:
    ok_1 = True
if s_2 == s_2[::-1]:
    ok_2 = True
if ok and ok_1 and ok_2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
class mint{
    public:
        long long x;
 
    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};
const int nmax=200005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
// modintを使うときはllをmintに
mint com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
vector<vector<int>> g(nmax);
vector<mint> dp(nmax),ans(nmax);
vector<int> c(nmax);

void dfs1(int cur,int pre=-1){
    c[cur]=0;
    dp[cur]=1;
    for(int to:g[cur]){
        if(to==pre){
            continue;
        }
        dfs1(to,cur);
        dp[cur]*=dp[to]*com(c[cur]+c[to],c[to]);
        c[cur]+=c[to];
    }
    c[cur]++;
}
int n;
void dfs2(int cur,int pre=-1,mint res=1){
    dp[cur]*=res*com(n-1,n-c[cur]);
    for(int to:g[cur]){
        if(to==pre){
            continue;
        }
        res=dp[cur]/dp[to]/com(n-1,c[to]);
        dfs2(to,cur,res);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    COMinit();
    rep(i,n-1){
        int a,b;cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs1(0);
    dfs2(0);
    mint ans=0;
    rep(i,n){
        cout << dp[i] << endl;
    }
}

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

int main() {
  int k;
  cin >> k;
  
  if(k%2 == 0){
    cout << (k/2) * (k/2) << endl;
  }
  else {
    cout << ((k+1)/2) * (k/2) << endl;
  }
}


Measured memory_bytes: 256
n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

k = max(sum(a)-k,0)

a.sort()
f.sort()
f.reverse()

# rは100%満たす。lは100%満たさない
l = -1
r = a[-1]*f[0]*2

while l+1!=r:
    x = (l+r)//2
    b = []
    for i in range(n):
        b.append(min(x//f[i], a[i]))
    if k<=sum(b):
        r=x
    else:
        l=x

print(r)

Measured memory_bytes: 121156
/**
 *    author:  math2do
 *    created: 21.11.2019 17:7:56
**/

#include <bits/stdc++.h>

using namespace std;

const int N = 3001;

char a[N];
char b[N];
char s[N];
int at = 0;

int dp[N][N];
int st[N][N];

void build(int i, int j, int na, int nb) {
  if (i == na) return;
  if (j == nb) return;

  int which = st[i][j];
  if (which == 0) {
    s[at++] = a[i];
    build(i + 1, j + 1, na, nb);
  } else if (which == 1) {
    build(i + 1, j, na, nb);
  } else{
    build(i, j + 1, na, nb);    
  } 
}

int solve(int i, int j, int na, int nb) {
  if (i == na) return 0;
  if (j == nb) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  int ans = 0;
  if (a[i] == b[j]) {
    ans = max(ans, 1 + solve(i + 1, j + 1, na, nb));
    st[i][j] = 0;
  } else {
    int exa = solve(i + 1, j, na, nb);
    int exb = solve(i, j + 1, na, nb);
    if (exa > exb) {
      st[i][j] = 1;
    } else {
      st[i][j] = 2;
    } 
    ans = max(ans, exa);
    ans = max(ans, exb);
  }
  return dp[i][j] = ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL
    freopen("lcs.in", "rt", stdin);
  #endif
  scanf("%s", a);
  scanf("%s", b);

  int na = strlen(a);
  int nb = strlen(b);

  for (int i = 0; i < na; i++) {
    memset(dp[i], -1, N * sizeof(int));
    memset(st[i], -1, N * sizeof(int));
  } 

  solve(0, 0, na, nb);
  build(0, 0, na, nb);
  s[at++] = '\0';

  printf("%s", s);
  return 0;
}


Measured memory_bytes: 71040
#include<bits/stdc++.h>
using namespace std;
#define fast                         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int                          long long int
#define double                       long double
#define ff                           first
#define ss                           second
#define pb                           push_back
#define eb                           emplace_back
#define all(x)                       (x).begin(), (x).end()
#define sz(x)                        ((int)(x).size())
#define len(x)                       ((int)(x).length())
#define pii                          pair<int,int>
#define vi                            vector<int>
#define vd                           vector<double>
#define vs                            vector<string>
#define mp                          map<int,int>
#define ms(x,y)                     memset(x,y,sizeof(x))
#define ump                         unordered_map<int,int>

#define lb                            lower_bound
#define ub                            upper_bound
#define nx                            cout<<"\n";
#define inf                           9223372036854775807
#define PI                            3.14159265

const int MOD = 1e9 + 7;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int add(int a, int b) {    return ((a % MOD) + (b % MOD)) % MOD;}

inline int multi(int a, int b) {   return ((a % MOD) * (b % MOD)) % MOD;}

inline int sub(int a, int b) {       a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;}

inline int power(int a, int b) {       a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;}  return res;}

bool isPrime(int  x) {      if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;}

int dfs(int i, int dp[], vi adj[])
{

  if (dp[i] != -1)return dp[i];
  int res = 0;
  for (int j : adj[i])
  {
    res = max(res, 1 + dfs(j, dp, adj));
  }
  return dp[i] = res;
}
int32_t main()
{
  fast ;


  int n, m; cin >> n >> m;
  int dp[n + 1];
  ms(dp, -1);

  vi adj[n + 1];

  for (int i = 0; i < m; i++)
  {
    int a, b; cin >> a >> b;
    adj[a].pb(b);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
  {
    ans = max(ans, dfs(i, dp, adj));
  }
  cout << ans;

}



Measured memory_bytes: 9216
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    string left = "qwert asdfg zxcvb";
    string right = "yuiop hjkl nm";
    map<char, bool> isLeft;
    for (char& c : left) isLeft[c] = true;
    for (char& c : right) isLeft[c] = false;

    while (true) {
        string s; cin >> s;
        if (s == "#") break;
        int n = s.length();
        vector<bool> a(n);
        for (int i = 0; i < n; i++) a[i] = isLeft[s[i]];
        int cnt = 0;
        for (int i = 0; i + 1 < n; i++) {
            if (a[i] != a[i + 1]) cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3064
import java.util.Scanner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main{
    public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
      		int[] height = new int[10];
      		for(int i=0; i<10; i++){
              height[i]=sc.nextInt();
            }
      			Arrays.sort(height);
              System.out.println(height[9]);
              System.out.println(height[8]);
              System.out.println(height[7]);
    }
}



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

#define ll long long int
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt")  
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 998244353

ll gcd(ll x, ll y){ 
	if(x<y) 
		swap(x,y); 
	if(x%y==0)
		return y;
	return gcd(y, x%y);
}

// ll pwm(ll a, ll n){
// 	ll ans = 1;
// 	while(n>0){
// 		if(n%2==1){
// 			ans = (ans * a)%mod;
// 		}
// 		a = (a*a)%mod;
// 		n /= 2;
// 	}
// 	return ans%mod;
// }

const int pwn = 100010;
// ll pw[pwn];
// void pwtwo(){
// 	pw[0] = 1;
// 	for(int i=1; i<pwn; i++){
// 		pw[i] = (pw[i-1]*2)%mod;
// 	}
// }


ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
ll modInverse(ll a, ll m) 
{ 	
	if(a==1)
		return 1;
	//cout<<"mi "<<a<<" "<<m<<" ";
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1){
        //cout << "Inverse doesn't exist"<<endl; 
        return -1;
    }
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        //cout<<res<<endl;
        return res;
        // cout << "modular multiplicative inverse is " << res; 
    } 
} 
  
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll fact[300005];
ll init(){
	fact[0] = 1ll;
	for(int i=1; i<300005; i++)
		fact[i] = (fact[i-1]*i)%mod;
}

ll ncr(ll n, ll r){
	// cout<<" "<<n<<" "<<r<<endl;
	if(r>n)
		return 0;
	
	ll ans = fact[n];

	//if(r!=0)
	ans = (ans*modInverse(fact[r], mod))%mod;
	// if(n-r!=0)
	ans = (ans*modInverse(fact[n-r], mod))%mod;

	return ans;
}

int main(){
	// finput;
	// foutput;
	fast;

	ll n, k, i, j, x, m,a,b, sum;
	ll ans = 0ll;
	// string s;
	cin>>n>>a>>b>>k;
	init();
	for(i=0; i<=n; i++){
		// i;
		sum = k - a*i;
		if(sum<0 || sum%b!=0){
			continue;
		}

		j = sum/b;

		ans += (ncr(n, j)*ncr(n, i))%mod;
		ans %= mod;
	}

	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
ll GCD(ll a, ll b) {
	if (b == 0)return a;
	return GCD(b, a%b);
}
ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}
ll mypow(ll a, ll b,ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}
/*
//Conbination!
ll c[51][51];
void comb(int n) {
	rep(i, 51) {
		rep(j, i + 1) {
			if (j == 0 || j == i)c[i][j] = 1;
			else c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
		}
	}
}
*/
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << c - d + b << " " << d + c - a << " " << a - d + b << " " << b + c - a << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
	string s = ReadLine();
	int ans = 700;
	for (int i = 0; i < 3; i++)
	{
	    if (s[i] == 'o'){ ans += 100; }
	}
	WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;

int INF=1e9;
struct edge { int from, to, cost; };

edge es[2005];
int d[1005];
int v, e;
bool neg = false;

void shortest_path(int s) {
    for (int i = 0; i < v; i++) d[i] = INF;
    d[s] = 0;
    for (int i = 0; i < v; i++) {
        bool update = false;
        for (int j = 0; j < e; j++) {
            edge e = es[j];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
                if (i == v - 1) {
                    neg = true;
                }
            }
        }
        if (!update) break;
    }
}

bool find_negative_loop() {
    memset(d, 0, sizeof(d));
    for (int i = 0; i < v; i++) {
        for (int j = 0; j < e; j++) {
            edge e = es[j];
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (i == v - 1) return true;
            }
        }
    }
    return false;
}


int main(void){
    int r;
    cin >> v >> e >> r;
    for (int i = 0; i < e; i++) {
        cin >> es[i].from >> es[i].to >> es[i].cost;
    }
    
    shortest_path(r);
    if (neg) cout << "NEGATIVE CYCLE" << endl;
    else {
        for (int i = 0; i < v; i++) {
            //shortest_path(r);
            if (d[i] != INF) cout << d[i] << endl;
            else cout << "INF" << endl;
        }
    }
    
}



Measured memory_bytes: 3128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	string s;
	cin>>s;
	REP(i,s.size()){
		cout<<"x";
	}
	cout<<endl;
	return 0;
}


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

int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<"Bad"<<endl;
            return 0;
        }
    }

    cout<<"Good"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;


int main() {
  int a,b;
  cin >> a >> b;
  int p[1000];
  for(int i = 1; i <= 999; i++){
    int h = i * (2 + (i - 1)) / 2;
    p[i] = h;
  } 
  int c = b - a;
  for(int i = 1; i < 999; i++){
    if (p[i + 1] - p[i] == c) cout << p[i] - a << endl;
  } 
	return 0;
}



Measured memory_bytes: 3584
' Imports System.Collections.Generic
' Imports System.Linq
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim S As String = Console.ReadLine()
        Dim O As String = "RUD"
        Dim E As String = "LUD"
        Dim flg As Boolean = True
        For idx As Integer = 0 To S.Length - 1
            If 1 = (idx + 1) Mod 2 AndAlso -1 = O.IndexOf(S(idx))
                flg = False
                Exit For
            End If
            If 1 = idx Mod 2 AndAlso -1 = E.IndexOf(S(idx))
                flg = False
                Exit For
            End If
        Next
        Console.WriteLine(If(flg, "Yes", "No"))
        Return
    End Sub
End Class

Measured memory_bytes: 25928
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  puts(abs(a - c) <= d ? "Yes"
                       : abs(a - b) <= d && abs(b - c) <= d ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
import numpy as np
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return np.array(arr)

A, B = map(int, input().split())

a = factorization(A)
b = factorization(B)

ans = 1+len(list(set(a[:,0])&set(b[:,0])))
if A==B and A==1:
  ans=1
print(ans)

Measured memory_bytes: 12504
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b,c) for(int i=(a);(i)<=(b);(i)+=(c))
#define ll long long
#define mp map<int,int>
using namespace std;
int a[200005]; ll ans=0;
bool pd[200005];
int main() {
	int n;
	cin>>n;
	rep(i,1,n,1) cin>>a[i];
	ford(i,n,1) {
		ll t=0;
		rep(j,i,n,i) if(pd[j]) t++;
		if(t%2!=a[i]) pd[i]=1,ans++;
	}
	cout<<ans<<"\n";
	rep(i,1,n,1)if(pd[i])cout<<i<<"\n";
	return 0;
}


Measured memory_bytes: 1920
left = "qwertasdfgzxcvb"
while True:
    s = raw_input()
    if s=="#":
        break
    ans = 0
    mode = -1
    for c in s:
        if mode==-1:
            mode = (c not in left)
            continue
        if (mode == 0 and c not in left) or (mode == 1 and c in left):
            mode ^= 1
            ans += 1
    print ans

Measured memory_bytes: 4208
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef  long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;

void input(){
    int n;
    cin >> n;
    vector<string>a(n);
    f(i, n)cin >> a[i];
    map<string, int>m;
    f(i, n)++m[a[i]];
    int mx = 0;
    for(auto &it : m)mx = max(mx, it.second);
    for(auto &it : m){
        if(it.second == mx)cout << it.first << endl;
    }
}
int main(){
    input();
    return 0;
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[130113];
int l[100310][3];
int j[302];

long long x,y,z,mod=1000000007;
//string r;
char r[111];

P u[1];
queue<int> q;

stack<int> s;
map<int,int> p;
vector<P> v;

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}


int main()
{
  scanf("%d %d",&a,&b);
  for(int t=2*a;t<3*a;t++)
    l[t-2*a][2]=b+t;
  for(int t=0,i=b,j=b+2*a-a/2-1;t<a-a/2;i+=2,j--,t++)
  {
    l[t][0]=i;
    l[t][1]=j;
  }
  for(int t=a-a/2,i=b+1,j=b+a*2-1;t<a;j--,i+=2,t++)
  {
    l[t][0]=i;
    l[t][1]=j;
  }
  for(int t=0;t<a;t++)
  if(l[t][0]+l[t][1]>l[t][2])
  {
    puts("-1");
    return 0;
  }
  for(int t=0;t<a;t++,puts(""))
  for(int h=0;h<3;h++)
    printf("%d ",l[t][h]);
}





Measured memory_bytes: 3456
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
signed main(){
    int n,m;
    cin>>n>>m;
    int k=m/n;
    vector<int> s;
    for(int i=1;i<=sqrt(m);i++){
        if(m%i==0){
            s.push_back(i);
            s.push_back(m/i);
        }
    }
    sort(s.begin(),s.end());
    for(int i=0;i<s.size();i++){
        if(s[i]>k){
            cout<<s[i-1]<<endl;
            break;
        }
    }
    if(s[s.size()-1]==k)cout<<s[s.size()-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A == 5 && B == 5 && C == 7){
    printf("YES");
  }else if(A == 5 && B == 7 && C == 5){
    printf("YES");
  }else if(A == 7 && B == 5 && C == 5){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int A, B;

int g(int l, int r, int k) {
  int K = (1LL<<(k-1));
  int br = 2*K-r;
  if (l >= K || l+1 >= br) return 2*K;
  int s = r+1;
  int e = 0;
  rep(j, 60) if (l&(1LL<<j)) e = j+1;
  s += 1LL<<e;
  s = min(s, 2*K);
  assert(s <= 2*K);
  return s;
}

int f(int l, int r, int k) {
  if (k == 0) return r-l+1;
  int mask = 1LL<<k;
  if ((r & mask) == 0) return f(l, r, k-1);
  if ((l & mask) > 0 && (r & mask) > 0) return f(l-mask, r-mask, k-1);
  return f(l, mask-1, k) + g(r-mask, mask-1-l, k);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> A >> B;
  cout << f(A, B, 60) << "\n";
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, m;
int r;
vector<int> e[100010];
vector<int> topo;
// bool used[100010];
int in[100010];
int parent[100010];

void init() {

}

// void dfs(int i) {
//   if (used[i]) return;
//   used[i] = true;
//   REP(j, SZ(e[i])) dfs(e[i][j]);
//   topo.push_back(i);
// }
//
// void makeTopo() {
//   topo.clear();
//   REP(i, n) dfs(i);
//   reverse(ALL(topo));
// }

void input() {
  REP(i, 100010) {
    e[i].clear();
    parent[i] = -1;
    in[i] = 0;
  }
  cin >> n >> m;
  REP(i, n+m-1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    in[b]++;
  }
  queue<int> q;
  REP(i, n) if (in[i] == 0) q.push(i);
  while(!q.empty()) {
    int i = q.front();
    // topo.push_back(i);
    q.pop();
    REP(j, SZ(e[i])) {
      in[e[i][j]]--;
      if (in[e[i][j]] == 0) {
        q.push(e[i][j]);
        parent[e[i][j]] = i;
      }
    }
  }
  // REP(i, n) {
  //   REP(j, SZ(e[topo[i]])) {
  //     parent[e[topo[i]][j]] = topo[i];
  //   }
  // }
  REP(i, n) cout << parent[i] + 1 << endl;
}

void solve() {

}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 7040
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
typedef long long ll;

int cnt[50];

int main(void) {
  int n, m;
  cin >> n >> m;
  REP(i, n) {
    int k;
    cin >> k;
    REP(j, k) {
      int a;
      cin >> a;
      cnt[a-1]++;
    }
  }
  int res = 0;
  REP(i, m) {
    if(cnt[i] == n) {
      ++res;
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
      int count = 0;
      for (int j = 1; j <= Math.sqrt(i); j++) {
        if (i % j == 0) {
          count += 2;
        }
      }
      if (count == 8) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
void main() {
	auto S = rs;
	if(S == "ABC") {
		writeln("ARC");
	} else writeln("ABC");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 2676
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Measured memory_bytes: 61848
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n, h;
  cin >> n >> h;
  vector<long>a(n), b(n);
  for(int i=0; i<n; i++){
    cin >> a[i] >> b[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  long i;
  for(i=0; i<n; i++){
    if(h<=0){
      cout << i;
      return 0;
    }
    if(b[i]<a[0])break;
    h-=b[i];
  }
  if(h<=0){
    cout << i;
    return 0;
  }
  while(h>0){
    h-=a[0];
    i++;
  }
  cout << i;
  return 0;
}
  

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
    int h, n, sum = 0, a;
    scanf("%d""%d", &h, &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a);
        sum += a;
    }
    if(sum < h){
        printf("No\n");
    }else{
        printf("Yes\n");
    }

}

Measured memory_bytes: 128
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
p = LIST()
if p == list(range(1, n + 1)):
    print('YES')
    exit()
for i in range(n):
    for j in range(i + 1, n):
        arr = deepcopy(p)
        arr[i], arr[j] = arr[j], arr[i]
        if arr == list(range(1, n + 1)):
            print('YES')
            exit()
print('NO')

Measured memory_bytes: 67032