akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
typedef long long LL;

LL counter_clockwise_start(int l, int n, const std::vector<LL>& x,
                           const std::vector<LL>& sums1, const std::vector<LL>& sums2,
                           int i) {
  int mid=(i+n)/2;
  LL walk = 2*(sums1[mid]-sums1[i-1]) + 2*sums2[mid+1];

  if ((i+n)%2 != 0) {
    walk -= l-x[mid+1];
  } else {
    walk -= x[mid];
  }

  return walk;
}

LL clockwise_start(int l, int n, const std::vector<LL>& x,
                   const std::vector<LL>& sums1, const std::vector<LL>& sums2,
                   int i) {
  int mid=(i+1)/2;
  LL walk = 2*(sums2[mid+1]-sums2[i+1]) + 2*sums1[mid-1];

  if (i%2 != 0) {
    walk += l-x[mid];
  } else {
    walk += x[mid];
  }

  return walk;
}

int main() {
  int l, n; std::cin >> l >> n;
  std::vector<LL> x(n+1);
  for (int i = 1; i <= n; ++i) std::cin >> x[i];

  std::vector<LL> sums1(n+1);
  std::vector<LL> sums2(n+2);
  for (int i = 1; i <= n; ++i) sums1[i] = sums1[i-1] + x[i];
  for (int i = n; i >= 1; --i) sums2[i] = sums2[i+1] + (l-x[i]);

  LL ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = std::max(ans, counter_clockwise_start(l, n, x, sums1, sums2, i));
    ans = std::max(ans, clockwise_start(l, n, x, sums1, sums2, i));
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 4992
n=int(input())
a=[int(i)for i in input().split()]
d=lambda x:x/2

def devide(x,lst):
    global d
    for i in lst:
        if i%2 ==1:
            return x
    return devide(x+1,list(map(d,lst)))

print(devide(0,a))

Measured memory_bytes: 9268
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] card;
	static Board b1;
	static Board b2;
	static int N, M, U, V;

	static class Board {
		int[] pos, row, col, diag;

		Board() {
			pos = new int[1000001];
			Arrays.fill(pos, -1);
			row = new int[N];
			col = new int[N];
			diag = new int[2];
		}

		int count(int turn, int prev) {
			int diff = prev < turn ? 1 : -1;
			for (int i = prev < turn ? prev + 1 : turn + 1; i <= (prev < turn ? turn : prev); ++i) {
				int p = pos[card[i]];
				if (p == -1) continue;
				int r = p >> 10;
				int c = p & 1023;
				row[r] += diff;
				col[c] += diff;
				if (r == c) diag[0] += diff;
				if (r == N - 1 - c) diag[1] += diff;
			}
			int ret = 0;
			for (int i = 0; i < N; ++i) {
				if (row[i] == N) ret++;
				if (col[i] == N) ret++;
			}
			if (diag[0] == N) ret++;
			if (diag[1] == N) ret++;
			if (N == 1) return ret > 0 ? 1 : 0;
			return ret;
		}
	}

	public static void main(String[] args) throws Exception {
		N = sc.nextInt();
		U = sc.nextInt();
		V = sc.nextInt();
		M = sc.nextInt();
		b1 = new Board();
		b2 = new Board();
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				b1.pos[Integer.parseInt(sc.next())] = (i << 10) + j;
			}
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				b2.pos[Integer.parseInt(sc.next())] = (i << 10) + j;
			}
		}
		card = new int[M];
		for (int i = 0; i < M; ++i) {
			card[i] = Integer.parseInt(sc.next());
		}
		Result res = solve();
		if (res == Result.USAGI) {
			System.out.println("USAGI");
		} else if (res == Result.NEKO) {
			System.out.println("NEKO");
		} else {
			System.out.println("DRAW");
		}
	}

	static Result solve() {
		Result resEnd = getResult(M - 1, -1);
		if (resEnd != Result.BOTH) {
			return resEnd;
		}
		int lo = 0;
		int hi = M - 1;
		int prev = M - 1;
		while (true) {
			int mid = (lo + hi) / 2;
			if (mid == prev) return Result.NONE;
			Result res = getResult(mid, prev);
			if (res == Result.USAGI || res == Result.NEKO) return res;
			if (res == Result.NONE) {
				lo = prev = mid;
			} else {
				hi = prev = mid;
			}
		}
	}

	static Result getResult(int turn, int prev) {
		int c1 = b1.count(turn, prev);
		int c2 = b2.count(turn, prev);
		if (c1 >= U) {
			return c2 >= V ? Result.BOTH : Result.USAGI;
		} else {
			return c2 >= V ? Result.NEKO : Result.NONE;
		}
	}

	enum Result {
		USAGI, NEKO, BOTH, NONE;
	}

}

Measured memory_bytes: 92176
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,d[110][3];
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			cin >> d[i][j];
		}
	}
	bool flag = 0;
	for(int i = 0; i <= n - 3; i++){
		if(d[i][0] == d[i][1] && d[i+1][0] == d[i+1][1] && d[i+2][0] == d[i+2][1]){
			flag = 1;
			break;
		}

	}
	if(flag == 1)
			cout << "Yes"<< endl;
		else
			cout << "No" << endl;
	return 0;
}

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

