akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double ABS(double a){return max(a,-a);}
double x[5];
double y[5];
double EPS=1e-9;
double PI=acos(-1.0);
int main(){
	while(1){
		for(int i=0;i<3;i++)scanf("%lf%lf",x+i,y+i);
		double gm=0;
		for(int i=0;i<3;i++)gm+=ABS(x[i])+ABS(y[i]);
		if(gm<EPS)break;
		double l1=sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]));
		double l2=sqrt((x[0]-x[2])*(x[0]-x[2])+(y[0]-y[2])*(y[0]-y[2]));
		double th=atan2(y[2]-y[0],x[2]-x[0])-atan2(y[1]-y[0],x[1]-x[0]);
		if(th<-PI)th+=PI*2;
		if(th>PI)th-=PI*2;
		if(th<0){
			th=-th;
		}
		double t2=atan2(y[2]-y[1],x[2]-x[1])-atan2(y[0]-y[1],x[0]-x[1]);
		double t3=atan2(y[0]-y[2],x[0]-x[2])-atan2(y[1]-y[2],x[1]-x[2]);
		
		if(t2<-PI)t2+=PI*2;
		if(t2>PI)t2-=PI*2;
		if(t2<0)t2=-t2;
		if(t3<-PI)t3+=PI*2;
		if(t3>PI)t3-=PI*2;
		if(t3<0)t3=-t3;
	//	printf("%f %f %f ",th,t2,t3);
		//printf("%f %f\n",l1,l2);
		
		double L=0;
		double R=10000;
		double R2,R3;
		for(int i=0;i<50;i++){
			double M=(L+R)/2;
			double X1=M/tan(th/2);
			double Y1=M;
			if(X1>l1||X1>l2){
				R=M;continue;
			}
			double left=0;
			double right=100000000;
			double X2,Y2;
			for(int j=0;j<50;j++){
				double md=(left+right)/2;
				X2=l1-md/tan(t2/2);
				Y2=md;
				//printf("%f %f %f\n",X1,X2,Y2);
				if(X2<X1){right=md;continue;}
				if((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2)>(M+md)*(M+md))left=md;
				else right=md;
			}
			R2=right;
			double X3,Y3;
			left=0;right=100000000;
			for(int j=0;j<50;j++){
				double md=(left+right)/2;
				X3=l2-md/tan(t3/2);
				Y3=md;
				if(X3<X1){right=md;continue;}
				if((X1-X3)*(X1-X3)+(Y1-Y3)*(Y1-Y3)>(M+md)*(M+md))left=md;
				else right=md;
			}
			R3=right;
			double xf=X3*cos(th/2)+Y3*sin(th/2);
			double yf=X3*sin(th/2)-Y3*cos(th/2);
			X3=xf*cos(th/2)-yf*sin(th/2);
			Y3=xf*sin(th/2)+yf*cos(th/2);
		//	if(Y3<Y2){R=M;continue;}
			//printf("(%f %f), (%f %f), (%f %f)\n",X1,Y1,X2,Y2,X3,Y3);
			if((X2-X3)*(X2-X3)+(Y2-Y3)*(Y2-Y3)>(R2+R3)*(R2+R3))R=M;
			else L=M;
		}
		printf("%.5f %.5f %.5f\n",R,R2,R3);
	}
}

Measured memory_bytes: 1216
import sys
input = sys.stdin.readline

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

s = [];  t = [];
for a in A:
    if a < 0:
        t.append(a)
    else:
        s.append(a)

P = 10 ** 9 + 7
# 非負にできるか判定
S = len(s)
T = len(t)
ok = False
if S > 0:
    if N == K:
        ok = (T % 2 == 0)
    else:
        ok = True
else:
    ok = (K % 2 == 0)

ans = 1
if not ok:
    A.sort(key = lambda x: abs(x))  # 絶対値小→大
    for i in range(K):
        ans = ans * A[i] % P
