akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#define IsDigit(x) ((x) >= '0' && (x) <= '9')
using namespace std;

int n, pos;
int last[200001], parity[200001], cross_edge[100001];
struct Edge{
	int y, prev, dir;
}edge[600000];


int Read(void)
{
	int c, ret(0);
	bool sign(false);
	
	c = getchar();
	while (!IsDigit(c) && c != '-')
		c = getchar();
	c == '-' && (sign = true, c = getchar());
	do
		ret = ret * 10 + c - '0';
	while ((c = getchar()) && IsDigit(c));
	return sign ? -ret : ret;
}


inline void AddBiEdge(const int x, const int y)
{
	edge[pos].y = y;
	edge[pos].prev = last[x];
	last[x] = pos++;
	edge[pos].y = x;
	edge[pos].prev = last[y];
	last[y] = pos++;
	return;
}


int main()
{
	int ance, root_A, root_B, curr;
	
	n = Read();
	pos = 2;
	for (int i = 1; i <= n; ++i) {
		ance = Read();
		if (ance == -1)
			root_A = i;
		else {
			AddBiEdge(i, ance);
			++parity[ance];
		}
	}
	for (int i = 1; i <= n; ++i) {
		ance = Read();
		if (ance == -1)
			root_B = n + i;
		else {
			AddBiEdge(n + i, n + ance);
			++parity[n + ance];
		}
	}
	for (int i = 1; i <= n; ++i)
		if ((parity[i] & 1) ^ (parity[n + i] & 1)) {
			printf("IMPOSSIBLE\n");
			return 0;
		}
		else
			if (~parity[i] & 1) {
				AddBiEdge(i, n + i);
				cross_edge[i] = pos - 2;
			}
	AddBiEdge(root_A, root_B);
	for (int src = 1; src <= n << 1; ++src) {
		while (last[src] && edge[last[src]].dir)
			last[src] = edge[last[src]].prev;
		if (!last[src])
			continue;
		curr = src;
		do {
			while (edge[last[curr]].dir)
				last[curr] = edge[last[curr]].prev;
			edge[last[curr]].dir = 1;
			edge[last[curr] ^ 1].dir = 2;
			curr = edge[last[curr]].y;
		}
		while (curr != src);
	}
	printf("POSSIBLE\n");
	for (int i = 1; i <= n; ++i)
		if (cross_edge[i])
			printf(edge[cross_edge[i]].dir == 1 ? "-1 " : "1 ");
		else
			printf("0 ");
	printf("\n");
	return 0;
}



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

typedef long long int llint;

struct shop{
	llint A;
	int B;
};

int main(){
	int N,M;
	vector<shop> shoplist; 
	cin >> N >> M;

	for(int i=0;i<N;i++){
		int a,b;
		cin >> a >> b;
		shoplist.push_back((shop){a,b});
	}

	sort(shoplist.begin(),shoplist.end(),[](shop sl,shop sr){
		return sl.A<sr.A;
	});

	llint cost=0;
	for(const shop& s : shoplist){
		if(s.B>=M){
			cost+=s.A*M;
			break;
		}else{
			M-=s.B;
			cost+=s.A*s.B;
		}
	}
	cout << cost << endl;
	return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1
#define TRUE 1
#define FALSE 0

void initialize(void);
void printBoard(void);
void recursive(int);

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],X[N][N];

int main(void){
  int k,r,c;
  int i,j;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      X[i][j] = FALSE;
    }
  }
  
  scanf(" %d",&k);
  for(i = 0; i < k; i++){
    scanf(" %d %d",&r,&c);
    X[r][c] = TRUE;
  }

  recursive(0);
  
  return 0;
}

void initialize(void){
  int i;
  
  for(i = 0; i < N; i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i = 0; i < 2*N-1; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void printBoard(void){
  int i,j;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(X[i][j]){
	if(row[i] != j)return;
      }
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      printf("%c",(row[i] == j ? 'Q':'.'));
    }
    printf("\n");
  }
}

//get row(i)
void recursive(int i){
  int j;
  if(i == N){ //putting Queen is succeded
    printBoard(); return;
  }

  for(j = 0; j < N; j++){
    //if (i,j) is attacked by others, ignore that case
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      continue;
    }
    //put Queen at (i,j)
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    //try next row
    recursive(i+1);
    //remove Queen from (i,j)
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
  //putting Queen has been failed
}



Measured memory_bytes: 2112
#include <cstdio>
#include <algorithm>
#include <set>