using namespace std;
int main(){
  long n;
   cin >>n;
  
  long res=0;
  long a;
  for(int i=0;i<n;i++){
    cin >> a;
    res^=a;
  }

 if(!res) cout << "Yes" << endl;
 else cout << "No" << endl;
  
}

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

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

int main(){
 
  int a,b;
  cin >> a >> b;
  
  if(a==b)
    cout << "Yes";
  else
    cout << "No";
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=505;
int read(){
	int f=1,g=0;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n;
ll pr[N+N],a[N][N],b[N+N];
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return b?(a/gcd(a,b)*b):a;}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%d",&n);n+=2;
	for (int i=2;pr[0]<=n+n+2;i++){
		int fl=1;
		for (int j=2;j*j<=i;j++)
		if (i%j==0){fl=0;break;}
		if (fl) pr[++pr[0]]=i;
	}
	int i=1,j=n+n+2;
	while (i<j){
		b[++b[0]]=pr[i++];
		b[++b[0]]=pr[j--];
	}
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++)
	if (!((i+j)&1)){
		int x=(i+j)>>1,y=(n-i+1+j)>>1;
		a[i][j]=b[x]*b[y+n];
	}
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++)
	if ((i+j)&1){
		a[i][j]=1;
		a[i][j]=lcm(a[i][j],a[i-1][j]);
		a[i][j]=lcm(a[i][j],a[i+1][j]);
		a[i][j]=lcm(a[i][j],a[i][j-1]);
		a[i][j]=lcm(a[i][j],a[i][j+1]);
		a[i][j]++;
	}
	for (int i=2;i<n;i++)
	for (int j=2;j<n;j++)
	printf("%lld%c",a[i][j],(j==n-1) ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 5120
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    print(s[:3])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll X; cin>>X;
  ll n = X/500;
  X -= 500*n;
  ll m = X/5;
  cout << n*1000+m*5 <<"\n";
}

Measured memory_bytes: 256
<?php

$n = (int)fgets(STDIN);
$res = '';
while (--$n >= 0) {
  $set = explode(' ', trim(fgets(STDIN)));
  $cards[$set[0]][(int)$set[1]] = 1;
}
foreach(array('S','H','C','D') as $val) {
  for ($i = 1; $i <= 13; $i++) {
    if (!isset($cards[$val][$i])) $res = $res."$val $i".PHP_EOL;
  }
}
echo $res;

Measured memory_bytes: 15332
# https://atcoder.jp/contests/abc140/submissions/7411285

def main():
    N = int(input())
    *a, = map(int, input().split())

    xtoi = [-1] * (N + 1)
    for i, x in enumerate(a):
        xtoi[x] = i

    L = [-1] * (N + 2)
    R = [N] * (N + 2)
    for i in range(N):
        L[i] = i - 1
        R[i] = i + 1

    ans = 0
    for x, ind in zip(range(N, 0, -1), reversed(xtoi)):
        # l1, ..., x, ..., r1
        # (ll,r1)
        l1 = L[ind]
        r1 = R[ind]
        ans += x * (ind - l1) * (r1 - ind)
        L[r1] = l1
        R[l1] = r1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 35624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 1e9 + 5;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