else:   # 非負にできる
    s.sort()    # 小→大
    t.sort(reverse = True)  # 絶対値小→大
    if K % 2 == 1:
        ans *= s.pop() # 一番大きい正の数を確保

    p = []
    while len(s) >= 2:
        x = s.pop()
        x = x * s.pop()
        p.append(x)

    while len(t) >= 2:
        x = t.pop()
        x = x * t.pop()
        p.append(x)

    p.sort(reverse = True)
    for i in range(K // 2):
        ans = ans * p[i] % P


print(ans % P)

Measured memory_bytes: 31692
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vvll t(n,vll(0));
  rep(i,m){
    ll u,v;
    cin>>u>>v;
    u--;v--;
    t[u].pb(v);
  }
  vvll ans(n,vll(3,-1));
  ll s,T;
  cin>>s>>T;
  s--;T--;
  ans[s][0]=0;
  queue<pll> que;
  que.pu(pll(s,0));
  while(sz(que)){
    pll now=que.front();
    que.pop();
    for(auto p:t[now.F]){
      if(ans[p][(now.S+1)%3]!=-1) continue;
      ans[p][(now.S+1)%3]=now.S+1;
      que.pu(pll(p,now.S+1));
    }
  }
    if(ans[T][0]==-1){
    COUT(-1);
  }
  else{
    COUT(ans[T][0]/3);
  }
}

Measured memory_bytes: 11136
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, mod - 2);
}

void precalc() {
}

const int maxn = 1e5 + 100;
const int maxd = 12;

int n, m, q;
vector<vector<int> > g;
int v[maxn], d[maxn], c[maxn];

bool read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  g.clear();
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", v + i, d + i, c + i);
    v[i]--;
  }
  return true;
}

int used[maxn][maxd];

int cols[maxn];

