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

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;}

int N,W;
int w[110],v[110];
long long dp[110][100010];

int main(){
    cin >> N >> W;
    for(int i=0;i<N;++i) cin >> w[i] >> v[i];
    for(int i=0;i<N;++i){
        for(int j=0;j<=W;++j){
            chmax(dp[i+1][j],dp[i][j]); //使わない。
            if(j-w[i]>=0) chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
        }
    }

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

}



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

int main()
{
    string s;
    cin >> s;
    string y = s.substr(0, 4);
    string m = s.substr(5, 2);
    string d = s.substr(8, 2);
    s = y + m + d;
    if (s > "20190430")
        cout << "TBD" << endl;
    else
        cout << "Heisei" << endl;
    return 0;
}

Measured memory_bytes: 3628
// i番目の数を知りたいとき、i以外の全てのjについてajのxorを取ると、どうなるんだろう、、
// すぬけくんは偶数匹いるので、
// i以外のスカーフに書かれている数はそれぞれ偶数回かけられるので、すべて0になる。
// なので、i番目の数を知りたいときi以外の全てのjについてajのxorを取ると、i番目のスカーフに書かれた数がわかる。
// i番目のスカーフの番号piから、i+1番目のスカーフの番号p(i+1)が知りたいときは、
// pi     = a1 xor a2 xor .... a(i-1) xor a(i+1) xor .... aN
// p(i+1) = a1 xor a2 xor .... a(i-1) xor ai xor a(i+2) xor .... aN
// p(i+1) = pi xor ai xor a(i+1)
// ↑考察は1-indexedだけど、実装は0-indexedです。
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    // p0を求める
    int p = 0;
    for (int i = 1; i < N; ++i) {
        p ^= a[i];
    }
    cout << p << " ";
    for (int i = 1; i < N; ++i) {
        p = p ^ a[i - 1] ^ a[i];
        cout << p << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    string S;
    cin >> S;

    if(S=="Sunny"){
        cout << "Cloudy" << endl;
    }else if(S=="Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
A.sort()
first = A[-1]
second = max((min(x, first-x), x) for x in A[:-1])
print(first, second[1])


Measured memory_bytes: 14428
import fractions
n,x=map(int,input().split())
x_i=list(map(int,input().split()))
ans=0
for i in range(n):
    if i==0:
        ans=abs(x-x_i[0])
    elif ans==1:
        break
    else:
        ans=fractions.gcd(ans,abs(x-x_i[i]))
print(ans)

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  string s; cin >> s;
  string space = " ";

  s.replace(5,1,space);
  s.replace(13,1,space);
  cout << s << endl;

  return;
}

signed main() {
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n, m;
  cin >> n;
  m = n;
  for(int i = 1; i <= sqrt(n); i++) {
    if(n % i) continue;
    ll x = n / i - 1;
    if(x > 0 && n / x == n % x)
      ans += n / i - 1;
    ll y = i - 1;
    if(y > 0 && n / y == n % y)
      ans += y;
  }
  // unordered_set<int> st;
  // ans += n - 1;
  // while(n % 2 == 0) {
  //   if(st.count(2) == 0) {
  //     ans += m / 2 - 1;
  //     st.insert(2);
  //   }
  //   n /= 2;
  // }
  // for(int i = 3; i <= sqrt(n); i += 2) {
  //   while(n % i == 0) {
  //     if(st.count(i == 0)) {
  //       ans += m / i - 1;
  //       st.insert(i);
  //     }
  //     n /= i;
  //   }
  // }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main( )
	{
		string w = Console.ReadLine().Trim();
		string input;
		int cnt = 0;
		while( null != (input = Console.ReadLine()) ) {
			string[] words = input.ToLower().Split( ' ' );
			for( var i=0; i<words.Length; i++ ) {
				if( w == words[i] ) {
					cnt++;
				}
			}
		}
		Console.WriteLine( cnt );
	}
}

Measured memory_bytes: 9200
#include <iostream>

using namespace std;

typedef long long ll;

ll dp[105][100005];

int main(int argc, char *argv[])
{
	int N, W, w[100005], v[100005];

	cin >> N >> W;

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

	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9;
const ll mod=998244353;
signed main(){
    ll n;cin>>n;
    vector<ll>d(100);
    ll ma=0;
    rep(i,n){
        ll a;cin>>a;
        ma=max(ma,a);
        d[a]++;
    }
    bool f=1;
    rep(i,(ma+1)/2){
        if(d[i])f=0;
    }
    REP(i,(ma+1)/2,ma+1){
        if(d[i]==0)f=0;
    }
    if(ma%2){
        if(d[(ma+1)/2]!=2)f=0;
    }else{
        if(d[ma/2]!=1)f=0;
    }
    if(f)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

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

using namespace std;

int main(){
  long long X, Y;
  long long ans=0;
  cin >> X >> Y ;

  if(abs(X) < abs(Y)){
    if(X < 0)ans++;
    if(Y < 0)ans++;
    ans += abs(Y) - abs(X);
  }else if(abs(X) == abs(Y)){
    if(X != Y)ans++;
  }else{
    if(X > 0)ans++;
    if(Y > 0)ans++;
    ans += abs(X) - abs(Y);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
if x == 1 or x == (2 * n - 1):
    print("No")
    exit()

print("Yes")

r = [x - 1, x, x + 1]
tmp = list(range(1, x - 1)) + list(range(x + 2, 2 * n))

ans = tmp[:n - 2] + r + tmp[n - 2:]

for i in ans:
    print(i)


Measured memory_bytes: 15312
N = int(input())
a = list(map(int,input().split(" ")))

dic = {i : 0 for i in range(9)}
for i in range(N):
	if (a[i] // 400) > 7:
		dic[8] += 1
	else:
		dic[(a[i] // 400)] += 1

minv = 0
for i in range(8):
	if dic[i] >= 1:
		minv += 1

print(max(minv,1),minv+dic[8])

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))

typedef struct{
	int b;
	ll c;
}sousa;


int comp(const void *a, const void *b){return ((sousa*)b)->c - ((sousa*)a)->c;}

int compare_longlong(const void *a, const void *b) {long long *A = (long long *)a;long long *B = (long long *)b;if (*A > *B) return 1;if (*A < *B) return -1;return 0;}


int main(void){
	int n,m;
	scanf("%d%d",&n,&m);
	ll a[n];
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	sousa bc[m];
	for(int i=0;i<m;i++){
		scanf("%d%lld",&bc[i].b,&bc[i].c);
	}
	qsort(a,n,sizeof(ll),compare_longlong);
	qsort(bc,m,sizeof(sousa),comp);
	int ij=0;
	ll ans=0;
	for(int i=0;i<n;i++){
		for(int j=ij;j<m;j++){
			if(a[i]>=bc[j].c)break;
			if(bc[j].b>0){
				a[i]=bc[j].c;
				bc[j].b--;
				if(bc[j].b==0)ij++;
			}
		}
		ans+=a[i];
	}
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4084
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    // 整数の入力                                                                                                      
    int N;
    cin >> N;

    // 出力                                                                                                            
    cout << (double)(ceil((double)N/2)/(double)N) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<assert.h>
using namespace std;

bool primeChecker(int object)
{
    assert (object > 1);
    int i = 2;
    while (i*i <=object) {
        if (object%i == 0) return false;
        i++;
    }
    return true;
}

int main()
{
    int n;
    int counter = 0;

    cin >> n;

    for (int i = 0; i < n; ++i) {
        int tmp;
        cin >> tmp;
        if (primeChecker(tmp)) counter++;
    }
    
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
    int N, M_a, M_b;
    int dp[400][400];
    int ans = INT32_MAX;
    for(int i = 0; i < 400; i++){
        for(int j = 0; j < 400; j++){
            dp[i][j] = -1;
        }
    }
    cin >> N >> M_a >> M_b;
    for(int i = 0; i < N;i++){
        int a, b, c;
        cin >> a >> b >> c;
        for(int i = 400-1; i >= 0; i--){
            for(int j = 400-1; j >= 0; j--){
                if(dp[i][j] > 0){
                    if(dp[i+a][j+b] > 0){
                        dp[i+a][j+b] = min(dp[i][j] + c, dp[i+a][j+b]);
                    }else{
                        dp[i+a][j+b] = dp[i][j] + c;
                    }
                }
            }
        }
        if(dp[a-1][b-1] > 0){
            dp[a-1][b-1] = min(dp[a-1][b-1], c);
        }else{
            dp[a-1][b-1] = c;
        }
    }
    for(int i = 1; (i*M_a <= 400 && i*M_b <= 400); i++){
        if(dp[i*M_a-1][i*M_b-1] > 0){
            ans = min(ans, dp[i*M_a-1][i*M_b-1]);
        }
    }
    if(ans != INT32_MAX)cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 896
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = input[0];
            var K = input[1];

            Console.WriteLine(Math.Min(N % K, K - N % K));
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<string>

using namespace std;

vector<int> list[100];
int item[100];

int saiki(int n){
	if(list[n].empty()==1){
		return item[n];
	}
	
	int cont=0;
	for(int i=0;i<list[n].size();i++){
		cont+=saiki(list[n][i]);
	}
	
	return min(cont,item[n]);
}

int main(){
	while(1){
		map<string,int> name;
		int n;
		cin>>n;
		if(n==0){
			break;
		}
		for(int i=0;i<n;i++){
			string a;int b;
			cin>>a>>b;
			name[a]=i;
			item[i]=b;
		}
		for(int i=0;i<100;i++){
			list[i].clear();
		}
		
		int m;
		cin>>m;
		for(int i=0;i<m;i++){
			string a;int b;
			cin>>a>>b;
			for(int j=0;j<b;j++){
				string c;
				cin>>c;
				list[name[a]].push_back(name[c]);
			}
		}
		
		string a;
		cin>>a;
		printf("%d\n",saiki(name[a]));
	}
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A[]=new int[N];
		boolean k=false;
		int min=1000000005,key=0,mi=min,ke=0;
		for(int i=0;i<N;i++){
			A[i]=stdIn.nextInt();
			if(min>A[i]){
				min=A[i];key=i;
			}
		}
		while(true){
			for(int i=0;i<N;i++){
				A[i]%=min;
				if(i==key)
					A[i]=min;
				if(A[i]==1){
					System.out.println(1);
					System.exit(0);
				}
				if(A[i]!=0&&i!=key){
					k=true;
					if(mi>A[i]){
						mi=A[i];
						ke=i;
					}
				}
			}
			if(k){
				min=mi;key=ke;
				mi=1000000005;k=false;
			}
			else
				break;
		}
		System.out.println(A[key]);
	}
}

Measured memory_bytes: 50308
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    X=ii()

    def is_ok(a,b):
        return a**5 <= X+b**5

    for a in range(-1010,1010):
        l,r = -INF,INF
        while r-l > 1:
            mid = (r+l)//2
            if is_ok(a,mid):
                r = mid
            else:
                l = mid
        b=r
        # print(a,b)
        if a**5-b**5==X:
            print(a,b)
            exit()




if __name__ == "__main__":
    main()

Measured memory_bytes: 73708
q = input().split(" ")
A = int(q[0])
B = q[1].split(".")
#print(B)
b0 = B[0]
b1 = B[1]
if b1[0]=="0":
  b1 = b1[1]

s = str(A*int(b1)//100)
#print(s)
print(A*int(b0) + int(s))

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

#define loop(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;
struct __{__(){ios_base::Init i;ios_base::sync_with_stdio(0);cin.tie(0);}}__;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

vector<int> a;
int n;

inline bool is_min(int i){
	if (i == 0 or a[i-1] > a[i]){
		if (i == n-1 or a[i+1] > a[i])
			return true;
	}
	return false;
}

inline bool is_max(int i){
	if (i == 0 or a[i-1] < a[i]){
		if (i == n-1 or a[i+1] < a[i])
			return true;
	}
	return false;
}

struct growing_sector{
	int min_ind;
	int max_ind;
	bool complete;

	growing_sector(int min_ind=-1, int max_ind = -1, bool complete = false){
		this->min_ind = min_ind;
		this->max_ind = max_ind;
		this->complete = complete;
	}
};

int main() {
	n = nxt();
	vector<int> a_dirty(n);
	for (int i = 0; i< n; ++i){
		a_dirty[i] = nxt();
	}

	a.push_back(a_dirty[0]);
	for (int i = 1; i< n; ++i){
		if (a_dirty[i] != a_dirty[i-1]){
			a.push_back(a_dirty[i]);
		}
	}
	int n = a.size();

	bool theres_min = false;
	vector<growing_sector> sectors;
	int sect_count = 0;

	for (int i = 0; i< n; ++i){
		if (is_min(i)){
			theres_min = true;
			sectors.push_back(growing_sector(i));
			++sect_count;
			continue;
		}
		if (theres_min && is_max(i)){
			sectors[sect_count-1].max_ind = i;
			sectors[sect_count-1].complete = true;
			theres_min = false;
		}
	}

	long long cash = 1000;

	for (growing_sector sct : sectors){
		// cout << a[sct.min_ind] << ' ' << a[sct.max_ind] << ' ' << sct.complete << endl;
		if (sct.complete){
			long long toBuy = floor(cash / a[sct.min_ind]);
			cash += (a[sct.max_ind] - a[sct.min_ind]) * toBuy;
		}
	}


	cout << cash << '\n';
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int main() {
  int N, M;
  cin >> N >> M;
  vector< int > S(M);
  for(int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int x;
      cin >> x;
      --x;
      S[i] |= 1 << x;
    }
  }
  vector< int > p(M);
  cin >> p;

  int ret = 0;
  for(int i = 0; i < 1 << N; i++) {
    int add = 0;
    for(int j = 0; j < M; j++) {
      int sum = __builtin_popcount(S[j] & i);
      add += sum % 2 == p[j];
    }
    ret += add == M;
  }
  cout << ret << endl;
}






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

int main(){
    long int N;
    cin >> N;
    long int i,j,k;
    long int tmp;
    long int l[N];
    long int ans = 0;
    for(i=0;i<N;i++)cin >> l[i];
    sort(l,l+N);
    for(i=0;i<N-2;i++){
        tmp=0;
        for(j=i+1;j<N-1;j++){
            k=j+1+tmp;
            while(l[i]+l[j]>l[k]){
                tmp++;
                k++;
                if(k>N-1)break;
            }
            ans += tmp;
            if(tmp>0)tmp--;
            }
        }
        cout << ans << endl;
    }

Measured memory_bytes: 256
from collections import deque
k=int(input())
d=deque()
for i in range(1,10): d.append(i)
for i in range(k):
  x=d.popleft()
  if i==k-1:
    print(x)
    break
  if x%10!=0:
    d.append(10*x+x%10-1)
  d.append(10*x+x%10)
  if x%10!=9:
    d.append(10*x+x%10+1)

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

vector < int > g[maxn];
vector < ll > cost[maxn];
bool visited[maxn];
int color[maxn];

void bfs(int src){
    queue < int >Q;

    Q.push(src);
    visited[src]=1;
    color[src]=1;

    while(!Q.empty()){
        int u=Q.front();
        Q.pop();

        for(int i=0 ; i<g[u].size() ; i++){
            int v=g[u][i];
            if(!visited[v]){

                visited[v]=1;
                Q.push(v);

                int w=cost[u][i];
                if(w%2==0){
                    color[v]=color[u];
                }else {
                    if(color[u]==0) color[v]=1;
                    else color[v]=0;
                }
            }
        }
    }
}


int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;


    f1(i,n-1){
        int u,v;
        ll w;
        cin >> u >> v >> w;

        g[u].pb(v);
        g[v].pb(u);
        cost[u].pb(w);
        cost[v].pb(w);
    }

    bfs(1);
    for(int i=1 ; i<=n ; i++){
        cout << color[i] << endl;
    } cout << endl;

    return 0;
}




Measured memory_bytes: 17152
#include<iostream>
#include<algorithm>
#include <vector>
#include <cmath>
#define endl "\n"
using namespace std;


int main()
{
    long long N,z;
    cin >> N;
    z=N;
    if (N % 1000 == 0)
    {
        cout << "0\n";
    }
    else
    {
        cout << 1000 - (N % 1000) << endl;
    }
}


Measured memory_bytes: 3636
a,b=map(int,input().split())
if a<=0 and b>=0:
    print('Zero')
elif a>0 and b>0:
    print('Positive')
elif a<0 and b<0:
    if ((-a)-(-b)+1)%2==0:
        print("Positive")
    else:
        print("Negative")


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

int main() {
	int L;
	int i,kozu[12],use[12],sum=0,fl=0,mon;
	while(1){
		cin >> L;
		if(L==0) break;
		for(i=0;i<12;i++){
			cin >> kozu[i] >> use[i];
			sum+=kozu[i]-use[i];
			if(sum>=L && fl==0){
				mon=i+1;
				fl=1;
			}
		}
		if(fl==1){
			cout << mon << endl;
		}else{
			cout << "NA" << endl;
		}
		sum=0;
		fl=0;
	}
	return 0;
}

Measured memory_bytes: 2992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		String str = sc.next();

		int sn = 0;
		for(int i = 0; i < str.length(); i++){
			sn += str.charAt(i) - '0';
		}

		System.out.println(Integer.parseInt(str) % sn == 0 ? "Yes" : "No");
	}

}


Measured memory_bytes: 21844
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();

		int ans = 0;
		for (char c : s) {
			if (c == '1') {
				ans++;
			}
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 20820
# D
N,X,Y = map(int,input().split())
lst = [[0]*N for i in range(N)]
dct = {i+1: 0 for i in range(N-1)}
for i in range(N):
    for j in range(i+1, N):
        if (i+1 <= X and j+1 >= Y):
            num = X - (i + 1) + 1 + j + 1 - Y
        elif (i+1 < X and j + 1 > X and  j+1 < Y):
            num = min(j-i, X - (i+1) + 1 + Y - (j+1))
        elif (i+1 >= X and j+1 < Y):
            num = min(j-i, i+1 - X + 1 + Y - (j+1))
        elif (i+1 > X and i + 1 < Y and  j+1 >= Y):
            num = min(j-i, i+1 - X + 1 + j+1 - Y)
        else:
            num = j - i
        dct[num] += 1
for i in dct.values():
    print(i)

Measured memory_bytes: 79836
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m,c,t,k; //入力
	
	int a[20][20];
	vector<int> b;

	int i,j,d=0,kari,old=0, flag = 0; //内部で使用;
	int ans = 0; //出力

	cin >> n>> m >> c;

	for (i = 0; i < m; i++) {
		cin >> kari;
		b.push_back(kari);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	//↑ここまで入力パート
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			d = d + a[i][j] * b[j];
		}
		d = d +c;
		if (d > 0)ans++;
		d = 0;
	}
	
	cout << ans << "\n";
}


Measured memory_bytes: 256
# 入力
N = int(input())
s = input()
xs = [
    1 if c == 'o' else
    -1
    for c in s
]

# 動物1と動物2の種別を決め打ちで割り当てて、矛盾がないかを検証する
dp = {
    l: {
        r: [0 for _ in range(N + 2)]
        for r in (1, -1)
    }
    for l in (1, -1)
}
for l in (1, -1):
    for r in (1, -1):
        dp[l][r][0] = l
        dp[l][r][1] = r
        for i in range(2, N + 2):
            dp[l][r][i] = dp[l][r][i - 2] * dp[l][r][i - 1] * xs[(i - 1) % N]


def f(l, r):
    return ''.join(
        'S' if dp[l][r][i] == 1 else
        'W'
        for i in range(N)
    )


ans = next(
    (
        f(l, r)
        for l in (1, -1)
        for r in (1, -1)
        if dp[l][r][N] == l and dp[l][r][N + 1] == r
    ),
    '-1'
)

# 出力
print(ans)


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

using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<P> p;
  int a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    p.push_back(P(a, b));
  }
  
  sort(p.begin(), p.end());
  ll i = 0;
  int j = 0;
  int ans;
  while (i < K) {
    i += p[j].second;
    ans = p[j].first;
    j++;
  }
  
  // 解答
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1400
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (N, M) = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var AB = Range(0, M).Select(i => ReadLine().Split(' ').Select(int.Parse).ToArray()).ToArray();

        var uf = new UnionFind(N);
        foreach (var (A, B) in AB)
            uf.Unite(A - 1, B - 1);

        var set = new HashSet<int>();
        for (int i = 0; i < N; i++)
            set.Add(uf.Find(i));

        var ans = set.Count() - 1;

        WriteLine(ans);
    }
}

class UnionFind
{
    private int[] d;
    public UnionFind(int n) => d = Enumerable.Repeat(-1, n).ToArray();
    public int Find(int x) => (d[x] < 0) ? x : d[x] = Find(d[x]);
    public bool Unite(int x, int y)
    {
        (x, y) = (Find(x), Find(y));
        if (x == y)
            return false;
        if (-d[x] < -d[y])
            (x, y) = (y, x);
        (d[x], d[y]) = (d[x] + d[y], x);
        return true;
    }
    public bool Same(int x, int y) => Find(x) == Find(y);
    public int Size(int x) => -d[Find(x)];
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 45084
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
string s;
int ans=1e9; 
int main()
{
	ios::sync_with_stdio(false);
    cin>>s;
    for(int i=1;i<s.length();i++)
    if(s[i]!=s[i-1])ans=min(ans,max(i,int(s.length())-i)); 
    cout<<min(ans,int(s.length()))<<endl;
    return 0;
}

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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

i64 a, b, c;

int main()
{
  cin >> a >> b >> c;
  int count = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    if (a == b && b == c) {
      cout << -1 << endl;
      return 0;
    }
    count++;
    i64 _a = b/2 + c/2;
    i64 _b = c/2 + a/2;
    i64 _c = a/2 + b/2;
    a = _a;
    b = _b;
    c = _c;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if(a==0)	cout << 1;
  else if(b==0)	cout << 2;
  else if(c==0)	cout << 3;
  else if(d==0)	cout << 4;
  else	cout << 5;
  return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;

    int n, m;
    n = s.size();
    m = t.size();

    vector< vector<int> > dp(n+1, vector<int>(m+1, 0));

    s = " "+s;
    t = " "+t;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            if (s[i] == t[j])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    // for (auto i : dp) {
    //     for (auto j : i) 
    //         cout << j << " ";
    //     cout << endl;
    // }
    
    string ans = "";
    while (dp[n][m] != 0) {
        if (s[n] == t[m]) {
            ans = s[n] + ans;
            n--;
            m--;
        }
        else if (dp[n-1][m] > dp[n][m-1])
            n--;
        else
            m--;
    }

    cout << ans << endl;
}


Measured memory_bytes: 35584
N,A,B = map(int, input().split())
*S, = input()

count = 0
bi = 0
for s in S:
    ans = 'No'
    if count < A+B:
        if s == 'a':
            ans = 'Yes'
            count += 1
        if s == 'b' and bi < B:
            ans = 'Yes'
            count += 1
            bi += 1
    print(ans)

Measured memory_bytes: 9980
import math

N, K = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * (N + 1)
M = [0] * (N + 1)

for i in range(N):
    B[i + 1] = B[i] + math.log10(A[i])

for i in range(K, N + 1):
    M[i] = B[i] - B[i - K]

for i in range(K + 1, N + 1):
    if M[i - 1] + 1e-10 < M[i]:
        print("Yes")
    else:
        print("No")

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

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

using namespace std;

int main(){
  double n;cin>>n;
  rep(i,3500)rep(j,3500){
    ll x=i+1;
    ll y=j+1;
    ll z = (n*x*y)/(4*x*y-n*x-n*y);
    if(z<0)continue;
    if(4*x*y*z==n*y*z+n*x*z+n*x*y){
      cout<<x<<' '<<y<<' '<<z;
      return 0;
    }
  }
  
  return 0;
}

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

int main() {
    string s; cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'o') cnt++;
    } 
    
    if (15-s.size() >= 8-cnt) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100100];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int x = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	int dap = (n - 1) / (m - 1);
	if ((n - 1) % (m - 1))
		dap++;
	printf("%d", dap);
}

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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n;
    cin>>n;
    if(n<1000){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
    return 0;
}

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

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