int main() {
  std::multiset<int> set;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++ i) {
    int x;
    scanf("%d", &x);
    set.emplace(x);
  }
  int result = 0;
  while (set.size() >= 2) {
    int x = *set.rbegin();
    set.erase(--set.end());
    int b = 1;
    while (b <= x) b <<= 1;
    int y = b - x;
    auto it = set.find(y);
    if (it != set.end())
      set.erase(it), ++ result;
  }
  printf("%d\n", result);
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=2015;
const int NN=1000001;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    set<ll> ans;
    ans.insert(n);
    ans.insert(max(2ll,n-1));
    ll t;
    for (ll i=2;i*i<=n;i++){
        t=n;
        while (t>=i){
            if (t%i==0){
                t/=i;
            }else {
                t%=i;
            }
        }
        if (t==1){
            ans.insert(i);
        }
    }
    n--;
    for (ll i=2;i*i<=n;i++){
        if (n%i==0){
            ans.insert(i);
            ans.insert(n/i);

        }
    }
    cout << ans.size() << E;
    r0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
int main(void){
    int d,t,s; cin >> d >> t >> s;
    if(d<=t*s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}



Measured memory_bytes: 3632
n=int(input())
x=list(map(int,input().split()))

min_i = [x[0]]
for i in range(1,n):
    min_i.append(min(min_i[i-1],x[i]))

count=0
for i in range(1,n):
    if min_i[i-1] < x[i]:
        count=count+1

print(n-count)


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

typedef long long ll;
ll mod=1e9+7;

ll dp[110][10];
ll fib[20]; 

int main(){
  ll h,w,k;
  cin >> h >> w >> k;
  fib[0]=0,fib[1]=1;
  for(int i=2;i<20;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }
  dp[0][1]=1;
  for(int i=2;i<=w;i++) dp[0][i]=0;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      dp[i][j]=(dp[i-1][j-1]*fib[w-j+1]%mod*fib[j-1]%mod+dp[i-1][j+1]*fib[w-j]%mod*fib[j]%mod+dp[i-1][j]*fib[j]%mod*fib[w-j+1]%mod)%mod;
    }
  }
  cout << dp[h][k] << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int count1 =0;
		int count2 =0;
		int count3 =0;
		int count4 =0;
		for (int i = 0; i < 6; i++) {
			int ab = sc.nextInt();
			if(ab==1){
				count1++;
			}else if(ab==2){
				count2++;
				
			}else if(ab==3){
				count3++;
			}else if(ab==4){
				count4++;
			}
		}

		
		List<Integer> list = new ArrayList<>();
		list.add(count1);
		list.add(count2);
		list.add(count3);
		list.add(count4);
		
		Collections.sort(list);
		// System.out.println(list);

		if(list.get(0)==1&&list.get(1)==1&&list.get(2)==2&&list.get(3)==2){

			System.out.println("YES");
		}else{

			System.out.println("NO");
		}

	}
}


Measured memory_bytes: 21844
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val a = nextInt()
    val b = nextInt()
    val c = nextInt()
    val x = nextInt()

    var cnt = 0

    for (i in 0..a) {
        for (j in 0..b) {
            for (k in 0..c) {
                if (i * 500 + j * 100 + k * 50 == x) cnt++
            }
        }
    }

    println(cnt)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33720
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>

using namespace std;

int main() {

	int N;
	cin >> N;

	vector<int> H(N);

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

	int sum = 1;

	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			if (H[j] > H[i])
				break;
			if (i == j)
				sum++;
		}
	}

	cout << sum << endl;


	
}



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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int main(void){
	int n,k;
	int h[200000];
	int i;
	long long int x;

	x = 0;

	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}

	qsort(h, n, sizeof(int), compare_int);

	for(i=0;i<n-k;i++){
		x += h[i];
	}

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

	return 0;
}



Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'



def main():
    N=ii()
    L=lmis()
    L.sort()
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                a, b, c = L[i], L[j], L[k]
                if a!=b!=c!=a:
                    # if abs(a-b)<c or abs(b-c)<a or abs(c-a)<b:
                    if a+b > c:
                        # print(i+1, j+1, k+1)
                        ans += 1
    print(ans)


main()



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

using namespace std;

int main() {
  int a;
  cin >> a;
  if (a > 9)
    a = a % 10;
  if (a == 3)
    cout << "bon";
  else if (a == 0 || a == 6 || a == 1 || a == 8)
    cout << "pon";
  else cout << "hon";
}