void solve() {
  reverse(v, v + q);
  reverse(d, d + q);
  reverse(c, c + q);
  memset(used, 0, sizeof(used));
  memset(cols, 0, sizeof(cols));
  for (int i = 0; i < q; i++) {
    vector<pair<int, int> > st(1, mp(v[i], d[i]));
    for (int l = 0; l < sz(st); l++) {
      int curv = st[l].first;
      int curd = st[l].second;
      if (used[curv][curd]) {
        continue;
      }
      if (!used[curv][0]) {
        cols[curv] = c[i];
      }
      for (int j = 0; j <= curd; j++) {
        used[curv][j] = 1;
      }
      if (!curd) {
        continue;
      }
      for (auto to : g[curv]) {
        st.pb(mp(to, curd - 1));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d\n", cols[i]);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



Measured memory_bytes: 16028
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      	int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int chenge = 0;
      	
        while(k != 0){
          if(chenge == 0){
         	 if(a % 2 == 1){
            	a--;
         	 }
         	 b = b + a / 2;
         	 a = a / 2;
             chenge = 1;
          }else{
             if(b % 2 == 1){
                b--; 
             }
             a = a + b / 2;
             b = b / 2;
             chenge = 0;
          }
            
          k--;
        }
      
          System.out.println(a);
          System.out.println(b);
      
    }
}

Measured memory_bytes: 35640
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b=map(int,input().split())
    for x in range(1,1100):
        if int(x*0.08)==a and int(x*0.1)==b:
            print(x)
            break
    else:print(-1)

if __name__=='__main__':
    main()

Measured memory_bytes: 38640
import math

def get_distance(point_A, point_B) :
    s = 0
    for i in range(len(point_A)) :
        s += pow(abs(point_A[i] - point_B[i]),2)
    
    return math.sqrt(s)


N,D = [int(i) for i in input().split()]
points = []
for i in range(N) :
    points.append([int(i) for i in input().split()])

count = 0
for i in range(N) :
    for k in range(i,N) :
        if (i == k) :
            continue
        
        d = get_distance(points[i], points[k])
        # print(d)
        if (float.is_integer(d)) :
            count += 1
        
print(count)


Measured memory_bytes: 3064
fn main() {
    let s = read::<String>();
    println!("{}", s.replace("2017", "2018"));
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main (String[] args)  {

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int ans = 0;
		if (x<=3) {
			ans+=(400000-x*100000);
		}
		if (y<=3) {
			ans+=(400000-y*100000);
		}
		if (x==1 && y==1) {
			ans+=400000;
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 23892
mod=10**9+7
N=int(input())
dp=[[[[[0 for m in range(4)]for l in range(4)]for k in range(4)]for j in range(4)]for i in range(N+1)]
for i in range(4):
    for j in range(4):
        for k in range(4):
            dp[3][0][i][j][k]=1
dp[3][0][0][2][1]=0
dp[3][0][0][1][2]=0
dp[3][0][2][0][1]=0

for n in range(4,N+1):
    for b in range(4):
        for c in range(4):
            for d in range(4):
                for a in range(4):
                    for i in range(4):
                        dp[n][b][c][d][a]+=dp[n-1][i][b][c][d]
                        dp[n][b][c][d][a]%=mod
                    dp[n][b][0][2][1]=0
                    dp[n][b][2][0][1]=0
                    dp[n][b][0][1][2]=0
                    dp[n][0][c][2][1]=0
                    dp[n][0][2][d][1]=0
ans=0
for a in range(4):
    for b in range(4):
        for c in range(4):
            for d in range(4):
                ans+=dp[N][a][b][c][d]
print(ans%mod)
#print(dp[3])

Measured memory_bytes: 4588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int h, w;
int dist[1002][1002];
queue<pi> que;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i,h+2) rep(j,w+2) {
        if (i == 0 || i == h+1 || j == 0 || j == w+1) dist[i][j] = 0;
        else dist[i][j] = inf;
    }
    rep(i,h) rep(j,w) {
        char A; cin >> A;
        if (A == '#') {
            dist[i+1][j+1] = 0;
            que.push(pi(i+1,j+1));
        }
    }
    while (!que.empty()) {
        pi q = que.front(); que.pop();
        for (int u = 0; u < 4; u++) {
            int tx = q.first + dx[u], ty = q.second + dy[u];
            if (dist[tx][ty] != inf) continue;
            dist[tx][ty] = dist[q.first][q.second] + 1;
            que.push(pi(tx,ty));
        }
    }
    int ans = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}

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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    char c;
    cin >> c;
    cout << (char)(c+1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int k, s, ans = 0;
	cin >> k >> s;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (0 <= (s - i - j) && (s - i - j) <= k) {
					ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
using namespace std;
int main(){
   int a[4];
   for(int i = 0; i < 5; i++) cin >> a[i];
   int k;
   cin >> k;
   int ans = 0;
   for(int i = 0; i < 5; i++){
       for(int j = 0; j < 5; j++){
           if(-k > (a[i]-a[j]) || (a[i]-a[j]) > k ) ans = 1;
       }
   }

   if(ans == 0) cout << "Yay!" << endl;
   else   cout << ":(" << endl;
}
       

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;

int main()
{
    //cout << "Hello world!" << endl;
    string t;
    cin>>t;
    ll n=t.length();


    for(ll i=0;i<n;i++){
        if(t[i]=='?'){
            t[i]='D';
        }
    }
    cout<<t<<endl;

}


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

typedef long long LL;
#define dbg(x) cout << #x"=" << x << endl;
LL h;

LL d(LL i){
    if(i == 1) return 1;
    else return 2*d(i/2)+1;
}

int main(){
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> h;
    cout << d(h) << endl;
    return 0;
}

/*
d[i] = 2*d[i/2]+1
*/

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

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

    cout << N / 3 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch RectangleCutting | diff RectangleCutting.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RectangleCutting.cpp && ./a.out

/*
 
 6/16/2019
 
 5:05-
 
 */

LL W,H,x,y;

void solve() {
  double res=0.5*W*H;
  int mul=(W%2==0&&x==W/2&&H%2==0&&y==H/2);
  cout<<res<<" "<<mul<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>W>>H>>x>>y;
  solve();
  
  return 0;
}


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

int main() {
  
  int N, sum;
  cin >> N;
  sum = 0;

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += r-l+1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())

f = max(a, b, c)
if f == a:
    print(a*10 + int(str(b+c)))
elif f == b:
    print(b*10 + int(str(a+c)))
else:
    print(c*10 + int(str(b+a)))

Measured memory_bytes: 9176
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	int n,m,a;
	bool f[M];
	rep(i,0,M)f[i]=true;
	cin>>n>>m;
	rep(i,0,m)cin>>a,f[a]=false;
	ll dp[M]={};
	dp[0]=1;
	if(f[1]==true?dp[1]=1:dp[1]=0);
	rep(i,2,n+1){
		if(f[i]==true)dp[i]=dp[i-1]+dp[i-2];
		else dp[i]=0;
		dp[i]%=1000000007;
	}
	print(dp[n]);
}

Measured memory_bytes: 1152
n, m = gets.split.map(&:to_i)

@neighbors = Array.new(n) { Array.new(n) { false } }

m.times do
  a, b = gets.split.map(&:to_i)
  @neighbors[a - 1][b - 1] = true
  @neighbors[b - 1][a - 1] = true
end

@path = 0

def dfs(v, visited)
  if visited.all? {|v| v == true }
    @path += 1
    return
  end

  @neighbors[v].each_with_index do |n, i|
    next if n == false
    next if visited[i]
    # p "#{v} conncted to #{i}"

    visited[i] = true
    dfs(i, visited)
    visited[i] = false
  end
end

visited = Array.new(n) { false }
visited[0] = true
dfs(0, visited)
p @path


Measured memory_bytes: 1788
import java.io.*;

public class Main{
	public static void main(String[] args){
		BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
		String s;
		double a=100000.0;
		int n,b;
		double p,q;
		try{
			while((s=reader.readLine()) !=null){
				n=Integer.parseInt(s);
				for(int i=0;i<n;i++){
					a +=a*0.05;
					p=a/1000;
					q=Math.ceil(p);
					a=q*1000;
				}
				b=(int)a;
				System.out.println(b);
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 15012
n=int(input())
xy=[[]for _ in range(n)]
for i in range(n):
  a=int(input())
  xy[i]=[list(map(int,input().split())) for _ in range(a)]
ans=0
for i in range(pow(2,n)):
  honest=[]
  for j in range(n):
    if ((i>>j)&1):
      honest.append(1)
    else:
      honest.append(0)
  n_honest=sum(honest)
  if n_honest<=ans:
    continue
  flg=True
  for k in range(n):
    if honest[k]==1:
      for x,y in xy[k]:
        if honest[x-1]==y:
          pass
        else:
          flg=False
          break
    if flg==False:
      break
  if flg:
    ans=n_honest
print(ans)


Measured memory_bytes: 47196
"""
author : halo2halo
date : 19,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
lis = list(map(int, readline().split()))

mot = 0
for i in lis:
    mot += 1 / i

print(1/mot)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N,K,Q;
    cin >>N>>K>>Q;
    vi tmp(N,0);

    rep(i,0,Q){
        int tmpi;
        cin>>tmpi;
        tmp[tmpi-1]++;
    }

    rep(i,0,N){
        if((Q-K)<tmp[i]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a, b;

	scanf("%d%d", &a, & b);

	if ((a == 1 && b == 2) || (a == 2 && b == 1)) //1と2がはずれの場合
	{
		printf("%d", 3);
	}
	else if ((a == 1 && b == 3) || (a == 3 && b == 1)) //1と3がはずれの場合
	{
		printf("%d", 2);
	}
	else //2と3がはずれの場合
	{
		printf("%d", 1);
	}
}

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

int main(){
  int ix, ih;
  double x, h;
  double s;
  scanf("%d %d",&ix,&ih);
  x=ix;h=ih;
  while (x != 0 || h != 0){
    //printf("%f %f\n",x,h);
    s=(x*x)+(sqrt(h*h+(x/2)*(x/2))*x)*2;
    printf("%f\n",s);
    scanf("%d %d",&ix,&ih);
    x=ix;h=ih;
  }
  return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;


const int maxN = static_cast<const int>(1e5 + 10);

int fa[maxN], dis[maxN], N, M;


int find(int x) {
    if(x == fa[x]) {
        return x;
    }
    int temp = fa[x];
    fa[x] = find(temp);
    dis[x] = dis[x] + dis[temp];
    return fa[x];
}

bool merge(int x, int y, int d) {
    int fx = find(x), fy = find(y);
    if(fx == fy) {
        return dis[y] - dis[x] == d;
    } else {
        fa[fx] = fy;
        dis[fx] = dis[y] - dis[x] - d;
        return true;
    }
}


int main() {
#ifdef ACM_XYZHAO_TEST
    freopen("../test.in", "r", stdin);
//	freopen("../test.out", "w", stdout);
#endif

    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; ++i) {
        fa[i] = i;
        dis[i] = 0;
    }
    int l, r, d;

    bool flag = true;
    for (int i = 0; i < M; ++i) {
        scanf("%d %d %d", &l, &r, &d);
        if(flag && !merge(l, r, d)) {
            flag = false;
        }
    }

    printf("%s\n", flag ? "Yes" : "No");

    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


ll dp[25][50005];

void solve() {
    int N, M; cin >> N >> M;
    vec c(M);
    rep(i, M) cin >> c[i];
    rep(i, 25)rep(j, 50005) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, M){
        Rep1(j, 0, N){
            if(j < c[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-c[i]]+1);
            }
        }
    }

    cout << dp[M][N] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}



Measured memory_bytes: 17072
n, k = map(int,input().split())
sn = [0 for x in range(n)]
for kind in range(k):
    d = int(input())
    a_lis = list(map(int,input().split()))
    for a in a_lis:
        sn[a-1] += 1
print(sn.count(0))


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

int main() {
  int N;
  cin >> N;
  int d[N];
  for (int i=0; i < N; ++i) {
    cin >> d[i];
  }
  sort(d, d + N);
  int minV = 0;
  int ans = 0;
  for (int i=0; i < N; ++i) {
    if (d[i] > minV) {
      minV = d[i];
      ++ans;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    
    if m==-1 or f==-1:
        print("F")
    elif m+f>=80:
        print("A")
    elif m+f>=65:
        print("B")
    elif m+f>=50:
        print("C")
    elif m+f>=30 and r>=50:
        print("C")
    elif m+f>=30:
        print("D")
    elif m+f<30:
        print("F")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int const N = 200000;
ll x[N + 1], an = 1e18;
int n;

void up(ll &x, ll y) { x = min(x, y); }
ll gt(int l, int r) { return x[r] - x[l - 1]; }

void fix(pair<ll, ll> &p) { if (p.first > p.second)swap(p.first, p.second); }

pair<ll, ll> gtsg(int l, int r){
	int bl = l, br = r - 1;
	while (br > bl){
		int bm = bl + br >> 1;
		ll a = abs(gt(l, bm) - gt(bm + 1, r)), b = abs(gt(l, bm  + 1) - gt(bm + 2, r));
		if (a < b)br = bm;
		else bl = bm + 1;
	}
	pair<ll, ll> an(gt(l, bl), gt(bl + 1, r));
	fix(an);
	return an;
}

void gosc(){
	int l = 2;
	f(r, 2, n - 1){
		while (true){
			ll c = gt(l, r);
			ll bf = gt(1, l - 1);
			pair<ll, ll> af = gtsg(r + 1, n);
			ll mn = min(bf, af.first);
			if (mn >= c)break;
			++l;
		}
		if (l <= r)up(an, max(gt(1, l - 1), gtsg(r + 1, n).second) - gt(l, r));
	}
}

bool gofs(ll k){
	int p3 = n - 1, p4 = n;
	f(r, 1, n - 2){
		ll c = gt(1, r);
		ll lim = c + k;
		while (p4 > 4 && gt(p4 - 1, n) <= lim)--p4;
		if (gt(p4, n) > lim || gt(p4, n) < c)continue;
		p3 = min(p3, p4 - 1);
		while (p3 > 3 && gt(p3 - 1, p4 - 1) <= lim)--p3;
		if (gt(p3, p4 - 1) < c || gt(p3, p4 - 1) > lim)break;
		//printf("%d %d %d\n", r, p3, p4);
		//printf("%lld %lld %lld %lld\n", gt(1, r), gt(r + 1, p3 - 1), gt(p3, p4 - 1), gt(p4, n));
		//printf("lim: %lld\n", lim);
		if (p3 > r + 1 && gt(r + 1, p3 - 1) <= lim && gt(r + 1, p3 - 1) >= c)return true;
	}
	return false;
}

void rv(){
	for (int i = n; i > 1; --i)x[i] -= x[i - 1];
	reverse(x + 1, x + n + 1);
	f(i, 2, n + 1)x[i] += x[i - 1];
}

int main(){
	scanf("%d", &n);
	f(i, 1, n + 1)scanf("%lld", x + i);
	f(i, 2, n + 1)x[i] += x[i - 1];
	f(i, 2, n - 1){
		pair<ll, ll> a = gtsg(1, i), b = gtsg(i + 1, n);
		ll mn = min(a.first, b.first);
		ll mx = max(a.second, b.second);
		up(an, mx - mn);
	}
	printf("%lld\n", an);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main()
{
    ios_base::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;

    int m = -1;

    for(int i = 0; i <= s.length() - t.length(); i++)
    {
        int counter = 0;
        for(int j = 0; j < t.length(); j++)
        {
            if(t[j] == s[i+j])
            {
                counter++;
            }
        }

        m = max(m,counter);
    }

    cout << t.length() - m;

}



Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	map<string, map<string, int>>U;
	for (int i = 0; i < a; i++) {
		int c;
		cin >> c;
		string d[10];
		for (int e = 0; e < c; e++)cin >> d[e];
		for (int f = 0; f < c-1; f++) {
			for (int g = f+1; g < c; g++) {
				U[min(d[f], d[g])][max(d[f], d[g])]++;
			}
		}
	}
	int k = 0;
	for (auto x = U.begin(); x != U.end(); x++) {
		for (auto y = x->second.begin(); y != x->second.end(); y++) {
			if (y->second >= b)k++;
		}
	}
	cout << k << endl;
	for (auto x = U.begin(); x != U.end(); x++) {
		for (auto y = x->second.begin(); y != x->second.end(); y++) {
			if (y->second >= b)cout << x->first << " " << y->first << endl;
		}
	}
}

Measured memory_bytes: 3584
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <queue>
using namespace std;
 
#define int long long
#define INF 1001001001
 
int32_t main() {
	
	double L;
	
	cin >> L;
	
	
	double ans = L/3.0;
	
	ans= ans* ans*ans;
	
	cout << fixed << setprecision(12) << ans << endl;
	
	 
    
    
 	
 	
}

Measured memory_bytes: 3212
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define ll long long
using namespace std;
int pos(int n)
{
    if(n<0)
        return 0;
    else
        return n;
}
bool pali(ll n)
{
    char a[10000]= {0};
    int num=0,tn=n;
    for(int i=0; i<tn; i++)
    {
        a[i]=n%10;
        n/=10;
        num=i;
        if(n<=0)
            break;

    }
    for(int i=0; i<num/2; i++)
    {
        if(a[i]!=a[num-i])
        {
            return false;
        }
    }
    return true;
}
int main()
{
    ll a,b,k;
    cin>>a>>b>>k;
    if((b-a+1)<=k*2){
        for(ll i=a;i<=b;i++)
            cout<<i<<endl;
    }
    else{
        for(ll i=a;i<a+k;i++)
            cout<<i<<endl;
        for(ll i=b-k+1;i<=b;i++)
            cout<<i<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int main(){
	int n,d,x;
	int a;
	cin>>n>>d>>x;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(d%a!=0) x+=(d/a+1);
		else x+=(d/a);
	} 
	cout<<x<<endl;
	return 0;
}


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

int main(){
	int n,r,i,j;
	char x;
	cin>>n;
	bool a[4][13];
	for(int z=0;z<4;z++){
		for(int Z=0;Z<13;Z++){
		a[z][Z]=false;
		}
		}
	for(int g=0;g<n;g++){
		cin>>x>>r;
		if(x=='S')i=0;
		if(x=='H')i=1;
		if(x=='C')i=2;
		if(x=='D')i=3;
		j=r-1;
		a[i][j]=true;
		}
for(int t=0;t<13;t++){
	if(a[0][t]==false)cout<<'S'<<' '<<t+1<<endl;
	}
for(int u=0;u<13;u++){
	if(a[1][u]==false)cout<<'H'<<' '<<u+1<<endl;
	}
for(int v=0;v<13;v++){
	if(a[2][v]==false)cout<<'C'<<' '<<v+1<<endl;
	}
for(int w=0;w<13;w++){
	if(a[3][w]==false)cout<<'D'<<' '<<w+1<<endl;
	}
	return 0;
	}



Measured memory_bytes: 3096
N = int(input())

A = []

for i in range(N):
    a = int(input())
    A.append([a, i+1])

A.sort()

for i in range(N):
    A[i].append(i+1)


ans = 0
for i in range(N):
    num, before, after = A[i]
    if before % 2 != after % 2:
        ans += 1

print(ans//2)


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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;
	vector<queue<ll> > que(n);
	map<pair<ll, ll>, ll > pmap;
	rep(i, n)rep(j, n-1){
		ll temp; cin>>temp;
		que[i].push(temp-1);
	}

	ll match = 0, day = 0;
	ll loop = true;
	queue<pair<pair<ll, ll>, ll> > Q;

	rep(i, n){
		ll opp = que[i].front(); que[i].pop();
		Q.push(mp(mp(i, opp), 1));
	}

	while(Q.size()){
		pair<pair<ll, ll>, ll> p = Q.front(); Q.pop();
		ll m = (p.fi).fi;
		ll opp = (p.fi).se;
		ll d = p.se; day = d;
		ll a = min(m, opp);
		ll b = max(m, opp);
		pmap[mp(a, b)]++;
		if (pmap[mp(a, b)] == 2){
			match++;
			if (que[a].size()){
				Q.push(mp(mp(a, que[a].front()), d+1));
				que[a].pop();
			}
			if (que[b].size()){
				Q.push(mp(mp(b, que[b].front()), d+1));
				que[b].pop();
			}
		}
	}

	if (match==n*(n-1)/2){
		cout << day << "\n";
	}else{
		cout << "-1\n";
	}

	return 0;
}

Measured memory_bytes: 32640
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll a;
    cin >> s >> a;

    REP(i, a) {
        if (s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << '1' << endl;

    return 0;
}

Measured memory_bytes: 256
#069c
import itertools

N = int(input())
a_list = [int(e) for e in input().split()]

def devide_2_and_4(n):
    if n%4==0:
        return(2)
    elif n%2==0:
        return(1)
    else:
        return(0)

a_list = [devide_2_and_4(a) for a in a_list]

cnt_four = a_list.count(2)
cnt_two = a_list.count(1)
cnt_one = a_list.count(0)

#OKな並びは 2・2 , 2・4 , 4・2 , 1・4 , 4・1
#∴4は前後何でもOK
#∴2は前後が2か4
#∴1は前後が4

if cnt_four - cnt_one <= -2: #1414141 111 状態
    print("No")
elif cnt_two > 0 and cnt_four - cnt_one <= -1: #1414141 222 状態
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS  vector<string>
#define VSS vector< vector<string> >
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<LL,LL>
const LL MOD = 1000000007;
const LL INF = 1e16;
LL facctorialMethod(int k);
int main(){
    LL a,b,ans;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	vector<int> vec(N);
	int sum = 0;
	for (size_t i = 0; i < N; i++)
	{
		cin >> vec[i];
		sum += vec[i];
	}

	int count = 0;
	for (size_t i = 0; i < N; i++)
	{
		if (sum / (float)(4 * M) > (float)vec[i])
		{
			continue;
		}
		count++;
	}

	cout << (count >= M ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 3040
import sys
from collections import deque
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


def make_tree_0index(N):
    edge_dic = {}
    for _ in range(N-1):
        x, y = na()
        x -= 1
        y -= 1
        if x in edge_dic:
            edge_dic[x].append(y)
        else:
            edge_dic[x] = [y]
        if y in edge_dic:
            edge_dic[y].append(x)
        else:
            edge_dic[y] = [x]
    return edge_dic


N, M = na()
if N == 1:
    print(1)
    exit()
edge_dic = make_tree_0index(N)


parent_array = [-2] * N
parent_array[0] = -1
node1 = deque([0])
node2 = deque([0])
node3 = deque([0])

while(len(node1)):
    n = node1.popleft()
    for v in edge_dic[n]:
        if parent_array[v] == -2:
            parent_array[v] = n
            node1.append(v)
            node2.append(v)
            node3.append(v)

ans1 = [0] * N

while(len(node2)):
    n = node2.pop()
    ans1[n] = 1
    for v in edge_dic[n]:
        if parent_array[n] == v:
            continue
        ans1[n] = (ans1[n] * (ans1[v]+1)) % M

ans2 = [0] * N

subans2 = [0] * N

while(len(node3)):
    n = node3.popleft()
    ans2[n] = 1
    if n != 0:
        ans2[n] = (ans2[n] * ans2[parent_array[n]] * subans2[n] + 1) % M

    reverse = [1]
    right = 1
    for v in edge_dic[n][::-1]:
        if parent_array[n] == v:
            continue
        right = (right * (ans1[v] + 1)) % M
        reverse.append(right)
    reverse.pop()

    left = 1
    for v in edge_dic[n]:
        if parent_array[n] == v:
            continue
        right = reverse.pop()
        subans2[v] = (left * right) % M
        left = (left * (ans1[v]+1)) % M


ans = [a*b % M for a, b in zip(ans1, ans2)]
print("\n".join(map(str, ans)))


Measured memory_bytes: 119140
import java.util.*;
import java.util.Collections;

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

        System.out.println(String.format("%d %d %d", Z, X, Y));
    }
}

Measured memory_bytes: 21716
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, K;
	std::cin >> A >> B >> K;
	if (B - A < K * 2) {
		for (int i = A; i <= B; ++i) {
			std::cout << i << "\n";
		}
	} else {
		for (int i = A; i < A + K; ++i) {
			std::cout << i << "\n";
		}
		for (int i = B - K + 1; i <= B; ++i) {
			std::cout << i << "\n";
		}
	}
}


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


int main() {
    int n,r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r+100*(10-n) << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    LIM = 10**18
    if 0 in A:
        print(0)
        return
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans>LIM:
            print(-1)
            return
    print(int(ans))

main()


Measured memory_bytes: 21652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

 
int main() {
    string s;
    cin>>s;
    int n=s.size();
    n--;
    ll ans=0;
    ll tmp;
    for(int bit=0;bit<(1<<n);bit++){
        
        tmp=s[0]-'0';
        rep(i,n){
            if(bit>>i & 1){
                ans+=tmp;
                tmp=0;
            }
            tmp=tmp*10+(s[i+1]-'0');
        }
        ans+=tmp;
        //cout<<tmp<<endl;
    }
    
    cout<<ans<<endl;
}

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

int main() {
    int n = 0;
    scanf("%d", &n);
    for (int i=0; i<=n/4; i++) {
        int buf = n - i*4;
        if (buf%7 == 0) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,i,j;
    char s1[15],s2[15];
    scanf("%d %d",&a,&b);
    for(i=0;i<b;i++)
    {
        s1[i]=a+'0';

    }
    s1[i]='\0';
     for(j=0;j<a;j++)
    {
        s2[j]=b+'0';

    }
    s2[j]='\0';
     if(a<b)
     {
        printf("%s\n",s1);
     }
     else if(a>b)
     {
        printf("%s\n",s2);
     }
      else if(a==b)
     {
        printf("%s\n",s2);
     }



    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int G , X;
  int a=0,b=0;
  G=0;
  X=0;
  int A ;
  cin >> A;
  for (int i=0;a==0;i++){
    if (A%2==0){
      A/=2;
      G=i+1;
    }
    if (A%2!=0)
      break;
  }
  for (int j=0;j<N-1;j++){
    int B;
    cin >> B;
    for (int k=0;b==0;k++){
      if (B%2==0){
        B/=2;
        X=k+1;
      }
      if (B%2!=0)
        break;
    }
    if (X <= G)
      G=X;
    
  }
  cout << G << endl;
  
    
}

Measured memory_bytes: 256
<?php

$nums = explode(' ',trim(fgets(STDIN)));
if ($nums[0]==$nums[1]){
  echo 'Draw';
} else if ($nums[0]== 1){
  echo 'Alice';
} else if ($nums[1]== 1){
  echo 'Bob';
} else if ($nums[0] > $nums[1]){
  echo 'Alice';
} else {
  echo 'Bob';
}

?>

Measured memory_bytes: 4604
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    S = cin.string()
    g,p = 0,0
    ans = 0
    for s in S:
        if p + 1 <= g:
            if s == "g":
                ans += 1
            p +=1
        else:
            if s == "p":
                ans -= 1
            g+=1
    print(ans)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 40048
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
int a[100005],ans=1926081700;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
       cin>>a[i];
    for(int i=1;i<=n-k+1;i++)
    {
        ans=min(ans,abs(a[i])+abs(a[i+k-1]-a[i]));
        ans=min(ans,abs(a[i+k-1])+abs(a[i+k-1]-a[i]));
    }
    cout<<ans;
    return 0;
}

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


int main()
{
  int n,a,b;
  string s;
  cin>>n>>a>>b>>s;
  int a_c=0,b_c=0;
  rep(i,n) {
    if(s.substr(i, 1) == "a" && a_c+b_c<a+b){
      a_c++;
      cout << "Yes" <<endl;
    }else if(s.substr(i, 1) == "b" && b_c<b && a_c+b_c<a+b){
      b_c++;
      cout << "Yes" <<endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 896