akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 2000*100 + 11;

int arr[NMAX];
int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
vector<pii> v;

void solve()
{
    cin>>n;
    multiset<pii> pos,neg;

    for(int i=0;i<n;i++){
        cin>>s;
        int min_d = 0, end_v = 0, cur = 0;
        for(auto ch:s){
            if(ch == '('){
                cur++;
            }else{
                cur--;
            }
            min_d = min(cur,min_d);
            end_v = cur;
        }
        if(end_v >= 0){
            pos.insert({abs(min_d),end_v});
        }else{
            neg.insert({-(end_v + abs(min_d)), abs(min_d)});
        }
    }

    int cur = 0;
    for(auto e:pos){
        int d = e.ff;
        int val = e.ss;

        if(d <= cur and cur >= 0){
            cur += val;
        }else{
            cout<<"No";
            return;
        }
    }

    for(auto e:neg){
        int val = e.ff;
        int d = e.ss;

        if(d <= cur and cur >= 0){
            cur += (-val) - d;
        }else{
            cout<<"No";
            return;
        }
    }
    if(cur == 0)
        cout<<"Yes";
    else
        cout<<"No";
}   

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 66016
A, B, K = map(int, input().split())
for i in range(K):
    if i % 2 == 0:
        if A % 2 != 0:
            A = A - 1
        A = A // 2
        B = B + A
    else:
        if B % 2 != 0:
            B = B - 1
        B = B // 2
        A = A + B
print(A, B)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a;
  cin >> a;
  cout << 1 - (a/2)/ (double) a << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    C = list(input())
    Rc = len(list(filter(lambda x:x=="R",C)))
    Wc = len(C) - Rc
    c = 0
    for i in range(Rc):
        if C[i] == "W":
            c+=1
    # print(Rc)
    # print(Wc)
    print(c)
    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 91000
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d){
    cout<<"Yes";
    return 0;
  }
  if(abs(a-b)<=d&&abs(b-c)<=d){
    cout<<"Yes";
    return 0;
  }
  cout<<"No";
  return 0;
}


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

using namespace std;

const int N = 202;
int a[N];

bool check(int n) {
    bool is = true;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 1) {
            is = false;
            break;
        }
    }
    return is;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int res = 0;
    while (check(n)) {
//        bool is = true;
//        for (int i = 0; i < n; i++) {
//            if (a[i] % 2 == 1) {
//                is = false;
//                break;
//            }
//        }
//        if (!is) break;
        res++;
        for (int i = 0; i < n; i++) {
            a[i] /= 2;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3592
def main(R,C,K,V):
    dp = [0]*(4*R*C)
    dp[1+4*0+4*C*0] = V[0][0]
    for k in range(4*R*C):
        n = k%4
        j = k//4%C
        i = k//(4*C)
        if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
        if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

    print(max(dp[-5:-1]))

if __name__ == '__main__':
    R,C,K = map(int,input().split())
    C += 1
    rcv = [list(map(int,input().split())) for _ in range(K)]
    V = [[0]*C for _ in range(R)]
    for i in range(K):
        r,c,v = rcv[i]
        r -= 1
        c -= 1
        V[r][c] = v
    main(R,C,K,V)

Measured memory_bytes: 451344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
        a[i] =a[i] +a[i-1];
    }
    for(int i=0;i<n;i++)
    cin>>b[i];
    for(int i=n-2;i>=0;i--)
    b[i] = b[i]+b[i+1];
    int ans =0;
    for(int i=0;i<n;i++)
        ans = max(ans,a[i]+b[i]);
    cout<<ans;
   return 0;
}

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

