akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
vector<int> solve(long long n, int tp){
	if(n == 1){
		vector<int> ans;
		return ans;
	}
	if(n & 1){
		vector<int> sol = solve(n - 1, tp + 1);
		sol.push_back(tp);
		return sol;
	}
	vector<int> sol = solve(n / 2, tp + 1);
	sol.insert(sol.begin(), tp);
	return sol;
}
int main(){
	long long n; cin >> n; n++;
	vector<int> sol = solve(n, 1);
	vector<int> cpy = sol;
	sort(cpy.begin(), cpy.end());
	cout << 2 * sol.size() << endl;
	for(int v : sol) cout << v << " ";
	for(int v : cpy) cout << v << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        int x = Integer.parseInt(a + b);
        int y = (int)Math.sqrt(x);
        if(x == y * y)System.out.println("Yes");
        else System.out.println("No");
        sc.close();
    }

}


Measured memory_bytes: 21844
N = int(input())
S = [1 if x == '.'  else 0 for x in list(input())]

cost = sum(S)
min_cost = cost 

for i in range(N):
    if S[i] == 0:
        cost += 1
    else:
        cost -= 1

    if min_cost > cost:
        min_cost = cost
        
print(min_cost)

Measured memory_bytes: 6436
#include<iostream>
#include<array>
#include<algorithm>
using namespace std;

int main(){
  array<pair<int, int>, 5> orders;

  for(int i = 0; i < 5; i++){
    int x;
    cin >> x;
    int ord = - ((x + 9) % 10);
    orders[i] = make_pair(ord, x);
  }
  sort(orders.begin(), orders.end());

  int ans = 0;
  for(int i = 0; i < 4; i++){
    ans += 10 * ((orders[i].second + 9) / 10);
  }
  ans += orders[4].second;

  cout << ans << endl;
}


Measured memory_bytes: 380
#include<iostream>
#include<string>
using namespace std;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c;
	return 0;
}

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

#define BUFFER_SIZE 2
#define STACK_SIZE 99

#define TYPE_NUM 1
#define TYPE_ADD 2
#define TYPE_SUB 3
#define TYPE_MUL 4
#define TYPE_DIV 5

typedef struct {
	int type;
	int number;
} Term;

int read_term(Term *p_term, FILE *p_file){
	int ok = 0;
	char buf[BUFFER_SIZE];
	int ch;

	for(;;){
		// Input
		ch = fgetc(p_file);
		if( ch == EOF ){
			break;
		}

		// Check
		if( isdigit( ch ) ){
			ok = 1;
			p_term->type = TYPE_NUM;
			memset( buf, '\0', BUFFER_SIZE * sizeof(char) );
			buf[0] = (char)ch;
			p_term->number = atoi(buf); 
			for(;;){
				ch = fgetc(p_file);
				if( ch == EOF || !isdigit(ch) ){
					break;
				}
				buf[0] = (char)ch;
				p_term->number = p_term->number * 10 + atoi(buf); 
			}
			break;
		} else if( ch == '+' ){
			ok = 1;
			p_term->type = TYPE_ADD;
			break;
		} else if( ch == '-' ){
			ok = 1;
			p_term->type = TYPE_SUB;
			break;
		} else if( ch == '*' ){
			ok = 1;
			p_term->type = TYPE_MUL;
			break;
		} else if( ch == '/' ){
			ok = 1;
			p_term->type = TYPE_DIV;
			break;
		}
	}

	return ok;
}

void process_term(Term *p_term, int *stack, int *p_posi){
		switch(p_term->type){
		case TYPE_NUM:
			stack[(*p_posi)+1] = p_term->number;
			(*p_posi)++;
			break;
		case TYPE_ADD:
			stack[(*p_posi)-1] = stack[(*p_posi)-1] + stack[(*p_posi)];
			(*p_posi)--;
			break;
		case TYPE_SUB:
			stack[(*p_posi)-1] = stack[(*p_posi)-1] - stack[(*p_posi)];
			(*p_posi)--;
			break;
		case TYPE_MUL:
			stack[(*p_posi)-1] = stack[(*p_posi)-1] *+ stack[(*p_posi)];
			(*p_posi)--;
			break;
		case TYPE_DIV:
			stack[(*p_posi)-1] = stack[(*p_posi)-1] / stack[(*p_posi)];
			(*p_posi)--;
			break;
		default:
			break;
		}
}