int main()
{
    ll n, w, wi, vi;
    cin >> n >> w;
    vector<ll> dp(w + 1, 0);
    for(ll i = 0; i < n; i++)
    {
        cin >> wi >> vi;
        for(ll j = w; j >= 0; j--)
        {
            if(j - wi >= 0)
            {
                //cout << dp[j] << ' ' << vi + dp[j - wi] << '\n';
                dp[j] = max(dp[j],  vi + dp[j - wi]);
                //cout << dp[j] << '\n';
            }
        }
        //for(ll j = 0; j < w; j++)
          //  cout << dp[j] << ' ';
        //cout << '\n';
    }
    cout << dp[w] << '\n';

}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    rep(i, N){
        ll x;
        cin >> x;
        if(x >= K)ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

def max2(S):
    if S[0] < S[1] and S[1] < S[2]:
        return True
    elif S[0] > S[1] and S[1] > S[2]:
        return True
    else:
        return False


cnt = 0

for i in range(1, n - 1):
    sub = p[i - 1 : i + 2]
    if max2(sub):
       cnt += 1
       
print(cnt)

Measured memory_bytes: 3064
n, k = map(int, input().split())
alst = list(map(int, input().split()))

for _ in range(k):
    tmp = [0 for _ in range(n + 1)]
    for i, num in enumerate(alst):
        min_ind = max(i - num, 0)
        max_ind = min(i + num + 1, n)
        tmp[min_ind] += 1
        tmp[max_ind] -= 1
    next_num = 0
    for i, num in enumerate(tmp[:-1]):
        next_num += num
        alst[i] = next_num
    if tmp[0] == n and tmp[-1] == -n:
        break
print(*alst)

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

A_ls = list(map(int,input().split(" ")))
B_ls = list(map(int,input().split(" ")))

S = 0

for i,b in enumerate(B_ls):
    if b > A_ls[i]:
        b -= A_ls[i]
        S += A_ls[i]
        if A_ls[i+1] >= b:
            A_ls[i+1] -=b
            S+=b
        else:
            S+=A_ls[i+1]
            A_ls[i+1] = 0 
    else:
        S += b

print(S)


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

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

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

int main() {
	int n, m; scanf("%d%d", &n, &m);
	std::vector<int> a(n), b(n);
	std::vector<std::pair<i64, i64>> vec;
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);

		vec.push_back({a[i], b[i]});
	}
	sort(begin(vec), end(vec));

	int cur = 0;
	i64 ans = 0;
	std::priority_queue<i64> qu;
	for(int i = 1; i <= m; i++) {
		while(cur < vec.size() and vec[cur].first <= i) qu.push(vec[cur++].second);
		if(qu.empty()) continue;
		ans += qu.top(); qu.pop();
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4336
import java.util.Scanner

object Main {
  def solve(S: String) = {
    var l = 0
    var r = S.count(_ == 'E')
    var res = r
    S.indices foreach { i =>
      if (i > 0 && S.charAt(i - 1) == 'W') l += 1
      if (S.charAt(i) == 'E') r -= 1
      res = math.min(res, r + l)
    }
    res
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    println(solve(sc.next()))
  }
}


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

int main(){
  long n;  cin >> n;
  vector<bool> notPrime(n+1, false);
  long ans = 1, m = 1e9+7;
  
  for(int i=2; i<=n; i++){
    if(notPrime[i])  continue;
    long cnt = 0, p = i * i;
    for(long j=i; j<=n; j+=i){
      notPrime[j] = true;
      cnt++;
    }
    while(p <= n){
      cnt += (long)(n / p);
      p *= i;
    }
    ans = ans * (cnt + 1) % m;
  }

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


Measured memory_bytes: 3600
n,k=map(int,input().split())
s=input()

if s[k-1]=="A":
    print(s[0:k-1]+"a"+s[k:n])
elif s[k-1]=="B":
    print(s[0:k-1]+"b"+s[k:n])
elif s[k-1]=="C":
    print(s[0:k-1]+"c"+s[k:n])


Measured memory_bytes: 3316
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int h, a; cin >> h >> a;
	cout << (h + a - 1) / a << "\n";

	return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit

setrecursionlimit(10**7)

def solve():
    N = int(stdin.readline())
    Adj = [[] for i in range(N)]

    for i in range(N - 1):
        a = int(stdin.readline()) - 1
        Adj[a].append(i + 1)

    ans = dfs(N, Adj, 0, -1)

    print(ans)

def dfs(N, Adj, v, p):
    dl = []

    for u in Adj[v]:
        if u == p:
            continue

        dl.append(dfs(N, Adj, u, v))

    dl.sort(reverse=True)

    if not dl:
        return 0

    res = max(dl[i] + i + 1 for i in range(len(dl)))

    return res

if __name__ == '__main__':
    solve()

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

int main() {
  int N;
  cin >> N;
  vector<uint64_t> L(100);

  L.at(0) = 2;
  L.at(1) = 1;

  for (int i=2; i<100; i++) {
    L.at(i) = L.at(i-1) + L.at(i-2);
  }

  cout << L.at(N) << endl;

}

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

using namespace std;

const int N = 111;
bool vis[N];
int a[N], b[N], c[N], d[N], match[N];
vector< int > gr[N];

bool aug ( int x )
{
	if( vis[x] ) return false;
	vis[x] = 1;
	for( int y : gr[x] )
	{
		if( match[y] == -1 || aug( match[y] ) )
		{
			match[y] = x;
			return true;
		}
	}
	return false;
}

int main()
{
	int n;
	scanf("%d", &n );

	for( int i = 0; i < n; ++ i )
		scanf("%d %d", a + i, b + i );

	for( int i = 0; i < n; ++ i )
		scanf("%d %d", c + i, d + i );

	for( int i = 0; i < n; ++ i )
	{
		for( int j = 0; j < n; ++ j )
			if( a[i] < c[j] && b[i] < d[j] )
				gr[i].push_back( j );
	}
	
	memset( match, -1, sizeof match );
	int ans = 0;
	for( int i = 0; i < n; ++ i )
	{
		memset( vis, 0, sizeof vis );
		ans += aug( i );
	}
	printf("%d\n", ans );
	return 0;
}

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

using namespace std;

typedef long long LL;
#define N 300000

const LL mod=1000000007;
LL n,m,p,fac[N],ifac[N],ipw[N],d[N];

void upd(LL &x,LL y){x=(x+y+mod)%mod;}

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

void add(LL l,LL r,LL x){
	if (l<=r){
		upd(d[l],x);
		upd(d[r+1],-x);
	}
}

LL C(LL x,LL y){return fac[x]*ifac[y]%mod*ifac[x-y]%mod;}

int main(){
	scanf("%lld%lld",&n,&m); p=n+m;
	fac[0]=1; for (LL i=1;i<=p;++i) fac[i]=fac[i-1]*i%mod;
	ifac[p]=inv(fac[p]); for (LL i=p-1;~i;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	ipw[0]=1; ipw[1]=inv(2);
	for (LL i=2;i<=p;++i) ipw[i]=ipw[i-1]*ipw[1]%mod;
	for (LL i=1;i<=n;++i){
		add(1,p-i-1,ipw[p-i]*C(p-i-2,m-1));
		add(p-i+1,p,ipw[p-i]*C(p-i-1,m-1));
	}
	for (LL i=1;i<=m;++i){
		add(1,p-i-1,ipw[p-i]*C(p-i-2,n-2));
		add(p-i,p-i,ipw[p-i]*C(p-i-1,n-1));
	}
	for (LL i=1;i<=p;++i){
		upd(d[i],d[i-1]);
		printf("%lld\n",d[i]);
	}
	
	return 0;
}
			

Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;


void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

ll mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};


int main(){
    ll n, k;
    cin >> n >> k;
    mint d[k+1];
    rep(i, k+1) {
        d[i] = 0;
    }
    REP(i, 1, k+1) {
        mint tmp = k / i;
        d[i] = tmp.pow(n);
    }

    rep(i, k+1) {
        ll i2 = k - i;
        if (i2 == 0) break;
        for(ll j = 2 * i2; j <= k; j += i2) {
            d[i2] -= d[j];
        }
    }

    mint ans = 0;
    REP(i, 1, k+1) {
        ans += d[i]*i;
    }

    cout << ans.x << endl;
}

Measured memory_bytes: 4432
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, d = 0; string a, b, c; cin >> n >> a >> b >> c;
	for (int h = 0; h < n; h++) {
		if (a[h] != b[h] && a[h] != c[h] && b[h] != c[h]) {
			d++; d++;
		}
		else if (a[h] == b[h] && a[h] == c[h] && b[h] == c[h]) {
			d == d;
		}
		else {
			d++;
		}
	}
	cout << d << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
const string nyan("(=^・ω・^=)");

int N, K;
string S;

int main() {
	cin >> N >> S >> K;
	for (int i = 0; i < N; ++i) {
		if (S[i] != S[K - 1]) {
			S[i] = '*';
		}
	}
	cout << S << endl;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

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

int main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<int> v;
  int now = s.size() - 1;
  while (0 < now) {
    bool can = false;
    for (int i = m; 0 < i; i--) {
      if (now - i < 0) continue;  // 行き過ぎ防止
      if (s[now - i] == '0') {
        v.push_back(i);
        now -= i;
        can = true;
        break;
      }
    }
    if (can == false) {
      cout << -1 << endl;
      return 0;
    }
  }
  reverse(v.begin(), v.end());
  cout << v << endl;
}


Measured memory_bytes: 1144
var
 s:ansistring;
 m,x,i:longint;
begin
 readln(s);
 x:=pos('C',s);
 for i:=length(s) downto 1 do
  if s[i]='F' then begin m:=i; break; end;
 if (x<>0) and (m<>0) and (x<m) then writeln('Yes')
                                       else writeln('No');
end.

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char s[110];int l;
	cin>>s;l=strlen(s);
	for(int i=0;i<l;++i)
	{s[i]='x';cout<<s[i];
	}
	
}

Measured memory_bytes: 256
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    char str[101][101];
    for(int i=0;i<101;i++)
        for(int j=0;j<101;j++)
        str[i][j]='#';
        getchar();
    for(int i=0;i<a;i++){
        for(int j=1;j<b+1;j++)
        scanf("%c",&str[i][j]);
        getchar();
    }
    for(int i=0;i<b+2;i++)printf("#");
    printf("\n");
    for(int i=0;i<a;i++){
        for(int j=0;j<=b+1;j++)
            printf("%c",str[i][j]);
        printf("\n");
    }
    for(int i=0;i<b+2;i++)printf("#");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        String ans = "";
        for(int i = 0; i < n; i++){
            ans += a[i];
            ans += b[i];
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 21460
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize
    }

    let mut f = HashMap::new();

    for i in 1..200 {
        for j in 1..200 {
            for k in 1..200 {
                let f_num = i * i + j * j + k * k + i * j + i * k + j * k;
                let count = f.entry(f_num).or_insert(0);
                *count += 1;
            }
        }
    }

    for i in 1..n + 1 {
        if let Some(num) = f.get(&i) {
            println!("{}", num);
        } else {
            println!("{}", 0);
        }
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 7640
#include <cstdio>
using namespace std;

int n;
int m;
int maxcnt;
int maxidx;
int a[1000];
int cnt[1000];

int main() {
    scanf("%d %d", &n, &m);
    for (int i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }

    for (int i=0; i<m; i++) {
        int b;

        scanf("%d", &b);
        for (int i=0; i<n; i++) {
            if (a[i] <= b) {
                cnt[i]++;
                if (maxcnt < cnt[i]) {
                    maxcnt = cnt[i];
                    maxidx = i;
                }
                break;
            }
        }
    }

    printf("%d\n", maxidx+1);
}

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

int main() {
  int N;
  cin>>N;
  
  int k=100;
  
  for(int i=0;i<N;i++){
    int j=0;
    int A;
    cin>>A;
    int x=A%2;
    
    while(x==0){
      A/=2;
      x=A%2;
      j++;
    }
    
    if(j<k){
      k=j;
    }
  }
  
  cout<<k<<endl;
}


Measured memory_bytes: 256
def examA():
    A, B = LI()
    ans = (A + B)%24
    print(ans)


import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

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

#define ll long long

char s[1011][1011],c;
int n,m,cnt=0;
ll vis[1011][1011],mod=(ll)(1e9+7);

int main() {
    scanf("%d%d ",&n,&m);
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            scanf("%c",&s[i][j]);
            if(s[i][j]=='#')
                vis[i][j]=0;
            else
            {
                if(i>1)
                   vis[i][j]=(vis[i-1][j]+vis[i][j-1])%mod;
            }
        }
        if(i==1)
        {
            int k=1;
            while(s[i][k]=='.'&&k<=m)
                vis[i][k]=1,k++;
        }
        scanf("%c",&c);
    }
    printf("%lld\n",vis[n][m]);
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    for(int i=0;i<MAX;i++){
        if(!is_prime[i]){
            sumprime[i]=sumprime[i-1]+i;
        }else{
            sumprime[i]=sumprime[i-1];
        }
    }
}
*/
/*
void lcs(char s1[],char s2[]){
    int n=strlen(s1);
    int m=strlen(s2);
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int sum=0;
            if(s1[i-1]==s2[j-1]){
                sum=1+dp[i-1][j-1];
            }
            else{
                sum=max(dp[i-1][j],dp[i][j-1]);
            }
            dp[i][j]=sum;
        }
    }
    
    int index=dp[n][m];
    //cout<<index<<endl;
    char ans[index+1];
    ans[index]='\0';
    index--;
    int x=n;
    int y=m;
    while(x>0 and y>0){
        if(dp[x-1][y]==dp[x][y-1] and dp[x-1][y]!=dp[x][y]){
            ans[index]=s1[x-1];
            index--;
            x--;
            y--;
        }else if(dp[x-1][y]>dp[x][y-1]){
            x--;
        }else{
            y--;
        }

    }
    //reverse(ans.begin(),ans.end());

    cout<<ans;
    return;
}
*/
double dp[3000][3000];
double p[3000];