Measured memory_bytes: 3612
// F - Absolute Minima
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int q;
	cin >> q;
	multiset<long long> s;
	multiset<long long>::iterator it;
	long long count = 0, x = 0, ans = 0;
	while (q--) {
		int op;
		cin >> op;
		if (op == 1) {
			long long a, b;
			cin >> a >> b;
			s.insert(a);
			ans += b;
			if (count == 0) {
				it = s.begin();
				x = *it;
			} else {
				long long t = x;
				ans += abs(a - x);
				if (a >= x) {
					if (count % 2 == 0) x = *++it, ans -= x - t;
				} else if (a < x) {
					if (count % 2 == 1) x = *--it;
				}
			}
			count++;
		} else if (op == 2) {
			cout << x << ' ' << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  map<char, int> amap;
  bool can = false;
  if(S.size()!=26) {
    can = true;
    for(int i=0;i<S.size();++i) {
      amap[S[i]]++;
    }
    for(char a='a';a<='z';++a) {
      if(amap[a]==0) {
        S.push_back(a);
        break;
      }
    }
  }
  else {
    vector<char> arr;
    arr.push_back(S[25]);
    for(int i=24;i>=0;--i) {
      for(int j=0;j<arr.size();++j) {
        if(arr[j]>S[i]) {
          can = true;
          S[i] = arr[j];
          for(int j=0;j<25-i;++j) S.pop_back();
          break;
        }
      }
      if(can) break;
      arr.push_back(S[i]);
      sort(arr.begin(), arr.end());
    }
  }
  if(can) cout<<S<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
//--GLOBAL---------------------------------
struct SegmentTreeLazy{
  ll N; //要素の個数より大きい2べき乗
  vector<ll> dat;
  vector<ll> lazy;
  vector<bool> need_eval;

  SegmentTreeLazy(ll n) {
    N = 1;
    while(N < n) N <<= 1;
    dat.resize(2*N-1, INF2);
    lazy.resize(2*N-1, INF2);
    need_eval.resize(2*N-1, false);
  }

  // k 番目のノードについて遅延評価を行う
  void eval(ll k, ll l, ll r) {
    if(need_eval[k]) {
      dat[k] = lazy[k];

      if(r - l > 1) { //最下段でないなら下にlazyを半分ずつ渡す
        lazy[2*k+1] = min(lazy[2*k+1],lazy[k]);
        lazy[2*k+2] = min(lazy[2*k+2],lazy[k]);
        need_eval[2*k+1] = true;
        need_eval[2*k+2] = true;
      }
      need_eval[k] = false;
    }
  }

  void update(ll a, ll b, ll x, ll k=0, ll l=0, ll r=-1) {
    if(r < 0) r = N; // [a,b) 0-indexed

    eval(k, l, r);

    if(b <= l || r <= a) return; //範囲外は返す

    if(a <= l && r <= b) { //被覆ならlazyに入れて評価
      lazy[k] =min(lazy[k],x);
      need_eval[k] = true;
      eval(k, l, r);
    }

    else { //それ以外は子のdatを計算してからもらってくる
      update(a, b, x, 2*k+1, l, (l+r)/2);
      update(a, b, x, 2*k+2, (l+r)/2, r);
      dat[k] = min(dat[2*k+1], dat[2*k+2]);
    }
  }

  ll getmin(ll a, ll b, ll k=0, ll l=0, ll r=-1) {
    if(r < 0) r = N; // [a,b) 0-indexed
    if(b <= l || r <= a) return INF2; //範囲外

    eval(k,l,r);
    if(a <= l && r <= b) return dat[k]; //被覆なら返す
    ll vl = getmin(a, b, 2*k+1, l, (l+r)/2);
    ll vr = getmin(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
  }
};

//--MAIN-----------------------------------
void Main() {
    ll N,M; 
    cin >> N>>M;

    vector<tuple<ll,ll,ll>> lrc;

    rep(i,M){
        ll l,r,c; cin>>l>>r>>c;
        lrc.emplace_back(l,r,c);
    }

    SORT(lrc);

    SegmentTreeLazy st(N);

    st.update(0,1,0);

    rep(i,M){
        ll l=get<0>(lrc[i]);
        ll r=get<1>(lrc[i]);
        ll c=get<2>(lrc[i]);
        ll x=st.getmin(l-1,l);
        if(x==INF2){
            cout<< -1<<"\n";
            return;
        }
        st.update(l,r,x+c);
    }

    if(st.getmin(N-1,N)==INF2){
        cout<< -1<<"\n";
        return;
    }

    cout<< st.getmin(N-1,N) <<"\n";


}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 6896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    long long n,a,b,c,d,max,min;
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    max=a,min=a;
    for (int i=0; i<n-1; i++){
        if ((max+min)/2<b){
            max=max+d;
            min=min+c;
        } else {
            max=max-c;
            min=min-d;
        }
    }
    if (min<=b && max>=b){
        printf("YES\n");
    } else {
        printf("NO\n");
    }
	return 0 ;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if (A == B && A != C){
			System.out.println("Yes");
		} else if (B == C && A != C){
			System.out.println("Yes");
		} else if (A == C && A != B){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}


	}
}

Measured memory_bytes: 21716
from functools import reduce
def gcd(a,b):
    if b>0:
        return gcd(b,a%b)
    else:
        return a

N,X=map(int,input().split())
x=[int(i)for i in input().split()]
dist=[abs(X-i)for i in x]
d=reduce(gcd,dist)
print(d)

Measured memory_bytes: 20412
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint h[100005];
vector<llint> G[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> h[i];
	llint u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		bool flag = true;
		for(int j = 0; j < G[i].size(); j++){
			if(h[i] <= h[G[i][j]]) flag = false;
		}
		if(flag) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 10280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int cnt[][] = new int[10][10];
		for(int n = 1 ; n <= N ; ++n){
			int last = n % 10;
			int first = String.valueOf(n).charAt(0) - '0';
			if(first != 0){
				cnt[first][last]++;
			}
		}
		long S = 0;
		for(int A = 1 ; A <= N ; ++A){
			int alast = A % 10;
			int afirst = String.valueOf(A).charAt(0) - '0';
			S += cnt[alast][afirst];
		}
		System.out.println(S);
	}
}