int main(int argc, char** argv){
	int stack[STACK_SIZE];
	int posi = -1;
	Term term;

	for(;;){
		// Input
		if( !read_term( &term, stdin ) ){
			break;
		}
		// Process
		process_term( &term, stack, &posi );
	}

	// Output
	printf("%d\n", stack[posi]);

	return 0;
}

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

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) d[i] = 0;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        d[a]++;
    }
    bool ok = true;
    if (n % 2 == 0) {
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0 && d[i] != 0) ok = false;
            if (i % 2 == 1 && d[i] != 2) ok = false;
        }
    } else {
        for (int i = 0; i < n; i++) {
            if (i == 0 && d[i] != 1) ok = false;
            if (i != 0 && i % 2 == 0 && d[i] != 2) ok = false;
            if (i % 2 == 1 && d[i] != 0) ok = false; 
        }
    }
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    if (n % 2 == 0) {
        for (int i = 1; i <= n / 2; i++) {
            ans *= 2;
            ans %= mod;
        }
    } else {
        for (int i = 1; i <= (n - 1) / 2; i++) {
            ans *= 2;
            ans %= mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll xx[100010];
int main(){
	ll n;
	scanf("%d",&n);
	char a[11];
	rep(i,0,n){
		scanf("%s",a);
		rep(j,0,10)for(int k=9;k>=1;k--)if(a[k-1]>=a[k]){
			char c=a[k];a[k]=a[k-1];a[k-1]=c;
		}
		ll s=0;
		rep(j,0,10)s=s<<5|(a[j]-'a');
		xx[i]=s;
	}
	sortup(xx,n);
	ll ans=0;
	rep(i,0,n){
		ll j=i+1;
		while(j<n&&xx[j]==xx[i])j++;
		ans+=(j-i)*(j-i-1)/2;
		i=j-1;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

int32_t main()
{
	int t=1;
	while(t--)
	{
		int n;
		cin >> n;
		set<int> s,s2;
		for(int i=1;i<=9;i++)
		s.insert(i);
		
		while(s2.size()<n)
		{
			s2.insert((*s.begin()));
			int x=(*s.begin());
			//cout << x << " ";
			s.erase(s.begin());
			int temp=x%10;
			
			if(temp==0)
			{
				s.insert(x*10);
				s.insert(x*10+1);
			}
			else if(temp==9)
			{
				s.insert(x*10+8);
				s.insert(x*10+9);
			}
			else
			{
				s.insert(x*10+temp-1);
				s.insert(x*10+temp);
				s.insert(x*10+temp+1);
			}
		}
		auto it=s2.end();
		it--;
		cout << (*it);
	}
}




Measured memory_bytes: 17152
x,y=map(int,input().split()) # 動物の総数ｘ足の総数ｙ本

ans="No"

for a in range(x+1):
    b=x-a
    if 2*a+4*b==y: # aは鶴　bは亀　
        ans="Yes"
print(ans)

Measured memory_bytes: 8868
#include <cstdio>
#include <algorithm>

using namespace std;

int v[100010], ap[100010], nr[100010], a[100010];

int main ()
{
   // freopen ("file.in", "r", stdin);

    int n, m, q;
    scanf ("%d %d %d", &n, &m, &q);

    nr[0] = n;
    for (int i = 1; i <= q; ++i)
        scanf ("%d", &v[q - i + 1]);

    int k = 0;
    for (int i = 1; i <= q; ++i)
        if (!ap[v[i]]) ap[a[++k] = v[i]] = k;

    for (int i = 1; i <= m; ++i)
        if (!ap[i]) ap[a[++k] = i] = k;

    for (int i = 1; i <= q; ++i)
    {
        int fr = ap[v[i]];
        if (nr[fr - 1] > 0) --nr[fr - 1], ++nr[fr];
    }

    for (int i = 0; i < m; ++i)
        if (nr[i] > 0)
        {
            for (++++i; i <= m; ++i)
                if (a[i] < a[i - 1])
                {
                    printf ("No\n");
                    return 0;
                }

            break;
        }

    printf ("Yes\n");

    return 0;
}


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

class P
{
    static void Main()
    {
        int[] ABC = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int res = 0;
        if (ABC.Max() == ABC.Min() && ABC.Max() % 2 == 0)
        {
            Console.WriteLine(-1);
            return;
        }
        int halfa;
        int halfb;
        int halfc;
        while (true)
        {
            if (res < 0)
            {
                Console.WriteLine(-1);
                return;
            }
            if (ABC[0] % 2 == 0 && ABC[1] % 2 == 0 && ABC[2] % 2 == 0)
            {
                halfa = ABC[0] / 2;
                halfb = ABC[1] / 2;
                halfc = ABC[2] / 2;
                ABC[0] = halfb + halfc;
                ABC[1] = halfc + halfa;
                ABC[2] = halfa + halfb;
                res++;
            }
            else
            {
                Console.WriteLine(res);
                return;
            }
        }
    }
}

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

int main(){
  int n;
  long long a,b,l;
  cin >> n;
  while(n--){
    cin >> a >> b;

    if(a*b>0){
      if(a<0)swap(a,b);
      a = abs(a); b = abs(b);
      l = 0;
      while(a<b){
	int k = __builtin_ctzll(a);
	while(a + (1LL<<k) > b)k--;
	a += 1LL<<k;
	l++;
      }
      cout << l << endl;
    }else cout << __builtin_popcountll(abs(a)) + __builtin_popcountll(abs(b)) << endl;
  }
}

Measured memory_bytes: 1176
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1]; for (int i = 0; i < n + 1; i++) { a[i] = 1; }for (int i = 2; i < n + 1; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;


signed main() {
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> spos = {0,n+1};
	vector<int> epos = {0,n+1};
	if (s[0] == '0') spos.push_back(1);
	int ans = 0;
	FOR (i,1,s.size()) {
		if (s[i] == '0' && s[i-1] == '1') spos.push_back(i+1);
		if (s[i] == '1' && s[i-1] == '0') epos.push_back(i);
	}
	if (s[n-1] == '0') epos.push_back(n);
	SORT(spos);
	SORT(epos);
	// cout << spos.size() << epos.size() << endl;
	// if (spos.size() != epos.size()) REP (i,10000000000000) s[1000000000000000] = 114514;
	// REP (i,epos.size()) cout << epos[i] << " ";
	// cout << spos.size() - 3 << k << endl;
	if ((int)((int)spos.size() - 3) < k) {cout << s.size() << endl;}
	else {
		
		REP (i,spos.size()-k-1) {
			int tmp = spos[i+k+1] - epos[i] - 1;
			// if (ans < tmp) cout << i << " " << spos[i] << endl;
			ans = max(ans,tmp);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, P;
  P = 0;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    if(x >= K - x){P += (K -x)*2;}
    else{P += x*2;}
  }
  cout << P << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)

using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int N, K;
    cin >> N >> K;
    if (K == 1) {
        cout << 0 << endl;
    } else {
        cout << (N - K) << endl;
    }

    return 0;
}


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

int main()
{
 int a, b;
 cin >> a >> b;
 int total = a + b;
 if(a % 3 == 0||b % 3 == 0||total % 3  == 0){
     cout << "Possible" << endl;
 }else {
     cout << "Impossible" << endl;
 }
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<ll> B(N - 1), A(N);
    rep(i, N - 1) cin >> B[i];
    A[0] = B[0];
    rep(i, N - 2) {
        A[i + 1] = min(B[i], B[i + 1]);
    }
    A[N - 1] = B[N - 2];
    cout << accumulate(A.begin(), A.end(), 0LL) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
using namespace std;
vvi in;
vector<string>s;
void f(int a,int c){
	rep(i,c)cout<<'.';
	cout<<s[a]<<endl;;	
	rep(i,in[a].size())f(in[a][i],c+1);
}
int main(){
	int n;
	cin>>n;
	in=vvi(n);
	s=vector<string>(n);
	rep(i,n){
		int a;
		cin>>a;
		cin>>s[i];
		if(a)in[a-1].pb(i);
	}
	f(0,0);
}

Measured memory_bytes: 1444
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
  string a, b, c;
  cin >> a >> b >> c;
  
  if((a[a.size()-1] == b[0]) && (b[b.size()-1] == c[0])) cout << "YES" << endl;
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long X = nx[1];
        //ちゅーごくじょーよてーり
        //オーダーによってSの終端が決定する
        //まず影響するのは降順のみなことは自明に分かって、
        //で、「次」を選ぶことができる順番は
        //「確率」「期待値」
        //aを取り除いた場合、その後に適用できるのはそれ以前全て。

        List<int> s = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToList();
        ModInt[] dp = new ModInt[X + 1];
        dp[X] = 1;
        ModInt remain = s.Count - 1;
        foreach (var mod in s)
        {
            ModInt[] newDP = new ModInt[X + 1];

            for (int i = 0; i < dp.Length; i++)
            {
                newDP[i % mod] += dp[i];
                newDP[i] += dp[i] * remain;
            }
            remain--;
            dp = newDP;
        }
        ModInt res = 0;
        for (int i = 0; i < dp.Length; i++)
        {
            res += dp[i] * i;
        }
        Console.WriteLine(res);
    }
}


struct ModInt
{
    const int MOD = 1000000007;
    long Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public ModInt(long data) { Data = data; Eval(); }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private long Eval() => (Data %= MOD) < 0 ? Data += MOD : Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator long(ModInt modInt) => modInt.Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator ModInt(long val) => new ModInt(val);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt a, ModInt b)
    {
        long res = a.Data + b.Data;
        return new ModInt() { Data = res >= MOD ? res - MOD : res };
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt a, ModInt b)
    {
        long res = a.Data - b.Data;
        return new ModInt() { Data = res < 0 ? res + MOD : res };
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt(a.Data * b.Data);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator /(ModInt a, ModInt b) => a * Power(b, MOD - 2);

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static ModInt Power(ModInt n, long m)
    {
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= n;
            n *= n;
            m >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 32152
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
const int MAXN = 1e5 + 5, MAXM = 2e3 + 5, BOUND = 2e5, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-3;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define lc(x) ch[x][0]
#define pii pair<int,int>
#define rc(x) ch[x][1]
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, X, a[205], dp[205][MAXN];
int f(int i, int x) {
	if (dp[i][x] != -1)return dp[i][x];
	int &ans = dp[i][x];
	if (i == 1)return ans = x % a[1];
	ans = (f(i - 1, x%a[i]) + 1LL * f(i - 1, x)*(i - 1)) % MOD;
	return ans;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> X;
	memset(dp, -1, sizeof(dp));
	rep(i, 1, n)cin >> a[i];
	sort(a + 1, a + 1 + n);
	cout << f(n, X) << '\n';
	return 0;
}

Measured memory_bytes: 80384
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    string s;
    cin >> s;
    if(s=="SUN"){
        cout<<"7";
    }else if(s=="MON"){
        cout<<"6";
    }else if(s=="TUE"){
        cout<<"5";
    }else if(s=="WED"){
        cout<<"4";
    }else if(s=="THU"){
        cout<<"3";
    }else if(s=="FRI"){
        cout<<"2";
    }else if(s=="SAT"){
        cout<<"1";
    }
    cout<<endl;
    return 0;
    
}


Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

def comb(n, k, mod):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % mod
        ret = ret * pow(i, mod - 2, mod) % mod
    return ret

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

X, Y = map(int, input().split())
mod = 10**9+7
ans = 0

if(X<Y):
  X, Y = Y, X

XY = X-Y

if((X - 2*XY)%3 == 0 and (Y-XY)%3 == 0):
  XX = XY+(X- 2*XY)//3
  YY = (X-2*XY)//3
  #print(XX,YY)
  if(YY==0):
    print(1)
  else:
    ans = comb(XX+YY, XX, mod)
    print(ans%mod)
else:
  print(0)




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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5+10;
const ll INF = 1LL << 60;

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


// Main Code

ll arr[N];
bool vis[N];
vector<pair<int, int>> g[N];
bool flag = true;
unordered_set<int> s;

void dfs(int r, int p)
{
	vis[r] = 1;
	for(auto x: g[r])
	{
		int curr = x.f;
		int dist = x.s;
		if(vis[curr] == 0)
		{
			arr[curr] = arr[r] + dist;
			dfs(curr, r);
		}
		else
		{
			if(arr[curr] != (arr[r] + dist)) 
			{
				flag = false;
				return;
			}
		}
	}
}

int main()
{
	
	int n, m;
	cin>>n>>m;
	int x, y, z;
	int root;
	rep(i, 0, m)
	{
		cin>>x>>y>>z;
		g[x].pb({y, z});
		g[y].pb({x, -z});
		s.insert(x), s.insert(y);
	}
	for(auto x: s)
	{
		if(vis[x] == 0)
		{
			arr[x] = 0;
			dfs(x, -1);
		}
	}
	if(flag) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 16548
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>
#include <string>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <stack>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long
const int INF = 1 << 29;
const ll llINF = 10000000000000000;

const int MOD = 1000000007;

#define MAX_N 100100
typedef pair<int, int> P;

int savingsnuuk(){
    struct senro{
        int next;
        int yen;
        int snuuk;
    };
    bool used[2][MAX_N] = {false};
    vector<senro> sunuke[MAX_N];
    ll ryoukin[3][MAX_N] = {0};
    REP(i, 2){
        REP(j, MAX_N){
            ryoukin[i][j] = llINF;
        }
    }
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    REP(i, m){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        senro uto = {v,a,b};
        senro vto = {u,a,b};
        sunuke[u].push_back(uto);
        sunuke[v].push_back(vto);
    }
    priority_queue<P, vector<P>, greater<P> > que[2];
    ryoukin[0][s] = 0;
    ryoukin[1][t] = 0;
    que[0].push(P(0,s));
    que[1].push(P(0,t));
    REP(tuuka, 2){
        while(!que[tuuka].empty()){
            P p = que[tuuka].top();
            que[tuuka].pop();
            int v = p.second;
            if(ryoukin[tuuka][v] < p.first) continue;
            REP(i, sunuke[v].size()){
                senro e = sunuke[v][i];
                int cost;
                if(tuuka == 0)cost = e.yen;
                else cost = e.snuuk;
                if(ryoukin[tuuka][e.next] > ryoukin[tuuka][v] + cost){
                    ryoukin[tuuka][e.next] = ryoukin[tuuka][v] + cost;
                    que[tuuka].push(P(ryoukin[tuuka][e.next], e.next));
                }
            }
        }
    }
    
    ryoukin[2][n] = llINF;
    REP(i, n){
        ryoukin[2][n - i - 1] = min(ryoukin[2][n - i], ryoukin[0][n - i - 1] + ryoukin[1][n - i - 1]);
    }
    REP(i, n){
        printf("%lld\n", 1000000000000000 - ryoukin[2][i]);
    }
    return 0;
}

int main(){
    savingsnuuk();
}


Measured memory_bytes: 12024
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI vs(n);
  FOR(v,vs) {
    cin >> v;
  }
  vector<vector<PI>> pop(2, vector<PI>(1e5+1, {0, 0}));
  REP(i,0,2) {
    for(int j=0; j<=1e5; j++) {
      pop[i][j].second = j;
    }
  }
  REP(i,0,2) {
    for(int j=i; j<n; j += 2) {
      pop[i][vs[j]].first++;
    }
  }
  REP(i,0,2) {
    sort(pop[i].rbegin(), pop[i].rend());
  }
  int keep;
  if(pop[0][0].second != pop[1][0].second) {
    keep = pop[0][0].first + pop[1][0].first;
  } else {
    keep = max(pop[0][0].first + pop[1][1].first,
               pop[0][1].first + pop[1][0].first);
  }
  cout << n - keep << endl;

  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <fstream>
#include <bitset>
using namespace std;

typedef long long ll;
const int N = 2e3;
const int W = 4e6;

int main()
{
    //ifstream cin("input.txt");

    int n, a[N];
    ll sum = 0, w;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        sum += a[i];
    }
    w = sum / 2;

    bitset<W> dp;
    dp[0] = 1;
    for (int i = 0; i < n; ++i)
        dp |= (dp << a[i]);
    ll j = w;
    while(!dp[j])
        --j;

    cout << max(j, sum - j);
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 607;
int n, m;
vector<int> graph[N];
double dp[N], dp2[N];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i = 0; i < m; ++i) {
        int s, t; cin >> s >> t;
        graph[s].push_back(t);
    }

    dp[n] = 0.0;
    for(int i = n-1; i > 0; --i) {
        int sz = graph[i].size();
        double tot = (double)sz;
        for(int child : graph[i]) {
            tot += dp[child];
        }
        dp[i] = tot/(double)sz;
    }

    double ans = dp[1];

    for(int i = n-1; i > 0; --i) {
        int sz = graph[i].size() - 1;
        if(sz == 0) continue;

        for(int j = n; j > i; --j) dp2[j] = dp[j];
        double mx = 0;
        double tot = (double)sz;
        for(int child : graph[i]) {
            double add = dp2[child];
            tot += add;
            mx = max(mx, add);
        }
        tot -= mx;
        dp2[i] = tot/(double)sz;
        for(int j = i-1; j > 0; --j) {
            int sz2 = graph[j].size();
            double tot2 = (double)sz2;
            for(int child : graph[j]) {
                tot2 += dp2[child];
            }
            dp2[j] = tot2/(double)sz2;
        }
        ans = min(ans, dp2[1]);
    }

    cout << fixed << setprecision(10) << ans << endl;
    
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int all = (1 << n);
    vector<int> a(all);
    for (int i = 0; i < all; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> p;
    p.push_back(a.back()); a.back() = - 1;
    for (int i = 0; i < n; i++){
        vector<int> s = p;
        sort(s.begin(), s.end());
        int ai = all - 1;
        for (int j = s.size() - 1; j >= 0; j--){
            while (ai >= 0 && (a[ai] == - 1 || a[ai] >= s[j])) ai--;
            if (ai < 0){
                cout << "No" << endl;
                exit(0);
            }
            p.push_back(a[ai]);
            a[ai] = - 1;
            ai--;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3060
/*Saurav Paul*/
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define endl '\n'
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define boost		          ios_base::sync_with_stdio(0);
#define eb                    emplace_back
#define mp                    make_pair
#define clr(x)                x.clear()
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()

using ll = long long int ;
using namespace std;
///////////////////////

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

////////////////////////
/*
template<typename T>T set_bit(T N,T pos){return N=N | (1<<pos);}
template<typename T>T reset_bit(T N,T pos){return N= N & ~(1<<pos);}
template<typename T> bool check_bit(T N,T pos){return (bool)(N & (1<<pos));}
template<typename T>void bin_print(T N){bitset<25>bit(N);cerr<<bit.to_string()<<"\n";}
template<typename T> void max_self(T &a, T b){
	a=max(a,b);
}
template <typename T > void min_self(T &a, T b){
	a=min(a,b);
}
template <typename T > void add_self(T &a, T b){
	a+=b;
}
*/
////////////////////////

template<typename T> void ara_read(T &v,ll n){
	ll temp;
	for(ll i=0; i< n; i++){
		scanf("%lld",&temp);
		v.emplace_back(temp);
	}
}
template<typename T> void ara_print(T &v){
	for(ll x : v)
		printf("%lld ",x);
	puts("");
}
////////////////////////
const int INF = 1e9 + 99;
using Pair = pair<int,int >;
using vec = vector<int> ;

int main()
{
	long long int n , d;
	cin >> n >>d;
	
	n = ceil((n*1.0)/(2*d+1));
	cout << n << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#define REP(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define REPN(i,n) for(int(i)=1;(i)<(int)(n);(i)++)
#define _abs(x) ((x)>0?(x):-(x))
#define ll  long long 
using namespace std;   
int main()
{
    ll n;
    string s;
    cin>>n>>s;
    if(n>=3200)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"red";
    } 
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a, b, c, n; scanf("%d%d%d%d", &a, &b, &c, &n);
	
	i64 ans = 0;
	for(int i = 0; i * a <= n; i++) {
		for(int j = 0; i * a + j * b <= n; j++) {
			int k = n - (i * a + j * b);
			if(k < 0 or k % c) continue;
			ans++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.close();
        if(N < 105) System.out.println(0);
        else if(N < 135) System.out.println(1);
        else if(N < 165) System.out.println(2);
        else if(N < 189) System.out.println(3);
        else if(N < 195) System.out.println(4);
        else System.out.println(5);

    }

}


Measured memory_bytes: 21844
<?php
list($x, $n) = explode(" ", trim(fgets(STDIN))); 
$p = explode(" ", trim(fgets(STDIN)));
 
$max = $x;
for($i=0; $i<101; $i++){
  if(!in_array($max, $p)) break;
  $max++;
}
$min = $x;
for($i=0; $i<101; $i++){
  if(!in_array($min, $p)) break;
  $min--;
} 
if($x-$min > $max-$x) echo $max;
else echo $min;

Measured memory_bytes: 16180
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

typedef pair<ll, ll> P;
vec d;
struct edge {
    ll to, cost;
};
vector<vector<edge>> G;

void dijkstra (ll s, ll V) {
    priority_queue<P, vector<P>, greater<P>> que;
    d.assign(V, inf);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;
        for (edge e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

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

    ll L;
    cin >> L;
    ll N = 0;
    while ((1 << N) <= L) N++;

    G.assign(N, vector<edge>());
    ll M = 2*(N-1);
    Rep (i, N-1) {
        G[i].push_back({i+1, 0});
        G[i].push_back({i+1, 1<<i});
    }

    ll tmp = L - (1 << (N-1));
    ll now = 1 << (N-1);
    for (ll i = 20; i >= 0; i--) {
        if (tmp & (1 << i)) {
            G[i].push_back({N-1, now});
            M++;
            now += 1 << i;
        }
    }

    cout << N << " " << M << "\n";
    Rep (i, N) {
        if (G[i].size() > 0) {
            for (auto nv : G[i]) {
                cout << i+1 << " " << nv.to+1 << " " << nv.cost << "\n";
            }
        }
    }
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i, n)  FOR(i,0,(n))


class AEatingSymbolsEasy {
public:
    void solve(std::istream &in, std::ostream &out) {
      string s;
      in >> s;
      int ans = 0;
      REP(i, s.length()) {
        if (s[i] == '+') {
          ans++;
        } else {
          ans--;
        }
      }
      out << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  AEatingSymbolsEasy solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
// 繰り返し回数N
// 一行目数値1　数値2 
// 二行目数値1　数値2 で渡された場合で渡された場合
public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String ansFlg = "";
    String ans = "";
    int stack = 0;
    String stackFlg = "";
    for (int i = 0; i < N; i++) {
      String token1 = sc.next();
      String token2 = sc.next();
      // 文字列比較は == ではなく　StringA.equals(StringB)
      if(token1.equals(token2)){
          stack += 1;
          stackFlg = "X";
          if(stack == 3){
              ansFlg = "X";
              break;
          }else{
              //特になし
          }
      }
      // stackFlgがない場合にstackをリセットし、その後スタックフラグを切る
      if(stackFlg.equals("X")){
          //特になし
      }else{
          stack = 0;
      }
      stackFlg = "";
    }
    
    if(ansFlg == "X"){
        ans = "Yes";
    }else{
        ans = "No";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35924
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    }
    println!("{}",if a<9&&b<9 {"Yay!"}else{":("})
}

Measured memory_bytes: 2160
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-05-10 20:45:53
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

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

    if (c >= a && c <= b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# 木を単方向に
def rerooting(n, edges, identity, merge, add_node):
    # 全方位木 dp
    # 参考1: https://qiita.com/keymoon/items/2a52f1b0fb7ef67fb89e
    # 参考2: https://atcoder.jp/contests/abc160/submissions/15255726
    from functools import reduce
    G = [[] for _ in range(n)]
    for a, b in edges:
        G[a].append(b)
        G[b].append(a)
    # step 1
    order = []  # 行きがけ順
    stack = [0]
    while stack:
        v = stack.pop()
        order.append(v)
        for u in G[v]:
            stack.append(u)
            G[u].remove(v)
    # 下から登る
    dp_down = [0]*n  # 自身とその下
    for v in order[:0:-1]:
        dp_down[v] = add_node(reduce(
            merge, (dp_down[u] for u in G[v]), identity
        ), v)
    # step 2
    # 上から降りる
    dp_up = [identity] * n  # 親とその先
    for v in order:
        Gv = G[v]
        if len(Gv) == 0:
            continue
        cum = identity
        right = [identity]
        for u in Gv[:0:-1]:
            cum = merge(dp_down[u], cum)
            right.append(cum)
        right.reverse()
        cum = dp_up[v]
        for u, cum_r in zip(Gv, right):
            dp_up[u] = add_node(merge(cum, cum_r), v)
            cum = merge(cum, dp_down[u])
    results = [add_node(
        merge(
            reduce(merge, (dp_down[u] for u in Gv), identity),
            dp_up[v]
        ), v
    ) for v, Gv in enumerate(G)]
    return results

class Combination:
    def __init__(self, n_max, mod=10**9+7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod-2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

def main():
    N = int(input())
    AB = [list(map(lambda x: int(x)-1, input().split())) for _ in range(N-1)]
    mod = 10**9 + 7
    comb = Combination(202020)
    identity = (1, 0)
    fac, facinv = comb.fac, comb.facinv
    def merge(a, b):
        a0, a1 = a
        b0, b1 = b
        return a0*b0*fac[a1+b1]*facinv[a1]*facinv[b1]%mod, a1+b1
    def add_node(a, idx):
        a0, a1 = a
        return a0, a1+1
    Ans = rerooting(N, AB, identity, merge, add_node)
    print("\n".join(str(ans) for ans, _ in Ans))

main()


Measured memory_bytes: 175736
import collections
s = input()
ls = len(s)
c = set(s)
mi = ls
valuePlaces = []
for v in c:
    co = 0
    valuePlaces.clear()
    for i in range(ls):
        if s[i] == v:
            valuePlaces.append(i)
    ushiro = ls-valuePlaces[-1]-1
    maxLen = 0
    len_vp = len(valuePlaces)
    for i in range(len_vp):
        start = valuePlaces[i]
        if i == 0:
            goal = -1
        else:
            goal = valuePlaces[i-1]
        maxLen = max(start-goal-1,maxLen)
    mi = min (mi,max(maxLen,ushiro))
print(mi)

Measured memory_bytes: 65868
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    rep(i,s.size()) cout<<"x";
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ff first
#define ss second
#define sfi(a) scanf("%d",&a)
#define sfi2(a,b) scanf("%d %d",&a,&b)
#define sfi3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define all(a) a.begin(),a.end()
#define keepu(a) a.erase(unique(all(a)),a.end())
#define inf 1e7
#define m_p make_pair
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("output.txt","r",stdin)
#define write freopen("input.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))

typedef long long ll;
const ll mod = 1e9+7;
const int sz = 500;


int main(){

    ll n,k;
    cin >> n >> k;

    ll val = 1;

    for(int i=1;i<=31;i++){
        val *= k;
        if(val>n){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int n ;	
	cin >> n ;	
	vector<int> a(3*n);
	rep(i,3*n) cin >>a[i];
	//最初のN個の要素の和を求め
	ll forward = 0 ;
	priority_queue<ll, vector<ll>,greater<ll>> pque_forward ;
	ll back = 0  ;
	rep(i,n){
		forward += a[i] ;
		pque_forward.push(a[i]);
	}
	priority_queue<ll> pque_back;
	rep(i,n){
		back += a[3*n-i-1] ;
		pque_back.push(a[3*n-i-1]);
	}
	//ラージK が0 からN-1の時、それぞれに付いて最大にしたものを配列としてもっておく
	vector<ll> MAX_forward(n+1,0);
	MAX_forward[0] = forward; 
	for(int i = 0 ; i < n ;  i++){
		//a[n+i]を使うか使わないかを判定。一番小さいものより大きいならﾄﾙ。
		ll mi = pque_forward.top() ; 
		if(mi < a[n+i]){
			pque_forward.pop();
			pque_forward.push(a[n+i]);
			MAX_forward[i+1] = MAX_forward[i] -mi + a[n+i] ;
		} else {
			MAX_forward[i+1] = MAX_forward[i];
		}
	}
	vector<ll> MIN_back(n+1,0);
	MIN_back[0] = back ; 
	for(int i = 0 ; i <  n; i++){
		//見る要素番号bi
		int bi = 2*n - i - 1; 
		//a[bi]を使うかどうかを判定する。
		ll ma = pque_back.top();
		if(ma > a[bi]){
			pque_back.pop();
			pque_back.push(a[bi]);
			MIN_back[i+1] = MIN_back[i] - ma + a[bi];
		} else {
			MIN_back[i+1] = MIN_back[i] ;
		}
	}
	//n+1回のループで最大となるところを出力する。
	ll ans = -1 * 1e14  ;
	rep(i,n+1){
		ll now = 0 ;

		now = MAX_forward[i] - MIN_back[n-i] ;
		chmax(ans,now);
	}
	cout << ans << endl;
}


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

int main()
{
  int n;
  cin>>n;
  int i,j,k,ans=0;
  for(i=1;i<=n;i++){
    j=i;k=0;
    while(j!=0){
      j/=10;
      k++;
    }
    if(k%2==1) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
l = []
while True:
	try:
		l.append(list(map(int, input().split())))
	except:
		break

d = {}

for e in l:
  if e[0] not in d:
    d[e[0]] = 1
  else:
    d[e[0]] += 1
  if e[1] not in d:
    d[e[1]] = 1
  else:
    d[e[1]] += 1

v = sorted(list(d.values()))

if v[0] == 1 and v[1] == 1 and v[2] == 2 and v[3] == 2:
  print("YES")
else:
  print("NO")

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

using namespace std;

int main()
{
   long long int n ;
    cin>>n;
    map<string ,long long  int> mp;
    while(n--)
    {
        string x;
        cin>>x;
        sort(x.begin() , x.end());
        mp[x]++;
    }
    long long int C=0;
    for( auto i : mp)
    {
        C+=( ( i.second*( i.second - 1 ) ) / 2 );
    }
    cout<<C<<endl;
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    int r,d,x,num;
    
    cin>>r>>d>>x;
    int ans=x;
    rep(i,10){
        ans*=r;
        ans-=d;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,ans,ary[100010],num, newary[100010];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>ary[i],newary[i]=ary[i];
	sort(ary+1,ary+n+1);
	for(int i=1;i<=n;i++)
	{
		num=newary[i];
		int up=upper_bound(ary+1, ary+n+1, num)-ary-1;
		if(up%2==0&&i&1) ++ans;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	ll x;
	cin >> x;
	// 500wooku
	ll gohya = x / 500;
	x -= gohya * 500;
	ll ans = gohya * 1000;
	ans += x / 5 * 5;
	cout << ans << endl;
}


Measured memory_bytes: 256
// デブンキー一家の大活躍.cpp : Defines the entry point for the console application.
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

bool check(bool a[], int n) {
	for (int i = 0; i < n; i++) {
		if (a[i] == false) {
			return false;
		}
	}

	return true;
}

int main(void)
{
	int result[1000], suffix = 0;

	while (1) {
		int ncity, nbridge, glaph[100][100] = { 0 };

		scanf("%d %d", &ncity, &nbridge);
		if (ncity == 0 && nbridge == 0) {
			break;
		}
		int a, b, value;
		for (int i = 0; i < nbridge; i++) {
			scanf("%d %d %d", &a, &b, &value);
			glaph[a][b] = value;
			glaph[b][a] = value;
		}

		int min, cost = 0, s;
		bool visit[100] = { false };
		visit[0] = true;

		int count = 0;
		while (check(visit, ncity) == false) {
			min = 100;
			for (int i = 0; i < ncity; i++) {
				if (visit[i] == true) { //始点
					for (int j = 0; j < ncity; j++) { //隣接点
						if (glaph[i][j] != 0 && visit[j] == false) {
							if (min > glaph[i][j]) {
								min = glaph[i][j];
								s = j;
							}
						}
					}
				}
			}

			visit[s] = true;
			cost += min;
		}

		result[suffix++] = cost;
	}

	for (int i = 0; i < suffix; i++) {
		printf("%d\n", result[i]);
	}

	return 0;
}

Measured memory_bytes: 1080