using namespace std;
int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    int t=1;
    //cin>>t;
    for(int tc=1;tc<=t;tc++){
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>p[i];
        }
        dp[0][0]=(1-p[0]);
        dp[0][1]=p[0];
        for(int i=1;i<n;i++){
            for(int j=0;j<=n;j++){
                dp[i][j]+=(1-p[i])*dp[i-1][j];
                if(j>0)
                    dp[i][j]+=p[i]*dp[i-1][j-1];
            }
        }
        double ans=0;
        for(int i=n/2+1;i<=n;i++){
            ans+=dp[n-1][i];
        }
        cout<<sp<<ans<<'\n';
    }
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 74116
/* C++標準ヘッダファイル */
/* 文字列ライブラリ */
#include <string>

/* コンテナライブラリ */
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

/* アルゴリズムライブラリ */
#include <algorithm>

/* 数値演算ライブラリ */
#include <cmath>

/* 入出力ライブラリ */
#include <iostream>

/* std使用<-namespace */
using namespace std;

/* define, typedef */
#define rpt(i, n) for(ll i = 0; i < (n); i++)  // リピート
typedef long long ll;


/* main関数 */
int main(void) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int count = 0;
	char cn = '\0';
	rpt(i, n) {
		if (cn != s[i]) {
			cn = s[i];
			count++;
		}
	}

	cout << count;

	return 0;
}


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