Measured memory_bytes: 39276
#include <bits/stdc++.h>
// it starts with your mind
using namespace std;
typedef long long ll;
#define len length

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

int n , a;
cin >> n;
if(n % 1000 == 0)
 a = 0 ;
else  a =1000 -  n % 1000 ;
cout << a;

   return 0;
}




Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
using namespace std;
int h,w,n,a[10010],ans[110][110],t[10010],px,py,tot,dir;
int main()
{
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;++i) scanf("%d",a+i);
    px=1,py=1,dir=1;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=a[i];++j) t[++tot]=i;
    for(int i=1;i<=tot;++i)
    {
        ans[px][py]=t[i];
        py+=dir;
        if(py>w||py==0) px++,py-=dir,dir*=-1;
    }
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=w;++j) printf("%d ",ans[i][j]);
        printf("\n");
    }
    return 0;
}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a+b+c-max({a,b,c})<<endl;
	return 0;
}

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

int main(void){
    double a,b,x;
    cin >> a >> b >> x;
    x /= a;
    double PI = acos(-1);
    double t1 = atan(2.0/a * (b - x/a));
    double t2 = atan(b*b/(2*x));
    printf("%.10f\n", (b <= a * tan(t2) ? t2 : t1) * 180.0/PI);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<p2,int> p3;
typedef vector<ll> vi;
const ll Mod = 7 + 1e9;
const ll INF32 = 5 + 2e9;
const ll INF64 = 1 + 1e18;
const ll MAX = 5+ 1e5;

int N,K,a[105];
int dp[105][MAX];




int main()
{
    cin >> N >> K ;
    for(int i=1;i<=N;i++)
        cin >> a[i];
    dp[0][0] = 1;
    for(int i=1;i<=N;i++)
    {
        ll sum = 0;
        for(int j=0;j<=K;j++)
        {
            sum = (sum + dp[i-1][j])%Mod;
            if( j - a[i] -1 >= 0 )
                sum = (sum - dp[i-1][j - a[i] -1 ] + Mod )%Mod ;
            dp[i][j] = sum;
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}


Measured memory_bytes: 40832
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toLong() }
    val B = (1..N).map {
        val index = it - 1
        A.get(index) - it
    }.sorted()

    val median = B.get(N / 2)
    val answer = B.map { Math.abs(it - median) }.sum()

    println(answer)
}

Measured memory_bytes: 80576
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

const double EPS = 1e-10;
#define equals(a, b) (fabs((a) - (b)) < EPS)

struct Point{
    double x, y;
    Point(){}
    Point(double x0, double y0){
        x = x0; y = y0;
    }

    Point operator +(const Point &p){
        return Point(x + p.x, y + p.y);
    }
    Point operator -(const Point &p){
        return Point(x - p.x, y - p.y);
    }
    Point operator *(const double &a){
        return Point(a * x, a * y);
    }
    Point operator /(const double &a){
        return Point(x / a, y / a);
    }

    double norm(){
        return x * x + y * y;
    }
    double abs(){
        return sqrt(norm());
    }

    bool operator == (const Point &p){
        return equals(x, p.x) && equals(y, p.y);
    }

    bool operator < (const Point &p){
        // if(x != p.x) return x < p.x;
        // else return y < p.y; 
        return x != p.x ? x < p.x : y < p.y ;
    }

};

typedef Point Vector;

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}

struct Circle{
    Point c;
    double r;
    Circle(){}
    Circle(Point c0, double r0){
        c.x = c0.x;
        c.y = c0.y;
        r = r0;
    }
    Circle(double x0, double y0, double r0){
        c.x = x0;
        c.y = y0;
        r = r0;
    }
};

