akhauriyash/Code-Regression huggingface dataset:
from cmath import pi, exp


def convolve(a, b):
    """配列a, bの畳み込みをFFT(fast Fourier transform)によって計算する
    res[k] = sum{i=0...n}a[i]*b[k-i]
    """
    def fft(a, inverse=False):
        # バタフライ演算用の配置入れ替え
        for i in range(n):
            j = 0
            for k in range(h):
                j |= (i >> k & 1) << (h - 1 - k)
            if i < j:
                a[i], a[j] = a[j], a[i]

        # バタフライ演算
        sign = 1.0 if inverse else -1.0
        b = 1
        while b < n:
            for j in range(b):
                w = exp(sign * 2.0j * pi / (2.0 * b) * j)
                for k in range(0, n, b*2):
                    s = a[j + k]
                    t = a[j + k + b] * w
                    a[j + k] = s + t
                    a[j + k + b] = s - t
            b *= 2
 
        # 逆変換時には配列のサイズで割る
        if inverse:
            for i in range(n):
                a[i] /= n
        return a

    def ifft(a):
        return fft(a, inverse=True)

    n = 1 << (len(a) + len(b) - 1).bit_length()
    h = n.bit_length() - 1
    a += [0] * (n - len(a))
    b += [0] * (n - len(b))
    
    # in-placeで計算を進めることに注意
    fft(a), fft(b)
    for i in range(n):
        a[i] *= b[i]
    ifft(a)

    res = [int(abs(v) + 0.5) for i, v in enumerate(a)]
    return res[1:]
            

n, m = map(int, input().split())
a = list(map(int, input().split()))

cnt = [0] * (10**5 + 10)
for i in range(n):
    cnt[a[i]] += 1 

cnt_pair = convolve(cnt[0:], cnt[0:])
len_cnt_pair = len(cnt_pair)
ans = 0
c = 0
for i, num in enumerate(cnt_pair[::-1]):
    val = len_cnt_pair - i
    if num + c <= m:
        ans += num * val
        c += num
    else:
        ans += (m - c) * val
        break
print(ans)

Measured memory_bytes: 147100
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,m,K,a[12][1010],s[12],f[12];
vi d[12];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>m>>K;
	fo(i,0,n) fo(j,0,m){
		char c;
		cin>>c;
		a[i][j]=c-'0';
	}
	int ans=1e9;
	fo(x,0,(1<<(n-1))){
		int an=0;
		memset(s,0,sizeof(s));
		vi v;
		v.clear();
		int h=x;
		while(h>0){
			v.pb(h%2);
			h/=2;
		}
		while(v.size()<n-1)v.pb(0);
		int g=0;
		fo(i,0,n)d[i].clear();
		d[0].pb(0);
		fo(i,1,n){
			if(v[i-1]==1)d[g].pb(i);
			else{
				d[++g].pb(i);
				an++;
			}
		}
		g++;
		bool b=1; 
		fo(i,0,m){
			fo(j,0,g)f[j]=0;
			fo(j,0,g){
				fo(k,0,d[j].size())f[j]+=a[d[j][k]][i];
				if(f[j]>K)b=0;
				if(s[j]+f[j]>K){
					an++;
					fo(e,0,g)s[e]=f[e];
				}else s[j]+=f[j];
			}
		}
		if(b)ans=min(ans,an);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for _ in range(N+1)]

for i in range(N+1):
    dp[i][0] = 1

for i in range(M+1):
    dp[0][i] = 1
    
MOD = 10**9+7

for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]
        else:
            dp[i+1][j+1] = dp[i][j+1]+dp[i+1][j]-dp[i][j]
        
        dp[i+1][j+1] %= MOD

print(dp[N][M]%MOD)

Measured memory_bytes: 72668
S = ''
while True:
  try:
    S += input().lower()
  except:
    break
ref_list = 'abcdefghijklmnopqrstuvwxyz'

