akhauriyash/Code-Regression huggingface dataset:
#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, H;
vi A, B;

int main() {
    cin >> N >> H;
    A.resize(N);
    B.resize(N);

    vp<int, int> C;
    C.reserve(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
        C.emplace_back(A[i], i);
        C.emplace_back(B[i], N + i);
    }

    sort(C.rbegin(), C.rend());

    ll sum = 0;
    int istart;
    int ans = 0;
    rep(i, 2 * N) {
        const auto& c = C[i];
        if (c.second < N) {
            ans += (H - sum + c.first - 1) / c.first;
            break;
        }
        sum += c.first;
        ans++;
        if (sum >= H) {
            break;
        }
    }

    write(ans);
}

Measured memory_bytes: 2672
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int r, g, b, n;
	cin >> r >> g >> b >> n;

	int dp[3001] = {};
	dp[0] = 1;

	for (int i = n; i >= 0;i--) {
		for (int j = i - r; j >= 0; j -= r) {
			dp[i] += dp[j];
		}
	}
	for (int i = n; i >= 0; i--) {
		for (int j = i - g; j >= 0; j -= g) {
			dp[i] += dp[j];
		}
	}
	for (int i = n; i >= 0; i--) {
		for (int j = i - b; j >= 0; j -= b) {
			dp[i] += dp[j];
		}
	}
	cout << dp[n] << endl;





	return 0;
}

Measured memory_bytes: 256
import sys


def dump(x):
    print >> sys.stderr, "{0}".format(x)

S = raw_input()
correct = "CODEFESTIVAL2016"
false_count = 0

for i in range(min(len(S), len(correct))):
    if S[i] != correct[i]:
        false_count += 1

print(false_count)