int main(){
    Point p1, p2;
    cin >> p1.x >> p1.y;
    cin >> p2.x >> p2.y;
    Vector v0 = p2 - p1;
    int Q;
    cin >> Q;

    rep(i, Q){
        Point p;
        cin >> p.x >> p.y;
        Vector v1 = p - p1;
        double r = dot(v0, v1) / v0.norm();
        Vector X = p1 + v0 * r;
        printf("%.10lf %.10lf\n", X.x, X.y);
    }
}


Measured memory_bytes: 3288
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

class UnionFind():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans


def main():
    N, M, K = map(int,input().split())
    friend = {}
    block = {}
    tree = UnionFind(N)

    for _ in range(M):
        a,b = map(lambda x:int(x)-1,input().split())
        tree.unite(a,b)
        for _ in range(2):
            if not a in friend.keys():
                friend[a] = [b]
            else:
                friend[a].append(b)
            a,b = b,a

    for _ in range(K):
        c,d = map(lambda x:int(x)-1,input().split())
        for _ in range(2):
            if not c in block.keys():
                block[c] = [d]
            else:
                block[c].append(d)
            c,d = d,c

    def solve(x):
        res = 0
        res += tree.get_size(x)

        if x in friend.keys():
            res -= len(friend[x])

        if x in block.keys():
            res -= len(list(filter(lambda y: tree.is_same_group(x,y),block[x])))

        return res - 1

    ans = []
    for i in range(N):
        ans.append(str(solve(i)))

    print(" ".join(ans))


if __name__ == "__main__":
  main()


Measured memory_bytes: 63724
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <atcoder/all>
#include <cstdio>

using namespace std;
using namespace atcoder;

long long int arr[200005];
long long int arr2[200005];
using F = int;

struct S {
	long long int a;
	int size;
};


S op(S l, S r) { return S{(l.a*arr[r.size])% 998244353 + r.a%998244353,l.size + r.size}; }

S e() { return S{ 0, 0 }; }

S mapping(F l, S r) 
{ 
	if (l == 0)
	{
		return r;
	}
	return S{ (arr2[r.size] * l)% 998244353,r.size };
}

F composition(F l, F r)
{
	if (l == 0)
	{
		return r;
	}
	return l;
}

F id() { return 0; }

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

	arr[0] = 1;
	arr2[0] = 0;
	for (int i = 1; i <= 200000; i++)
	{
		arr[i] = (arr[i - 1] * 10) % 998244353;
		arr2[i] = (arr2[i - 1] * 10 + 1) % 998244353;
	}

	int n, q;
	cin >> n >> q;

	vector<S> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = S{ 1, 1 };
	}
	lazy_segtree <S, op, e, F, mapping, composition, id> seg(a);

	for (int i = 0; i < q; i++)
	{
		int l, r, d;
		cin >> l >> r >> d;
		seg.apply(l - 1, r, d);
		long long int res = seg.prod(0, n).a;
		cout << res << '\n';
	}

	return 0;
}


Measured memory_bytes: 18780
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	string s;
	cin >> s;
	if(s=="Sunny")
		cout << "Cloudy" << endl;
	else if(s=="Cloudy")
		cout << "Rainy" << endl;
	if(s=="Rainy")
		cout << "Sunny" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int w,h,x,y,r;
  scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);

  if(x < 0 || y < 0)printf("No\n");
  else if(x+r <= w && y+r <= h)printf("Yes\n");
  else if(x+r > w || y+r > h)printf("No\n");
  return 0;
}

Measured memory_bytes: 584
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){

var line = chunk.toString();

var r = Number(line);

var cicrlearea= r*r*Math.PI
  var cicr= 2*r*Math.PI

console.log(cicrlearea.toFixed(5),cicr.toFixed(5));
});