for i in range(len(ref_list)):
    print('{0:s} : {1:d}'.format(ref_list[i], S.count(ref_list[i])))


Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main() {
  ll N;
  cin >> N;
  map<char, ll> M;
  rep(i, N) {
    string s;
    cin >> s;
    M[s.at(0)]++;
  }

  ll res = 0;
  ll b = 0;
  char* C = "MARCH";
  char* p = C;
  ll O[5];
  while (*p) {
    if (M[*p] > 0) b++;
    O[p-C] = M[*p];
    p++;
  }
  
  if (b < 3) {
    cout << 0 << endl;
    return 0;
  }


  foreach_comb(5, 3, [&](int *ind) {
  //  std::cout << indexes[0] << ',' << indexes[1] << ',' << indexes[2] << std::endl;
  
  res += O[ind[0]] * O[ind[1]] * O[ind[2]];
  });  
  cout << res << endl;
}


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

ll max(vector<ll> v)
{
    return *max_element(v.begin(), v.end());
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout
        << max({a * c, b * c, a * d, b * d});
}

Measured memory_bytes: 3596
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    string S; cin >> S;
    int N = S.size();

    int ans=N/2;
    if (N%2==1) {
        int k = N/2;    
        char c = S[k];
        int l = k, r = k;
        while(0<=l && r<N) {
            if (S[l]==c && S[r]==c) {
                l--; r++;
                k++;
            } else {
                break;
            }
        }
        ans = k;
    } else {
        int k = N/2;    
        char c = S[k];
        int l = k-1, r = k;
        while(0<=l && r<N) {
            if (S[l]==c && S[r]==c) {
                l--; r++;
                k++;
            } else {
                break;
            }
        }
        ans = k;
    }

    cout << ans << endl;

    return 0;
}

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

long long calc(string s, int s_len, int a) {
  long long cur = s[0]-'0', res = 0;
  for (int i=1; i<s_len; i++) {
    if ((a >> (i-1)) & 1) {
      res += cur;
      cur = 0;
    } else {
      cur *= 10;
    }
    cur += s[i]-'0';
  }
  return res + cur;
}

int main() {
  string s;
  cin >> s;
  long long ans = 0;
  int s_len = (int)s.length();
  int bound = 1 << (s_len-1);
  for (int i=0; i<bound; i++) {
    ans += calc(s, s_len, i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n+1];
	int s =0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s += a[i];
	}
	float k = float(s)/float(4*m);
	int count = 0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=k)
		count++;
	}
	if(count>=m)
	cout<<"Yes\n";
	else 
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
local t
do
  local _accum_0 = { }
  local _len_0 = 1
  local _list_0 = {
    "dream",
    "dreamer",
    "erase",
    "eraser"
  }
  for _index_0 = 1, #_list_0 do
    local e = _list_0[_index_0]
    _accum_0[_len_0] = e:reverse()
    _len_0 = _len_0 + 1
  end
  t = _accum_0
end
local s = io.read("*l"):reverse()
local c = 1
local l = s:len()
while c <= l do
  local k = nil
  for _index_0 = 1, #t do
    local e = t[_index_0]
    if s:sub(c, c + e:len() - 1) == e then
      k = e
      break
    end
  end
  if k == nil then
    print("NO")
    return 
  end
  c = c + k:len()
end
return print("YES")


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	int k = 1;
	int ans = 0;
	rep(i, N) {
		if (A[i] != k) {
			++ans;
		} else {
			++k;
		}
	}
	if (k == 1) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
function Main(input: string) {
  const lines: string[] = input.split('\n');
  const params1 = lines[0].split(' ');
  const params2 = lines[1].split(' ');

  const n = parseInt(params1[0]);
  const m = parseInt(params1[1]);
  const x = parseInt(params1[2]);

  const a = params2.map(x => parseInt(x));

  const costL = a.filter(n => n < x).length;
  const costR = a.filter(n => n > x).length;

  const min = Math.min(costL, costR);

  console.log(min);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N, ans = 0;
    in >> N;
    vector<ll> A(N), B(N), C(N-1);
    REP_IN(i, N, A[i]);
    REP_IN(i, N, B[i]);
    REP_IN(i, N-1, C[i]);

    REP(i, N){
        ans += B[A[i]-1];
        if(A[i] == A[i-1]+1){
            ans += C[A[i-1]-1];
        }

    }
    out << ans << endl;





}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr << endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    string s;
    cin >> s;
    int cnt = 0;
    int ans = 0;
    rep(i, 3) {
        if (s[i] == 'R') cnt++;
        else {
            chmax(ans, cnt);
            cnt = 0;
        }
    }
    chmax(ans, cnt);
    cout << ans << endl;
}

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


Measured memory_bytes: 3680
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

