akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());



int main(){
	int n;
	while(cin>>n,n){
		vint v(n,0);
		int c=0;
		int b=0;
		rep(i,100){
			char t;
			cin>>t;
			// cout<<c<<" ";
			if(t=='M'){
				v[c]++;
			}
			else if(t=='S'){
				b+=v[c];
				b++;
				v[c]=0;
			}
			else if(t=='L'){
				v[c]+=b;
				v[c]++;
				b=0;
			}
			c++;
			c%=n;
		}
		sort(ALL(v));
		rep(i,n){
			if(i) cout<<" ";
			cout<<v[i];
		}
		cout<<" "<<b<<endl;
	}
}

Measured memory_bytes: 1216
def calc_prime(x):
    prime = set()
    
    if not x % 2: prime.add(2)
    while not x % 2: x //= 2
        
    i = 3
    while i ** 2 <= x:
        if not x % i: prime.add(i)
        while not x % i: x //= i
        i += 2
        
    if x != 1: prime.add(x)
    
    return prime

A, B = map(int, input().split())

print(len(calc_prime(A) & calc_prime(B)) + 1)

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

int main(){
    int n,a,b,c;
    cin >> a >> b >> c >> n;
    int p=0;
    int ah=0;
    int bh=0;
    int ch=0;
    for(int i=0; i!=1000000; i++){
        if(ch == c){
            if(bh == b){
                if(ah == a){
                    break;
                }else{
                    ch = 0;
                    bh = 0;
                    ah = ah + 1;
                    if(ah * 500 == n){
                        p = p + 1;
                    }
                }
            }else{
                ch = 0;
                bh = bh + 1;
                if(bh * 100 + ah * 500 == n){
                    p = p + 1;
                }
            }
        }else{
            ch = ch + 1;
            if(ch * 50 + bh * 100 + ah * 500 == n){
                p = p + 1;
            }
        }
    }
    cout << p << '\n';
    return 0;
}

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

int main() {

    int N,A;
    cin >> N >> A;

    N = N % 500;



    string ans;
    if(N <= A){
        ans = "Yes";
    }else{
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;

    int ans[N]{};

    for(int x=1;x*x<N;x++){
        for(int y=1;y*y<N;y++){
            for(int z=1;z*z<N;z++){
                int w=x*x+y*y+z*z+x*y+x*z+y*z;
                if(w>N){
                    break;
                }
                w--;
                // if(x==y&&y==z){
                //     ans[w]++;
                // }else if(x==y || y==z || x==z){
                //     ans[w]+=3;
                // }else{
                //     ans[w]+=6;
                // }
                ans[w]++;
            }
        }
    }

    rep(i,N){
        cout << ans[i] << endl;
    }

    



}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N = 1e6 + 7;

struct Edge{
	int u, v, w;

	Edge(){
		u = v = w = 0;
	}

	Edge(int _u, int _v, int _w) :
		u(_u), v(_v), w(_w) {}
};

int x, cnt = 0, bit[22];
vector <Edge> sv;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> x;
	x--;
	int tmp = x;
	while(tmp > 0){
		bit[++cnt] = tmp % 2;
		tmp /= 2;
	}
	for(int i = 1; i < cnt; i++){
		sv.pb(Edge(i, i + 1, 0));
		sv.pb(Edge(i, i + 1, 1 << (i - 1)));
	}
	int now = (1 << (cnt - 1));
	for(int i = cnt - 1; i >= 1; i--){
		if(i == 1){
			sv.pb(Edge(i, cnt, now));
			if(bit[i] == 1) sv.pb(Edge(i, cnt, now + 1));
		}
		else if(bit[i] == 1){
			sv.pb(Edge(i, cnt, now));
			now += (1 << (i - 1));
		}
	}
	if(x == 1) cnt = 2, sv.pb(Edge(1, 2, 0)), sv.pb(Edge(1, 2, 1));
	cout << cnt << " " << (int)sv.size() << "\n";
	for(auto p : sv){
		cout << p.u << " " << p.v << " " << p.w << "\n";
	}
}


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

int syoku(int n,vector<int> x,vector<int> y,vector<int> z){
  int count=0;
  rep(j,n){
  count+= y[x[j]-1];
    
    if(j<n-1 && x[j]+1==x[j+1]){
      count+=z[x[j]-1];
    }
  }
 
  
  return count;
}



int main() {
  int n;
  cin>>n;
  vector<int> a(n), b(n), c(n-1);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n-1) cin>>c[i];
  //////////////////////
  int ans=syoku(n,a,b,c);
  cout<<ans<<endl;
}











Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		String s = stdIn.next();
		String t = stdIn.next();
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		String u = stdIn.next();
		
		if(u.equals(s)) {
			System.out.println((a-1)+" "+b);
		}else {
			System.out.println(a+" "+(b-1));
		}
		
		
		
	}

}


