akhauriyash/Code-Regression huggingface dataset:
#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 int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
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;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

int gcd(int x,int y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
	return (x * y / gcd(x, y));
}

signed main(){
	string s,t="ABC";
	int N;in(N,s);
	int ans = 0;
	REP(i,s.size()-t.size()+1){
		if(s.substr(i,3)==t)ans++;
	}
	out(ans);
	/*
	int N,M;
	in(N,M);
	auto a = mv(N);
	in(a);
	int mi = *min_element(ALL(a));
	int g = 1;
	REP(i,N)g = lcm(g,a[i]);
	int ans = M/(g/2)-M/g;
	int NG = 0.5*mi;
	NG--;
	ans -= NG/(g/2)-NG/g;
	out(ans);*/
}

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

int main(){
	int n;
	cin >> n;
	if(n>=195) cout << 5 << endl;
	else if(n>=189) cout << 4 << endl;
	else if(n>=165) cout << 3 << endl;
	else if(n>=135) cout << 2 << endl;
	else if(n>=105) cout << 1 << endl;
	else cout << 0 << endl;
}

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

//このように絞った方が良いかも
//import java.io.Closeable;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.PrintWriter;
//import java.util.NoSuchElementException;
//import java.util.Scanner;


/**
 * Base_version with PrintWriter and FastScanner
 */ 
 
class Main { 
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();//Scanner→FastScanner, Delete(System.in)
      	int x = sc.nextInt();//longをintに戻した
      	int t = sc.nextInt();//longをintに戻した
      	PrintWriter out = new PrintWriter(System.out);
        out.println(Math.max(x - t, 0));
      	out.flush();
    }
}