bool is_palindrome(string s)
{
    auto len = s.length;
    foreach (d; 0..len/2) if (s[d] != s[$-d-1]) return false;
    return true;
}

alias P = Tuple!(string, "l", string, "r");

void main()
{
    auto N = readln.chomp.to!int;
    string[] SS;
    long[] CS;
    foreach (_; 0..N) {
        auto sc = readln.split;
        SS ~= sc[0];
        CS ~= sc[1].to!long;
    }
    long[P][P] G;
    void add_path(P p) {
        foreach (i; 0..N) {
            auto c = CS[i];
            string s, t;
            if (p.r == "") {
                s = p.l;
                t = SS[i];
            } else {
                s = SS[i];
                t = p.r;
            }
            auto len = min(s.length, t.length);
            size_t l, r = t.length-1;
            P q;
            foreach (d; 0..len) {
                if (s[l+d] != t[r-d]) goto ng;
            }
            if (s.length > t.length) {
                q.l = s[len..$];
                if (is_palindrome(q.l)) q.l = "";
            } else if (s.length < t.length) {
                q.r = t[0..$-len];
                if (is_palindrome(q.r)) q.r = "";
            }
            if (p in G && q in G[p]) {
                G[p][q] = min(G[p][q], c);
            } else {
                G[p][q] = c;
            }
            ng:
        }
    }
    auto E = P("", "");
    foreach (i; 0..N) {
        auto s = SS[i];
        auto c = CS[i];
        if (is_palindrome(s)) {
            auto p = P(s, "");
            G[p][E] = 0;
        }
        foreach (j; 1..s.length+1) {
            add_path(P(s[$-j..$], ""));
            add_path(P("", s[0..j]));
        }
    }

    alias S = Tuple!(P, "p", long, "c");
    long[P] DP;
    S[] ss;
    foreach (i; 0..N) ss ~= S(P(SS[i], ""), CS[i]);
    auto Q = heapify!"a.c > b.c"(ss);
    while (!Q.empty) {
        auto p = Q.front.p;
        auto c = Q.front.c;
        Q.popFront();
        if (p !in G) continue;
        foreach (q, d; G[p]) if (q !in DP || DP[q] > c + d) {
            DP[q] = c + d;
            Q.insert(S(q, c + d));
        }
    }
    writeln(E in DP ? DP[E] : -1);
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b || b == c || c == a) {
    if (a == b && b == c) {
      cout << 1 << endl;
      return 0;
    }
    cout << 2 << endl;
    return 0;
  }
  cout << 3 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String ans[] = {"Christmas", "Christmas Eve", "Christmas Eve Eve", "Christmas Eve Eve Eve"};
		int d;
		d = sc.nextInt();
		sc.close();
      
		System.out.println(ans[25-d]);
	}
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << endl;
	else cout << 10 << endl;
}

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

	solve();
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int N=100005;
int X[N],cha[N],p[N],cnt[N];
int a[N],dfn[N],c[N];
vector<long long> O[N];
int n,m,k,num,s;
void find(int x,int len){
    dfn[x]=len,c[x]=num;
    cnt[num]++;
    O[num].push_back(x);
    if(!c[p[x]]) find(p[x],len+1);
}
signed main (){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    scanf("%lld",&X[i]),cha[i-1]=X[i]-X[i-1];
    for(int i=1;i<=n;i++) 
    p[i]=i;
    
	scanf("%lld%lld",&m,&k);
    for(int i=1;i<=m;i++)
    scanf("%lld",&a[i]),
	swap(p[a[i]],p[a[i]-1]);
	
    for(int i=1;i<=n;i++)if(!dfn[i]) 
	num++,find(i,0);
    s=X[1],printf("%.1lf\n",1.0*s);
    for(int i=1;i<n;i++){
    	int pos=(dfn[i]+k)%O[c[i]].size();
		printf("%.1lf\n",1.0*(s+=cha[O[c[i]][pos]]));
	}
}

Measured memory_bytes: 13300
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N;
  cin>>N;
  std::vector<int> a(N),b(N);
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)cin>>b[i];
  int am=0;
  int bm=0;
  for(int i=0;i<N;i++){
    if(a[i]>b[i])am+=a[i]-b[i];
    else bm+=(b[i]-a[i])/2;
  }
  if(bm>=am)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define cmax(_i,_j) ((_i)<(_j)?(_i)=(_j):0)