// code
// ------------------------------------------------
int main() {

  string s;
  cin >> s;

  int c = count(all(s),'o');

  cout << 700 + 100 * c << endl;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
#define INF (int)1e18


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}


signed main()
{
	fio
	inp(n) inp(t)
	vector<pair<int,int>> x(n);
	fo(i,n)
		cin>>x[i].F>>x[i].S;
	sort(all(x));
	int dp[t]={0};
	int fans=0;
	fo(i,n)
	{
		int a=x[i].F,b=x[i].S;
		int dpp[t];
		fo(j,t)
		{
			dpp[j]=dp[j];
			fans=max(fans,dp[j]+b);
		}
		fo(j,t)
		{
			if(j+a<t)
			{
				dp[j+a]=max(dp[j+a],dpp[j]+b);
			}
		}
	}
	cout<<fans<<'\n';
	printclock;
}

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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C>> X;
  int count = 0;
  
  for(int a = 0; a<=A; a++){
    for(int b = 0; b<=B; b++){
      for(int c = 0; c<=C; c++){
        if(X == 500*a + 100*b + 50*c){ 
          count++;
        }
      }
    }
  }
  cout << count<< endl;
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int a[101];
int n,k;
int solve(int k){
    if(k == 0){
        return 0;
    }
    if(dp[k] != 0){
        return dp[k];
    }
    for(int i=0;i<n;i++){
        if(k >= a[i] && !solve(k-a[i])){
            dp[k] = 1;
        }
    }
return dp[k];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(dp,0,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    bool ans = solve(k);
    if(ans){
        cout<<"First"<<"\n";
    }
    else{
        cout<<"Second"<<"\n";
    }
    
}

Measured memory_bytes: 5376
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e15;

LL N, P, Q;
LL C[500010];

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

  LL sum = 0;
  cin >> N >> P >> Q;
  REP(i,N){
	cin >> C[i];
	C[i] += i * P;
	sum += C[i];
  }
  sort(C, C+N);

  LL ans = sum, bias = P * N * (N - 1) / 2;
  REP(k,N){
	sum -= C[k];
	sum += 2 * k * P + Q * P;
	ans = max(ans, sum);
  }

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

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

vector<int> cnt;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		cnt.push_back(x);
	}
	sort(cnt.begin(),cnt.end());
	cnt.erase(unique(cnt.begin(),cnt.end()),cnt.end());
	cout<<cnt.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long