long long n, k, mod = 1e9+7, a[100][60][60], b[2][60][60], ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			cin >> a[0][i][j];
	for(int i=0; ((long long)1<<i)<k; ++i)
		for(int j1=0; j1<n; ++j1)
			for(int j2=0; j2<n; ++j2)
				for(int j3=0; j3<n; ++j3){
					a[i+1][j1][j2] += a[i][j1][j3] * a[i][j3][j2];
					a[i+1][j1][j2] %= mod;
				}
/*	for(int i=0; i<2; ++i){
		cout << i << "\n";
		for(int j1=0; j1<n; ++j1)
			for(int j2=0; j2<n; ++j2)
				cout << a[i][j1][j2] << " \n"[j2==n-1];
		cout << "\n";
	}
*/	for(int i=0; i<n; ++i) b[0][i][i] = 1;
	int t = 0;
	for(int i=0; (k>>i)>0; ++i){
		if((k>>i)%2==1){
			for(int j1=0; j1<n; ++j1)
				for(int j2=0; j2<n; ++j2)
					b[1-t][j1][j2] = 0;
			for(int j1=0; j1<n; ++j1)
				for(int j2=0; j2<n; ++j2)
					for(int j3=0; j3<n; ++j3){
						b[1-t][j1][j2] += a[i][j1][j3] * b[t][j3][j2];
						b[1-t][j1][j2] %= mod;
					}
			t = 1 - t;
		}
	}