#define cmin(_i,_j) ((_i)>(_j)?(_i)=(_j):0)
#define N (1<<19)
using namespace std;
namespace runzhe2000
{
	int n, a[N];
	
	int nodecnt;
	struct node
	{
		node *ch[2];
		int mx1, mx2, dep;
		node(){ch[0]=ch[1]=NULL;mx1=mx2=0;}
	}s[N*20];

	struct TRIE
	{
		node *root;
		void init()
		{
		    root = &s[++nodecnt];
		    root->dep = n;
		}
		void insert(int x)
		{
		    node *p = root;
		    for(int pos = 1<<(n-1), i = n-1; pos; pos>>=1, i--)
		    {
		        if(!p->ch[0])p->ch[0]=&s[++nodecnt], p->ch[0]->dep = i;
		        if(!p->ch[1])p->ch[1]=&s[++nodecnt], p->ch[1]->dep = i;
		        int son = x&pos?1:0;
		        p=p->ch[son];
		        if(a[x] >= p->mx1) p->mx2 = p->mx1, p->mx1 = a[x];
		        else if(a[x] > p->mx2) p->mx2 = a[x];
		    }
		}
		void dfs2(node *l, node *p)
		{
//printf("l = %ld(%d %d) p = %ld(%d %d)\n",l-s,l->mx1,l->mx2,p-s,p->mx1,p->mx2);
			if(l->mx1 >= p->mx1) p->mx2 = p->mx1, p->mx1 = l->mx1;
		    else if(l->mx1 > p->mx2) p->mx2 = l->mx1;
//printf("l = %ld(%d %d) p = %ld(%d %d)\n",l-s,l->mx1,l->mx2,p-s,p->mx1,p->mx2);
		    
			if(l->mx2 >= p->mx1) p->mx2 = p->mx1, p->mx1 = l->mx2;
		    else if(l->mx2 > p->mx2) p->mx2 = l->mx2;
		    
			if(l->dep == 0) return;
		    
		    dfs2(l->ch[0],p->ch[0]);
		    dfs2(l->ch[1],p->ch[1]);
		}
		void dfs(node *p)
		{
			if(p->dep == 0) return;
			dfs(p->ch[0]);
			dfs(p->ch[1]);
			dfs2(p->ch[0],p->ch[1]);
//printf("p = %ld mx1 = %d mx2 = %d ch0 = %ld ch1 = %ld\n",p-s,p->mx1,p->mx2,p->ch[0]-s,p->ch[1]-s);
		}
		void build()
		{
			dfs(root);
		}
		int solve(int x)
		{
//printf("solve %d\n",x);
			node *p = root;
			
			int ans = 0;
			
		    for(int i = n-1; ~i; i--)
		    {
		    	if((x>>i)&1)
		    	{
		    		
		  			cmax(ans, p->ch[0]->mx1+p->ch[0]->mx2);
		   			
		   			p = p->ch[1];
		    	}
		    	else p = p->ch[0];
//printf("p = %ld\n",p-s);
		    }
		    
		    cmax(ans, p->mx1+p->mx2);
			
			return ans;
		}
	}T;

	
	void main()
	{
		scanf("%d",&n);T.init();
		for(int i = 0, ii = 1<<n; i < ii; i++) scanf("%d",&a[i]), T.insert(i);
		T.build();
		for(int i = 1, ii = 1<<n; i < ii; i++) printf("%d\n",T.solve(i));
	}
}
int main()
{
	runzhe2000::main();
}

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

public class Main {
	Scanner sc = new Scanner(System.in);

	class p2 implements Comparable<p2> {
		int a;
		int b;

		p2(int a, int b) {
			this.a = a;
			this.b = b;
		}