//add 
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long  getKey(char str[]){
    long long sum =0,p=1, i;
    for(i = 0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    return key % M;
}

int h2(int key){
    return 1+(key % (M-1));
}

int find(char str[]){
    long long key,i,h;
    key = getKey(str);
    for(i = 0;; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key,i,h;
    key = getKey(str);
    for(i = 0;; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}


int main(){
    int i, n, h;
    char str[L], com[9];
    for(i = 0; i < M;i++) H[i][0] = '\0';
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%s %s", com, str);

        if(com[0] == 'i'){
            insert(str);
        } else {
            if( find(str)){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


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

int main(){
    long long n, k, sum=0;
    cin >> n >> k;
    vector<long long> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    sort(h.begin(), h.end());
    for(int i=0; i<=n-k-1; i++){
        sum += h[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

char c ;

bool isalpha ( ) ;

int main ( )
{
	while ( 1 ) {
		c = getchar ( ) ;
		if ( c == EOF ) break ;
		if ( isalpha ( ) ) {
			c -= ( 'a' - 'A' ) ;
		}
		putchar ( c ) ;
	}
	return 0 ;
}

bool isalpha ( )
{
	return ( c >= 'a' && c <= 'z' ) ;
}

Measured memory_bytes: 892
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

typedef long long LL;

#define MAXN 200010

int n, k, l;
int f1[MAXN], f2[MAXN];
map<pair<int, int> , int> m;

int Find(int *f, int u)
{
    return f[u] ? f[u] = Find(f, f[u]) : u;
}

void Init()
{
    int i, u, v, fu, fv;
    scanf("%d %d %d", &n, &k, &l);
    for(i = 1; i <= k; ++i){
        scanf("%d %d", &u, &v);
        fu = Find(f1, u);
        fv = Find(f1, v);
        if(fu == fv) continue;
        f1[fv] = fu;
    }
    for(i = 1; i <= l; ++i){
        scanf("%d %d", &u, &v);
        fu = Find(f2, u);
        fv = Find(f2, v);
        if(fu == fv) continue;
        f2[fv] = fu;
    }
}

void Work()
{
    int i;
    for(i = 1; i <= n; ++i){
        ++m[{Find(f1, i), Find(f2, i)}];
    }
    for(i = 1; i < n; ++i){
        printf("%d ", m[{Find(f1, i), Find(f2, i)}]);
    }
    printf("%d\n", m[{Find(f1, i), Find(f2, i)}]);
}

int main()
{
    Init();
    Work();
    return 0;
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int mod = 1000000007;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, a, b;
    cin >> n >> a >> b;
    mint ans = mint(2).pow(n) - 1;
    for (auto k : vi{a, b}) {
        mint comb = 1;
        mint div = 1;
        for (int i = 0; i < k; ++i) comb *= (n-i);
        for (int i = 1; i <= k; ++i) div *= i;
        comb /= div;
        ans -= comb;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []
c = []
for i in range(n):
    if  i % 2 == 1:
        b.append(a[i])
    else:
        c.append(a[i])
if n % 2 == 0:
    b.reverse()
    ans = b + c
else:
    c.reverse()
    ans = c + b
print(' '.join(map(str,ans)))

Measured memory_bytes: 31300
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int q[N];
#define f(i,a,b) for(int i=a;i<b;i++)
#define read(x)  scanf("%d",&x)
int main(){
	double n;
	scanf("%lf",&n);
double a=100;
if(a>=n){printf("0");
return 0;}
for(int i=1;i<=1e8;i++){
	a*=1.01;
	long long  b=a;
	a=b;
	if(a>=n){
			printf("%d",i);
	return 0;
	}
}
return 0;
}


Measured memory_bytes: 3816
X = int(input())

for A in range(1000):
    A5 = A**5
    for B in range(1000):
        B5 = B**5
        if A5 - B5 == X:
            print(A, B)
            exit()
        elif A5 + B5 == X:
            print(A, -B)
            exit()
        else:
            continue

Measured memory_bytes: 63704
N,M=gets.split.map(&:to_i)
P=[]
for i in 1..M
	P<<gets.split.map(&:to_i)
end
Q=Array.new(N).map{[]}
P.each{|e|
	Q[e[0]-1]<<e
}
Q.each{|e|
	e.sort_by!{|f|f[1]}
	e.each_with_index{|f,i|f<<i}
}
P.each{|e|
	puts ("%06d"%e[0].to_s)+("%06d"%(e[2]+1).to_s)
}

Measured memory_bytes: 24752
#include <bits/stdc++.h>
using namespace std;
int N, A[2];
inline int Check(int x, int dir)
{
	dir = dir ? 1 : -1;
	if (A[x] + dir == 0 || A[x] + dir == N + 1 || A[x] + dir == A[x ^ 1]) return 0;
	return 1;
}
int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	scanf("%d%d%d", &N, &A[0], &A[1]);
	/*
	if (A[0] == 1 && A[1] == 2)
	{
		cout<<"Borys"<<endl;
		return 0;
	}
	*/
	int fl = 0;
	while (1)
	{
		//cout<<A[0]<<" "<<A[1]<<endl;
		if (Check(fl, A[fl ^ 1] > A[fl]))
			A[fl] += (A[fl ^ 1] > A[fl]) ? 1 : -1;
		else if (Check(fl, ((A[fl ^ 1] > A[fl]) ^ 1)))
			A[fl] += (A[fl ^ 1] > A[fl]) ? -1 : 1;
		else 
		{
			if (!fl) cout<<"Borys"<<endl;
			else cout<<"Alice"<<endl;
			return 0;
		}
		fl ^= 1;
	}
	return 0;
}

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

ll dp[3030][3030][3];
ll A[3030];

void add(ll& a, ll b) { (a += b) %= mod; }

int main() {
    int N, S; cin >> N >> S;
    rep(i,N) cin >> A[i];
    dp[0][0][0] = 1;
    rep(i,N) {
        rep(j,S+1) {
            add(dp[i+1][j][0], dp[i][j][0]);
            add(dp[i+1][j][1], dp[i][j][0]+dp[i][j][1]);
            add(dp[i+1][j][2], dp[i][j][0]+dp[i][j][1]+dp[i][j][2]);
            if(j+A[i] > S) continue;
            add(dp[i+1][j+A[i]][1], dp[i][j][0]+dp[i][j][1]);
            add(dp[i+1][j+A[i]][2], dp[i][j][0]+dp[i][j][1]);
        }
    }
    cout << dp[N][S][2] << endl;
    return 0;
}


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

int main(void) {
  int X, N;
  cin >> X >> N;
  set<int> p;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    p.insert(tmp);
  }
  int ans = X;
  int diff = 10000;
  for (int i = 101; i >= 0; i--) {
    if (p.find(i) != p.end()) continue;
    if (abs(X - i) <= diff) {
      ans = i;
      diff = abs(X - i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val (n, m) = readListInt()
    var a = readListLong().sorted().toMutableList()
    var list = mutableListOf<Pair<Int, Long>>()
    repeat(m) {
        var (b, c) = readListLong()
        list.add(b.toInt() to c)
    }
    val calcList = list.sortedByDescending {
        it.second
    }
    var idx = 0
    calcList.forEach { p ->
        repeat(p.first) {
            if (idx > a.size - 1 || a[idx] > p.second) return@forEach
            a[idx] = p.second
            idx++
        }
    }
    println(a.sum())


}


private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 101004
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int n;cin>>n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	ll x = a[0];
	ll ans = 0;
	for(int i = 1; i < n; i++) {
		if (x > a[i]){
			ans += x - a[i];
		}
		else{
			x = a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
    // 配列の最大値を取得
    int max = *max_element(vec.begin(), vec.end());
    // 配列の最大値のイテレータを取得
    vector<int>::iterator maxIt = max_element(vec.begin(), vec.end());
    // 配列の最大値までの距離を取得
    int maxIndex = distance(vec.begin(), maxIt);
    // 隣り合う重複要素を削除し、末尾のゴミを削除
    // (uniqueは、重複を取り除いた範囲の末尾の次を指すイテレータを返す)
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
*/

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

    if (d == 25) cout << "Christmas";
    else if (d == 24) cout << "Christmas Eve";
    else if (d == 23) cout << "Christmas Eve Eve";
    else cout << "Christmas Eve Eve Eve";

    cout << endl;
}




Measured memory_bytes: 256
//	Totally unrelated and not AT ALL stolen from hohohaha's, generic_placeholder_name's or katoriyuu's template
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define rep(i,s,end) for(int i = (s); i <  (end); ++i)
#define rep0(i, end) for(int i =   0; i <= (end); ++i)
#define rep1(i, end) for(int i =   1; i <= (end); ++i)
#define lb lower_bound
#define ub upper_bound

#define vt vector
#define endl "\n"

#define fileopen(filename, in_type, out_type) if (fopen(filename in_type, "r")) {freopen(filename in_type, "r", stdin);freopen(filename out_type, "w", stdout);}
#define local_input(x) if (x && fopen("input.txt","r")) freopen("input.txt","r",stdin);
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fscan(x)   scanf("%d",  &x)
#define fscandb(x) scanf("%lf", &x)
#define fscanll(x) scanf("%lld",&x)
//	Until next time, remember:
//			You are closer than you think.
//						_Dan Lok_

#define db double
#define ll long long
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define pi 3.1415926535897932	//faster than pi = acos(-1); but sometimes doesn't work?
//	srand(chrono::steady_clock::now().time_since_epoch().count());
//	freopen("input.txt","r",stdin);

#define lnode id<<1
#define rnode id<<1|1
#define mn 100002

int a[2][mn];
void input(const int& o){
	string s; cin >> s; a[o][0] = 0; rep(i,0,s.length()){
		a[o][i+1] = a[o][i] + (s[i] == 'A' ? 2 : 1);
	}
	return;
}
signed main()
{
	fastio;
	input(0); input(1); int q; cin >> q; while(q--){
		int l,r,l1,r1; cin >> l >> r >> l1 >> r1;
		cout << ((a[0][r]-a[0][l-1]) % 3 != (a[1][r1]-a[1][l1-1]) % 3 
		? "NO\n" : "YES\n");
	}
	return 0;
}
// with the aura of Dora, AC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Why is there a one in my row of exclamation marks?




Measured memory_bytes: 4540
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
pair <int, int> a[N];
int f[2][N];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, t;
	cin >> n >> t;
	for (int i = 1; i <= n; ++i)
		cin >> a[i].first >> a[i].second;
	sort(a + 1, a + 1 + n);
	int m = 0, ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		int cur = i % 2, lst = 1 - cur;
		memset(f[cur], 0, sizeof(f[cur]));
		ans = max(ans, m + a[i].second);
		for (int j = 0; j < a[i].first; ++j)
			f[cur][j] = f[lst][j];
		for (int j = a[i].first; j < t; ++j)
		{
			f[cur][j] = max(f[lst][j], f[lst][j - a[i].first] + a[i].second);
			m = max(m, f[cur][j]);
			ans = max(ans, f[cur][j]);
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof i);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) (x&-x)
#define siz(v) (long long)v.size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

int main() {
    EmiliaMyWife

    ll a, b, g, n, x=1, y=1;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        g=__gcd(a, b);
        a/=g;
        b/=g;
        x=a*max(x/a+!!(x%a), y/b+!!(y%b));
        y=b*max(x/a+!!(x%a), y/b+!!(y%b));
    }
    cout << (x+y);

	return 0;
}


Measured memory_bytes: 256
//AnkitCode99 here....
#include<bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)
using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
	fast;
   

	ll h,a;
	cin>>h>>a;
	cout<<ceil(h,a);
}
//Goodbye...

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<limits.h>

using namespace std;


int main()
{
  int low=INT_MAX;
  int high=INT_MIN;
  int n,i;
  scanf("%d",&n);
  int p[n];
  for(i=0;i<n;i++)
  {
      scanf("%d",&p[i]);
      if(low>p[i])
        low=p[i];
      if(high<p[i])
        high=p[i];
  }
  printf("%d\n",high-low);
    return 0;
}


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;  
  int ans = 0;
  for(int i=0, cur; i<n; i++){
    cin >> cur;
    if(cur >= k) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  intll n , m ;
  cin >> n >> m ;
  intll ans = 0;
  
  ans += min(n,m/2);
  m -= 2*ans;
  ans += m/4;
  
  cout << ans ;


}


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

int kugyu(const void* tomatuharuka, const void* igutiyuka) {
	int hayamisaori = *(const int*)tomatuharuka, hanazawakana = *(const int*)igutiyuka;
	return hayamisaori < hanazawakana ? -1 : hayamisaori > hanazawakana;
}

int N;
int A[114514];
int B[114514];
int C[114514];

/* target以下の要素数を求める */
int mizuhasu(const int data[], int N, int target) {
	int le = 0, greater = N - 1;
	if (data[0] > target) return 0;
	if (data[N - 1] <= target) return N;
	while (le + 1 < greater) {
		int mid = le + (greater - le) / 2;
		if (data[mid] <= target) le = mid; else greater = mid;
	}
	return le + 1;
}

int64_t asumisu[114514];

int main(void) {
	int i;
	int64_t mareitaso = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%d", &B[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%d", &C[i]) != 1) return 1;
	}
	qsort(A, N, sizeof(*A), kugyu);
	qsort(B, N, sizeof(*B), kugyu);
	qsort(C, N, sizeof(*C), kugyu);

	for (i = 0; i < N; i++) {
		int mikakosi = mizuhasu(C, N, B[i]);
		asumisu[i] = N - mikakosi;
	}
	asumisu[N] = 0; /* 使えるパーツBがそもそも無い */

	/* k個目のパーツBが使えるなら、k+1個目以降も使える */
	for (i = N - 1; i > 0; i--) {
		asumisu[i - 1] += asumisu[i];
	}

	for (i = 0; i < N; i++) {
		int satorina = mizuhasu(B, N, A[i]);
		/* Bの最初satorina個がA[i]以下 → satorina個目(0-origin)以降が使える */
		mareitaso += asumisu[satorina];
	}

	printf("%" PRId64 "\n", mareitaso);
	return 0;
}


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt = 0;
    for(int i=0; i<=a; i++){
    	for(int j=0; j<=b; j++){
    		for(int k=0; k<=c; k++){
    			if(500*i + 100*j + k*50 == x)cnt++;
    		}
    	}
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3700
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

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

int main()
{
	string S;

	cin >> S;

	ll ans = 0;
	ll count = 0;
	for (int j = 0; j < S.size(); ++j)
	{
		if (S[j] == 'B')
		{
			++count;
		}
		else
		{
			ans += count;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3712
import math
n = int(input())
ans = 0
if n > 104:
    for i in range(105,n+1)[::2]:
        cnt = 0
        for j in range(1,math.ceil(i**0.5)):
            if i%j == 0:
                cnt += 2
            if j**2 == i:
                cnt -= 1
        if cnt == 8:
            ans += 1
print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

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

    int sum = a * b;
    if(sum % 2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <utility>
#include <string>
#include <queue>

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

typedef long long ll;

using namespace std;

void solve(){
    string s;
    int n;
    
    cin >> s;
    cin >> n;

    rep(i, n){
        string q;
        cin >> q;

        if(q == "replace"){
            int x, y;
            string ss;
            cin >> x >> y >> ss;
            s.replace(x, y-x+1, ss);
        }else if(q == "reverse"){
            int x, y;
            cin >> x >> y;
            reverse(s.begin()+x, s.begin()+y+1);
        }else if(q == "print"){
            int x, y;
            cin >> x >> y;
            cout << s.substr(x, y-x+1) << endl;
        }
    }
}

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


Measured memory_bytes: 3264
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	int[] ary = new int[N];
      	boolean hasOdd = false;
      
      	for(int i = 0; i < N; i++) {
        	ary[i] = sc.nextInt();
          	if(ary[i] %2 == 1) hasOdd = true;
        }
      	if(hasOdd) {
        	System.out.println(0);  
        } else {
          	int min = Integer.MAX_VALUE;
			for(int i : ary) {
              	int count = 0;
           		while(i %2 == 0) {
                	i /= 2;
                  	count++;
                }
              	if(count < min) min = count;
            }
          	System.out.println(min);
        }
    }
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    long long n = S.size();
    long long ans = n * (n - 1) / 2 + 1;
    vector<long long> freq(26, 0);
    for (char c : S) ++freq[int(c - 'a')];
    for (auto f : freq){
        ans -= f * (f - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 720
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    Node[] nodes = new Node[n + 1];
    for (int i = 0; i < n; i++) {
      nodes[i + 1] = new Node(i + 1, Integer.parseInt(sc.next()));
    }
    for (int j = 0; j < m; j++) {
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      nodes[a].addOther(nodes[b].h);
      nodes[b].addOther(nodes[a].h);
    }
    int ans = 0;
    for (int i = 1; i < n + 1; i++) {
      if (nodes[i].isGood()) {
        ans++;
      }
    }
    pw.println(ans);
  }

  static class Node {

    int i;
    int h;
    int otherH = 0;

    public Node(int i, int h) {
      this.i = i;
      this.h = h;
    }

    void addOther(int otherH) {
      this.otherH = Math.max(this.otherH, otherH);
    }

    boolean isGood() {
      return h > otherH;
    }
  }
}


Measured memory_bytes: 62436
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#define pie 3.141592653589793238
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> sunuke(n);
  
  for(int i=0; i<k; i++){
    int d;
    cin >> d;
    for(int j=0; j<d; j++){
      int temp;
      cin >> temp;
      sunuke[temp-1]++;
    }
  }
  
  int count=0;
  for(int i=0; i<n; i++){
    if(sunuke[i]==0) count++;
  }
  
  cout << count << endl;
  
  return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int cnt[300005];
vector<int> target[300005];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w, m;
    cin >> h >> w >> m;
    for (int i=0; i<m; i++) {
        int hi, wi;
        cin >> hi >> wi;
        target[wi].push_back(hi);
        cnt[hi]++;
    }

    multiset<int> st;
    for (int i=1; i<=h; i++)
        st.insert(cnt[i]);

    int ret = 0;
    for (int i=1; i<=w; i++) {
        for (int j : target[i]) {
            st.erase(st.find(cnt[j]));
            st.insert(cnt[j] - 1);
        }
        ret = max(ret, (int) target[i].size() + *st.rbegin());
        for (int j : target[i]) {
            st.erase(st.find(cnt[j] - 1));
            st.insert(cnt[j]);
        }
    }

    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 35288
#coding: UTF-8
N=int(input())
L=list(map(int,input().split()))
print(' '.join(map(str,L)))
for i in range(1,N):
    v=L[i]
    j=i-1
    while j>=0 and L[j]>v:
        L[j+1]=L[j]
        j-=1
    L[j+1]=v
    print(' '.join(map(str,L)))

Measured memory_bytes: 7664
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

int n, a, b, c, d, q, ans;

int main() {
	INIT
	string s;
	cin >> s;
	string s1 = s, s2 = s;
	if (s1[0] == '0') s1[0] ='1';
	else s1[0] = '0';
	++a;
	for (int i = 1;i < s.size(); ++i) {
		if (s1[i] == s1[i - 1]) {
			if (s1[i] == '0') s1[i] ='1';
			else s1[i] = '0';
			++a;
		}
	}
	for (int i = 1;i < s.size(); ++i) {
		if (s2[i] == s2[i - 1]) {
			if (s2[i] == '0') s2[i] ='1';
			else s2[i] = '0';
			++b;
		}
	}
	cout << min(a, b);
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	vector<int>h(n);
	for(int i=0;i<n;i++) cin>>h[i];
	vector<int> dp(n);
	dp[1]=abs(h[0]-h[1]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp.back()<<endl;


	return 0;
}

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

int main() {
    int n,k;
    cin>>n>>k;
    int a[n],dp[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i<=k)
            dp[i]=abs(a[i]-a[0]);
        else
            dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i+j>=n)
                break;
            dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
        }
    }
    cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 4384
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

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

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

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

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

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

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

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  char a,b; cin>>a>>b;
  if(a==b) COUT("=");
  else if(a<b) COUT("<");
  else COUT(">");
}













Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    char c;
    int suu[26]= {0},i,j;
     
    while(scanf("%c", &c) != EOF){
        for (j=0; j<26; j++){
            if(c == 'a'+j || c == 'A'+j){
                suu[j]++;
            }
        }
    }
    for(i=0; i<26; i++){
        printf("%c : %d\n", 'a'+i, suu[i]);
    }
     
    return 0;
}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
//int choose2(ll x){
	//	return x*(x-1)/2;}
const int INF = 1001001001;

int main() {
	ll R;
		cin >> R;
		cout << 6.28318530717958623200* R;
	
}

Measured memory_bytes: 3784
n = int(input())

s = []

for i in range(n):
    s.append(input()*2)

ans = 0

for i in range(n):
    flag = True
    for j in range(n):
        for k in range(n):
            if s[j][k+i]!=s[k][j+i]:
                flag = False
                break
        if not flag:
            break
    if flag:
        ans += n

print(ans)

Measured memory_bytes: 43340
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main()
{
  int x, n, a;
  cin >> x >> n;
  map<string, int> p;
  rep(i, n)
  {
    cin >> a;
    p[to_string(a)] = 1;
  }
  if (p[to_string(x)] == 0)
  {
    cout << x;
    return 0;
  }
  rep(i, 101)
  {
    if (p[to_string(x - i)] == 0)
    {
      cout << x - i;
      return 0;
    }
    if (p[to_string(x + i)] == 0)
    {
      cout << x + i;
      return 0;
    }
  }
}


Measured memory_bytes: 3672
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin). unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    
    let s = get().to_string();
    
    println!("{}", s.replace("2017", "2018"));
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    for (int j = 0; j < q; ++j) {
        int k;
        cin >> k;
        cout << (binary_search(a.begin(), a.end(), k) ? 1 : 0) << endl;
    }
}


Measured memory_bytes: 3112
def bfs(s: str, n: int, i: int, j: int, k: int):
    return k+int(s[j:]) if i==n-1 else bfs(s,n,i+1,i+1,k+int(s[j:i+1]))+bfs(s,n,i+1,j,k)

s=input()
n=len(s)
print(bfs(s,n,0,0,0))

Measured memory_bytes: 9132
#include <stdio.h>
#define MAX 10000

typedef struct{
	int parent;
	int left;
	int right; }Node;

Node Tree[MAX];
int n;

void preParse(int u){
    if ( u == -1) return;
        printf(" %d", u);
        preParse(Tree[u].left);
        preParse(Tree[u].right);
}

void inParse(int u){
    if ( u == -1) return;
        inParse(Tree[u].left);
        printf(" %d", u);
        inParse(Tree[u].right);
}

void postParse(int u){
    if ( u == -1) return;
        postParse(Tree[u].left);
        postParse(Tree[u].right);
        printf(" %d", u);
}

int main(void)
{
    int i, v, l, r, root;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        Tree[i].parent = -1;
    }

    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        Tree[v].left = l;
        Tree[v].right = r;
        if (l != -1 ) Tree[l].parent = v;
        if (r != -1 ) Tree[r].parent = v;
    }

    for (i = 0; i < n; i++){
        if (Tree[i].parent == -1) 
        root = i;
    }

    printf("Preorder\n");
    preParse(root); printf("\n");
    printf("Inorder\n");
    inParse(root); printf("\n");
    printf("Postorder\n");
    postParse(root); printf("\n");

    return 0;
}


Measured memory_bytes: 2096
n = int(input())
lr = [tuple(map(int, input().split())) for _ in range(n)]

left_sort = sorted(lr, key=lambda tup: tup[0])     # O(nlogn)

joy_from_left = [0]
min_right = float('inf')
max_left = 0
for l, r in left_sort:     # O(n)
    min_right = min(r, min_right)
    max_left = max(l, max_left)
    joy_from_left.append(max(0, min_right - max_left + 1))

joy_from_right = [0]
min_right = float('inf')
max_left = 0
for l, r in reversed(left_sort):       # O(n)
    min_right = min(r, min_right)
    max_left = max(l, max_left)
    joy_from_right.append(max(0, min_right - max_left + 1))

joy_pair = max(l+r for l, r in zip(joy_from_left, reversed(joy_from_right)))        # O(n)


longest = max(left_sort, key=lambda tup: tup[1]-tup[0])     # O(n)
longest_joy = longest[1] - longest[0] + 1

removed = list(filter(lambda tup: tup!=longest, left_sort))     # O(n)
min_right = min(r for _, r in removed)
max_left = max(l for l, _ in removed)
except_longest_joy = max(0, min_right - max_left + 1)

print(max(joy_pair, longest_joy + except_longest_joy))    # O(nlogn) + O(n) = O(nlogn)


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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int mod = 1e9 + 7;
const int N = 600001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int n, m, jc[N], inv[N];

int add(int x, int y) {x += y; return x >= mod ? x - mod : x;}
int dec(int x, int y) {x -= y; return x < 0 ? x + mod : x;}
int C(int n, int m) {return (LL)jc[n] * inv[m] % mod * inv[n - m] % mod;}
int pow_mod(int a, int k) {int ans = 1; for(; k; k >>= 1, a = (LL)a * a % mod) if(k & 1) ans = (LL)ans * a % mod; return ans;}

int gt(LL S, int rr) {
	if(S < 0) return 0;
	int ans = 0;
	for(int i = 0, t = 0; i <= S && t <= n - m; i += rr, t++) {
		if(t & 1) ans = dec(ans, (LL)C(n - m, t) * C(n + S - i, n) % mod);
		else ans = add(ans, (LL)C(n - m, t) * C(n + S - i, n) % mod);
	} return (LL)ans * C(n, m) % mod;
}

int solve(int n, int S) {
	int ans = C(n + S, n);
	for(int i = 1; i <= S; i++) ans = dec(ans, dec(gt(S - (LL)m * i, i), gt(S - (LL)m * (i + 1), i)));
	return ans;
}

int main() {
	n = read(), m = read(); int l = read(), r = read();
	jc[0] = 1; for(int i = 1; i <= n + r; i++) jc[i] = (LL)jc[i - 1] * i % mod;
	inv[n + r] = pow_mod(jc[n + r], mod - 2); for(int i = n + r; i >= 1; i--) inv[i - 1] = (LL)inv[i] * i % mod;
	put(dec(solve(n, r), solve(n, l - 1)));
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

//-----CODE------//
void solve(void)
{ 
  int N,M,V,P;
  cin>>N>>M>>V>>P;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  sort(ALL(vec));
  reverse(ALL(vec));
  int L = 0, R = N;
  while(R - L > 1)
  {

    int mid = (L+R)/2;

    int VOTE = M*V;
    int check = 0;
    if(mid <= P -1)check = 1;

    int TH = vec[mid] + M;

    VOTE -=M;
    VOTE -= M*(N-1 - mid);
    VOTE -=(P-1)*M;
    for (int i = P-1; i < mid; i++)
    {
      VOTE -= TH  - vec[i];
    }
    if(VOTE <= 0)check = 1;
    if(TH < vec[P-1])check = 0;
    if(check)
    {
      L = mid;
    }
    else
    {
      R=mid;
    }
    
    
    
  }
  cout<<L+1<<endl;
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int v = sc.nextInt();
        int e = sc.nextInt();
        int s = sc.nextInt();
        int[][] edge = new int[e][3];
        for (int i = 0; i < e; i++) {
            edge[i][0] = sc.nextInt();
            edge[i][1] = sc.nextInt();
            edge[i][2] = sc.nextInt();
        }
        long[] ans = bellmanFord(v, edge, s);
        if(ans == null) System.out.println("NEGATIVE CYCLE");
        else for(long a : ans){
            if(a == Long.MAX_VALUE) System.out.println("INF");
            else System.out.println(a);
        }

        sc.close();

    }
    public static long[] bellmanFord(int n, int[][] edge, int s){
        long d[] = new long[n];
        Arrays.fill(d, Long.MAX_VALUE);
        d[s] = 0;
        for (int i = 0; i < n; i++) {
            for(int j = 0; j < edge.length; j++){
                int[] e = edge[j];
                if(d[e[0]] != Long.MAX_VALUE && d[e[1]] > d[e[0]] + e[2]){
                    d[e[1]] = d[e[0]] + e[2];
                    if(i == n - 1){
                        d = null;
                        break;
                    }
                }
            }
        }
        return d;
    }

}



Measured memory_bytes: 37072