Measured memory_bytes: 15592
#include <stdio.h>
int main(void)
{
	int a,b,t,i,j;
	while(scanf("%d %d",&a,&b) != EOF)
	{
		if(a < b){
				t = a;
				a = b;
				b = t;
			 }
		i = a;
		j = b;
		while(a != 0 && b != 0)
		{
			a = a % b;
			if(a == 0){
					printf("%d %d\n",b,i/b*j);
					break ;
			  	}
			b = b % a;
			if(b == 0){
					printf("%d %d\n",a,i/a*j);
					break ;
			  	}
		}
	}

	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N;
	cin >> N;
	if (N == 1) {
		cout << 1 << endl;
	}
	else {
		vector<ll> A(N+1);
		A.at(0) = 2;
		A.at(1) = 1;
		for (ll i = 2; i <=N; i++) {
			A.at(i) = A.at(i - 1) + A.at(i - 2);
		}
		cout << A.at(N ) << endl;
	}
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

void umin(int &a, int b) {
	a = min(a, b);
}

const int N = 2020;
const int INF = 1e18;
int n, num[2 * N], dp[N][N], w[2 * N][N], b[2 * N][N], pw[2 * N], pb[2 * N];
char col[2 * N];


signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

	cin >> n;
	for (int i = 1; i <= 2 * n; ++i) {
		cin >> col[i] >> num[i];
		if (col[i] == 'W') {
			pw[num[i]] = i;
			++w[i][num[i]];
		} else {
			pb[num[i]] = i;
			++b[i][num[i]];
		}
	}
	for (int i = 1; i <= 2 * n; ++i) {
		for (int j = n; j >= 0; --j) {
			w[i][j] += w[i - 1][j] + w[i][j + 1] - w[i - 1][j + 1];
			b[i][j] += b[i - 1][j] + b[i][j + 1] - b[i - 1][j + 1];
		}
	}
	fill_n(dp[0], N * N, +INF);
	dp[0][0] = 0;
	
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i + 1 <= n) {
				int pos = pw[i + 1];
				umin(dp[i + 1][j], dp[i][j] + w[pos - 1][i + 1] + b[pos - 1][j + 1]);
			}
			if (j + 1 <= n) {
				int pos = pb[j + 1];
				umin(dp[i][j + 1], dp[i][j] + w[pos - 1][i + 1] + b[pos - 1][j + 1]);
			}
		}
	}

	cout << dp[n][n] << "\n";
    return 0;
}


Measured memory_bytes: 159744
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << 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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int n;