int main() {
  int X,N;
  cin >> X >> N;
  
  if (N == 0){
    cout << X << endl;
    return 0;
  }
  
  vector<int>P(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  
  vector<int>p(102,200);
  for (int i = 0; i < 102; i++) {
      for (int j = 0; j < N; j++) {
        if (P.at(j) == i){
          break;
        }
        else if (P.at(j) != i && j == N-1){
          p.at(i) = i;
      }
    }
  }

  int count = 0;
  
  for (int j = 0; j < 55; j++) {
    if (count != 0){
      break;
    }
    for (int i = 0; i < 102; i++) {
      if (p.at(i) == X - j){
        cout << p.at(i) << endl;
        count ++;
        break;
      }
      else if (p.at(i) == X + j){
        cout << p.at(i) << endl;
        count ++;
        break;
      }
    }
  }
}



Measured memory_bytes: 3604
N, M = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

judge = true
sum = A.inject(:+)
A.map{|a| a/sum.to_f}.sort.reverse[0..(M-1)].each do |share|
  judge = false if share < 1.to_f / (4 * M)
end

puts judge ? 'Yes' : 'No'

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String[] X = null;
		Scanner sc = new Scanner(System.in);
		String ip = sc.nextLine();
		X = ip.split(" ", 0);
		int W = Integer.parseInt(X[0]);
		int H = Integer.parseInt(X[1]);
		int x = Integer.parseInt(X[2]);
		int y = Integer.parseInt(X[3]);
		int r = Integer.parseInt(X[4]);


		if (r<=x&&x<=(W-r)&&r<=y&&y<=(H-r)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 26304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int a[200005],b[200005];
int main(void){
	int n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		if(a[i]==b[n-1]){
			cout<<b[n-2]<<endl;
		}else{
			cout<<b[n-1]<<endl;
		}
	}
	
}


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

typedef long long ll;

int main(){
    int k, n;
    cin >>k>>n;
    int a[n], m=0;
    for(int i=0; i<n; i++) cin >> a[i];
    m = a[n-1] - a[0];
    for(int i=1; i<n; i++){
        m = min(m, k - (a[i] - a[i-1]));
    }
    cout << m << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
struct indata {
    int now; int dist;
};

int main() {
    cin >> n;
    vector< vector<int> > graph(n, vector<int>());
    for(int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            v--;
            graph.at(u).push_back(v);
            // graph.at(v).push_back(u);
        }
    }
    
    indata first;
    first.now = 0; first.dist = 0;
    queue<indata> que;
    que.push(first);

    vector<bool> visited(n, false);
    vector<int> distgraph(n, 1e9);

    while(!que.empty()) {
        indata exeq = que.front();
        que.pop();
        visited.at(exeq.now) = true;
        chmin(distgraph.at(exeq.now), exeq.dist);
        for(int i = 0; i < graph.at(exeq.now).size(); ++i) {
            if(!visited.at(graph.at(exeq.now).at(i))) {
                indata next;
                next.now = graph.at(exeq.now).at(i);
                next.dist = exeq.dist + 1;
                que.push(next);
            }
        }
    }

    for(int i = 0; i < n; ++i) {
        if(distgraph.at(i) == 1e9) {
            cout << i+1 << " " << -1 << endl;
        }else {
            cout << i+1 << " " << distgraph.at(i) << endl;
        }
    }
}


Measured memory_bytes: 3296
#include <stdio.h>

int greatest(int a, int b) {
	int c;
	while (0 != b) {
		c = a % b;
		a = b; 
		b = c; 
	}
	return a;
}

int main(){

	int a,b,c;

	scanf("%d %d",&a,&b);
	c = greatest(a,b);
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2756
S = int(input())
s = S ** 0.5
if s == int(s):
    s = int(s)
else:
    s = int(s) + 1

a = s
d = s
b = 0
c = 0

diff = s ** 2 - S
q = int(diff ** 0.5) + 1
for i in range(1, q):
    if diff % i == 0 and diff // i <= 10**9:
        b = i
        c = diff // i
        break

print('{} {} {} {} {} {}'.format(0,0,a,b,c,d))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3632
//
// Created by Hideaki Imamura on 2020-03-10.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll N, K;
vector<ll> A, pos, neg;
ll n_zero, n_pos, n_neg;

// 積がx以下の(i,j)の数 for (pos, neg)
ll f(ll x) {
    ll ret = 0;
    int j = n_pos - 1;
    for (int i = n_neg - 1; i >= 0; --i) {
        while (j >= 0 && neg[i] * pos[j] <= x) j--;
        ret += n_pos - 1 - j;
    }
    return ret;
}

// 積がx以下の(i,j)の数 for (pos, pos) or (neg, neg)
ll g(ll x) {
    ll ret = n_pos * n_neg + n_zero * (n_pos + n_neg) + n_zero * (n_zero - 1) / 2;
    int j = n_neg - 1;
    for (int i = 0; i < n_neg - 1; ++i) {
        while (j >= 0 && neg[i] * neg[j] <= x) j--;
        ret += min((int)n_neg - j - 1, (int)n_neg - i - 1);
    }
    j = 0;
    for (int i = n_pos - 1; i >= 1; --i) {
        while (j < n_pos && pos[i] * pos[j] <= x) ++j;
        ret += min(i, j);
    }
    return ret;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        A.push_back(a);
        if (a == 0) {
            n_zero++;
        } else if (a > 0) {
            pos.push_back(a);
        } else {
            neg.push_back(a);
        }
    }
    sort(A.begin(), A.end());
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    n_pos = pos.size();
    n_neg = neg.size();

    if (K <= n_pos * n_neg) {
        ll l = - 1e18 - 1LL;
        ll r = 0;
        while (r - l > 1) {
            ll m = (l + r) / 2;
            if (f(m) >= K) {
                r = m;
            } else {
                l = m;
            }
        }
        cout << r << endl;
    } else if (K <= n_pos * n_neg + n_zero * (n_pos + n_neg) + n_zero * (n_zero - 1) / 2) {
        cout << 0 << endl;
    } else {
        ll l = 0;
        ll r = 1e18 + 1LL;
        while (r - l > 1) {
            ll m = (l + r) / 2;
            if (g(m) >= K) {
                r = m;
            } else {
                l = m;
            }
        }
        cout << r << endl;
    }
    return 0;
}




Measured memory_bytes: 5608
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        k: u64
    }
    let mut res = 0;
    for a in 1..=k {
        for b in 1..=k {
            let x = num::integer::gcd(a, b);
            for c in 1..=k {
                res += num::integer::gcd(x, c);
            }
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
int main (){
    int p,q,r;
    cin >> p >> q >>r;
    vector<int> sum(6);
    // abc
    sum[0] = p + q;
    // acb
    sum[1] = r + q;
    // bca
    sum[2] = q + r;
    // bac
    sum[3] = p + r;
    // cab
    sum[4] = r + p;
    // cba
    sum[5] = q + p;
    int ans;
    ans = *min_element(sum.begin(),sum.end());
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N), B(N);
  for(int i=0;i<N;++i) cin>>A[i]>>B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if(N%2==0) {
    cout<<(B[N/2]+B[N/2-1])-(A[N/2]+A[N/2-1])+1<<endl;
  }
  else {
    cout<<B[(N-1)/2]-A[(N-1)/2]+1<<endl;
  }
}



Measured memory_bytes: 6412
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   inf  1000000007;
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int  I[100005],L[100005];

inline void solve(){
    int n; cin>>n; 
    int  a[n+1], lis = 0 ; 
    I[0] = -inf ; 
    for (int i=1;i<=n;i++){
    	cin >> a[i] ; 
    	I[i] = inf ; 
    	L[i] = 1 ; 
    } 
    reverse (a+1,a+n+1);
    for (int i=1;i<=n;i++) { 
    	int  l = 0, r = lis ; 
    	while (l <= r){ 
    		int  mid = ( l + r ) >> 1 ; 
    		if (I[mid] <= a[i]) l = mid + 1 ; 
    		else r = mid - 1 ; 
    	} 
    	I[l] = a[i] ; 
    	if (l > lis) lis = l ; 
    }
    co (lis) ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 5916
#include<iostream>
using namespace std;

int main(){
int n, x;

while(1){
 cin  >> n >> x;
 if(n == 0 && x == 0) break;

 int count = 0; 
 for(int i = 1; i <= n; i++){
  for(int j = i+1; j <= n; j++){
   for(int k = j+1 ; k <= n; k++){
     if(i+j+k == x) count += 1;
       }
     }
   }
 cout << count << endl;
 }
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[n],a1,a2,a3;
    double mi=0;
    r(i,n)cin>>a[i];
    r(i,16)r(j,16)r(k,16){
      int R=i,b[256]={};
      r(l,n){
        R=(j*R+k)%256;
        b[(a[l]+R)%256]++;
      }
      double h=0;
      r(l,256)if(b[l])
        h-=(double)b[l]*log((double)b[l]);
      if(mi>h){
        mi=h;
        a1=i;
        a2=j;
        a3=k;
      }
    }
    cout<<a1<<' '<<a2<<' '<<a3<<endl;
  }
}

Measured memory_bytes: 3212
def main():
    n = int(input())
    strings =[input() for i in range(n)]

    ans = {}
    count = 0
    for s in strings:
        c = tuple(sorted(s))
        if c in ans:
            count += ans[c]
            ans[c] = ans[c] + 1
        else:
            ans[c] = 1

    print(count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 127364
import sys
data = []
for i in range(5):
    data.append(int(input()))
k = int(input())
data.sort()
for i in range(5):
    for j in data[i+1:]:
        if j - data[i] > k:
            print(':(')
            sys.exit()
        else:
            continue
print('Yay!')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int chnum(string s) {
    int slen = s.length();
    int res = 0;
    for(int i = 0; i < slen; ++i) {
        if(i == 0) {
            if(s[i] == 'm') res += 1000;
            else if(s[i] == 'c') res += 100;
            else if(s[i] == 'x') res += 10;
            else if(s[i] == 'i') res += 1;
        }else {
            if(s[i] == 'm') {
                if(s[i-1] != 'c' && s[i-1] != 'x' && s[i-1] != 'i') {
                    int ch = s[i-1] - '0';
                    res += (1000*ch);
                }else res += 1000;
            }else if(s[i] == 'c') {
                if(s[i-1] != 'm' && s[i-1] != 'x' && s[i-1] != 'i') {
                    int ch = s[i-1] - '0';
                    res += (100*ch);
                }else res += 100;
            }else if(s[i] == 'x') {
                if(s[i-1] != 'm' && s[i-1] != 'c' && s[i-1] != 'i') {
                    int ch = s[i-1] - '0';
                    res += (10*ch);
                }else res += 10;
            }else if(s[i] == 'i') {
                if(s[i-1] != 'm' && s[i-1] != 'c' && s[i-1] != 'x') {
                    int ch = s[i-1] - '0';
                    res += ch;
                }else res += 1;
            }
        }
    }
    return res;
}

int n;

int main() {
    cin >> n;
    while(n--) {
        string l, r; cin >> l >> r;
        int nl = chnum(l), nr = chnum(r);
        int sum = nl + nr;
        int mc = sum/1000;
        sum %= 1000;
        int cc = sum/100;
        sum %= 100;
        int xc = sum/10;
        sum %= 10;
        int ic = sum;
        string ans;
        if(mc != 0) {
            if(mc != 1) {
                char mch = mc+'0';
                ans.push_back(mch);
            }
            ans.push_back('m');
        }
        if(cc != 0) {
            if(cc != 1) {
                char cch = cc+'0';
                ans.push_back(cch);
            }
            ans.push_back('c');
        }
        if(xc != 0) {
            if(xc != 1) {
                char xch = xc+'0';
                ans.push_back(xch);
            }
            ans.push_back('x');
        }
        if(ic != 0) {
            if(ic != 1) {
                char ich = ic+'0';
                ans.push_back(ich);
            }
            ans.push_back('i');
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3176
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

public class Main {

	public static int gcd(int x, int y) {
		if (y == 0) {
			return x;
		} else {
			return gcd(y, x % y);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			final int c = sc.nextInt();

			if (a == 0 && b == 0 && c == 0) {
				break;
			}

			final int D = b * b - 4 * a * c;

			if (D < 0) {
				System.out.println("Impossible");
			} else if (D >= 0) {
				boolean found = false;
				int cur_d = D;

				for (int i = 0; i <= 20000; i++) {
					
					//System.out.println(i + " " +  cur_d);
					
					if (cur_d == i * i) {
						found = true;
						break;
					}else if(i >= 2 && cur_d % (i * i) == 0){
						cur_d /= (i * i);
						i--;
					}
				}
				
				//System.out.println(D);

				if (!found) {
					System.out.println("Impossible");
				} else {
					final int x = (int) (2 * a);
					final int r_ = (int) (-b + Math.sqrt(D));
					final int s_ = (int) (-b - Math.sqrt(D));
					
					//System.out.println(x + " " + r_ + " " + s_);
					
					final int gcd_p = gcd(x, Math.abs(r_));
					final int gcd_q = gcd(x, Math.abs(s_));
					
					int p = x / gcd_p;
					int r = -(r_ / gcd_p);
					int q = x / gcd_q;
					int s = -(s_ / gcd_q);
					
					if (p < 0 && r < 0) {
						p = -p;
						r = -r;
					}

					if (q < 0 && s < 0) {
						q = -q;
						s = -s;
					}

					if (p > q) {
						System.out.println(p + " " + r + " " + q + " " + s);
					} else {
						System.out.println(q + " " + s + " " + p + " " + r);
					}
				}
			}

		}

	}

}

Measured memory_bytes: 13000
from copy import deepcopy
from heapq import heappop, heappush

n = int(input())
a = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(n)]

d = [0] * n

ans = 0
temp = []
for x in range(n):
    heappush(temp, x)
while 1:
    next_temp = []
    while len(temp) > 0:
        x = heappop(temp)
        if d[x] >= n-1:
            continue
        y = a[x][d[x]]
        #print(x, y)
        if y not in next_temp:
            if a[y][d[y]] == x:
                heappush(next_temp, x)
                heappush(next_temp, y)
    #print(next_temp)
    for t in next_temp:
        d[t] += 1
    if len(next_temp) == 0:
        break
    temp = [] + next_temp
    ans += 1

#print(d)

if d.count(n-1) == n:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 71644
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements < num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define int long long int
//Binary_Search->dp->greedy
//auto check = [&](ll x){};
void solve(){
	string s;
	cin>>s;
	ll n=s.length();
	vvl dp(n,vl(2));
	dp[0][0]=1;
	dp[0][1]=2;
	for(int i=1;i<n;i++){
		if(s[i]=='1'){
			dp[i][0]=(dp[i-1][1]+(dp[i-1][0]*3%mod))%mod;
			dp[i][1]=(dp[i-1][1]*2)%mod;
		}
		else{
			dp[i][0]=dp[i-1][0]*3%mod;
			dp[i][1]=dp[i-1][1];
		}
	}
	ll ans=(dp[n-1][0]+dp[n-1][1])%mod;
	cout<<ans<<endl;
 
}
int main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
return 0;
}    

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll x,y;
    cin >> x >> y;
    if (x > 0 && y > 0 && x < y){
        cout << y - x << endl;
    }
    else if (x > 0 && y > 0 && x > y){
        cout << x - y + 2 <<  endl;
    }
    else if (x == 0 && y > 0){
        cout << y - x << endl;
    }
    else if (x < 0 && y == 0){
        cout << y - x << endl;
    }
    else if (x >= 0 && y <= 0){
        cout << abs(abs(x) - abs(y)) + 1 << endl;
    }
    else if (x <= 0 && y >= 0){
        cout << abs(abs(x) - abs(y)) + 1 << endl;
    }
    else if (x < 0 && y < 0 && x < y){
        cout << y - x << endl;
    }
    else if (x < 0 && y < 0 && x > y){
        cout << x - y + 2 << endl;
    }
}


Measured memory_bytes: 3492
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] X = new int[M];
        int[] D = new int[M];
        for(int i=0;i<M;i++){
            X[i]=sc.nextInt();
        }
        Arrays.sort(X);
        for(int i=1;i<M;i++){
            D[i]=X[i]-X[i-1];
        }
        System.err.println(Arrays.toString(X));
        System.err.println(Arrays.toString(D));
        Arrays.sort(D);
        for(int i=0;i<=M-N;i++){
            ans += D[i];
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 60020
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let x = sc.read::<usize>() - 1;
        let y = sc.read::<usize>() - 1;
        graph[x].push(y);
        graph[y].push(x);
    }

    if dfs(0, 0, &graph) == 0 {
        println!("Bob");
    } else {
        println!("Alice");
    }
}