/*	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			cout << b[t][i][j] << " \n"[j==n-1];
*/	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j){
			ans += b[t][i][j];
			ans %= mod;
		}
	cout << ans << "\n";
}

Measured memory_bytes: 2048
import sys

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

N = ir()
XL = []
for _ in range(N):
    x, l = lr()
    XL.append((x+l, 2 * l))

XL.sort()
r = - 10 ** 10
answer = 0
for right, l in XL:
    if r <= right - l:
        answer += 1
        r = right

print(answer)



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    
    int h1, s1, h2, s2;
    cin >> h1 >> s1 >> h2 >> s2;
    
    while (true) {
        h2 -= s1;
        if (h2 <= 0) {
            cout << "Yes" << endl;
            break;
        }
        
        h1 -= s2;
        if (h1 <= 0) {
            cout << "No" << endl;
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9+7;

void add(ll &a, ll b)
{
    a = (a+b) % MOD;
}
ll mod_pow(ll x, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;

    vector<ll> mem(k+1);
    for(ll x = k; x >= 1; x--)
    {
        ll tmp = mod_pow(k/x, n);
        for(ll i = 2*x; i <= k; i += x)
        {
            add(tmp, -mem[i]);
            add(tmp, MOD);
        }
        mem[x] = tmp;
        add(ans, x * tmp % MOD);
        add(ans, MOD);
    }
    cout << ans << endl;
}



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

long long solve(long long N, long long x)
{
    long long ans = 0;
    unsigned long long curr = x;

    while(N >= curr)
    {
        ans += N / curr;
        curr *= x;
    }

    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    long long N;
    cin >> N;

    if(N % 2)
    {
        cout << 0 << "\n";
        return 0;
    }
 
    long long two = N / 2 + solve(N / 2, 2);
    long long five = solve(N / 2, 5);

    cout << min(two, five) << "\n";
    return 0;
}


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

int main() {
  long A,B,K;
  cin >> A >> B >> K;
  long N,M;
  N = A - K;
  M = A + B - K;
  
  if (M < 0) {
    cout << 0 << " " << 0 <<endl;
  }
  else if (N <= 0) {
    cout << 0 << " " << M <<endl;
  }
  else {
    cout << N << " " << B <<endl;
  }
  

}


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

int main() {
  int A,B;
  int ans = 0;

  cin >> A >> B;

  if (A > B) {
    ans = A;
    A--;
  }
  else {
    ans = B;
    B--;
  }
  ans = ans + max(A, B);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}


int main(){
 ll n;
 cin>>n;
 ll a[n+1];
 ll ct[n+1] = {};
 for(ll i=2;i<=n;i++){
 	cin>>a[i];
 	ct[a[i]]++;
 }
 for(ll i = 1;i<=n;i++) cout<<ct[i]<< " ";
 cout<<endl;
}

Measured memory_bytes: 6724
def vacation(n, a):
  dp = [0]*3

  
  for i in range(3):
    dp[i] = a[0][i]

    
  for i in range(1, n):
    temp = [0]*3
    for j in range(3):
      for k in range(3):
        if(j!=k):
          temp[j] = max(temp[j], dp[k]+a[i][j])
    dp = temp
  return max(dp)
    


n = int(input())
a = []
for i in range(n):
  g = list(map(int, input().split()))
  a.append(g)
print(vacation(n, a))


Measured memory_bytes: 61844
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string s;
int main() {
	cin >> s;
	for (int i = ((int)s.size() - 1) / 2 * 2; i >= 2; i -= 2) {
		string t1 = s.substr(0, i / 2), t2 = s.substr(i / 2, i / 2);
		if (t1 == t2) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  int a=n%10;
  n/=10;
  int b=n%10;
  n/=10;
  if(a==7||b==7||n==7)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  
  return 0;
}


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

int main() {
	int H, W;
	cin >> H >> W;

	vector<vector<char>> a( H, vector<char>(W) );

	for( int i = 0; i < H; ++i ) {
		for( int j = 0; j < W; ++j ) {
			cin >> a.at( i ).at( j );
		}
	}

	for( int row = H-1; row >= 0; --row ) {
		int black = 0;

		for( int col = 0; col < W; ++col ) {
			if( a.at( row ).at( col ) == '#' ) {
				black++;
			}
		}

		if( black == 0 ) {
			a.erase( a.begin() + row );
		}
	}

	for( int col = W-1; col >= 0; --col ) {
		int black = 0;

		for( int row = 0; row < a.size(); ++row ) {
			if( a.at( row ).at( col ) == '#' ) {
				black++;
			}
		}

		if( black == 0 ) {
			for( int row = 0; row < a.size(); ++row ) {
				a.at( row ).erase( a.at( row ).begin() + col );
			}
		}
	}

	for( auto&& r: a ) {
		for( auto&& c: r ) {
			cout << c;
		}

		cout << endl;
	}
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
pa = A * X
pb = B * Y
pab = pa + pb
pc_max = C * max(X, Y) * 2
pc_min = C * min(X, Y) * 2
if X > Y:
    n = X - Y
    pc_min += A * n
else:
    n = Y - X
    pc_min += B * n
print(min(pab, pc_max, pc_min))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

vector<vector<int>> G;
vector<int> cnt;
vector<int> res;

void dfs(int u,int p,int ans){
	if(cnt[u] > 0) ans += cnt[u];
	res[u] = ans;
	for(int v : G[u]){
		if(v == p) continue;
		dfs(v,u,ans);
	}
}

int main(){
	int N,Q; cin >> N >> Q;
	G.resize(N);
	cnt.resize(N);
	res.resize(N);
	rep(i,N-1){
		int a,b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<Pi> px(Q);
	rep(i,Q){
		cin >> px[i].first >> px[i].second;
		px[i].first--;
		cnt[px[i].first] += px[i].second;
	}

	dfs(0,0,0);

	rep(i,N){
		cout << res[i];
		if(i != N-1) cout << " ";
	}
	cout << endl;
    
}
   


Measured memory_bytes: 25856
/*
#include<bits/stdc++.h>
#define getin scanf
using namespace std;
const int N = 200005;
int n;
int a[N];
int tag;
map<int,int>pos;
bool check(int len){
	pos.clear();
	for(int i=1;i<=n;i++){
		if(!i or a[i]>a[i-1])continue;
		int now = a[i];
		while(now>=1&&pos.count(now)&&pos[now]==len-1){
			pos.erase(now);
			now--;
		}
		if(now<1)return 0;
		if(!pos.count(now))pos[now]=1;
		else pos[now]++;
		if(pos[now]>len)return 0;
		for(auto it = pos.begin();it!=pos.end();it++){
			if(it-> first > now){
				auto tmp = it;
				it++;
				pos.erase(tmp);
			}else {
				it++;
			}
		}
	}
	return 1;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int l=1,r=26;
	getin("%d",&n);
	for(int i=0;i<n;i++){
		getin("%d",&a[i]);
	}
	while(l<=r){
		int mid = (l + r)/2;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	cout<<l;
	return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
map<int,int> pos;
int n;
int a[maxn];
bool check(int mxnum)
{
//	cout<<"check "<<mxnum<<endl;
	pos.clear();
	for(int i=0;i<n;i++)
	{
		if(!i||a[i]>a[i-1])continue;
		int here=a[i];
	//	cout<<here<<endl;
	//	cout<<pos.count(here)<<" "<<pos[here]<<endl;
		while(here>=1&&pos.count(here)&&pos[here]==mxnum-1)
		{
			pos.erase(here);
		//	cout<<here<<endl;
			here--;
		}
		if(here<1)return 0;
		if(!pos.count(here))pos[here]=1;
		else pos[here]++;
	//	cout<<here<<" "<<pos[here]<<endl;
		if(pos[here]>=mxnum)return 0;
		for(map<int,int>::iterator it=pos.begin();it!=pos.end();)
			if(it->first>here)
			{
				map<int,int>::iterator tmp=it;
				it++;
	//			cout<<tmp->first<<endl;
				pos.erase(tmp);
			}
			else it++;
	//	system("pause");
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int l=0,r=n;
	while(r-l>1)
	{
		int mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
bool flag[10000001];
 
int main(){
    int n=0,ans=0;
    for(int i=0;i <= 1000000;i++){
        if(i<=1)flag[i]=false;
        else flag[i]=true;
    }
    for(int i=2;i <= 1001 ;i++){
        if(flag[i]==true){
            for(int j=i*2 ; j<=1000000 ; j=j+i){
                flag[j] = false;
            }
        }
    }
    while(cin>>n){
        ans=0;
        for(int i=0;i <= n;i++){
            if(flag[i]==true){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2136
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  sc.nextLine()
  val a = sc.nextLine().split(" ").map(_.toDouble)


  println(loop(a, 0).toInt.toString)

  def loop(list: Seq[Double], count: Double): Double = {
    list.forall(_ % 2d == 0d) match {
      case true => loop(list.map(_ / 2), count + 1d)
      case false => count
    }
  }

}


Measured memory_bytes: 25516
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>
#include <cassert>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


ll fact[1000010];

int main() {
    fact[0] = 1;
	for (int i = 1; i < 1000010; i++) {
		fact[i] = ((ll)fact[i - 1] * i) % MOD;
	}

    int N, M; cin>>N>>M;
    vector<int> A(N), B(M);
    multiset<int> anum, bnum;
    set<int> allnum;
    for(int i = 0; i < N; i++)
    {
        cin>>A[i];
        anum.insert(A[i]);
        allnum.insert(A[i]);
    }
    for(int i = 0; i < M; i++)
    {
        cin>>B[i];
        bnum.insert(B[i]);
        allnum.insert(B[i]);
    }
    sort(all(A)); sort(all(B));
    
    for(auto x : allnum){
        if(anum.count(x)>1||bnum.count(x)>1){
            cout<<0<<endl;
            return 0;
        }
    }

    ll res=1;
    for(int k = N*M; k>0; k--){
        if(anum.find(k)!=anum.end()&&bnum.find(k)==bnum.end()){
            res*=(B.end()-lower_bound(B.begin(), B.end(), k));
            res%=MOD;
        }else if(bnum.find(k)!=bnum.end()&&anum.find(k)==anum.end()){
            res*=(A.end()-lower_bound(A.begin(), A.end(), k));
            res%=MOD;
        }else if(anum.find(k)==anum.end()&&bnum.find(k)==bnum.end()){
            res*=((B.end()-lower_bound(B.begin(), B.end(), k))*(A.end()-lower_bound(A.begin(), A.end(), k))-N*M+k);
            res%=MOD;
        }
    }

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, k;
    cin >> n >> k;

    if ((n + 1) / 2 >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
fn far_reaching(graph: &[Vec<(usize, i64)>], start: usize) -> Vec<i64> {
    let size = graph.len();
    let mut is_reached: Vec<bool> = vec![false; size];
    let mut dist = vec![-1; size];
    let mut stack = vec![start];
    dist[start] = 0;
    'dfs: while !stack.is_empty() {
        let from = *stack.last().unwrap();
        if !is_reached[from] {
            is_reached[from] = true;
        }
        for &(to, weight) in &graph[from] {
            if !is_reached[to] {
                dist[to] = dist[from] + weight;
                stack.push(to);
                continue 'dfs;
            }
            // For each edgse.
        }
        // Postorder
        let _from = stack.pop().unwrap();
    }
    dist
}

fn solve(graph: Vec<Vec<(usize, i64)>>) {
    let (x, _) = far_reaching(&graph, 0)
        .into_iter()
        .enumerate()
        .max_by_key(|e| e.1)
        .unwrap();
    let x_dfs = far_reaching(&graph, x);
    let (y, _) = x_dfs
        .clone()
        .into_iter()
        .enumerate()
        .max_by_key(|e| e.1)
        .unwrap();
    let y_dfs = far_reaching(&graph, y);
    for i in 0..graph.len() {
        let max = std::cmp::max(x_dfs[i], y_dfs[i]);
        println!("{}", max);
    }
}

use std::io::{BufRead, BufReader};
fn main() {
    let mut read = BufReader::new(std::io::stdin())
        .lines()
        .filter_map(|e| e.ok());
    let v = {
        let line = read.next().unwrap();
        let line: Vec<&str> = line.split(' ').collect();
        let v: usize = line[0].parse().unwrap();
        v
    };
    let graph = {
        let mut graph: Vec<Vec<_>> = vec![vec![]; v]; // Adj list
        for edge in read {
            let mut edge = edge.split(' ');
            let start: usize = edge.next().unwrap().parse().unwrap();
            let end: usize = edge.next().unwrap().parse().unwrap();
            let weight: i64 = edge.next().unwrap().parse().unwrap();
            graph[start].push((end, weight));
            graph[end].push((start, weight));
        }
        graph
    };
    solve(graph);
}



Measured memory_bytes: 5056
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin >> a >> b >>c >> d;
    if((a+b)>(c+d)) cout << "Left" << endl;
    if((a+b)<(c+d)) cout << "Right" << endl;
    if((a+b) == (c+d)) cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 256
# ABC 131, B - bite eating
X = [int(el) for el in input().split(' ')]
n = X[0]
l = X[1]

A = [abs(l + i - 1) for i in range(1, n+1)]

j = A.index(min(A)) + 1
B = [(l + i - 1) for i in range(1, n+1) if i != j]
print(sum(B))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define u(x, a, b) for(ll x = a; x < b; x++)
#define d(x, a, b) for(ll x = a; x > b; x--)

typedef long long ll;
typedef long double ld;

#define MAXI 100010
#define MOD 1000000007

int main(){
	string s, t;
	cin >> s >> t;
	ll cnt = 0;
	u(one, 0, 3){if(s[one]==t[one]){cnt++;}}
	
	cout << cnt;
}

Measured memory_bytes: 3584
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)


ans = 0
for n in range(N):
    Hn = H[n]
    for to in G[n]:
        if H[to] >= H[n]:
            break
    else:
        ans += 1

print(ans)


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

int main(void){
    string s;
    cin >> s;

    if(s=="SUN"){
        cout << 7 << endl;
    }else if(s=="MON"){
        cout << 6 << endl;
    }else if(s=="TUE"){
        cout << 5 << endl;
    }else if(s=="WED"){
        cout << 4 << endl;
    }else if(s=="THU"){
        cout << 3 << endl;
    }else if(s=="FRI"){
        cout << 2 << endl;
    }else if(s=="SAT"){
        cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256