Measured memory_bytes: 2568
#include<iostream>
#include<algorithm>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define Z 10500
using namespace std;
int d[Z+1];
int main(){
	int n,m,k,r,l;
	while(true){
		cin>>n>>k>>m>>r;
		if(!(n+m+k+r))break;
		rep(i,0,Z)d[i]=0;
		k=1,l=n;
		rep(i,0,Z)d[i]+=k/l,k%=l,k*=10;
		if(m)rep(i,1,n){k=1,l=i*n;rep(j,0,Z)d[j]+=k/l,k%=l,k*=10;}
		for(int i=Z;i>0;i--)d[i-1]+=d[i]/10,d[i]%=10;
		cout<<d[0]<<".";
		rep(i,1,r+1)cout<<d[i];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3072
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
num=0
for i in range(n):
  num+=min(a[i],b[i])
  b[i]=max(0,b[i]-a[i])
  num+=min(b[i],a[i+1])
  a[i+1]=max(0,a[i+1]-b[i])
print(num)

Measured memory_bytes: 18624
n = int(input())
li = [list(map(int, input().split())) for i in range(n-1)]

for i in range(n-1):
	time = li[i][0] + li[i][1]
	for j in range(i+1, n-1):
		now = li[j][1]
		if now < time:
			now += li[j][2] * (-(-(time-now)//li[j][2]))
		time = now
		time += li[j][0]
	print(time)
print(0)


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main()
{
	int L, M, N, sum, i, k;
	while(1)
	{	
		cin >> L;
		if ( L == 0 )break;
		else
		{
			k = 0;
			sum = 0;
			for ( i = 0; i < 12; i++ )
			{
				cin >> M >> N;
				sum = (sum + (M - N));
				if ( sum < L )k++;
			}
			k = k + 1;
			if ( sum < L )cout << "NA" << endl;
			else cout << k << endl;
		}
	}	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int X,Y;
	cin>>X>>Y;
	int ans=0;
	switch(X){
		case 1:
			ans+=300000;
			break;
		case 2:
			ans+=200000;
			break;
		case 3:
			ans+=100000;
			break;
	}
	switch(Y){
		case 1:
			ans+=300000;
			break;
		case 2:
			ans+=200000;
			break;
		case 3:
			ans+=100000;
			break;
	}
	if (X==1 && Y==1){
		ans+=400000;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++) {
    cin>>p.at(i);
  }
  int ans=0;
  for(int i=0;i<n-2;i++) {
    if(p.at(i+1)!=max(p.at(i),max(p.at(i+1),p.at(i+2)))&&p.at(i+1)!=min(p.at(i),min(p.at(i+1),p.at(i+2)))){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
def count(n):
    cnt = 0
    while n > 0:
        cnt += n & 1
        n >>= 1
    return cnt


N = int(input())

shogen = [[] for _ in range(N)]

for i in range(N):
    a = int(input())
    for _ in range(a):
        shogen[i].append(list(map(int, input().split())))
ans = 0
for i in range(1 << N):
    ok = True
    for j in range(N):
        if not (i & (1 << j)):
            continue
        for s in shogen[j]:
            if ((i >> (s[0] - 1)) & 1) ^ s[1]:
                ok = False
    if ok:
        ans = max(ans, count(i))
print(ans)

Measured memory_bytes: 3064
use proconio::*;

fn run() {
    input! {
        n: usize,
        s: String,
    }
    let mut map = std::collections::BTreeMap::new();
    map.insert('R', 0);
    map.insert('G', 1);
    map.insert('B', 2);
    let s: Vec<usize> = s.chars().map(|c| *map.get(&c).unwrap()).collect();
    let mut cnt = [0u64; 3];
    for &k in s.iter() {
        cnt[k] += 1;
    }
    let mut ans = cnt.iter().fold(1, |s, a| s * *a);
    for d in 1..=((n - 1) / 2) {
        for s in s.windows(2 * d + 1) {
            let (a, b, c) = (s[0], s[d], s[2 * d]);
            if a != b && b != c && c != a {
                ans -= 1;
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2172
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, l = LI()
    A = LI()

    for i in range(n - 1):
        if A[i] + A[i + 1] >= l:
            k = i
            print('Possible')
            break
    else:
        print('Impossible')
        return 0

    for i in range(k):
        print(i + 1)

    for i in range(k, n - 1)[::-1]:
        print(i + 1)

    return 1


main()


Measured memory_bytes: 14432
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#define MAX_W 1000
#define MAX_P 100

using namespace std;
typedef unsigned long long int ull;

int mat[MAX_W][MAX_W];
int pattern[MAX_W][MAX_W], tmp[MAX_W][MAX_W];
int w, h, p;
int cv[123];
ull hash[MAX_W][MAX_W];

void move(){
	for(int i = 0; i < p; i++){
		for(int j = 0; j < p; j++){
			pattern[i][j] = tmp[i][j];
		}
	}
}
void rotate(){
	for(int i = 0; i < p; i++){
		for(int j = 0; j < p; j++){
			tmp[j][p - 1 - i] = pattern[i][j];
		}
	}
	move();
}
void mirror(){
	for(int i = 0; i < p; i++){
		for(int j = 0; j < p; j++){
			tmp[i][p - 1 - j] = pattern[i][j];
		}
	}
	move();
}
void compute_hash(int a[MAX_W][MAX_W], int n, int m){
	const ull B1 = 9973;
	const ull B2 = 100000007;

	ull t1 = 1, t2 = 1;
	for(int i = 0; i < p; i++){
	       	t1 *= B1;
		t2 *= B2;
	}

	for(int i = 0; i < n; i++){
		ull e = 0;
		for(int j = 0; j < p; j++) e = e * B1 + a[i][j];

		for(int j = 0; j + p <= m; j++){
			tmp[i][j] = e;
			if(j + p < m) e = e * B1 + a[i][j + p] - a[i][j] * t1;
		}
	}

	for(int j = 0; j + p <= m; j++){
		ull e = 0;
		for(int i = 0; i < p; i++){
			e = e * B2 + tmp[i][j];
		}

		for(int i = 0; i + p <= n; i++){
			hash[i][j] = e;
			if(i + p < n) e = e * B2 + tmp[i + p][j] - tmp[i][j] * t2;
		}
	}
}
int solve(){
	set<ull> s;	
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 4; j++){
			/***
			for(int a = 0; a < p; a++){
				for(int b = 0; b < p; b++){
					cout<<pattern[a][b];
				}
				cout<<endl;
			}
			cout<<endl;
			/***/
			compute_hash(pattern, p, p);
			s.insert(hash[0][0]);
			rotate();
		}
		mirror();
	}
	compute_hash(mat, h, w);
	int res = 0;
	for(int i = 0; i + p <= h; i++){
		for(int j = 0; j + p <= w; j++){
			if(s.find(hash[i][j]) != s.end()){
				res++;
			}
		}
	}
	return res;
}
int main(){
	for(int i = 0; i < 26; i++){
	       	cv[i + 65] = i;
		cv[i + 97] = i + 26;
	}
	for(int i = 0; i < 10; i++) cv[i + 48] = i + 52;
	cv[43] = 62;
	cv[47] = 63;

	while(scanf("%d %d %d\n", &w, &h, &p) && (w || h || p)){
		for(int i = 0; i < h; i++){
			string s;
			cin>>s;
			for(int j = 0; j < s.length(); j++){
				int t = cv[s[j]];
				for(int k = 0; k < 6 && j * 6 + k < w; k++){
					mat[i][j * 6 + k] = (t >> (5 - k)) & 1;
				}
			}
		}
		for(int i = 0; i < p; i++){
			string s;
			cin>>s;
			for(int j = 0; j < s.length(); j++){
				int t = cv[s[j]];
				for(int k = 0; k < 6 && j * 6 + k < p; k++){
					pattern[i][j * 6 + k] = (t >> (5 - k)) & 1;
				}
			}
		}
		printf("%d\n", solve());
	}
	return 0;
}

Measured memory_bytes: 18876
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for ai in range(N-2):
        a = L[ai]
        for bi in range(ai+1,N-1):
            b = L[bi]
            cmax = a + b
            m_index = bisect.bisect_left(L,cmax)
            ans += max(m_index - bi - 1, 0)

    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include<stdio.h>


int main(){

  int a, b, result;
  char op;


  while(1){

    scanf("%d %c %d", &a, &op, &b);

    switch(op){

    case '+':

      result = a + b;
      break;

    case '-':

      result = a - b;
      break;

    case '*':

      result = a * b;
      break;

    case '/':

      result = a / b;
      break;

    }

      if(op == '?')

	break;
  
  printf("%d\n", result);

  }

    
  return 0;
  
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if (X>Y) {
        cout << min(A*X+B*Y, min(C*Y*2+A*(X-Y), C*X*2)) << endl;
    } else {
        cout << min(A*X+B*Y, min(C*X*2+B*(Y-X), C*Y*2)) << endl;
    }
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

LL big_mod(LL val,LL pow,LL mod);
LL mod_inverse(LL val,LL mod);






int main()
{
//    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    char s[5];
    S("%s",&s);
    int x=(s[0]-48)*10+(s[1]-48);
    int y=(s[2]-48)*10+(s[3]-48);
    if((x == 0 && y == 0)  ||  (x == 0 && y > 12)  ||  (x >12  && y == 0)  ||  (x >12  && y > 12))
    {
        P("NA");
    }
    else if(x < 13 && y< 13 && x > 0 && y > 0)
    {
        P("AMBIGUOUS");
    }
    else
    {
        if(x > 12 || x == 0)
        {
            P("YYMM");
        }
        else
        {
            P("MMYY");
        }
    }
    return 0;
}







LL big_mod(LL val,LL pow,LL mod)
{
    LL res = 1;
    val = val % mod;
    while(pow > 0)
    {
        if(pow & 1)
        {
            res = (res*val) % mod;
        }
        pow = pow >> 1;
        val = (val*val) % mod;
    }
    return res;
}

LL mod_inverse(LL val,LL mod)
{
    LL mod1 = mod;
    if(mod == 1)
    {
        return 0;
    }
    LL y = 0;
    LL x = 1;
    LL quotient,temp;
    while(val > 1)
    {
        quotient = val / mod;
        temp = mod;
        mod = val % mod;
        val = temp;
        temp = y;
        y = x - quotient * y;
        x = temp;
    }
    if(x < 0)
    {
        x += mod1;
    }
    return x;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,m;
int k[12];
int s[12][12];
int p[12];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>k[i];
		for(int j=1;j<=k[i];j++)
			cin>>s[i][j]; 
	}
	for(int i=1;i<=m;i++)
		cin>>p[i];
	int res=0;
	for(int mask=0;mask<(1<<n);mask++){
		int tt=0;
		for(int i=1;i<=m;i++){
			int tot=0;
			for(int j=1;j<=k[i];j++){
				if((mask>>(s[i][j]-1))&1)
					tot++;
			}
			if(tot%2==p[i]%2)
				tt++;
		}
		if(tt==m)
			res++;
	}
	cout<<res<<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];
  memset(a,0,sizeof a);
  while(m--){
    int s,c;
    cin>>s>>c;
    if(s==1 && c==0 && n!=1) {cout<<-1;return(0);}
    if(!a[s-1]) a[s-1]=c;
    else if(a[s-1]!=c) {cout<<-1;return(0);}
    
  }
  if(!a[0] && n!=1) a[0]=1;
  for(int i=0;i<n;i++)
    cout<<a[i];
}

Measured memory_bytes: 256
from math import cos, radians, sqrt

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

ab = abs(0.5*((h*60)+m)) - (6.0*m)
ab = min(ab, 360-ab)

c = a*a + b*b - 2*a*b*cos(radians(ab))
print(sqrt(c))


Measured memory_bytes: 9512
#include<stdio.h>
#define MAX 2001
#define INF 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n;
int A[MAX][MAX];

int mst(){
  int u,mini,i,j,v;
  static int sum=0;
  int col[MAX],d[MAX],p[MAX];
  
  for(i=0; i<n; i++){
    col[i]=WHITE;
    d[i] = INF;
    p[i] = -1;
  }

  d[0]=0;
  
  while(1){
    mini = INF;
    u = -1;
    for(i=0; i<n; i++){
      if(col[i] != BLACK && d[i] < mini){
	mini = d[i];
	u = i;
      }
    }
    if(u == -1)break;
    col[u] = BLACK;
    for(v=0; v<n; v++){
      if(col[v] != BLACK && A[u][v] != INF){
	if(A[u][v] < d[v]){
	  d[v] = A[u][v];
	  p[v] = u;
	  col[v] = GRAY;
	}
      }
    }
  }

  for(i=0; i<n; i++){
    if(p[i] != -1)sum += A[i][p[i]];

  }
  return sum;
}


int main(){
  int i,j,min;
  //配列A[][]に全部INFを投下
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      A[i][j]=INF;
    }
  }
  //表に入れる
  scanf("%d",&n);
  for(i=0; i<n; i++){
    for(j=0;j<n; j++){
      scanf("%d",&A[i][j]);
      if(A[i][j] == -1)A[i][j] = INF;
    }
  }

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



Measured memory_bytes: 2148
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

// UnionFind
struct UnionFind {
    vector< int > data;
    
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
 
    bool unite(int x, int y) {//要素xとyの各々の木を併合（もともと同じ木ならfalse）
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    
    int find(int k) {//要素kが属する木の根を得る
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    
    int size(int k) {//要素kが属する木の要素数
        return (-data[find(k)]);
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = find(x);
        int ry = find(y);
        return rx == ry;
    }

};

int main(){
    ll N;
    cin>>N;
    map<ll,vector<ll>> mp;
    set<ll> st;
    map<ll,ll> idx;
    vector<ll> x(N),y(N);
    REP(i,N){
        cin>>x[i]>>y[i];
        mp[x[i]].push_back(y[i]);
        st.insert(y[i]);
    }
    ll cnt=0;
    for(auto itr=st.begin();itr!=st.end();itr++){
        idx[*itr]=cnt;
        cnt++;
    }
    UnionFind tree(N);
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ll X=itr->first;
        vector<ll> VY=itr->second;
        REP(i,VY.size()){
            ll Y=VY[i];
            tree.unite(idx[Y],idx[VY[0]]);
        }
    }
    ll ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ll X=itr->first;
        vector<ll> VY=itr->second;
        ans+=(tree.size(idx[VY[0]])-VY.size());
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 16392
import sys


class BinarySearchTree:
    class Node:
        __slots__ = ('value', 'left', 'right')

        def __init__(self, value):
            self.value = value
            self.left = None
            self.right = None

        def has_left(self):
            return self.left is not None

        def has_right(self):
            return self.right is not None

        def __str__(self):
            return str(self.value)

    def __init__(self):
        self.root = None

    def insert(self, value):
        if self.root is None:
            self.root = self.Node(value)
            return

        node = self.root
        while True:
            if node.value > value:
                if node.has_left():
                    node = node.left
                else:
                    node.left = self.Node(value)
                    break
            else:
                if node.has_right():
                    node = node.right
                else:
                    node.right = self.Node(value)
                    break

    def find(self, value):
        if self.root is None:
            return False

        node = self.root
        while True:
            if node.value > value:
                if node.has_left():
                    node = node.left
                else:
                    return False
            elif node.value < value:
                if node.has_right():
                    node = node.right
                else:
                    return False
            else:
                return True

    def preorder(self):
        def _preorder(node):
            yield node
            if node.has_left():
                yield from _preorder(node.left)
            if node.has_right():
                yield from _preorder(node.right)
        if self.root is not None:
            yield from _preorder(self.root)

    def inorder(self):
        def _inorder(node):
            if node.has_left():
                yield from _inorder(node.left)
            yield node
            if node.has_right():
                yield from _inorder(node.right)
        if self.root is not None:
            yield from _inorder(self.root)

    def postorder(self):
        def _postorder(node):
            if node.has_left():
                yield from _postorder(node.left)
            if node.has_right():
                yield from _postorder(node.right)
            yield node
        if self.root is not None:
            yield from _postorder(self.root)


def run():
    _ = int(input())
    tree = BinarySearchTree()

    for line in sys.stdin:
        if line.startswith('insert'):
            tree.insert(int(line[7:]))
        elif line.startswith('find'):
            if tree.find(int(line[5:])):
                print("yes")
            else:
                print("no")
        elif line.startswith('print'):
            print(' {}'.format(' '.join([str(n) for n in tree.inorder()])))
            print(' {}'.format(' '.join([str(n) for n in tree.preorder()])))
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Measured memory_bytes: 74116
#include <stdio.h>

int main(void)
{
    long int N, K, A, B;

    scanf("%ld", &N);
    scanf("%ld", &K);
    A = N % K;
    B = K - A;

    if (A <= B)
        printf("%ld\n", A);
    else
        printf("%ld\n", B);
    
    return 0;
     
}

Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,p = LI()
    print((a*3+p)//2)
    return

#B
def B():
    n = I()
    s = [None for i in range(n)]
    for i in range(n):
        l = input().split()
        s[i] = l+[i]
    s.sort(key = lambda x:(x[0],-int(x[1])))
    for i,a,b in s:
        print(b+1)
    return

#C
def C():
    def dfs(d,k):
        if d == n:
            l.append(k)
        else:
            dfs(d+1,k+[0])
            dfs(d+1,k+[1])
    n,m = LI()
    l = []
    dfs(0,[])
    qu = LIR(m)
    p = LI()
    ans = 0
    for k in l:
        s = 0
        for q in range(m):
            num = qu[q][0]
            lis = list(map(lambda x:x-1, qu[q][1:]))
            su = 0
            for i in lis:
                su ^= k[i]
            if su == p[q]:
                s += 1
        if s == m:
            ans += 1
    print(ans)
    return

#D
def D():
    n,k = LI()
    v = LI()
    ans = -float("inf")
    for l in range(min(k,n)+1):
        for r in range(min(k,n)-l+1):
            m = 0
            q = v[:l]+v[n-r:]
            q.sort()
            res = max(0,k-r-l)
            for i in range(len(q)):
                if q[i] < 0 and res > 0:
                    res -= 1
                else:
                    m += q[i]
            if m > ans:
                ans = m
    print(ans)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

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


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

int main(void){
    char c;
    cin>>c;
    char vowels[] = {'a', 'i', 'u', 'e', 'o'};
    bool ok = false;
    for (char vowel: vowels){
        if(c==vowel) ok = true;
    }
    cout<<((ok) ? "vowel" : "consonant")<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::collections::HashMap;



fn main() {
    let _n = read::<usize>();
    let an = read_vec();


    let mut hmap: HashMap<i64, i64> = HashMap::new();
    for a in an.iter() {
        let c = hmap.entry(*a).or_insert(0);
        *c += 1;
    }

    let default_ans = {
        let mut ans = 0;
        for v in hmap.values() {
            ans += *v * (*v - 1) / 2;
        }
        ans        
    };

    for a in an.iter() {
        let c = hmap.get_mut(a).unwrap();
        let mut ans  = default_ans - *c * (*c-1)/2;
        *c -= 1;
        ans += *c * (*c - 1) / 2;
        println!("{:?}", ans);
        *c += 1;
    }
}
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 18064
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    long long u = min({a, b, c, d, e});
    cout << (n+u-1) / u + 4 << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

a, b = list(map(int, sys.stdin.buffer.readline().split()))
if a > b:
    print( a * 2 - 1)
elif a == b:
    print(a * 2 )
else:
    print(b * 2 - 1)
    


Measured memory_bytes: 14164
let last_i = ref 0

let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let extract (t : int array) =
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= !last_i && t.(l) > t.(i) then l else i in
    let m = if r <= !last_i && t.(r) > t.(m) then r else m in
    if i = m then ()
    else begin
      let tmp = t.(i) in
      t.(i) <- t.(m);
      t.(m) <- tmp;
      max_heapify m
    end in
  let ret = t.(1) in
  t.(1) <- t.(!last_i);
  decr last_i;
  max_heapify 1;
  ret

let insert x (t : int array) =
  let rec doit i =
    let p = parent i in
    if i <= 1 || t.(p) >= t.(i) then ()
    else begin
      let tmp = t.(i) in
      t.(i) <- t.(p);
      t.(p) <- tmp;
      doit p
    end in
  incr last_i;
  t.(!last_i) <- x;
  doit !last_i

let () =
  let t = Array.make 2000001 0 in
  let rec doit () =
    let op = Scanf.scanf "%s " (fun i -> i) in
    if op = "end" then ()
    else if op = "extract" then begin
      extract t |> Printf.printf "%d\n";
      doit ()
    end else begin
      insert (Scanf.scanf "%d " (fun i -> i)) t;
      doit ()
    end in
  doit ()

Measured memory_bytes: 20332
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String str=s.nextLine();
        int[] arr=new int[26];
        for(int i=0;i<str.length();i++){
            arr[str.charAt(i)-'a']++;
        }
        for(int i=0;i<26;i++){
            if(arr[i] %2!=0){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");

    }
}


Measured memory_bytes: 21844
arr = map(int, input().split())
cnt_5 = cnt_7 = 0
for num in arr:
    if num == 5:
        cnt_5 += 1
    elif num == 7:
        cnt_7 += 1

if cnt_5 == 2 and cnt_7 == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int L[1000];
bool table[1020];
int n,m;

bool solve() {
  for (int i=1; i<n; ++i) {
    int hoge = L[i-1]-table[i-1];
    if (hoge == L[i]) table[i+m-1] = 0;
    else if (hoge == L[i]-1) table[i+m-1] = 1;
    else return 0;
  }
  return 1;
}

int main() {
  while(cin >> n >> m, n||m) {
    REP(i, n) cin >> L[i];
    string s = string(m-L[0], '0') + string(L[0], '1');
    bool ok = 0;
    do {
      REP(i, m) table[i] = (s[i]=='1');
      if (solve()) {
        ok = 1;
        break;
      }
    } while(next_permutation(ALL(s)));
    if (ok) {
      REP(i, n+m-1) cout << table[i];
      cout << endl;
    } else {
      cout << "Goofy" << endl;
    }
  }
  
}

Measured memory_bytes: 928
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

A, B, C = list(map(int, sys.stdin.buffer.readline().split()))
A, B = B, A
A, C = C, A
print(A, B, C)


Measured memory_bytes: 24928
H, W = map(int, input().split())

A = [[None for c in range(W)] for r in range(H)]
for i in range(H):
    line = input()
    for j in range(W):
        A[i][j] = 0 if line[j] == '.' else 1

D = [[0 for c in range(W)] for r in range(H)]
for i in range(H):
    for j in range(W):
        up_left = []
        if i >= 1:
            up_left.append([A[i-1][j], D[i-1][j]])
        if j >= 1:
            up_left.append([A[i][j-1], D[i][j-1]])
        if A[i][j] == 0:
            if not up_left:
                D[i][j] = 0
                continue
            D[i][j] = min(map(lambda x: x[1], up_left))
        else:
            if not up_left:
                D[i][j] = 1
                continue
            D[i][j] = min(map(lambda x: (1-x[0])+x[1], up_left))

print(D[-1][-1])

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

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

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

int main(){
	int n;
	int a[100010];
	int cnt[100010] = {};
	scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
		cnt[a[i]] ++;
	}
	
	int x = 0;
	rep(i,100010)x += max(0,cnt[i]-1);
	cout << n-((x+1)/2)*2 << endl;
}



Measured memory_bytes: 1024
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])

for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 47548
import java.text.DecimalFormat;
import java.util.*;

public class Main {

    public static void main(String [] commandLineArgument){

        Scanner input = new Scanner(System.in);
        double l  = input.nextDouble();
        double single = l/3;
        double answer = single * single * single;
        System.out.println(String.format("%.6f" , answer));
        input.close();
    }

}



Measured memory_bytes: 24272
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){

    string s;
    cin >> s;

    vector <char> ans(s.length());
    int ansl = 0;

    for (int i = 0; i < s.length(); i++){
        if (s[i] != 'B'){
            ans[ansl] = s[i];
            ansl ++;
        }else if(ansl > 0){
            ansl --;
        }
    }
    
    for (int i = 0; i < ansl; i++){
        cout << ans[i];
    }
    cout << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const long long MOD = 1000000007;

int dp[60][4][4];

void solve(long long N, std::vector<std::string> S){
    S[0] = "$" + S[0];
    S[1] = "$" + S[1];
    dp[0][3][3] = 1;

    for(int i = 1; i <= N; ++i) {
        for(int j = 0; j < 3; ++j) for(int k = 0; k < 3; ++k) {
            if(S[0][i] == S[1][i]) {
                if (j != k) continue;
                for(int l = 0; l < 4; ++l) for(int m = 0; m < 4; ++m) {
                    if (l == j || m == k) continue;
                    dp[i][j][k] = (dp[i][j][k] + dp[i-1][l][m]) % MOD;
                }
            } else {
                if (j == k) continue;
                for(int l = 0; l < 4; ++l) for(int m = 0; m < 4; ++m) {
                    if (S[0][i-1] == S[0][i] && l != j) continue;
                    if (S[0][i-1] != S[0][i] && l == j) continue;
                    if (S[1][i-1] == S[1][i] && m != k) continue;
                    if (S[1][i-1] != S[1][i] && m == k) continue;
                    dp[i][j][k] = (dp[i][j][k] + dp[i-1][l][m]) %MOD;
                }
            }
        }
    }
    int res = 0;
    for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j) {
        res = (res + dp[N][i][j]) % MOD;
    }
    cout << res << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(2);
    for(int i = 0 ; i < 2 ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

const int INF = numeric_limits<int>::max();

constexpr int MAX_N = 105;

int A, B, D[11][11];

int F[MAX_N][MAX_N];

int main() {
    cin >> A >> B;
    for (int j = 0; j < A; ++j) {
        for (int k = 0; k < B; ++k) {
            cin >> D[j][k];
        }
    }

    for (int j = 0; j < MAX_N; ++j) for (int k = 0; k < MAX_N; ++k) {
        for (int a = 0; a < A; ++a) for (int b = 0; b < B; ++b) {
            F[j][k] = max(F[j][k], D[a][b] - (a+1) * j - (b+1) * k);
        }
    }

    for (int a = 0; a < A; ++a) for (int b = 0; b < B; ++b) {
        int min_dist = INF;
        for (int j = 0; j < MAX_N; ++j) {
            for (int k = 0; k < MAX_N; ++k) {
                min_dist = min(min_dist, (a+1) * j + (b+1) * k + F[j][k]);
            }
        }
        if (min_dist != D[a][b]) {
            printf("Impossible\n");
            return 0;
        }
    }

    printf("Possible\n%d %d\n", 2*MAX_N, 2*(MAX_N-1) + MAX_N*MAX_N);
    for (int j = 0; j < MAX_N-1; ++j) {
        printf("%d %d X\n", (j+1), (j+2));
    }
    for (int j = 0; j < MAX_N-1; ++j) {
        printf("%d %d Y\n", MAX_N+(j+1), MAX_N+(j+2));
    }
    for (int j = 0; j < MAX_N; ++j) {
        for (int k = 0; k < MAX_N; ++k) {
            printf("%d %d %d\n", (j+1), 2*MAX_N-k, F[j][k]);
        }
    }
    printf("%d %d\n", 1, 2*MAX_N);
    return 0;
}


Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <bits/stdc++.h>

using namespace std;

class AConnectionAndDisconnection {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        string s;
        cin >> s;
        long k;
        cin >> k;
        char now = s[0];
        long long int cnt = 1;
        long long int forward = 0;
        long long int middle = 0;
        long long int backward = 0;
        for (int i = 1; i < s.size(); ++i) {
            if (s[i] == now) cnt += 1;
            else {
                if (forward == 0) forward = cnt;
                else {
                    if (cnt != 1) middle += cnt / 2;
                }
                now = s[i];
                cnt = 1;
            }
        }
        backward = cnt;
        if (s[0] == now) {
            if (forward == 0 && middle == 0) cout << s.size() * k / 2 << endl;
            else cout << middle * k + (forward + backward) / 2 * (k - 1) + forward / 2 + backward / 2 << endl;
        } else {
            cout << (forward / 2 + middle + backward / 2) * k << endl;
        }
    }
};


int main() {
    AConnectionAndDisconnection solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify

N, K = map(int, input().split())
V = list(map(int, input().split()))

# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000

# Operation A, B: Remove left or right
# Operation C, D: Add to left or right

S = 0
for take in range(min(N, K) + 1):
    for takeL in range(take + 1):
        for takeR in range(take - takeL + 1):
            hand = []
            for i in range(takeL):
                heappush(hand, V[i])
            for i in range(takeR):
                if N - i - 1 < takeL:
                    break
                heappush(hand, V[N- i - 1])
            S = max(sum(hand), S)
            for _ in range(K - take):
                if not hand or hand[0] >= 0:
                    break
                heappop(hand)
                S = max(sum(hand), S)
print(S)



Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int n;

	scanf("%d" ,&n);

	if (n < 10)
		printf("%d" ,n);
	else if (n < 100)
		printf("9");
	else if (n < 1000)
		printf("%d" ,9 + (n - 99));
	else if (n < 10000)
		printf("909");
	else if (n < 100000)
		printf("%d" ,9 + 900 + (n - 9999));
	else
		printf("90909");
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();

		List<Integer> list = new ArrayList<>();
		list.add(P + Q);
		list.add(R + Q);
		list.add(P + R);

		Collections.sort(list);
		System.out.println(list.get(0));

	}
}	

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int h[N];
  for(int i=0; i<N; i++) cin >> h[i];
  int x, count, sum=0, zeros=0;
  while(zeros<N){
    count = 0;
    x = 0;
    zeros=0;
    for(int i=0; i<N; i++){
      if(x==0 && h[i]>0) count++;
      x = h[i];
      if(h[i]>0) h[i]--;
      else zeros++;
    }
    sum += count;
  }
  
  cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 },
			{ 1, 1 } };
	static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
	static int ans;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (true) {

			int n = sc.nextInt();

			if (n == 0) {
				break;
			}
			String[] s = new String[n];
			String[] codes = new String[n];
			int maxLength = 0;
			int maxCount = 0;

			for (int i = 0; i < n; i++) {
				s[i] = sc.next();
				codes[i] = "";

				for (int j = 0; j < s[i].length(); j++) {
					if (j == 0) {
						codes[i] += s[i].charAt(0);
					} else {
						char preChar = s[i].charAt(j - 1);
						if (preChar == 'a' || preChar == 'i' || preChar == 'u' || preChar == 'e' || preChar == 'o') {
							codes[i] += s[i].charAt(j);
						}
					}
				}
				if (maxLength < codes[i].length()) {
					maxCount = 1;
					maxLength = codes[i].length();
				} else if (maxLength == codes[i].length()) {
					maxCount++;
				}
			}

			int idx = -1;
			ans = -1;
			boolean hasSameCode = true;

			while (hasSameCode && idx < maxLength) {
				idx++;
				hasSameCode = false;

				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						if (i == j) {
							continue;
						}
						if (codes[i].substring(0, Integer.min(idx + 1, codes[i].length()))
								.equals(codes[j].substring(0, Integer.min(idx + 1, codes[j].length())))) {
							hasSameCode = true;
						}
					}
				}
			}

			ans = idx + 1;
			if (idx == maxLength) {
				ans = -1;
			}

			System.out.println(ans);
		}

	}

	// BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	// //二分探索
	// k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// 二分探索
	// k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}



Measured memory_bytes: 97676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.awt.Point;

public class Main {
    static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    // static long MOD = (long) 1e9 + 7;

    static class Solver {
        int X, N;
        int[] p;

        // write your code
        void solve(InputReader in, PrintWriter out) {
            X = in.nextInt();
            N = in.nextInt();
            p = new int[N];
            for (int i = 0; i < N; i++) {
                p[i] = in.nextInt();
            }

            int diff = INF;
            int ans = INF;
            for (int i = 0; i <= 101; i++) {
                boolean flag = true;
                for (int j = 0; j < N; j++) {
                    if (p[j] == i) {
                        flag = false;
                        break;
                    }
                }
                int newDiff = Math.abs(i - X);
                if (flag && newDiff < diff) {
                    diff = newDiff;
                    ans = i;
                }
            }
            out.println(ans);
        }

        void debug(Object... os) {
            System.err.println(Arrays.deepToString(os));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 32848
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
S = np.array([list(map(int, input().split())) for i in range(D)])

last_day = np.zeros(26, dtype=int)

ans = []
for d in range(1, D+1):
    decrease = c * (d - last_day)
    sd = decrease.sum()
    diff = [S[d-1, i] - sd + decrease[i] for i in range(26)]
    choice = np.argmax(diff)
    ans.append(choice+1)
    last_day[choice] = d


print(*ans, sep='\n')

Measured memory_bytes: 27524