fn dfs(v: usize, p: usize, graph: &Vec<Vec<usize>>) -> usize {
    let mut grundy = 0;
    for &next in graph[v].iter() {
        if next == p {
            continue;
        }
        grundy ^= dfs(next, v, graph) + 1;
    }
    grundy
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 16636
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 998244353
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, j, k, a;
	cin >> num >> k;
	vector<vector<ll>> dp(num + 1, vector<ll>(k + 1, 0));
	dp[0][0] = 1;
	rep(j, num) {
		cin >> a;
		rep(i, k + 1)
			dp[j + 1][i] = (dp[j][i] << 1) % MOD;
		rep(i, k - a + 1) {
			dp[j + 1][i + a] += dp[j][i];
			dp[j + 1][i + a] %= MOD;
		}
	}
	cout << dp[num][k] << "\n";
	return 0;
}

Measured memory_bytes: 73640
#include <stdio.h>
#include <stdlib.h>


int main(void) {

  char c[5];
  char c1, c2;
  int num1, num2;

  c1 = 0;
  num1 = 0;
  c2 = 0;
  num2 = 0;

  scanf("%s", c);

  for (int i=0;i<4;i++) {
    if (c1 == 0) {
      c1 = c[i];
      num1++;
    } else if (c[i] == c1) {
      num1++;
    } else if (c2 == 0) {
      c2 = c[i];
      num2++;
    } else if (c[i] == c2) {
      num2++;
    } else {
      printf("No\n");
      return 0;
    }
  }

  if (num1 == 2 && num2 == 2) {
    printf("Yes\n");
    return 0;
  } else {
    printf("No\n");
    return 0;
  }
}

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