Measured memory_bytes: 25172
h,w=map(int,input().split())
s=['.'*(w+2)]
for i in range(h):
  a='.'+input()+'.'
  s.append(a)
s.append('.'*(w+2))
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=='#' and(s[i-1][j]!='#' and s[i+1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#'):
      print('No')
      exit()      
print('Yes')

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

int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    int yoko = tx-sx;
    int tate = ty-sy;

    int i;

    for(i = 0;i < yoko;++i){
        cout << "R";
    }
    for(i = 0;i < tate;++i){
        cout << "U";
    }
    for(i = 0;i < yoko;++i){
        cout << "L";
    }
    for(i = 0;i < tate;++i){
        cout << "D";
    }
    cout << "D";
    for(i = 0;i <= yoko;++i){
        cout << "R";
    }
    for(i = 0;i <= tate;++i){
        cout << "U";
    }
    cout << "L";
    cout << "U";
    for(i = 0;i <= yoko;++i){
        cout << "L";
    }
    for(i = 0;i <= tate;++i){
        cout << "D";
    }
    cout << "R" << endl;
    return 0;
}

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

using namespace std;

long cnt;
vector<int> g;
vector<int> v;
int n;

void insertionsort(int gg){
    int vv,j;
    for(int i=gg;i<n;i++){
        vv = v[i];
        j = i - gg;
        while(j >= 0&&v[j] > vv){
            v[j+gg] = v[j];
            j = j - gg;
            cnt++;
        }
        v[j+gg] = vv;
    }
}

int shellsort(){
    cnt = 0;
    for(int i=1;;){
        if(i > n)break;
        g.push_back(i); 
        i = 3*i + 1;
    }
    for(int i=g.size()-1;i>=0;i--){
        insertionsort(g[i]);
    }
    return g.size();
}

int main(void){
    cin >> n;
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        v.push_back(k);
    }
    int size = shellsort();
    cout << size << endl;
    for(int i=g.size()-1;i>=0;i--){
        cout << g[i];
        if(i != 0)cout << " ";
        else cout << "\n";
    }
    cout << cnt << endl;
    for(int i=0;i<v.size();i++){
        cout << v[i] << endl;
    }
}


Measured memory_bytes: 6956
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
  if(a>=13){
  	cout<<b;
  }else if(a<=12&&a>=6){
  	cout<<b/2;
  }else if(a<=5){
  	cout<< 0;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int ma = 200010;
vector<bool> che(ma);
vector<int> add(ma);
void dfs(const Graph &G,int v){
    for(auto t : G[v]) if(!che[t]){
        add[t] += add[v];
        che[t] = 1;
        dfs(G,t);
    }
}

int main(){
    int n,q;
    cin >> n >> q;
    Graph G(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,q){
        int a,b;
        cin >> a >> b;
        a--;
        add[a] += b;
    }
    che[0] = 1;
    dfs(G,0);
    rep(i,n) cout << add[i] << endl;
}

Measured memory_bytes: 23552
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <string>
using namespace std;
#define lli long long int
#define MAX 100000000
int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int num = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == '0')
            num++;
    }
    cout << 2 * min(num, (int)S.length() - num) << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a + b == 15)System.out.println("+");
		else if(a * b == 15)System.out.println("*");
		else System.out.println("x");
		}

}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int IINF = INT_MAX;