int main() {
    while (cin >> n) {
        int res = 0;
        while (n > 1) {
            n = (n+2)/3;
            ++res;
        }
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> Vec;
void rotatex(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[1];a[1]=a[2];a[2]=a[3];a[3]=tmp;
  tmp=a[4];a[4]=a[5];a[5]=a[6];a[6]=a[7];a[7]=tmp;
}

void rotatey(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[1];a[1]=a[5];a[5]=a[4];a[4]=tmp;
  tmp=a[3];a[3]=a[2];a[2]=a[6];a[6]=a[7];a[7]=tmp;
}

void rotatez(Vec &a){
  int tmp;
  tmp=a[0];a[0]=a[4];a[4]=a[7];a[7]=a[3];a[3]=tmp;
  tmp=a[1];a[1]=a[5];a[5]=a[6];a[6]=a[2];a[2]=tmp;
}

int main(){
  string s[8];
  set<Vec> sv;
  map<Vec,bool> mv;
  while(cin>>s[0]){
    int i,j,k,ans=0;
    sv.clear();mv.clear();
    for(i=1;i<8;i++) cin>>s[i];
    sort(s,s+8);
    set<string> ss;
    Vec v;
    for(i=0;i<8;i++) ss.insert(s[i]),v.push_back(ss.size()-1);
    do{
      if(sv.find(v)!=sv.end()) continue;
      ans++;
      for(i=0;i<4;i++){
	rotatez(v);
	for(j=0;j<4;j++){
	  rotatey(v);
	  for(k=0;k<4;k++){
	    rotatex(v);
	    sv.insert(v);
	  }
	}
      }
    }while(next_permutation(v.begin(),v.end()));
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 7584
#include <iostream>
using namespace std;
long long S[10001], key;
int n;

bool linerSearch(){
    int i=0;
    S[n]=key;
    while(S[i]!=key){
        i++;
    }
    if(i == n)  return false;
    return true;
}

int main(void){
    int q, count=0;
    long long T[501];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> S[i];
    }
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> T[i];
    }
    for(int i=0; i<q; i++){
        key = T[i];
        if(linerSearch())   count++;
    }
    cout << count << endl;
    return 0;
}


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

#define xx first
#define yy second

const int N = 3001;
const ll oo = 1e16;

int n, a[N];
ll memo[N][N];

ll dp(int i, int j) {
    if (i == j)
        return a[i];
    if (memo[i][j] != -oo)
        return memo[i][j];
    ll ans = -oo;
    ans = max(ans, a[i] - dp(i + 1, j));
    ans = max(ans, a[j] - dp(i, j - 1));
    return memo[i][j] = ans;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        fill(memo[i], memo[i] + n, -oo);
    cout << dp(0, n - 1) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 74124
import java.util.Scanner;

public class Main{
	static final int MAX = 1000;
	static final int INF = 1 << 21;
	static final int WHITE = 0;
	static final int GRAY = 1;
	static final int BLACK = 2;
	static int n, r, q;
	static Edge[]e;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    n = scan.nextInt();
	    q = scan.nextInt();
	    e = new Edge[q];
	    r = scan.nextInt();	// 始点
	    for(int i = 0; i < q; i++) {
	    	int s = scan.nextInt();
	    	int t = scan.nextInt();
	    	int d = scan.nextInt();
	    	e[i] = new Edge(s, t, d);
	    }
	    scan.close();
	    //bellmanFord();
	    if(bellmanFord()) {
	    	System.out.println("NEGATIVE CYCLE");
	    }else {
	    	for(int i = 0; i < n; i++) {
		    	if(d[i] == INF) {
		    		System.out.println("INF");
		    	}else {
		    		System.out.println(d[i]);
		    	}
		    }
	    }


	}
    static int[]d = new int[MAX];
	static boolean bellmanFord() {
        for(int i = 0; i < n; i++) {
            d[i] = INF;
        }
        d[r] = 0;
        for(int i = 0; i < n; i++) {
        	for(int j = 0; j < q; j++) {
        		if(d[e[j].from] != INF && d[e[j].to] > d[e[j].from] + e[j].cost) {
        			d[e[j].to] = d[e[j].from] + e[j].cost;
        			if(i == n - 1) return true;
        		}
        	}
        }
        return false;
	}
	static class Edge{
		int from, to, cost;
		public Edge(int from, int to, int cost) {
			this.from = from;
			this.to= to;
			this.cost = cost;
		}
	}
}



Measured memory_bytes: 37796
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parent = [i for i in range(self.n)]
    self.rank = [0] * self.n
  
  def find_root(self, x):
    if self.parent[x] == x:
      return x
    else:
      self.parent[x] = self.find_root(self.parent[x])
      return self.parent[x]
  
  def unite(self, x, y):
    rx = self.find_root(x)
    ry = self.find_root(y)
    if rx == ry:
      return
    if self.rank[rx] < self.rank[ry]:
      self.parent[rx] = ry
    else:
      self.parent[ry] = rx
      if self.rank[rx] == self.rank[ry]:
        self.rank[rx] += 1
  
  def is_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

N, M = map(int, input().split())
edge = []
bridge = 0
for _ in range(M):
  e = list(map(lambda x: int(x)-1, input().split()))
  edge.append(e)

for i in range(M):
  uf = UnionFind(N)
  for j in range(M):
    if j == i:
      continue
    uf.unite(edge[j][0], edge[j][1])
  
  root = uf.find_root(0)
  for i in range(1, N):
    if root != uf.find_root(i):
      bridge += 1
      break

print(bridge)

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

string S; int K, leng, rem, a[1000009], dp[1000009]; vector<int>H;

void suffix_array() {
	vector<char>F;
	for (int i = 0; i < S.size(); i++)F.push_back(S[i]);
	sort(F.begin(), F.end());
	for (int i = 0; i < F.size(); i++) {
		a[i] = lower_bound(F.begin(), F.end(), S[i]) - F.begin(); a[i]++;
	}
	for (int i = 0; i < 19; i++) {
		vector<long long>E;
		for (int j = 0; j < S.size(); j++) {
			E.push_back(1000000LL * a[j] + a[(1 << i) + j]);
		}
		sort(E.begin(), E.end());
		for (int j = 0; j < S.size(); j++) {
			int pos1 = lower_bound(E.begin(), E.end(), 1000000LL * a[j] + a[(1 << i) + j]) - E.begin();
			a[j] = pos1 + 1;
		}
	}
	vector<pair<int, int>>G;
	for (int i = 0; i < S.size(); i++) G.push_back(make_pair(a[i], i));
	sort(G.begin(), G.end());
	H.push_back(0);
	for (int i = 0; i < G.size(); i++) H.push_back(G[i].second);
}
bool solve(int pos) {
	for (int i = 0; i <= S.size(); i++) dp[i] = (1 << 30);
	dp[0] = 0;
	for (int i = 0; i < S.size(); i++) {
		dp[i + leng - 1] = min(dp[i + leng - 1], dp[i] + 1);
		if (a[i] > pos) continue;
		dp[i + leng] = min(dp[i + leng], dp[i]);
	}
	if (dp[S.size()] > rem) return false;
	return true;
}

int main() {
	cin >> K >> S; leng = (S.size() + K) / (K + 1); rem = (K + 1)*leng - S.size();
	suffix_array();
	int L = 1, R = S.size() + 1, M, minx = (1 << 30);
	for (int i = 0; i < 20; i++) {
		M = (L + R) / 2;
		bool I = solve(M);
		if (I == true) { minx = min(minx, M); R = M; }
		else { L = M; }
	}
	cout << S.substr(H[minx], leng) << endl;
	return 0;
}

Measured memory_bytes: 7192
R=range(9)
def f1(M):
  global F
  for y in R:
    A=M[y]
    if len(set(A))==9: continue
    for x in R:
      if A.count(A[x])>=2: F[y][x]="*"
  return
def f2(M):
  global F
  for x in R:
    A=[M[y][x] for y in R]
    if len(set(A))==9: continue
    for y in R:
      if A.count(A[y])>=2: F[y][x]="*"
  return
def f3(M):
  global F
  for i in R:
    x=i%3*3
    y=i/3*3
    A=M[y][x:x+3]+M[y+1][x:x+3]+M[y+2][x:x+3]
    if len(set(A))==9: continue
    for j in R:
      if A.count(A[j])>=2: F[y+j/3][x+j%3]="*"
  return

n=input()
while n:
  M=[]
  F=[[" " for _ in [0]*9] for _ in [0]*9]
  M=[map(int,raw_input().split()) for _ in [0]*9]
  f1(M)
  f2(M)
  f3(M)
  for i in R:
    s=zip(F[i],map(str,M[i]))
    print "".join([a+b for a,b in s])
  if n>1: print
  n-=1

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

int main(void) {
	vector<int> v;
	v.push_back(2);
	v.push_back(3);
	int i, j;
	bool flag;
	for (i = 5; i < 999999; i++) {
		flag = true;
		for (j = 2; j <= sqrt(i); j++) {
			if (i % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			v.push_back(i);
		}
	}
	int n;
	while (cin >> n) {
		i = distance(v.begin(), lower_bound(v.begin(), v.end(), n));
		if (v[i] == n)
			cout << i + 1 << endl;
		else 
			cout << i << endl;
	}

}


Measured memory_bytes: 3356
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main(){
int H,W;
cin>>H>>W;
int N;
cin>>N;
int painted=0;
int paint_count[N+1];
rep3(i,N){
    cin>>paint_count[i];
}
int grid[H+1][W+1];
rep3(i,H){
    if(i%2==1){
        rep3(j,W){
            grid[i][j]=painted+1;
            paint_count[painted+1]--;
            if(paint_count[painted+1]==0){
                painted++;
            }
        }

    }
    else{
        repr3(j,W){
            grid[i][j]=painted+1;
            paint_count[painted+1]--;
            if(paint_count[painted+1]==0){
                painted++;
            }

        }


    }
}
rep3(i,H){
    rep3(j,W){
        if(j!=W){
        cout<<grid[i][j]<<" ";
        }
        else{
           cout<<grid[i][j]<<endl; 
        }
    }
}



return 0;
}

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

using namespace std;

int main() {
    int t, no;
    cin >> t;

    //if (t > 3) no = 27 * (t*(t-1)*(t-2))/6;
        //else no = t * t * t;

    cout << t * t * t << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9+5;
int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin>>h[i];
    vector<int> dp(n,INF);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j <= i+k; j++){
            if(j<n){
                dp[j] = min(dp[j],dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    
    rep(i,0,8){
        if(s.substr(0,7-i)+s.substr(n-i,i)=="keyence"){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    
    cout<<"NO"<<endl;
    
}



Measured memory_bytes: 384
loop do
  n = gets.to_i
  break if n.zero?
  arr = n.times.map { gets.to_i }

  count = 0
  (n-2).downto(0) do |i|
    0.upto(i) do |j|
      if arr[j] > arr[j+1]
        arr[j], arr[j+1] = arr[j+1], arr[j]
        count += 1
      end
    end
  end

  puts count
end

Measured memory_bytes: 6104
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {

    ll A, B, C ,D;
    cin >> A >> B >> C >> D;

    cout << min(A, B) + min(C, D) << endl;

}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [[] for _ in range(M + 10)]
ans = 0
for _ in range(N):
  a, b = map(int, input().split())
  if a > M:
    continue
  AB[a].append(b)
import heapq
reward = []
heapq.heapify(reward)
for i in range(1, M + 1):
  for item in AB[i]:
    heapq.heappush(reward, -item)
  if reward:
    ans -= heapq.heappop(reward)
print(ans)

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

int main(){
    int p,s,count1=0,count2=0,count3=0,count;
    cin >> p >> s;
    for(int i=0;i<=p;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k<=j;k++){
                if(i+j+k==s && i>j && j>k)count1++;
                else if(i+j+k==s && i==j && j>k)count2++;
                else if(i+j+k==s && i>j && j==k)count2++;
                else if(i+j+k==s && i==j && j==k)count3++;
            }
        }
    }
    count = count1*6+count2*3+count3;
    cout << count;
    return 0;
}

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

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

using namespace std;
typedef long long ll;

#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
    ll x;
    cin>>x;
    ll kai=0;
    ll total=100;
    while(total<x){
        total*=1.01;
        kai++;
    }
    cout<<kai<<endl;
    return 0;
}

Measured memory_bytes: 3624
N, M = map(int, input().split())

Hl = [int(x) for x in input().split()]
al = []

for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  if Hl[a] > Hl[b]:
    al.append(b+1)
  elif Hl[a] < Hl[b]:
    al.append(a+1)
  else:
    al.extend([a+1,b+1])

al = set(al)
print(len(Hl) - len(al))

Measured memory_bytes: 91312