// ABC117 A - Entrance Examination
// 2020.07.01

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  double T, X; cin >> T >> X;
  double ans = T/X;
  cout << fixed << setprecision(10) << ans << endl;;
}

Measured memory_bytes: 3788
#include<cstdio>
#include<cmath>
#define rg32 register int
#define rg8 register char
typedef long long ll;
const double eps=1e-6;
int n,k;
int a[200005];
inline int read() {
	rg32 x=0,f=1;rg8 s=getchar();
	while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
	while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
	return x*f;
}
inline bool check(double x) {
	ll sum=0;
	//for(register int i=1;i<=n;++i) sum+=(int)ceil(a[i]*1.00/x)-1;
	for(rg32 i=1;i<=n;++i) {
		ll val=a[i]/x;
		if(fabs(a[i]-x*val)>eps) ++val;
		sum+=val-1;
	}
	return sum<=k;
}
int main() {
	n=read(),k=read();
	for(rg32 i=1;i<=n;++i) a[i]=read();
	double l=0,r=1e9;
	while(r-l>eps) {
		double mid=l+(r-l)/2;
		if(check(mid)) {r=mid;}
		else {l=mid;}
	} 
	printf("%lld\n",(ll)(r+1-eps));
	return 0;
}

Measured memory_bytes: 2380
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int n[5];
    int ans=0;
    rep(i,5){
        int a;
        cin>>a;
        if(a%10!=0) {
            int b = 10 - a % 10;
            ans += a - a%10+10;
            n[i] = b;
        }else{
            n[i]=0;
            ans+=a;
        }
        //cout<<n[i]<<endl;
    }
    sort(n,n+5);

    ans+=10-n[4];
    ans-=10;
    cout<<ans<<endl;

    return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

