akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string a, b, c;
  cin >> a >> b >> c;
  
  map<char, string> s = {{'a', a}, {'b', b}, {'c', c}};
  char nex = 'a';
  char cur;
  while (true) {
    if (s[nex].empty()) {
      printf("%c\n", toupper(nex));
      return 0;
    }
    cur = nex;
    nex = s[cur][0];
    s[cur] = s[cur].substr(1);
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.time.Year;
import java.util.Random;
import java.math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        long n = sc.nextInt();
        long d = sc.nextInt();
        long x = 0;
        long y = 0;
        long d2=d*d;
        long a = 0;
        int bigger = 0;
        int smaller = 0;
        while(true){
            x = sc.nextInt();
            y = sc.nextInt();
            a=(Math.abs(x)*Math.abs(x) + Math.abs(y)*Math.abs(y)); 
            if(a > d2){
                bigger++;
            }else{
                smaller++;
            }
            if(bigger+smaller >= n){
                System.out.println(smaller);
                break;
            }
        }
    }
}
     

Measured memory_bytes: 59128
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int c[3][3];
int main(){
    for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j){
        cin >> c[i][j];
    }

    bool ok = true;
    for(int i = 0; i < 2; ++i){
        int p = c[i+1][0] - c[i][0];
        for(int j = 1; j < 3; ++j){
            if(p != c[i+1][j] - c[i][j]) ok = false;
        }
    }
    for(int i = 0; i < 2; ++i){
        int p = c[0][i+1] - c[0][i];
        for(int j = 1; j < 3; ++j){
            if(p != c[j][i+1] - c[j][i]) ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {
  int k, s;
  cin >> k >> s;
  long ans = 0;
  rep(i, k+1){
    rep(j, k+1){
      if ( 0 <= s-i-j & s-i-j <=k) ans++;
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

int main() {
    int a,b;
    string s;
    cin >> a >> b >> s;
    bool flag = true;
    rep(i,a) if(s[i] == '-') flag = false;
    if(s[a] != '-') flag = false;
    rep2(i,a+1,a+b+1) if(s[i] == '-') flag = false;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n=input()
length = len(n)
x = n[0]

# 10のくらいがｘ未満の場合はｘのゾロ目でよい
if n[1] < x:
    x = x*length
# 10の位がxより大きい場合はx+1のゾロ目
elif n[1] > x:
    x = str(int(x) + 1)*length
# 10の位がxと同じ場合は1の位を調べる
else:
    # 1に位がx未満ならばのゾロ目
    if n[2] < x:
        x = x *length
    # 1の位がxより大きい場合はx+1のゾロ目
    elif n[2] > x:
        x = str(int(x)+1)*length

    else:
        x = x * length
# 999の場合は別処理
if int(n) == 999:
    x = '999'

print(x)
        
        


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll mp(ll a,ll b){
ll res=1;
while(b){
if(b&1) { res=(res*a)%mod; }
a=(a*a)%mod;
b>>=1;
}
return res;
}
int main(){
ll n; cin>>n;
ll f=(mp(10,n)-(2*mp(9,n))%mod+mp(8,n)+mod)%mod;
cout<<f<<'\n';
return 0;
}


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

int main() {
	int a[26] = {}, i;
	char c;
	while (cin.get(c)) {
		if (c == 'EOF')break;
		else if ('a' <= c && c <= 'z')a[c - 'a']++;
		else if ('A' <= c && c <= 'Z')a[c - 'A']++;
		}
	for (i = 0; i < 26; i++) {
		c = 'a' + i;
		cout << c << " : " << a[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1132
fun main(arr:Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    for(i in (0 until h)) {
        for(j in (0 until w)) {
            if(map[i][j] != '#') {
                continue
            }
            var canPaint = false
            for(k in (i-1..i+1)) {
                if(k < 0 || k >= h) {
                    continue
                }
                for(l in (j-1..j+1)) {
                    if(l < 0 || l >= w) {
                        continue
                    }
                    if(i==k && j == l) {
                        continue
                    }
                    if(i != k && j != l) {
                        continue
                    }
                    if(map[k][l] == '#') {
                        canPaint  = true
                        break
                    }
                }
                if(canPaint) {
                    break
                }
            }
            if(!canPaint) {
                println("No")
                return
            }
        }
    }
    println("Yes")
}


Measured memory_bytes: 37868
#include<iostream>
#include<algorithm>

using namespace std;

int N;
int x[100], y[100], h[100];

bool isok(int cx, int cy, int ch) {
	for (int i = 0; i < N; i++) {
		if (h[i] != max(0, ch - abs(x[i] - cx) - abs(y[i] - cy)))
			return false;
	}
	return true;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> x[i] >> y[i] >> h[i];

	int minh = *min_element(h, h + N);
	for (int X = 0; X <= 100; X++) {
		for (int Y = 0; Y <= 100; Y++) {
			for (int ht = 0; ht <= 200; ht++) {
				if (isok(X, Y, minh + ht)) {
					cout << X << " " << Y << " " << minh + ht << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string S;
  int L,K;
  cin>>K;
  cin>>S;
  char ch;
  L=S.length();
  if (L<=K)
  {cout<<S<<"";}
  else
  {for(int i=0;i<=(K-1);i++)
  {ch=S.at(i);
  cout<<ch;}
  cout<<"...";}
  return 0;

  }

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    long long a,b,n;
    scanf("%lld%lld%lld",&a,&b,&n);
    if (b <= a){
        ll ans = 0;
        for (ll i = 0; i <= min(b,n); i++){
            ans = max(ans,(a*i)/b - a*(i/b));
        }
        printf("%lld",ans);
        return 0;
    }
    ll ans = 0;
    for (ll i = 0; i < a; i++){
        if (i*b <= n*a){
            ans = max(ans,i);
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 3756
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map>  
#include<stack>
using namespace std;

string str, str1, str2;
int main()
{
	cin >> str;
	cin >> str1;
	cin >> str2;
	string a, b, c;
	a = str[0]-'a'+'A';
	b = str1[0]-'a'+'A';
	c = str2[0]-'a'+'A';
	cout << a << b << c << endl;
}

Measured memory_bytes: 256
int main()
{
	int s,k,c,r;
	scanf("%d%d",&s,&k);
	for(;k--;printf("%d\n",c<r?c%3+1:r%3+1))
	{
		scanf("%d%d",&c,&r);
		c=c<=s/2+s%2?c-1:s-c;
		r=r<=s/2+s%2?r-1:s-r;
	}
	return 0;
}

Measured memory_bytes: 596
#define _CRT_SECURE_NO_WARNINGS
#define lp(i,n) for(int i=0;i<n;i++)
#include<bits/stdc++.h>


using namespace std;
int main() {
	int n;
	cin >> n;
	if (n <= 999)
		cout << "ABC" << endl;
	else
		cout << "ABD" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 3005
#define ll long long
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int n, mod, fac[N], inv[N], S[N][N];
int Pow(int a, int k, int m)
{
	if (!k)
		return 1;
	int p = Pow(a, k / 2, m);
	if (k & 1)
		return (ll)p * p % m * a % m;
	return (ll)p * p % m;
}
int C(int n, int m)
{
	if (n < m)return 0;
	if (m < 0)return 0;
	return (ll)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main()
{
	Read(n), Read(mod);
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = (ll)fac[i - 1] * i % mod;
	inv[n] = Pow(fac[n], mod - 2, mod);
	for (int i = n; i >= 1; i--)
		inv[i - 1] = (ll)inv[i] * i % mod;
	S[0][0] = 1;
	for (int i = 1; i <= n + 1; i++)
		for (int j = 1; j <= i; j++)
			S[i][j] = (S[i - 1][j - 1] + (ll)j * S[i - 1][j]) % mod;
	int ans = 0;
	for (int i = 0; i <= n; i++)
	{
		int sum = 0;
		for (int x = 0; x <= i; x++)
			sum = (sum + (ll)Pow(Pow(2, n - i, mod), x, mod) * S[i + 1][x + 1] % mod) % mod;
		sum = (ll)sum * Pow(2, Pow(2, n - i, mod - 1), mod) % mod * C(n, i) % mod;
		if (i & 1)
			ans = (ans + mod - sum) % mod;
		else
			ans = (ans + sum) % mod;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 31244
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	cout<<a[n>>1]-a[(n>>1)-1]<<'\n';
}

Measured memory_bytes: 768
#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;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()


int main() {
    int R,G,B,N;
    cin >> R >> G >> B >> N;

    int ans=0;
    
    FOR(r,0,((N+R-1)/R)+1){
        FOR(g,0,((N+G-1)/G)+1){
            int rest = (N-R*r-G*g);
            if(rest<0)break;
            if(rest%B==0){
                ans++;
            }
        }
    }


    cout << ans << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define N 100005
using namespace std;

typedef long long ll;
ll n, m, ans, z, s[3], v[N];
vector<ll> a[N];
void f(ll p, ll q) {
	ll i;
	if (v[p] != 0 && q != v[p]) z = 1;
	if (v[p] != 0) return;
	v[p] = q;
	s[q]++;
	for (i = 0; i < a[p].size(); i++) {
		f(a[p][i], 3 - q);
	}
}

//ll g(ll p) {
//	if (p <= 2) return 0;
//	return p * (p - 1) / 2 - (p - 1);
//}
int main()
{
	ll i, t1, t2;
	cin >> n >> m;
	for (i = 0; i <m; i++) {
		scanf ("%lld %lld", &t1, &t2);
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	f(1, 1);
	if(z == 1) ans = n * (n - 1) / 2;
	else ans = s[1] * s[2];
	ans -= m;
//	ans += g(s[1]);
//	ans += g(s[2]);
	cout << ans << endl;
    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a-c) <= d || max(abs(a-b), abs(b-c)) <= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int N, Q, i, j ,l ,r;
  scanf("%d %d", &N, &Q);
  int acnum[N];
  char S[N];
  scanf("%s",S);
  acnum[0]=0;
  for(i=1; i<N; i++){
    if(S[i] == 'C' && S[i-1] == 'A') {
        acnum[i]=acnum[i-1]+1;
    }else{
        acnum[i]=acnum[i-1];
    }
  }
  for(i=0; i<Q; i++){
    scanf("%d %d", &l, &r);
    printf("%d\n", acnum[r-1] - acnum[l-1]);
  }
  
  return 0;
}

Measured memory_bytes: 1280
// 動的計画法
// knapsack

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int n_max = 100 + 5;
const ll v_max = 1e5 + 5;

int n,W,value;
ll w[n_max], v[n_max];

ll dp[n_max][v_max]; //[i][j]---i番目の品物の中で、価値の総和がj以下で最大の時の重さの最小値

int main() {
  cin >> n >> W;
  rep(i,n) {
    cin >> w[i] >> v[i];
    value += v[i];
  }
  rep(i,n+1) rep(j, value+1) dp[i][j] = INF;
  rep(i,n+1) dp[i][0] = 0;
  rep(i, n+1) {
    rep(j, value+1) {
      if(j >= v[i]) {
        dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]);
      } else dp[i+1][j] = dp[i][j];
    }
  }
  // cout << "[1:dp[1][30]] = " << 1 << " : " << dp[1][30] << endl;
  for (int i = value; i >= 0; i--) {

    if(dp[n][i] <= W) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 80128
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Unboxed as VU
import Control.Monad

powMod :: Int -> Int -> Int -> Int
powMod n k m
    | k == 0 = 1
    | odd k = (powMod n (k-1) m) * n `mod` m
    | otherwise = t * t `mod` m
        where
            t = powMod n (k `quot` 2) m

invModWithFermat :: Int -> Int -> Int
invModWithFermat a m = powMod a (m - 2) m

solve :: Int -> Int -> Int -> Int
solve n a b = (n' - (na * a' `mod` m) - (nb * b' `mod` m) - 1) `mod` m
    where
        m = 10 ^ 9 + 7
        n' = ((powMod 2 n m) + m) `mod` m
        a' = invModWithFermat (VU.foldl' (\acc x -> x * acc `mod` m) 1 $ VU.fromList [1..a]) m
        b' = invModWithFermat (VU.foldl' (\acc x -> x * acc `mod` m) 1 $ VU.fromList [1..b]) m
        na = VU.foldl' (\acc x -> x * acc `mod` m) 1 $ VU.fromList [n, n-1..n-a+1]
        nb = VU.foldl' (\acc x -> x * acc `mod` m) 1 $ VU.fromList [n, n-1..n-b+1]

main = do
    [n,a,b] <- map read . words <$> getLine :: IO [Int]
    print $ max 0 (solve n a b)


Measured memory_bytes: 892
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 0;
	if (*ci == '-') {
		pn = 1;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	if (pn) tmp = -tmp;
	return tmp;
}

ll A[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	rep1(i, N) {
		A[i] = getint() + A[i - 1];
	}

	pakuri_sort(N + 1, A);

	ll kotae = 0;
	int kazu = 1;
	rep(i, N) {
		if (A[i + 1] != A[i]) kazu = 1;
		else kotae += kazu++;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 4852
A,B,K = map(int,input().split())
ans = []
for i in range(A,A+K):
    if i <= B:
        ans.append(i)
for i in range(B-K+1,B+1):
    if not i in ans and A <= i:
        ans.append(i)
for i in ans:
    print(i)


Measured memory_bytes: 38256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize, v: usize, p: usize,
        mut a: [usize; n],
    }
    a.sort();
    a.reverse();
    let border = a[p-1];

    let mut ok = p-1;
    let mut ng = n;
    while ng > ok + 1 {
        let mid = (ok + ng) / 2;
        let score = a[mid] + m;
        if score < border {
            ng = mid;
            continue;
        }
        let upper_vote = m * (p - 1);
        let lower_vote = m * (n - mid - 1);
        let middle_vote = a[p-1..mid].iter().map(|&v| score - v).sum::<usize>();
        if m + upper_vote + lower_vote + middle_vote >= m * v {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok + 1);
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
const int mx=1e5+9;
const int mod=1e9+7;
vector<int>t[mx];
vector<vector<long long>>dp(mx,vector<long long>(2,-1));
//Black=1,white=0
long long solve(int parrent,int v,int col){
	if(dp[v][col]!=-1){return dp[v][col];}
	dp[v][col]=1;
	for(auto child:t[v]){
		long long subtree=1;
		if(child==parrent){continue;}
		if(col==1){subtree=solve(v,child,0);}
		else if(col==0){
			subtree=(solve(v,child,1)+solve(v,child,0))%mod;
			}
		dp[v][col]=(subtree*dp[v][col])%mod;
		}
	
	return dp[v][col];
	}
	

int main(){
	int n,x,y;
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>x>>y;
		t[x].push_back(y);
		t[y].push_back(x);
		}
		long long ans=(solve(0,1,1)+solve(0,1,0))%mod;
		cout<<ans;
	return 0;
	}




Measured memory_bytes: 20864
import java.util.Map.Entry;
import java.util.*;

import org.w3c.dom.css.Counter;


public class Main {
    public static void main(final String[] args){
        final Scanner s = new Scanner(System.in);
        final int N = Integer.parseInt(s.next());
        final int M = Integer.parseInt(s.next());
        HashSet<Integer> peak = new HashSet<Integer>();
        HashMap<Integer,Integer> nameAndHigh = new HashMap<Integer,Integer>();
        HashSet<Integer> outList = new HashSet<Integer>();
        
        for(int i=1; i <= N ;i++){
           //peak.add(Integer.parseInt(s.next()));
           nameAndHigh.put(i,Integer.parseInt(s.next()));
        }
        
        for(int i=0; i<M ;i++){
            int peakNameOne = Integer.parseInt(s.next());
            int peakNameTwo = Integer.parseInt(s.next());
            int peakOne = nameAndHigh.get(peakNameOne);
            int peakTwo = nameAndHigh.get(peakNameTwo);
            int losePeak;
            if(peakOne<peakTwo){
                losePeak= peakNameOne;
                if(!outList.contains(losePeak)){
                    outList.add(losePeak);
                }
            }else if(peakOne>peakTwo){
                losePeak = peakNameTwo;
                if(!outList.contains(losePeak)){
                    outList.add(losePeak);
                }
            }else{
                losePeak= peakNameOne;
                if(!outList.contains(losePeak)){
                    outList.add(losePeak);
                }
                losePeak = peakNameTwo;
                if(!outList.contains(losePeak)){
                    outList.add(losePeak);
                }
            }


         }

         System.out.println(N-outList.size());;
    }
}


Measured memory_bytes: 75372
import heapq

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p = list(map(lambda x: x*(-1), p))
q=list(map(int,input().split()))
q = list(map(lambda x: x*(-1), q))
r=list(map(int,input().split()))
r = list(map(lambda x: x*(-1), r))


#print(p)
p.sort()
p=p[:x]
q.sort()
q=q[:y]
r.sort()
r=r[:min(len(r),x+y)]
#print(p,q,r)

heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

result=0

xx=x
yy=y
result=0
rrr=min(len(r),x+y)
for _ in range(x+y):
    #heappop(a)
    #heapq.heappush(a, -2) 

    if xx>0 and yy>0 and rrr>0:
        qq=heapq.heappop(q)
        pp=heapq.heappop(p)
        rr=heapq.heappop(r)
        
        maximum=min(pp,qq,rr)
        if qq==maximum:
            result+=-1*qq
            yy=yy-1
            heapq.heappush(p, pp) 
            heapq.heappush(r, rr) 
        elif pp==maximum:
            result+=-1*pp
            xx=xx-1
            heapq.heappush(q,qq)
            heapq.heappush(r, rr) 
        else:
            result+=-1*rr
            rrr=rrr-1
            heapq.heappush(p, pp)
            heapq.heappush(q, qq) 
    
    elif yy>0 and rrr>0:
        qq=heapq.heappop(q)
        rr=heapq.heappop(r)
        
        maximum=min(qq,rr)
        if qq==maximum:
            result+=-1*qq
            yy=yy-1
            heapq.heappush(r, rr) 
        else:
            result+=-1*rr
            rrr=rrr-1
            heapq.heappush(q, qq) 
    elif xx>0  and rrr>0:
        pp=heapq.heappop(p)
        rr=heapq.heappop(r)
        
        maximum=min(pp,rr)
        if pp==maximum:
            result+=-1*pp
            xx=xx-1
            heapq.heappush(r, rr) 
        else:
            result+=-1*rr
            rrr=rrr-1
            heapq.heappush(p, pp)
    else:
        qq=heapq.heappop(q)
        pp=heapq.heappop(p)
        
        maximum=min(pp,qq)
        if qq==maximum:
            result+=-1*qq
            yy=yy-1
            heapq.heappush(p, pp) 
        elif pp==maximum:
            result+=-1*pp
            xx=xx-1
            heapq.heappush(q,qq)
        
    
    

print(result)

Measured memory_bytes: 134252
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include <sstream>
 
using namespace std;
 
bool is_prime(int n){
 
  for(int i=2; i*i<=n; i++)
    if(n%i==0)return false;
  return true;
}
 
string toString(int a){
  ostringstream oss;
  oss << a;
  return oss.str();
}
 
int toInt(string s){
  istringstream iss(s);
  int a;
  iss >> a;
  return a;
}
 
int main(void){
  int n,c;
  string str="",C="";
 
  cin >> n >> c;
 
  for(int i=0;i<n;i++)str+="9";
   
  if(c>=0)C=c+'0';
 
  if(c<0 && n>1){
    cout << str << str << endl;
    return 0;
  }
  while(true){
    string rstr=str;
    reverse(rstr.begin(),rstr.end());
     
    string res=str+C+rstr;
    int ans=toInt(res);
 
    if(is_prime(ans)){
      cout << ans << endl;
      return 0;
    }
 
    int tmp=toInt(str);
    tmp--;
    str=toString(tmp);
  }
 
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	ll res = 0;
	int bit = 0, at = 0;
	for(int i = 0; i < N; i++) {
		while((bit & A[at]) == 0 && at < N) {
			bit |= A[at];
			at++;
		}
		bit ^= A[i];
		res += at - i;
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
    int n,count=0;
    scanf("%d",&n);
    int ar[n+4],i;
    for(i=1;i<=n;i++)
        scanf("%d",&ar[i]);
    for(i=2;i<n;i++)
    {
        if((ar[i]<ar[i+1] && ar[i]>ar[i-1])||(ar[i]>ar[i+1]&&ar[i]<ar[i-1]))
            count++;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MOD (1e9 +7)
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define PI acos(-1.0)
#define ld long double
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9; 
using namespace std;


void solve()
{
    ld a, b, h , m;
    cin >> a >> b >> h >> m;
    ld angle;
    angle = abs(h*5+(m/12.0) - m);
      
    // cout << angle;
    if(angle - 30 > 1e-9) angle = 60 - angle;
    long double cone = PI * (angle/30.0 );
    long double ans = sqrt(b*b + a*a - 2*a*b * cos(cone) );
    printf("%0.20llf", ans);

}

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

    // int t; cin >> t;
    // int i = 1;
    // while(t--){
    //     //cout << "Case " << i++ << ": " ;
    //     solve();
    //     cout  << endl;
    // }
    solve();

    return 0;
}

Measured memory_bytes: 4156
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        print(('#.'*w)[i % 2:][:w]) #[@:@]はその範囲を切り取る
                                    #[:@]は最初から＠まで,[@:]は@から最後まで,[:]は全て
    print()


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

int main(){

    int n, v[100000];
    cin >> n;
    for( int i = 0; i < n; i++ ) cin >> v[i];


    int num_even[100001] = {}, num_odd[100001] = {};
    int num_even_max = 0, num_odd_max = 0;
    int even_max = 0, odd_max = 0;

    for( int i = 0; i < n; i++ ){
        if( i % 2 == 0 ) num_even[v[i]]++;
        else num_odd[v[i]]++;
    }

    for( int i = 1; i <= 100000; i++ ){
        if( num_even_max < num_even[i] ){
            num_even_max = num_even[i];
            even_max = i;
        }
        if( num_odd_max < num_odd[i] ){
            num_odd_max = num_odd[i];
            odd_max = i;
        }
    }

    if( even_max == odd_max ){
        int num_even_sub = 0, num_odd_sub = 0;
        
        for( int i = 1; i <= 100000; i++ ){
            if( num_even_sub < num_even[i] && i != even_max ) num_even_sub = num_even[i];
            if( num_odd_sub < num_odd[i] && i != odd_max ) num_odd_sub = num_odd[i];
        }
        cout << n - max( num_even_max + num_odd_sub, num_even_sub + num_odd_max ) << endl;    
    }else{
        cout << n - num_even_max - num_odd_max << endl;
    }

    return 0;

}

Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int q = sc.nextInt();
			ArrayList<PriorityQueue<Integer>> S = new ArrayList<PriorityQueue<Integer>>();
			for(int i=0;i<n;i++) {
				S.add(new PriorityQueue<>(Collections.reverseOrder()));
			}

			for(int i=0;i<q;i++) {
				int query = sc.nextInt();
				int t = sc.nextInt();
				switch(query) {
				case 0:
					S.get(t).add(sc.nextInt());
					break;
				case 1:
					if(S.get(t).size()>0)
						System.out.println(S.get(t).peek());
					break;
				case 2:
					if(S.get(t).size()>0)
						S.get(t).poll();
					break;
				}
			}
		}
	}
}


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

#include <math.h>
#include <stdlib.h>


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

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    string ans = "";
    for(int i = 0; i < s.length(); i++){
        if(i%2 == 0) ans = ans + s[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 656
#include<iostream>

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

using namespace std;

int main(){
    int n, x, ans = 0,sum = 0; cin >> n >> x;
    REP(i, n){
        int y; cin >> y;
        sum += y;
        ans += (sum <= x);
    }
    cout << ans + 1;                                                   
}


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

using namespace std;

//#define FILE_IO

int N;
char s[100007];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    fgets(s + 1, 100005, stdin);
    N = strlen(s + 1) - 1;

    int ppr = N / 2;
    for(int i = 1; i <= N; i++)
        if(s[i] == 'p')
            ppr--;
    printf("%d\n", ppr);

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		String s=stdIn.next();
		char a[]=new char[s.length()];
		a[0]=s.charAt(0);
		if(s.length()>1){
			a[1]=s.charAt(1);
		}
		int z=2,y=0,A=0;
		long ans=0;
		boolean key=false;
		while(z<s.length()){
			a[z]=s.charAt(z);
			if(a[z-2]=='A')
				A++;
			else
				A=0;
			if(key)
				A--;
			key=false;
			if(a[z-2]=='A'&&a[z-1]=='B'&&a[z]=='C'){
				a[z-2]='B';a[z-1]='C';a[z]='A';ans++;
				a[z-2-A+1]='B';
				a[z-1-A+1]='C';
				if((z-2)-(z-2-A+1)==1)
					a[z-1]='A';
				if((z-2)-(z-2-A+1)>1){
					a[z-1]='A';a[z-2]='A';
				}
				ans+=(z-2)-(z-2-A+1);
				key=true;z++;
				if(z<s.length())
					a[z]=s.charAt(z);
			}
			z++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27608
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
const int mod=1e9+7;
int H,W;
int wideN[2005][2005]={};
int highN[2005][2005]={};
int ans=0;
string s[2005];
int main(){
    cin>>H>>W;
    for(int i=0;i<H;i++){
        cin>>s[i];
        int tmp=0;
        int l=0;
        for(int j=0;j<W;j++){
            if(s[i][j]=='.'){
                tmp++;
            }else{
                for(int k=l;k<j;k++){
                    wideN[i][k]=tmp;
                }
                l=j+1;
                tmp=0;
            }
        }
        for(int k=l;k<W;k++){
            wideN[i][k]=tmp;
        }
    }
    for(int i=0;i<W;i++){
        int tmp=0;
        int u=0;
        for(int j=0;j<H;j++){
            if(s[j][i]=='.'){
                tmp++;
            }else{
                for(int k=u;k<j;k++){
                    if(tmp!=0 && wideN[k][i]!=0){
                        ans=max(ans,tmp+wideN[k][i]-1);
                    }
                }
                u=j+1;
                tmp=0;
            }
        }
        for(int k=u;k<H;k++){
            if(tmp!=0 && wideN[k][i]!=0){
                ans=max(ans,tmp+wideN[k][i]-1);
            }
        }
    }
    cout<<ans;
    return 0;
}

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

namespace agc017_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long[] ret = new long[] { 1, 0 };
            ret[a[0] % 2]++;
            for (int i = 1; i < x[0]; i++)
            {
                if (a[i] % 2 == 0)
                {
                    ret[0] *= 2; ret[1] *= 2;
                }
                else
                {
                    long n = ret.Sum(); ret[0] = n; ret[1] = n;
                }
            }
            Console.WriteLine(ret[x[1]]);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
 int p, q, r;
 cin >> p >> q >> r;

 int ans = min(p+q, q+r);
 ans = min(ans, r+p);

 cout << ans << endl;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int A = 0;
    int B = 0;
    int C = 0;
    cin >> A;
    cin >> B;
    cin >> C;
    
    int X = 0;
    cin >> X;
    
    int count = 0;
    for(int i_a = 0; i_a <= A; i_a++) {
        for(int j_b = 0; j_b <= B; j_b++) {
            for(int k_c = 0; k_c <= C; k_c++) {
                if(i_a*500+j_b*100+k_c*50 == X) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    
    return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 1555;
const int MAX_M = 1555;
const int MAX_W = 1111;
int h[MAX_N + 1];
int w[MAX_N + 1];
int N, M;

int main()
{
  while(cin >> N >> M, N){
    rep(i, N) cin >> h[i + 1];
    rep(i, M) cin >> w[i + 1];

    rep(i, N) h[i + 1] += h[i];
    rep(i, M) w[i + 1] += w[i];

    vi l, r;
    rep(i, N + 1) rep(j, i) l.pb(h[i] - h[j]);
    rep(i, M + 1) rep(j, i) r.pb(w[i] - w[j]);

    vi la(N * MAX_W), ra(M * MAX_W);
    vrep(v, l) la[*v] += 1;
    vrep(v, r) ra[*v] += 1;

    int res = 0;
    rep(i, min(N, M) * MAX_W) res += la[i] * ra[i];

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 27552
#include <iostream>
using namespace std;
int main() {

int N;
int A;
int B;
int Max;
int min;


cin >> N;
cin >> A;
cin >> B;

Max = A;
if (A>B) Max = B;


if (A+B<N) min=0;
else min = A+B-N;

cout <<  Max;
cout << " ";
cout << min;
cout <<endl;


}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;

long long LCM(long long a, long long b)
{
  long long r, x, tmp, lcm;

  x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最小公倍数を出力 */
  lcm = x/b;
 
  return lcm;
}

int main(void)
{
	//入力部
	//文字数の入力
	long long N, M;
    cin>>N>>M;
	
	//文字の入力
	string S, T;
	cin>>S;
	cin>>T;

	//最小公倍数計算部
	long long lc = LCM(N, M);
	
	long long nd = lc/N;
	long long md = lc/M;

	//計算部
	bool judge = true;
	for(long long i=0, j=0; i<N || j<M; i+=md, j+=nd)
	{
		if(S[i] != T[j]) judge = false;
	}

	if(judge) cout<<lc<<endl;
	else cout<<"-1"<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    #include <bitset> 
    #include <unordered_set>
using namespace std;
#define for1(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,maxn) for1(i,0,maxn)
#define ford(i,b,a) for(int i=(int)(b)-1;i>=a;--i)
typedef long long ll;
typedef unsigned long long int128;
typedef pair<int,int> pii;
typedef pair<int,pii > piii;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-10
#define pi acos(-1)
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define dprintf(...) printf(__VA_ARGS__)
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1^1)
const int maxn=1e5+10;
int N,L,Q;
int x[maxn],cnt[maxn],num[maxn];
int fa[maxn][20];
vector<int> nxt[maxn];
bool vis[maxn];
inline bool chk(int v,int stp,int to)
{
	int res=v;
	rep(i,20)
	{
		if(stp&(1<<i))res=fa[res][i];
	}
//	cout<<v<<" "<<stp<<" "<<to<<endl;
//	system("pause");
//	int sz=cnt[fa[i]];
//	if(num[i]+stp>=cnt[fa[i]])return 1;
//	return nxt[fa[i]][num[i]+stp]>=to;
	return res<=to;
}
int main()
{
	scanf("%d",&N);
	rep(i,N)
		scanf("%d",x+i);
	scanf("%d",&L);
//	rep(i,N)fa[i]=i;
	num[0]=0;
	int cur=0;
	for1(i,1,N)
	{
		while(x[i]-x[cur]>L)cur++;
		fa[i][0]=cur;
	//	cout<<cur<<endl; 
	}
	rep(i,N)
	{
		for(int lg=0;lg<19;lg++)
		{
			fa[i][lg+1]=fa[fa[i][lg]][lg];
		//	cout<<i<<" "<<lg+1<<" "<<fa[i][lg+1]<<endl;
		}
	}
//	rep(i,N)cout<<num[i]<<endl 
//	system("pause");
	scanf("%d",&Q);
	while(Q--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--,b--;
		if(a>b)swap(a,b);
		int L=0,R=N-1;
		while(L<R)
		{
			int mid=(L+R)>>1;
	//		cout<<chk(b,mid,a)<<" "<<L<<" "<<R<<" "<<mid<<endl;
			if(chk(b,mid,a))R=mid;
			else L=mid+1;
		}
	//	system("pause");
		printf("%d\n",L);
	}
	return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

class UnionFind {
public:
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ
    
    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
};

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

    UnionFind Uni(n);
    Uni.init(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        Uni.unite(a, b);
    }

    ll ans = 0;
    rep(i, n) {
        chmax(ans, Uni.size(i));
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 6356
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int>a(3 * N);
	for (int i = 0; i < 3 * N; i++) {
		cin >> a[i];
	}

	priority_queue<int, vector<int>, greater<int>>red;
	priority_queue<int>blue;

	long long sumA = 0, sumB = 0, ans = -1e18;
	vector<long long>A(N+1), B(N+1);
	for (int i = 0; i < N; i++) {
		sumA += a[i];
		red.push(a[i]);
		sumB -= a[3 * N - 1 - i];
		blue.push(a[3 * N - 1 - i]);
	}
	A[0] = sumA;
	B[0] = sumB;

	for (int i = 0; i < N; i++) {
		red.push(a[N + i]);
		sumA += a[N + i];
		sumA -= red.top();
		red.pop();

		A[i + 1] = sumA;
	}

	for (int i = 0; i < N; i++) {
		blue.push(a[2*N - i - 1]);
		sumB -= a[2 * N - i - 1];
		sumB += blue.top();
		blue.pop();

		B[i + 1] = sumB;
	}

	for (int i = 0; i < N + 1; i++) {
		ans = max(ans, A[i] + B[N - i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3964
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        Ws: [i64; N],
    }

    let mut ans = std::i64::MAX;
    for i in 0..N - 1 {
        let s1: i64 = Ws.iter().take(i + 1).sum();
        let s2: i64 = Ws.iter().skip(i + 1).sum();
        ans = min(ans, (s1 - s2).abs());
    }

    println!("{}", ans);
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int x = in.nextInt();

		boolean prime[] = new boolean[2*x+1];
		for(int i=0; i<2*x; i++)
			prime[i] = true;

		for (int p=2; p<=2*x; p++) {
			if(prime[p] == true) {
				if (p >= x) {
					System.out.println(p);
					System.exit(0);
				}
				for(int i = p*2; i<=2*x; i += p)
					prime[i] = false;
			}
		}
	}
}



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

#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 main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, q;
    cin >> n >> q;
    fenwick_tree<long long> fw(n);
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    for (int i=0; i<q; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 0)
            fw.add(x, y);
        else
            cout << fw.sum(x, y) << "\n";
    }

    return 0;
}


Measured memory_bytes: 8256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    vector<int> C(N), F(N);
    vector<long long> S(N);
    cin  >> N;
    
    for ( int i = 0; i < N-1; i++ ) {
        cin >> C[i] >> S[i] >> F[i];
    }
    
    for ( int i = 0; i < N-1; i++ ) {
        long long time = 0;
        for ( int j = i; j < N-1; j++ ) {
            if ( time < S[j] ) { time += S[j] - time + C[j]; }
            else {
                time += (time%F[j] ? F[j]-(time%F[j]) : 0) + C[j];
            }
            // cout << time << endl;
        }
        cout << time << endl;
    }
    
    cout << 0 << endl;
    
    return 0;
}

Measured memory_bytes: 768
#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "functional"
#include "cmath"

# define INF ((long long int)1e12)

int main() {
    // get values from input
    int a, b, q;
    std::vector<long long int> s, t, x;

    std::cin >> a >> b >> q;
    for (int i = 0; i < a; ++i) {
        long long int s_i;
        std::cin >> s_i;
        s.push_back(s_i);
    }
    for (int i = 0; i < b; ++i) {
        long long int t_i;
        std::cin >> t_i;
        t.push_back(t_i);
    }
    for (int i = 0; i < q; ++i) {
        long long int x_i;
        std::cin >> x_i;
        x.push_back(x_i);
    }

    // main procedure
    s.insert(s.begin(), -INF);
    s.push_back(INF);
    t.insert(t.begin(), -INF);
    t.push_back(INF);

    for (int i = 0; i < q; ++i) {
        auto s_forward = lower_bound(s.begin(), s.end(), x[i]);
        auto s_back = s_forward - 1;
        auto t_forward = lower_bound(t.begin(), t.end(), x[i]);
        auto t_back = t_forward - 1;

        std::vector<long long int> walk_distance(4);
        long long int nearer_distance, farer_distance;

        walk_distance[0] = x[i] - std::min(*s_back, *t_back);
        walk_distance[1] = std::max(*s_forward, *t_forward) - x[i];

        farer_distance = std::max(x[i] - *s_back, *t_forward - x[i]);
        nearer_distance = std::min(x[i] - *s_back, *t_forward - x[i]);
        walk_distance[2] = nearer_distance * 2 + farer_distance;

        farer_distance = std::max(*s_forward - x[i], x[i] - *t_back);
        nearer_distance = std::min(*s_forward - x[i], x[i] - *t_back);
        walk_distance[3] = nearer_distance * 2 + farer_distance;

        // output
        std::cout << *std::min_element(walk_distance.begin(), walk_distance.end()) << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3828
N,X = map(int,input().split())
p=[0]*(N+1)
num=[0]*(N+1)
for i in range(N+1):
    p[i] = 2**(i+1)-1
for i in range(N+1):
    num[i] = 2**(i+2)-3
def f(L,x):
    if L == 0:
        return 0 if x<=0 else 1
    elif x < ((2**(L+2)-4)//2+1):
        return f(L-1,x-1)
    else:
        return p[L-1]+1+f(L-1,x-2-num[L-1])

print(f(N,X))


Measured memory_bytes: 38384