int main() {
    int dp[55];
    fill(dp,dp+55,IINF/2);
    dp[0] = 0;
    for(int i=2;i<=50;i++){
        dp[i] = dp[i-2] + 380;
        if(i>=3) dp[i] = min(dp[i], dp[i-3] + 550);
        if(i>=5) dp[i] = min(dp[i], dp[i-5] + 850);
        if(i>=10) dp[i] = min(dp[i], dp[i-10] + 1520);
        if(i>=12) dp[i] = min(dp[i], dp[i-12] + 1870);
        if(i>=15) dp[i] = min(dp[i], dp[i-15] + 2244);
    }
    int n;
    while(cin >> n, n){
        cout << dp[n/100] << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let k = input::<i64>();

    let e = k / 2;
    let o = k / 2 + k % 2;
    println!("{}", e * o);
}


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

int main(){
  int N;cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  int ans=0;
  int now=1;
  bool can=true;
  while(can){
    ans++;
    now=A.at(now-1);
    if(now==2) break;
    if(ans==100000000) can=false;
  }
  if(can) cout<<ans<<endl;
  else cout<<-1<<endl;
}


Measured memory_bytes: 3780
#include <iostream>

int main()
{
	int n;
	bool flag = false;
	std::cin >> n;
	for (int i = 1; i < 10; i++)
	{
		if (n % i == 0 && n / i < 10)
		{
			flag = true;
			break;
		}
	}
	std::cout << (flag ? "Yes" : "No") << std::endl;
	return 0;
}

Measured memory_bytes: 256
N = int(raw_input())
A = map(int, raw_input().split())
i = 0
flag = 1
while flag:
    flag = 0
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A_j = A[j]
            A[j] = A[j-1]
            A[j-1] = A_j
            flag = 1
            i += 1
print " ".join(map(str, A))
print i

Measured memory_bytes: 6452
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc143/abc143_c.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;
  string s;
  cin >> s;

  string ans = "";
  ans.push_back(s[0]);
  int j = 0;
  repi(i, 1, s.size()) {
    if (ans[j] != s[i]) {
      ans.push_back(s[i]);
      j++;
    }
  }

  cout << ans.size() << endl;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n; cin >> n;
    int ar[n+5] = {};
    for(int i = 1; i <= n; i++)
    {
        cin >> ar[i];
    }
    unsigned long long ans = 1000;
    long long note = 0;
    vector<int>v;
    for(int i = 1; i <= n; i++)
    {
        //cout << ar[i] << " ";
        if(ar[i] > ar[i+1])
        {
            v.push_back(ar[i]);
            note = ans/v[0];
            ans = ans%v[0];
            ans += note*v[v.size()-1];
            note = 0;
            v.clear();
            //cout << endl;
        }
        else
        {
            v.push_back(ar[i]);
        }
    }
    cout << ans << endl;
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int f(int n){
  int res=0;
  while(n){
    res+=n%10;
    n/=10;
  }
  return res;
}

int main(){
  int N;
  int ans=65536;

  cin>>N;
  for (int i=1;i<N/2+1;i++){
    if (ans>(f(i)+f(N-i))){
      ans=(f(i)+f(N-i));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2**20)  # 再帰回数上限の向上 かなり多くしないとREになる


class Node:
    def __init__(self,
                 parent,
                 left,
                 right):
        self.parent = parent
        self.left = left  # 一番左の**子**ノードということに注意
        self.right = right


def get_depth(T: dict, u: int):
    '''
    Tは木の構造と見立てたdict
    uはTのノード
    '''
    d = 0
    while T[u].parent is not None:
        u = T[u].parent
        d += 1  # 親をたどりながらdを増やしていく。


D = {}  # 深さを保存しておく用のdict


def get_all_depth(T: dict, u: int, p: int):
    '''
    一度にすべてのノードの深さを取得する関数(再帰的に処理を行う)。
    一気に全体の深さを求めるならばこちらの方がオーダーが小さい。
    pは現在扱う深さ
    '''
    D[u] = p
    # ココらへんの動きは図を参照、ふさごとに深さ優先探索している感じ
    if T[u].right is not None:
        # 右の兄弟ノード(深さは同じ)から入れていく
        get_all_depth(T, T[u].right, p)
    if T[u].left is not None:
        # 兄弟を入れ終わったら次は下のふさへ
        get_all_depth(T, T[u].left, p+1)


def ret_children(T, u):
    chilren = []
    c = T[u].left
    while c is not None:
        chilren.append(c)
        c = T[c].right
    return chilren

# 答え出力用

def print_for_a_node(T: dict, node: int, D: dict):
    node_type = 'internal node' if T[node].left is not None else 'leaf'
    if T[node].parent is None:
        parent = -1
        node_type = 'root'
    else:
        parent = T[node].parent
    children = ret_children(T, node)

    print(
        f'node {node}: parent = {parent}, depth = {D[node]}, {node_type}, {children}')


# この問題は入力をNoneに適する形に整形するのも少し難しい
n = int(input())

T = {k: Node(None, None, None) for k in range(n)}  # pythonぽくないけど初期化
for _ in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0:  # もし子ノードがなければ次へ
        continue
    T[tmp[0]].left = tmp[2]  # 一番左の子ノードは即座にわかる
    T[tmp[2]].parent = tmp[0]  # 子の親ノードも即座に与えられる
    prev_sibling = tmp[2]  # 前のノード番号を覚えておく用
    for sib in tmp[3:]:
        T[prev_sibling].right = sib
        T[sib].parent = tmp[0]  # 子から親を与えている
        prev_sibling = sib

for node in range(n):
    if T[node].parent is None:
        get_all_depth(T, node, 0)  # rootを入れなければいけないことに注意
        # Dに深さが入った
        break

for node in range(n):
    print_for_a_node(T, node, D)


Measured memory_bytes: 141960
# coding: utf-8

n = input()
m = 0
rank = 1
for i in range(1, n+1):
    j = i
    c = 0
    while True:
        if j % 2 == 0:
            j /= 2
            c += 1

        else:
            if m < c:
                m = c
                rank = i
            break

print rank


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
    int n, k, s;
    cin>>n>>k>>s;
    for(int i = 0; i<k; ++i)
    {
        cout<<s<<" ";
    }

    for(int i = k; i<n; ++i)
    {
        cout<<(s==1e9?1:1000000000)<<" ";
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;

    vector<long long> food(m, 0);

    for(long long i = 0; i < n; i++){
        long long k;
        cin >> k;
        for(long long j = 0; j < k; j++){
            long long a;
            cin >> a;
            food[a-1]++;
        }
    }

    long long count = 0;

    for(long long i = 0; i < m; i++){
        if(food[i] == n){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void) {

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

    int A[100][100];
    int b[100];
    int Ab[100] = {0};

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

    //multiply
    for (i = 0; i < n; ++i) {
        for (j = 0; j < m; ++j) {
            Ab[i] += A[i][j] * b[j];
        }
    }

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

    return 0;
}

Measured memory_bytes: 640
# D
from collections import deque

n, m, s, t = map(int, input().split())
cost_y = [10**15]*(n+1)
cost_s = [10**15]*(n+1)

G_y = dict()
G_s = dict()
for i in range(1, n+1):
    G_y[i] = dict()
    G_s[i] = dict()

for _ in range(m):
    u, v, a, b = map(int, input().split())
    G_y[u][v] = a
    G_y[v][u] = a
    G_s[u][v] = b
    G_s[v][u] = b

# for yen
cost_y[s] = 0
queue = deque([s])
while len(queue) > 0:
    u = queue.popleft()
    for v in G_y[u].keys():
        if cost_y[u] + G_y[u][v] < cost_y[v]:
            queue.append(v)
            cost_y[v] = cost_y[u] + G_y[u][v]
            
# for snuke
cost_s[t] = 0
queue = deque([t])
while len(queue) > 0:
    u = queue.popleft()
    for v in G_s[u].keys():
        if cost_s[u] + G_s[u][v] < cost_s[v]:
            queue.append(v)
            cost_s[v] = cost_s[u] + G_s[u][v]
            
res_list = []
res = cost_y[-1] + cost_s[-1]
for i in range(n, 0, -1):
    res = min(res, cost_y[i] + cost_s[i])
    res_list.append(res)
for i in range(n-1, -1, -1):
    print(10**15 - res_list[i])

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

template<class T>
struct segtree_max
{
	vector<T> t;
	T bound;
	
	segtree_max(int a, T val)
	{
		this->bound = val;
		t.assign(4*a,bound);
	}
	
	void build(T a[], int v, int tl, int tr) 
	{
		if (tl == tr) t[v] = a[tl];
		else 
        {
			int tm = (tl + tr) / 2;
			build(a, v*2, tl, tm);
			build(a, v*2+1, tm+1, tr);
			t[v] = max(t[v*2], t[v*2+1]);
		}
	}
	
	T query(int v, int tl, int tr, int l, int r) 
	{
		if (l > r) return bound;
		if (l == tl && r == tr) return t[v];
		int tm = (tl + tr) / 2;
		return max(query(v*2, tl, tm, l, min(r, tm)), query(v*2+1, tm+1, tr, max(l, tm+1), r));
	}
	
	void update(int v, int tl, int tr, int pos, T new_val) 
	{
		if (tl == tr) t[v] = max(t[v],new_val);
		else 
		{	
			int tm = (tl + tr) / 2;
			if (pos <= tm) update(v*2, tl, tm, pos, new_val);
			else update(v*2+1, tm+1, tr, pos, new_val);
			t[v] = max(t[v*2], t[v*2+1]);
		}
	}
	
};
segtree_max<int> T(300009,0);
int a[300009];
int dp[300009];

void solve()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans=0;
	int m1=0,m2=300000;
	for(int i=n;i>0;i--)
	{
		int l=max(m1,a[i]-k);
		int r=min(m2,a[i]+k);
		dp[i]=1+T.query(1,m1,m2,l,r);
		T.update(1,m1,m2,a[i],dp[i]);
		ans = max(ans,dp[i]);
	}
	cout<<ans<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 10336
# include <iostream>
# include <cstdio>

using namespace std ;

int dis[505][505] ;
bool already[505][505] ;
int xx[4] = { 0 , 0 , 1 , -1 } ;
int yy[4] = { 1 , -1 , 0 , 0 } ;
 
void dfs( int x , int y )
{
    int nowdis = dis[x][y] + already[x][y] ;
    for ( int i = 0 ; i < 4 ; i++ )
    {
        int newx = x + xx[i] , newy = y + yy[i] ;
        if ( dis[newx][newy] > nowdis )
        {
            dis[newx][newy] = nowdis ;
            dfs( newx , newy ) ;
        }
    }
}
 
int main() 
{
    int n ;
    scanf("%d" , &n) ;
    for ( int i = 1 ; i <= n ; i++ )
    {
        for ( int j = 1 ; j <= n ; j++ )
        {
            dis[i][j] = min( min( n + 1 - i , i ) , min( j , n + 1 - j ) ) 
            - 1 ;
            already[i][j] = true ;
        }
    }

    int res = 0 ;
    for ( int i = 1 ; i <= n * n ; i ++ )
    {
        int id ;
        scanf("%d" , &id) ;
        int x = ( id + n - 1 ) / n ;
        int y = id % n ;
        if ( y == 0 ) y += n ;
        res += dis[x][y] ;
        already[x][y] = false ;
        dfs( x , y ) ;
    }
    printf("%d\n" , res) ;
    return 0 ;
}

Measured memory_bytes: 20348
#include <bits/stdc++.h>
using namespace std; 
#define rep(i, N) for (int i = 0; i < (int)N; i++)

int main(){
    int n,k;
    cin >> n>>k;
    int ans = 0;
    while(n>0){
       n/=k;
       ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld k, a, b, f = 0;
      cin >> k >> a >> b;
      for(lld i = a; i <= b; i+=1){
      	if (i%k == 0){
      		f = 1;
      		break;
      	}
      }
      if (f == 0)
      	cout << "NG";
      else
      	cout << "OK";
      return 0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if (K % 2 == 0)
    cout << A - B << endl;
  else
    cout << B - A << endl;
  return 0;
}

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

int main(int argc, char const* argv[])
{
  string str;
  cin >> str;
  int i = 0;
  int ans = 0;
  while(1){
    if(str.size() == 0 || str.size() == i+1) break;
    if( str[i] != str[i+1]) {
      str.erase(i, 2);
      ans += 2;
      i -= (i==0? 1:2);
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(){
	int n;
	string s;
	int k;
	cin >>n>>s>>k;
	char a=s[k-1];
	for(auto i = s.begin();i!=s.end();i++){
	if (*i!=a)
		*i='*';
	}
	cout <<s;

}

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

public class Main {
	
	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   int n = in.readInt();
	   int arr[] = new int[100003];
	   for(int i = 0; i<n; i++) {
		   int a = in.readInt();
		   if(a != 0) {
			  arr[a-1]++; 
		   }
			   arr[a]++;  
			   arr[a+1]++;
	   }
	   int max = 0; 
	   for(int i : arr) {
		 max = Math.max(max, i);
	   }
	   System.out.println(max);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main(){
	ll n,min,i,a,x,y;
	cin >> n;
	min = n+1;
	i = sqrt(n);
	while (i>=1)
	{
		a = n % i;
		if (a == 0) {
			x = n / i;
			y = i;
			break;
		}
		i--;
	}
	cout <<x+y-2  << endl;
	}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		if (x.compareTo(y) > 0) {
			System.out.println('>');
		} else if (x.compareTo(y) == 0) {
			System.out.println('=');
		} else {
			System.out.println('<');
		}

	}

}


Measured memory_bytes: 20948
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,k,mx;
	while(cin>>n>>k,n){
		int a[100000]={0},b[100000]={0};
		rep(i,n)cin>>a[i]; rep(i,k)b[0]+=a[i]; mx=b[0];
		rep(i,n-k)b[i+1]=b[i]+a[i+k]-a[i],mx=mx>b[i+1]?mx:b[i+1];
		cout<<mx<<endl;
	}
	return 0;
}

Measured memory_bytes: 1660
N,S=*$<
t=1
"RGB".chars{t*=S.count _1}
N.to_i.times{|i|0.upto(i/2){a,b,c=S[i],S[i-_1],S[i-_1*2]
a==b||(a+b)[c]||t-=1}}
p t

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

int main() {
    /*変数定義，入力*/
    string s;
    cin >> s;
    
    //int A, B;cin >> A >> B;
    //vector<int> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    rep(i, s.size()){
        if(i%2 == 0){
            if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    /*出力*/
    cout << "Yes" << endl;

    /*終了*/
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
    double n,i,min,q;
    scanf("%lf",&n);
    min=n+1;
    q=sqrt(n);
    for(i=1;i<=q;i++)
    {
        if(fmod(n,i)==0)
        {
            if(min>i+n/i)
                min=i+n/i;
        }
    }
    printf("%1.0f\n",min-2);

}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() 
{
   int x , y ;
	 cin>>x>>y ;
	int a , b , c ;
	 a=x*y ;
	 b=x-y ;
	 c=x+y ;
	 
	if (a==0 && b==0 && c==0)
		cout<<0 ;
	 else if (a>b && a>=c) 
		 cout<<a ;
	 else if (b>a && b>=c) 
		 cout<<b ;
	 else if (c>a && c>=b) 
		 cout<<c ;
	
     return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int cnt = 0;
int n;
void check(long x, int a, int b, int c){
  if(x > n)return;
  if(a&b&c)cnt++;
  check(x*10+3,1,b,c);
  check(x*10+5,a,1,c);
  check(x*10+7,a,b,1);
}

int main(){
  cin >> n;
  check(0,0,0,0);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
class P0173
  $fee1=200
  $fee2=300

  def main
    while !(line=gets).nil?
      c, a, m=line.split
      puts "#{c} #{a.to_i+m.to_i} #{a.to_i*$fee1+m.to_i*$fee2}"
    end
  end
end

P0173.new.main

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

bool check()
{
    for(int i=0;i<s.size();i++)
        if (s[i]=='?') return true;
    return false;
}

int gett()
{
    int i=0,d=0;
    while (i<s.size())
    {
        if (s[i]==' ') break;
        if (d==0) d=s[i]-'0';
        else d=d*10+s[i]-'0';
        i++;
    }
    s.erase(s.begin(),s.begin()+i+1);
    return d;
}

int main()
{
  
    while(1>0)
    {
        s.clear();
        getline(cin,s);
        scanf("\n");
        if (check()) return 0;
        s=s+' ';
        int a=gett();

        char h=s[0];
        s.erase(s.begin(),s.begin()+2);
        //cout<<s<<endl;
        int b=gett();
        double sum=0;
        if (h=='+') sum=a+b;
        else if (h=='-') sum=a-b;
            else if (h=='*') sum=a*b;
                else sum=a/b;
       // cout<<a<<h<<b<<endl;
        printf("%.0f\n",sum);
    }
}



Measured memory_bytes: 3316
using System;
using System.IO;
using System.Collections.Generic;

namespace _134
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_134C();
        }

        public static void solve_134C()
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int[] nums = new int[n];

            int max1 = Int32.MinValue;
            int maxIdx1 = -1;
            for (int i = 0; i < n; i++)
            {
                nums[i] = Convert.ToInt32(Console.ReadLine());

                if (max1 < nums[i])
                {
                    max1 = nums[i];
                    maxIdx1 = i;
                }
            }

            int max2 = Int32.MinValue;
            int maxIdx2 = -1;
            for (int i = 0; i < n; i++)
            {
                if (i != maxIdx1 && max2 < nums[i])
                {
                    max2 = nums[i];
                    maxIdx2 = i;
                }
            }

            for (int i = 0; i < n; i++)
            {
                if (i == maxIdx1)
                {
                    Console.WriteLine(max2);
                }
                else
                {
                    Console.WriteLine(max1);
                }
            }
        }

        public static void solve_134B()
        {
            string[] nd = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(nd[0]);
            int d = Convert.ToInt32(nd[1]);

            int res = n % (d * 2 + 1) == 0 ? n / (d * 2 + 1) : n / (d * 2 + 1) + 1;

            Console.WriteLine(res);
        }
        public static void solve_134A()
        {
            int r = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(3 * r * r);
        }
    }
}


Measured memory_bytes: 17236
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	a := nextInts(n)
	sort.Ints(a)
	b := make([]int, n)
	c := make([]int, n)
	left := n / 2
	if n%2 == 0 {
		left--
	} else {
		b[0] = a[n/2]
		c[0] = a[n/2]
	}
	right := left + 1
	for i := 0; i < n/2; i++ {
		// log.Println(left, right, i)
		if i%2 == 0 {
			b[left] = a[i]
			b[right] = a[n-i-1]
			c[left] = a[n-i-1]
			c[right] = a[i]
		} else {
			b[left] = a[n-i-1]
			b[right] = a[i]
			c[left] = a[i]
			c[right] = a[n-i-1]
		}
		left--
		right++
	}
	log.Println(b)
	log.Println(c)
	rtn := 0
	rtn1 := 0
	for i := 1; i < n; i++ {
		rtn += Abs(b[i] - b[i-1])
		rtn1 += Abs(c[i] - c[i-1])
	}

	fmt.Println(Max(rtn, rtn1))
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 9984
#include<stdio.h>

struct DICE {
	int top;
	int north;
	int south;
	int east;
	int west;
	int bottom;
};
struct DICE dice;

void N() {
	int num[6];
	num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
	num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
	dice.top = num[1]; dice.south = num[5]; dice.east = num[2];
	dice.west = num[3]; dice.north = num[0]; dice.bottom = num[4];
}
void S() {
	int num[6];
	num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
	num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
	dice.top = num[4]; dice.south = num[0]; dice.east = num[2];
	dice.west = num[3]; dice.north = num[5]; dice.bottom = num[1];
}
void E() {
	int num[6];
	num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
	num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
	dice.top = num[3]; dice.south = num[1]; dice.east = num[0];
	dice.west = num[5]; dice.north = num[4]; dice.bottom = num[2];
}
void W() {
	int num[6];
	num[0] = dice.top; num[1] = dice.south; num[2] = dice.east;
	num[3] = dice.west; num[4] = dice.north; num[5] = dice.bottom;
	dice.top = num[2]; dice.south = num[1]; dice.east = num[5];
	dice.west = num[0]; dice.north = num[4]; dice.bottom = num[3];
}

void Roll(int T, int F) {
	if (dice.east == F || dice.west == F) E();
	while (dice.south != F) N();
	while (dice.top != T) W();
}

int main() {
	int nums[6];
	int q,question[25][2];
	for (int i = 0; i < 6; i++) {
		scanf("%d", &nums[i]);
	}
	dice.top = nums[0]; dice.south = nums[1]; dice.east = nums[2];
	dice.west = nums[3]; dice.north = nums[4]; dice.bottom = nums[5];
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d", &question[i][0], &question[i][1]);
		Roll(question[i][0],question[i][1]);
		printf("%d\n", dice.east);
	}


	return 0;
}


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

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

  if (a > b) {
    cout << "a > b" << endl;
  } else if (a < b) {
    cout << "a < b" << endl;
  } else {
    cout << "a == b" << endl;
  }

  return 0;
}


Measured memory_bytes: 3084
from heapq import heappop, heappush

def prim(adjacent:list, root=0):
    n = len(adjacent)
    visited = [False] * n
    min_cost = 0
    q = [(0, root)]
    while q:
        weight, vi = heappop(q)
        if visited[vi]:
            continue
        visited[vi] = True
        min_cost += weight
        for vj, weight in adjacent[vi]:
            heappush(q, (weight, vj))
    return min_cost

n = int(input())
xordered = []
yordered = []
for i in range(n):
    x, y = map(int, input().split())
    xordered.append((x, y, i))
    yordered.append((y, x, i))
xordered.sort()
yordered.sort()

adjacent = [[] for _ in range(n)]
for i in range(n-1):
    x0, y0, v0 = xordered[i]
    x1, y1, v1 = xordered[i+1]
    weight = min(abs(x0-x1), abs(y0-y1))
    adjacent[v0].append((v1, weight))
    adjacent[v1].append((v0, weight))
    x0, y0, v0 = yordered[i]
    x1, y1, v1 = yordered[i+1]
    weight = min(abs(x0-x1), abs(y0-y1))
    adjacent[v0].append((v1, weight))
    adjacent[v1].append((v0, weight))

print(prim(adjacent))



Measured memory_bytes: 145744
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int edge[400010], nxt[400010], head[200010];
int ecnt = 0;

int fac[200010], facinv[200010];
int dp[200010], sz[200010];
int n, x, y;

inline int quickmul(int x, int y) {
    int ret = 1, mul = x;
    while (y) {
        if (y & 1) {
            ret = (LL)ret * mul % mod;
        }
        mul = (LL)mul * mul % mod;
        y >>= 1;
    }
    return ret;
}

inline void addedge(int x, int y) {
    ++ecnt;
    edge[ecnt] = y;
    nxt[ecnt] = head[x];
    head[x] = ecnt;
}

void dfs1(int u) {
    dp[u] = sz[u] = 1;
    for (int i = head[u]; i; i = nxt[i]) {
        int v = edge[i];
        if (!sz[v]) {
            dfs1(v);
            dp[u] = (LL)dp[u] * dp[v] % mod * facinv[sz[v]] % mod;
            sz[u] += sz[v];
        }
    }
    dp[u] = (LL)dp[u] * fac[sz[u] - 1] % mod;
}

void dfs2(int u) {
    for (int i = head[u]; i; i = nxt[i]) {
        int v = edge[i];
        if (sz[v] < sz[u]) {
            dp[v] = (LL)dp[u] * fac[n - sz[v] - 1] % mod * fac[sz[v]] % mod * facinv[sz[v] - 1] % mod * facinv[n - sz[v]] % mod;
            dfs2(v);
        }
    }
}

inline void work() {
    cin >> n;
    fac[0] = facinv[0] = 1;
    for (int i = 1; i <= n; ++i) {
        fac[i] = (LL)fac[i - 1] * i % mod;
        facinv[i] = quickmul(fac[i], mod - 2);
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> y;
        addedge(x, y);
        addedge(y, x);
    }
    dfs1(1);
    dfs2(1);
    for (int i = 1; i <= n; ++i) {
        cout << dp[i] << "\n";
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int M = 2200000;
const int md=1e9+7;
typedef long long ll;
int n,m,k;
int fac[M],inv[M];
void ini(){
    inv[0] = inv[1] = 1;
    fac[0] = fac[1] = 1;
    fo(i,2,M-1) {
        inv[i] = 1ll*(md-md/i)*inv[md%i]%md;
    }
    fo(i,2,M-1) {
        inv[i] = 1ll*inv[i-1]*inv[i]%md;
        fac[i] = 1ll*fac[i-1]*i%md;
    }
}
ll C(int a,int b) {
    if(b<0 || a<b) return 0;
    return 1ll*fac[a]*inv[a-b]%md*inv[b]%md;
}
ll f(int a,int b) {
    return C(a+b,a);
}
int main(){
    ini();
    int r1,r2,c1,c2;
    cin>>r1>>c1>>r2>>c2;
    ll ans=f(r1,c1);
    fo(i,r1+1,r2)
        ans=(ans+f(i,c2))%md;
    fo(i,c1+1,c2)
        ans=(ans+f(r2,i))%md;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(!(a[i]&1)){
            if((a[i]%3&&a[i]%5)){
               cout<<"DENIED"<<endl;
               return 0;
            }
        }
    }
    cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

ans = 0
if N < 3:
  print(0)
else:
  for i in range(N-2):
    for j in range(i+1, N-1):
      for k in range(j+1, N):
        if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
          continue
        if abs(L[i]-L[j]) < L[k] < L[i] + L[j]:
          ans += 1
  print(ans)

Measured memory_bytes: 9200
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n;
	cin>>n;
	if(n%2){
		rep(i, n){
			rep(j, n-1){
				int k = (i+j+1)%n+1;
				cout<<k<<(j==n-2?"\n":" ");
			}
		}
	} else {
		if(n==2){
			cout<<-1<<endl;
			return 0;
		}
		rep(i, n){
			rep(j, n-1){
				int j2 = j;
				if(j==0&&i<n/2) j2 = n/2-1;
				if(j==n/2-1&&(i<n/2)) j2 = 0;
				int k = (i+j2+1)%n+1;
				cout<<k<<(j==n-2?"\n":" ");
			}
		}
	}
	return 0;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	ll w, h, x, y;
	cin >> w >> h >> x >> y;
	double ans = w * h / 2.0;
	bool eq = (x*2==w) & (y*2==h);
	printf("%.16f ", ans);
	cout << eq << endl;
	return 0;
}

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

int main() {
  vector<int> row;
  vector<vector<int>> nums;
  bool err = false;
  int temp;
  for (int i=0; i<3; i++) {
    row.clear();
    for (int j=0; j<3; j++) {
      cin >> temp;
      row.push_back(temp);
    }
    nums.push_back(row);
  }
  for (int i=0; i<2; i++) {
    if (abs(nums[i][0]-nums[i+1][0])!=abs(nums[i][1]-nums[i+1][1]) || abs(nums[i][1]-nums[i+1][1])!=abs(nums[i][2]-nums[i+1][2])) err = true;
  }
  for (int i=0; i<2; i++) {
    if (abs(nums[0][i]-nums[0][i+1])!=abs(nums[1][i]-nums[1][i+1]) || abs(nums[1][i]-nums[1][i+1])!=abs(nums[2][i]-nums[2][i+1])) err = true;
  }
  if (err) cout << "No";
  else cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
  int main(){
      int a,b,k;
      cin >> k >> a >> b ;
      int m=(b/k);
      if(a<=m*k){
          cout << "OK" << endl;
      }
      else {
          cout << "NG" << endl;
      }
      return 0;
  }

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

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

    Graph G(n);
    vector<pair<int, int>> vp;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[b].emplace_back(a);
        G[a].emplace_back(b);
        vp.emplace_back(a, b);
    }

    int K = 0;
    map<pair<int, int>, int> I;
    vector<int> cs(n, 0);

    vector<int> used(n, 0);
    queue<int> que;
    used[0] = 1;
    que.emplace(0);

    while(!que.empty()) {
        int v = que.front();
        que.pop();
        if (K < (int)G[v].size()) K = G[v].size();
        int cur = 1;
        for (int u : G[v]) {
            if (used[u]) continue;
            if (cur == cs[v]) cur++;
            cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
            used[u] = 1;
            que.emplace(u);
        }
    }

    cout << K << endl;
    for (auto p : vp) cout << I[p] << endl;

    return 0;
}

Measured memory_bytes: 20084
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def df(n):
    if(n<2): return 1
    return n*df(n-2)

def resolve():
    n=int(input())

    # 奇数のときは 0
    if(n&1):
        print(0)
        return

    # n が小さいときは愚直にやる
    if(n<=100):
        x=df(n)
        ans=0
        while(x%10==0):
            ans+=1
            x//=10
        print(ans)
        return

    # そうでなければ n 偶数に対して 10 の倍数を調べる
    ans=0
    while(n):
        ans+=n//10
        n//=5
    print(ans)

resolve()

Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#define NOT_FOUND 0

int linearSearch(int,int);

int S[10001];
int T[501];

int main()
{
  int i,j;
  int n,q;
  int count=0;

  scanf("%d",&n);

  if(n > 10000)
    exit(1);

  for(i = 0; i<n; i++) 
    scanf("%d",&S[i]);

  scanf("%d",&q);

  if(q > 500)
    exit(2);

  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
    if(linearSearch(n,T[i]) != NOT_FOUND){
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}

int linearSearch(int n, int key)
{
  int i = 0;
  S[n] = key;
  while(S[i] != key){
    i++;
  }
  if( i == n)
    return 0;
  return 1;
}    
	
  



Measured memory_bytes: 2744