/*
int	gcd(int A, int B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}
*/

#define	MOD 1000000007

int	main() {
	int K, X;
	cin >>K >>X;
	if (K*500>=X)
		cout <<"Yes" <<endl;
	else
		cout <<"No" <<endl;
	return 0;
}



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

int main()
{
  long long n, a, b;
  cin >> n >> a >> b;
  
  if (n % (a+b) <= a)
  	cout << n / (a+b) * a + n % (a+b) << endl;
  else
    cout << (n / (a+b) + 1) * a << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;

const int N=100005;
int n;
LL C,ans,x[N],v[N],ssum[N],nsum[N],smx1[N],smx2[N],nmx1[N],nmx2[N];

int main(){
	scanf("%d%lld",&n,&C);
	for(int i=1;i<=n;++i)
		scanf("%lld%lld",&x[i],&v[i]);
	for(int i=1;i<=n;++i){
		ssum[i]=ssum[i-1]+v[i];
		smx1[i]=max(smx1[i-1],ssum[i]-x[i]);
		smx2[i]=max(smx2[i-1],ssum[i]-2*x[i]);
	}
	for(int i=n;i>=1;--i){
		nsum[i]=nsum[i+1]+v[i];
		nmx1[i]=max(nmx1[i+1],nsum[i]-(C-x[i]));
		nmx2[i]=max(nmx2[i+1],nsum[i]-2*(C-x[i]));
	}
	for(int i=0;i<=n;++i){
		ans=max(ans,smx1[i]);
		ans=max(ans,nmx1[i]);
		ans=max(ans,smx2[i]+nmx1[i+1]);
		ans=max(ans,smx1[i]+nmx2[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6400
#include <stdio.h>

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

	int n;
	scanf("%d", &n);
	long l[100];
	l[0] = 2;
	l[1] = 1;

	for(int i = 2; i <= n; i++) {
		l[i] = l[i-1] + l[i-2];
	}

	printf("%ld", l[n]);

	return 0;
}

Measured memory_bytes: 128
judge = {'AC':0,'WA':0,'TLE':0,'RE':0}
N = int(input())
for i in range(N):
    judge[input()]+=1
print('AC x ' + str(judge['AC']))
print('WA x ' + str(judge['WA']))
print('TLE x ' + str(judge['TLE']))
print('RE x ' + str(judge['RE']))

Measured memory_bytes: 9204
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cout << setprecision(10);
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	// hour coordinate
	double deg_h = ((h*360)/12) * (M_PI/180.0) + ((m*30)/60) * (M_PI/180.0);
	double deg_m = ((m*360)/60) * (M_PI/180.0);
	double hx = a * sin(deg_h);
	double hy = a * cos(deg_h);
	double mx = b * sin(deg_m);
	double my = b * cos(deg_m);
	double dist = sqrt((hx-mx) * (hx-mx) + (hy-my) * (hy-my));
	cout << dist << '\n';
	
	return 0;
}


Measured memory_bytes: 4012
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    p = [x - 1 for x in inl()]
    cnt = 0
    i = 0
    while i < n:
        if i != p[i]:
            i += 1
        elif i + 1 < n and (i + 1) == p[i + 1]:
            cnt += 1
            i += 2
        else:
            cnt += 1
            i += 1

    return cnt


print(solve())


Measured memory_bytes: 19996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), x = scanner.nextInt();
			System.out.println(((x >= a) && (x <= a + b)) ? "YES" : "NO");
		}
	}
}