		public int compareTo(p2 t) {
			if (a - t.a == 0) {
				return b - t.b;
			}
			return a - t.a;
		}
	}

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}

			int h[] = new int[n];
			int r[] = new int[n];

			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}

			int m = sc.nextInt();
			int h2[] = new int[m];
			int r2[] = new int[m];
			for (int j = 0; j < m; j++) {
				h2[j] = sc.nextInt();
				r2[j] = sc.nextInt();
			}
			p2 d[] = new p2[n + m];

			for (int i = 0; i < n; i++) {
				d[i] = new p2(h[i], r[i]);
			}
			for (int j = 0; j < m; j++) {
				d[n + j] = new p2(h2[j], r2[j]);
			}

			Arrays.sort(d);

			int dp[] = new int[n + m];
			Arrays.fill(dp, 1);
			dp[0] = 1;
			int max = 0;
			for (int i = 0; i < n + m; i++) {
				for (int j = 0; j < i; j++) {
					if (d[i].a > d[j].a && d[i].b > d[j].b) {
						dp[i] = Math.max(dp[i], dp[j] + 1);
					}
				}
				max = Math.max(dp[i], max);
			}
			System.out.println(max);
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int ans = S.size();
    for (int i; i < 2; i++)
    {
        int cnt = 0;
        for (int j = 0; j < S.size(); j++)
        {
            if (j % 2 == 0 && S[j] == char(i + '0'))
            {
                cnt++;
            }
            if (j % 2 != 0 && S[j] != char(i + '0'))
            {
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
n=int(input())
l=[[0]*9 for j in range(9)]
for i in range(1,n+1):
    i=str(i)
    if i[0]!='0' and i[-1]!='0':
        l[int(i[-1])-1][int(i[0])-1]+=1
ans=0
for i in range(9):
    for j in range(9):
        ans+=l[i][j]*l[j][i]
print(ans)

Measured memory_bytes: 40556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int A,B; cin >>A>>B;
    int ans = 0;

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


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

int main() {
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int> > key_(M,vector<int>(2,0));
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        key_[i][0]=a;
        for(int j=0; j<b; j++){
            int c;
            cin >> c;
            c--;
            key_[i][1]+=(1<<c);
        }
    }
    
    int state=(1<<N)-1;
    vector<vector<int> > dp(M+1,vector<int>(state+1,MOD));
    for(int i=0; i<=M; i++){
        dp[i][0]=0;
    }
    for(int i=0; i<M; i++){
        for(int j=0; j<state+1; j++){
            dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
            dp[i+1][j|key_[i][1]]=min(dp[i+1][j|key_[i][1]], dp[i][j]+key_[i][0]);
        }
    }
    if(dp[M][state]==MOD){
        dp[M][state]=-1;
    }

    //cout_mat(dp);

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

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    vi v(n);
    for(int i = 0; i < n; i++)cin>>v[i];
    sort(all(v));
    ld s=v[0];
    for(int i = 1; i < n; i++){
        s=(s+v[i])/2;
    }
    cout<<fixed<<setprecision(10)<<s;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int ctoi(const char c){
   switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
   }
}

int main(){
  string s;
  cin>>s;
  ll n=s.size();
  vector <ll> dp(n);
  vector <ll> a(n);
  vector <ll> b(n);
  rep(i,n){
    char c=s[i];
    int d=ctoi(c);
    a[i]=d;
  }
  reverse(a.begin(),a.end());
  
  b[0]=1;
  if(n>1){
    for (int i=1;i<n;i++){
      b[i]=10*b[i-1]+std::pow(2,i-1);
    }
  }
  
  dp[0]=a[0];
  if (n>1){
    for(int i=1;i<n;i++){
      dp[i]=2*dp[i-1]+a[i]*b[i];
    }
  }
  
  cout<<dp[n-1]<<endl;
  
  
  
}

Measured memory_bytes: 512
import numpy as np

def main():
	n = int(input())
	sosuu = []
	sosuucount = []
	
	for i in range(2, n+1):
		num = i
		sosuuf = 1
		
		for j in range(len(sosuu)):
			if(num % sosuu[j] == 0):
				sosuuf = 0
				while(num % sosuu[j] == 0):
					num /= sosuu[j]
					sosuucount[j] += 1
		if (sosuuf == 1):
			sosuu.append(num)
			sosuucount.append(1)
	num75 = 0
	num25 = 0
	num15 = 0
	num5 = 0
	num3 = 0
	for i in range(len(sosuu)):
		if(sosuucount[i]+1 >= 75):
			num75 += 1
		if(sosuucount[i]+1 >= 25):
			num25 += 1
		if(sosuucount[i]+1 >= 15):
			num15 += 1
		if(sosuucount[i]+1 >= 5):
			num5 += 1
		if(sosuucount[i]+1 >= 3):
			num3 += 1
	r = num75 + num25*(num3-1)+num15*(num5-1) + num5*(num5-1)*(num3-2)/2
	
	print(int(r))
	
	#print(sosuu)
	#print(sosuucount)
	#print(num3, num5, num15, num25, num75)
main()

Measured memory_bytes: 12648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
 
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef complex<double> P;
typedef complex<double> Vec;
typedef pair<int, int> pii;
typedef pair<int, pii> p;
 
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int n, m;
vector<int> g[8];

int main() {
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	vector<int> num(n);
	REP(i, n) num[i] = i;
	
	int ans = 0;
	do {
		if (num[0] != 0) continue;

		bool f = true;
		FOR(i, 1, n) {
			vector<int>::iterator it = find(ALL(g[num[i - 1]]), num[i]);
			if (it == g[num[i - 1]].end()) f = false;
		}
		if (f) ans++;
		
	} while (next_permutation(ALL(num)));
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
build = [[[0]*10,[0]*10,[0]*10],[[0]*10,[0]*10,[0]*10],[[0]*10,[0]*10,[0]*10],[[0]*10,[0]*10,[0]*10]]
n = int(input())
for i in range(n):
    b, f, r, v = [int(x) for x in input().split()]
    build[b-1][f-1][r-1] += v
count = 0
for i1 in build:
    for i2 in i1:
        line = ""
        for i3 in i2:
            line += " " + str(i3)
        print(line)
    if count < 3:
        print("#"*20)
        count += 1

Measured memory_bytes: 7728
<?php
fscanf(STDIN, "%d %d", $N, $T);
$ans = 'TLE';
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $c, $t);
    if ($T >= $t) {
        if ($ans === 'TLE') {
            $ans = $c;
        } else {
            $ans = min($c, $ans);
        }
    }
}
echo $ans;


Measured memory_bytes: 4728
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll h,w;
    cin >> h >> w;
    if(w == 1 || h == 1){
        print(1);
        return 0;
    } else {
        if(h % 2 == 0) {
            print(w * (h / 2));
        } else {
            ll ans = w * (h / 2);
            ll tmp = round_up(w, 2LL);
            ans += tmp;
            print(ans);
        }

    }
    
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	
	long long ans1 = 0, ans2 = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (i % 2 == 0 && sum <= 0) {
			ans1 += -sum + 1;
			sum = 1;
		}
		else if (i % 2 == 1 && sum >= 0) {
			ans1 += sum + 1;
			sum = -1;
		}
		
	}

	sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (i % 2 == 1 && sum<= 0) {
			ans2 += -sum + 1;
			sum = 1;
		}
		else if (i % 2 == 0 && sum >= 0) {
			ans2 += sum + 1;
			sum = -1;
		}
	}
	cout << min(ans1, ans2) << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int k;
    cin >> k;
    if (k%2==0 or k%5==0)
    {
        cout << -1 << endl;
        return 0;
    }
    int M[k];
    M[0] = 7%k;
    for (int i = 0; i < k; i++)
    {
        if (M[i]==0)
        {
            cout << i+1 << endl;
            return 0;
        }
        M[i+1] = (( (M[i]%k)*(10%k) )%k + 7%k)%k;
    }
}


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