signed main() {
  while (true) {
    int m, n1, n2;
    cin >> m >> n1 >> n2;
    if (!m && !n1 && !n2) return 0;
    int p[m];
    for (int i = 0; i < m; i++) {
      cin >> p[i];
    }
    int diff = p[n1 - 1] - p[n1];
    int ans = n1;
    for (int i = n1 + 1; i <= n2; i++) {
      int res = p[i - 1] - p[i];
      if (res >= diff) {
        diff = res;
        ans = i;
      }
    }
    cout << ans << endl;
  }
}



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

using namespace std;

typedef long long LL;
const int MAXN=100000+10;
vector<int> G[MAXN];
LL dp[MAXN],suf[MAXN],pre[MAXN],pro[MAXN];
int n,MOD;

void dfs(int nod,int fa){
	dp[nod]=1;
	int len=G[nod].size();
	for(int i=0;i<len;i++){
		int son=G[nod][i];
		if(fa!=son){
			dfs(son,nod);
			dp[nod]=dp[nod]*(dp[son]+1)%MOD;
		}
	}
}

void sch(int nod,int fa){
	int len=G[nod].size(),m=0;
	
	pre[0]=1;
	for(int i=0;i<len;i++){
		int son=G[nod][i];
		if(son==fa) continue;
		m++;
		pre[m]=pre[m-1]*(dp[son]+1)%MOD;
	}
	
	suf[m+1]=1;
	for(int i=len-1;i>=0;i--){
		int son=G[nod][i];
		if(son==fa) continue;
		suf[m]=suf[m+1]*(dp[son]+1)%MOD;
		m--;
	}
	
	m=0;
	for(int i=0;i<len;i++){
		int son=G[nod][i];
		if(son==fa) continue;
		m++;
		pro[son]=(pro[nod]*1ll*pre[m-1]%MOD*suf[m+1]+1)%MOD;
	}
	
	for(int i=0;i<len;i++){
		int son=G[nod][i];
		if(son==fa) continue;
		sch(son,nod);
	}
}