Measured memory_bytes: 35688
#include "bits/stdc++.h"

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long k;
  vector<pair<int, int> > infos;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    infos.push_back(make_pair(a, b));
  }
  sort(infos.begin(), infos.end());
  long long now = 0;
  for(auto info : infos) {
    now += info.second;
    if(now >= k) {
      cout << info.first << "\n";
      break;
    }
  }
}

Measured memory_bytes: 1400
import re
def main():
    n = int(input())
    A = list(map(int,input().split()))
    xor = A[0]
    for a in A[1:]:
        xor = xor^a
    Ans = []
    for a in A:
        Ans.append(a^xor)
    print(*Ans, sep=" ")
    return 

if __name__ == "__main__":
    main()

Measured memory_bytes: 32104
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
long long int mod = pow(10, 9) + 7;
long long int modPow(long long int x, long long int n){
    long long int tmp = 1;
    for(long long int i = 0; i < n; i++ ){
        tmp = tmp * x % mod;
    }
    return tmp;
}

int main(){
    long long int n;
    cin >> n;
    long long int all;
    all = modPow(10, n);
    long long int zero;
    zero = modPow(9, n);
    long long int nine;
    nine = modPow(9, n);
    long long int two; 
    two = modPow(8, n);
    long long int res; 
    // zero = 9 * 9;
    // cout << all << " " << zero << " " << nine << " " << two << endl;
    res = (all - zero - nine + two);
    res = res % mod;
    if(res < 0){
        res = res + mod;
    }
    cout << res << endl; 

}
// 100 - 81 - 81 + 64

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

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    long long sum=0;
    for(long long int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            sum+=i;
    }
    cout<<sum;
    return 0;
}


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