int main(){
  string S, T;
  cin >> S >> T;
  int lens = S.size();
  for (int i=0; i<lens; i++){
    bool flag = true;
    for (int j=0; j<lens; j++){
      if (T[j] != S[(i+j)%lens]){
        flag = false;
        break;
      }
    }
    if (flag){cout << "Yes" << endl; return 0;}
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>

using namespace std;

void solve()
{
	string s;
	cin >> s;
	map<char, int> ma;
	for (int i = 0; i < s.size(); ++i)
	{
		++ma[s[i]];
	}
	bool isOK = true;
	map<char, int>::iterator it = ma.begin();
	while (it != ma.end())
	{
		if (it->second % 2 == 1)
		{
			isOK = false;
		}
		++it;
	}
	if (isOK)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,arr[200001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for (int i=1;i<=5;i++){
        cin>>n;
        if (n==0) cout<<i;
    }
    /*
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>arr[i];
    }
    */
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int N, K;
long long t[100000], dif[100001];
long long ans = 0;

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

	for (int i = 0; i < N; i++) {
		cin >> t[i];

		if (i != 0) {
			dif[i - 1] = t[i] - t[i - 1] - 1;
		}
	}

	sort(dif, dif + N - 1);
	reverse(dif, dif + N - 1);

	ans += N;
	K--;

	for (int i = K; i < N - 1; i++) {
		ans += dif[i];
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 4696
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n; ll k;
    cin >> n >> k;
    ll num[100001] = {0};
    REP(i, n){
        int a, b; cin >> a >> b;
        num[a] += b;
    }
  
    ll cnt = k;
    REP(i, 100001){
        if(cnt <= num[i]){
            cout << i << "\n";
            break;
        }
        else cnt -= num[i];
    }
    return 0;
}

Measured memory_bytes: 1024
# coding:utf-8

s = raw_input()

flag = 0
if s[0] == s[1]:
    print "1 2"
    flag = 1
else:
    for i in range(2, len(s)):
        if s[i] == s[i - 1]:
            print(str(i) + " " + str(i + 1))
            flag = 1
            break
        elif s[i] == s[i - 2]:
            print(str(i - 1) + " " + str(i + 1))
            flag = 1
            break
        else:
            continue
if flag == 0:
    print "-1 -1"

Measured memory_bytes: 5892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderC
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        Dictionary<long, long> dic = new Dictionary<long, long>();

        long current = 2;
        double sqrt = Math.Sqrt(n);
        while (current <= sqrt)
        {
            if (n % current == 0)
            {
                n /= current;
                if (dic.ContainsKey(current))
                {
                    dic[current]++;
                }
                else
                {
                    dic.Add(current, 1);
                }
            }
            else
            {
                current++;
            }
        }
        if (n != 1)
        {
            dic.Add(n, 1);
        }

        long answer = 0;

        foreach (var item in dic)
        {
            long num = item.Value;

            long max = num;
            for (long i = 1; i <= max; i++)
            {
                if (num >= i)
                {
                    answer++;
                    num -= i;
                }
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27832
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

res = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                res.append(A[i] + B[j] + C[k])
            else:
                break

res.sort(reverse=True)
for i in range(K):
    print(res[i])


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

int main(){
  string S;
  cin >>S;
  int count=0;
  int n=S.size();
  for(int i=0;i<(n/2);i++){
    if(S[i]==S[n-1-i]){
      count++;
    }
  }
       cout<<(n/2)-count<<endl;
       return 0;

}


Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    for(int i = n;; ++ i) {
        string x = to_string(i);
        set<char> se;
        rep(j, (int)x.size()) se.insert(x[j]);
        if(se.size() == 1) {
            cout << x << endl;
            return;
        }
    }
}

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

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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpi(i,n) for( int (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#if __cplusplus < 201703L
  std::ostream& co_(){ return std::cout << std::endl; }
  std::istream& cn_(){ return std::cin; }
  template<class Head, class... Args>
  std::ostream& co_( Head&& head, Args&&... args ){ std::cout << head; return co_(std::forward<Args>(args)...); }
  template<class Head, class... Args>
  std::istream& cn_( Head&& head, Args&&... args ){ std::cin >> head; return cn_(std::forward<Args>(args)...); }
#else
  template<class... Args>
  std::ostream& co_( Args... args ){ return std::cout << ... << args << std::endl; }
  template<class... Args>
  std::istream& cn_( Args... args ){ return std::cin >> ... >> args; }
#endif
#define co(...) co_(__VA_ARGS__);
#define cn(...) cn_(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rgt(x,i) (x).begin(), (x).begin()+(i)

int main(){
  int n;cn(n)
  vector<vector<pair<int,ll>>> d(n+1);
  rep(i,n-1){
    int a,b;ll c;
    cn(a,b,c)
    d[a].push_back(make_pair(b,c));
    d[b].push_back(make_pair(a,c));
  }
  vector<ll> dt(n+1,-1);
  int q,k;cn(q,k);
  dt[k]=0ll;
  stack<pair<int,ll>> st;
  st.push(make_pair(k,0ll));
  while(!st.empty()){
    auto v = st.top(); st.pop();
    for( auto w : d[v.first] ){
      if ( dt[w.first] < 0 ){
        dt[w.first] = v.second + w.second;
        st.push(make_pair(w.first,v.second + w.second));
      }
    }
  }
  rep(i,q){
    int x,y;cn(x,y)
    co(dt[x]+dt[y])
  }
}

Measured memory_bytes: 11888