int main(){
	cin>>n>>MOD;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	
	dfs(1,-1);
	pro[1]=1;
	sch(1,-1);
	
	for(int i=1;i<=n;i++){
		cout<<dp[i]*pro[i]%MOD<<endl;
	}
	return 0;
}
 

Measured memory_bytes: 14208
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd(a, b):
    if b == 0:
        return a
    if a == 0:
        return b
    elif a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


def gcd_m(*args):
    if len(args) == 0:
        return 0
    if len(args) == 1:
        return args[0]
    if len(args) >= 2:
        ret = gcd(args[0], args[1])

    for value in args[2:]:
        ret = gcd(ret, value)
    return ret


def solve(inputs):
    [N] = string_to_int(inputs[0])
    # A = [0] + (string_to_int(inputs[1])) + [0]
    A = string_to_int(inputs[1])

    if N == 2:
        return max(A)

    left_gcd_memo = deque([0])
    right_gcd_memo = deque([0])

    for v in A:
        left_gcd_memo.append(gcd(left_gcd_memo[-1], v))
    left_gcd_memo.append(0)
    for v in reversed(A):
        right_gcd_memo.appendleft(gcd(right_gcd_memo[0], v))
    right_gcd_memo.appendleft(0)

    max_gcd = 0
    for i in range(0, len(A)):
        left = left_gcd_memo[i]
        right = right_gcd_memo[i+2]
        g = gcd(left_gcd_memo[i], right_gcd_memo[i+2])
        max_gcd = g if g > max_gcd else max_gcd

    return max_gcd


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 15604
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << max(10 * A + B + C,max( A + 10 * B + C, A + B + 10 * C)) << endl;
}