#define MAX 200003
#define MOD 1000000007

long long modpow(long long a,long long n,long long mod){
  long long res=1;
  while(n>0){
    if(n&1){       //nのbitと...00001を比較  nが2で割り切れるならtrue
      res=(res*a)%mod;
    }
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

long long modinv(long long a,long long mod){
  return modpow(a,mod-2,mod);
}

long long fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=(fac[i-1]*i)%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

long long COM(int n,int k){
  if(n<k){
    return 0;
  }
  if(n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

Graph G;
vector<map<int,pair<ll,int>>> ans;

pair<ll,int> solve1(int v,int p){
  if(G.at(v).size()==1&&p>=0){
    return ans.at(v)[p]=make_pair(1,1);
  }
  ll Ans=1;
  ll sum=0;
  for(auto nv:G.at(v)){
    if(p==nv){
      continue;
    }
    pair<ll,int> pp=solve1(nv,v);
    Ans*=pp.first*finv[pp.second]%MOD;
    Ans%=MOD;
    sum+=pp.second;
  }
  Ans*=fac[sum];
  Ans%=MOD;
  return ans.at(v)[p]=make_pair(Ans,sum+1);
}

void solve2(int v,int p){
  ll Ans=1;
  ll sum=0;
  for(auto nv:G.at(v)){
    Ans*=ans.at(nv)[v].first*finv[ans.at(nv)[v].second]%MOD;
    Ans%=MOD;
    sum+=ans.at(nv)[v].second;
  }
  for(auto nv:G.at(v)){
    if(p==nv){
      continue;
    }
    ll x=(Ans*fac[ans.at(nv)[v].second]%MOD)*modinv(ans.at(nv).at(v).first,MOD)%MOD;
    ll y=sum-ans.at(nv)[v].second;
    ans.at(v)[nv]=make_pair(x*fac[y]%MOD,y+1);
  }
  for(auto nv:G.at(v)){
    if(nv==p){
      continue;
    }
    solve2(nv,v);
  }
}

int main(){
  int N;
  cin>>N;
  G.resize(N);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }

  COMinit();

  ans.resize(N);
  solve1(0,-1);
  solve2(0,-1);
  for(int v=0;v<N;v++){
    ll Ans=1;
    ll sum=0;
    for(auto nv:G.at(v)){
      Ans*=ans.at(nv)[v].first*finv[ans.at(nv)[v].second]%MOD;
      Ans%=MOD;
    }

    cout<<Ans*fac[N-1]%MOD<<endl;
  }

}


Measured memory_bytes: 54900
# Matrix Multiplication

info = [int(i) for i in input().rstrip().split()]
n = info[0]
m = info[1]
l = info[2]

matrixA = []
matrixB = []
for i in range(n):
    row = [int(j) for j in input().rstrip().split()]
    matrixA.append(row)
for j in range(m):
    row = [int(k) for k in input().rstrip().split()]
    matrixB.append(row)
# print(matrixA)
# print(matrixB)

for i in range(n):
    multipleRow = []
    for k in range(l):
        total = 0
        for j in range(m):
            total += matrixA[i][j] * matrixB[j][k]
        multipleRow.append(str(total))
    # print(multipleRow)
    print(' '.join(multipleRow))



Measured memory_bytes: 6240
function Main(input) {
    lines = input.split("\n");
    const [a, b] = lines.shift().split(' ');
    
    console.log(a < b ? Array(+b).fill(a).join('') : Array(+a).fill(b).join(''));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

struct Point{
	double x, y;
};


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

	int x = 0, n;
	string s;
	cin >> n >> s;

	int m = 0;
	REP(i, n) {
		if (s[i] == 'I') {
			x++;
		} else if (s[i] == 'D') {
			x--;
		}

		m = max(m, x);
	}

	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int cont=0;
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    for(int x=0; x*r<=n; x++){
        for(int y=0; x*r + g*y<=n;y++){
            if((n-(r*x)-(g*y))%b==0){


                cont++;}
        }
    }

    cout<<cont;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// B - Strings with the Same Length
// https://atcoder.jp/contests/abc148/tasks/abc148_b
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        char[] S = scanner.next().toCharArray();
        char[] T = scanner.next().toCharArray();
        scanner.close();

        for (int i = 0; i < N; i++) {
            System.out.print(S[i]);
            System.out.print(T[i]);
        }
        System.out.println();
    }
}


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
   int n, h;
   cin >> n >> h;
   vector<pair<int, int>> d(n);
   for (auto& p : d) {
       cin >> p.first >> p.second;
   }
   int best = 0;
   for (auto p : d) {
       best = max(best, p.first);

   }
   sort(d.begin(), d.end(), [] (auto& l, auto& r) {
       return l.second > r.second;
   });
   d.eb(0, 0);
   int cnt = 0;
   for (auto p : d) {
       if (h <= 0) {
           break;
       }
       if (p.second < best) {
           cnt += (h + best - 1) / best;
           break;
       } else {
           ++cnt;
           h -= p.second;
       }
   }

   cout << cnt << "\n";
}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define mod 1000000007
#define PI acos(-1)
int main()
{
	IOS
	int n;
	cin>>n;
	int a[n+1],i;
	int ans=0;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i%2==1&&a[i]%2==1)
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin >> str;
    for(int i = 0; i < str.length(); i++){
        if((i % 2 == 0 && str[i] == 'L')
                || (i % 2 == 1 && str[i] == 'R')){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256