Measured memory_bytes: 3600
# coding: utf-8
N, M = map(int, input().split())
st = [list(map(int, input().split())) for _ in range(N)]
ch = [list(map(int, input().split())) for _ in range(M)]
for i, j in st:
    min = float('inf')
    min_num = 0
    for num, xy in enumerate(ch):
        if abs(i - xy[0]) + abs(j - xy[1]) < min:
            min = abs(i - xy[0]) + abs(j - xy[1])
            min_num = num + 1
    print(min_num)


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

int g[15][15];

int bit_counter(int val) {
    int ans = 0;
    while (val > 0) {
        ans += val % 2;
        val /= 2;
    }
    return ans;
}

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

    rep(i, N) rep(j, N) g[i][j] = -1;
    rep(i, N){
        int m;  cin >> m;
        rep(j, m) {
            int a, x; cin >> a >> x;
            a--;
            g[i][a] = x;
        }
    }

    int ans = 0;
    rep(i, 1 << N) {
        vector<int> d(N);
        rep(j, N) {
            if (i >> j & 1) {
                d[j] = 1;
            }
        }
        bool ok = true;
        rep(j, N) {
            if (d[j]) {
                rep(k, N) {
                    if (g[j][k] == -1) continue;
                    if (g[j][k] != d[k]) ok = false;
                }
            }
        }

        if (ok) ans = max(ans, bit_counter(i));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#include<math.h>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
int v[MAXN];
char s[MAXN];
int main(){
    double a;
    cin>>a;
    cout<<a*2*M_PI;
}

Measured memory_bytes: 3260
function Main(input) {
  	input = input.split("\n");
  	var strLength = parseInt(input[0], 10);
  	var words = input[1];
  	var temp = words.substring(0, strLength / 2);
  	var result = words == (temp + temp) ? "Yes" : "No";
   	console.log('%s', result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<set>
#include<queue>
#include<utility>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<numeric>
#include<functional>
#include<string>
#include<iostream>

using namespace std;
const long long int one = 1;
const long long int big = (one<<20);
typedef long long int llint;


//	. 0x2e	X 0x58	S 0x53	1~ 0x31~
bool solve(void){
	int i,j,na,nb,ans=0,gen=0;
	string A;
	string B;
	cin >> A;
	if(cin.eof()){return false;}
	cin >> B;
	B.resize(B.size()+4000,'#');
	A.resize(A.size()+4000,'@');//#??¨???@??¨?????\????????????(??????)
	for(i=0;i<B.size()-4000;i++){
		for(j=0;j<A.size()-4000;j++){
			if(A[j]==B[i+j]){ gen++; } else{ ans=max(ans,gen);gen=0; }
		}
		ans=max(ans,gen);gen=0;
	}
	swap(A,B);
	for(i=0;i<B.size()-4000;i++){
		for(j=0;j<A.size()-4000;j++){
			if(A[j]==B[i+j]){ gen++; } else{ ans=max(ans,gen);gen=0; }
		}
		ans=max(ans,gen);gen=0;
	}
	printf("%d\n",ans);
	
	return true;
}
int main(void){
	while(solve()){}
	return 0;
}

Measured memory_bytes: 3136
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
A,B,H,M=map(int,input().split())

ap=((H*60+M)/(12*60))*2*math.pi
bp=M/60*2*math.pi
#print(ap)
#print(bp)
print(((A*math.sin(ap)-B*math.sin(bp))**2+(A*math.cos(ap)-B*math.cos(bp))**2)**.5)


Measured memory_bytes: 73392
import sys

def solve():
    
    while True:
        try:
            n = input()        
        except EOFError:
            break
        d = sorted(map(int,raw_input().split()))
        for i in range(1,n):
            d[i] += d[i-1]
        print sum(d)
                            
if __name__ == "__main__":
    solve()
 

Measured memory_bytes: 4232
s = list(input())
a = int(s[0]+s[1])
b = int(s[2]+s[3])
if 0<a<13 and 0<b<13:
    print('AMBIGUOUS')
elif 0<a<13:
    print('MMYY')
elif 0<b<13:
    print('YYMM')
else:
    print('NA')


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n,m;
ll x[2],y[2];

bool in(ll cx,ll cy){
    return x[0] <= cx && cx <= x[1] && y[0] <= cy && cy <= y[1];
}

int main(){
    cin >> n >> m;
    vector<P> vp;
    rep(i,n){
        ll xx,yy;
        cin >> xx >> yy;
        vp.push_back(P(xx,yy));
    }
    sort(ALL(vp));
    rep(i,m){
        ll ans = 0;
        cin >> x[0] >> y[0] >> x[1] >> y[1];
        rep(j,n){
            ans += in(vp[j].first,vp[j].second);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3208
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	cin >> s;
	if (s[0] == '9' || s[1] == '9') cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256