akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, K;
  cin >> N >> K;
  vector<ll> h(N);
  REP(i, N) { cin >> h.at(i); }
  sort(h.begin(), h.end());
  ll ans = 1e9;
  for (int i = 0; i < N - K + 1; ++i) {
    ans = min(h.at(i + K - 1) - h.at(i), ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits>
#include <map>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>

typedef long long li;
using namespace std;

li max(li a, li b) {
    return a > b ? a : b;
}

li max(li a, li b, li c) {
    return max(a, max(b, c));
}

li max(li a, li b, li c, li d) {
    return max(a, max(b, max(c, d)));
}

li max(li a, li b, li c, li d, li e) {
    return max(a, max(b, max(c, max(d, e))));
}


li pow_mod(li n, li e, li mod)
{
    li r = 1;
    
    while(e > 0)
    {
        if(e & 1)
            r *= n;
            r %= mod;
        
        n *= n;
        n %= mod;
        e >>= 1;
    }
    
    return r;
}

double solve(int n, unordered_map<int, double> & m) {
    double maxV = 0.0;
    
    if (m.count(n)) return m[n];
    if (n == 0) return 0.0;
    
    for (int i = 1; i <= n; i++) {
        maxV = max(maxV, solve(n - i, m)+ (double)i / (double)n);
    }
    
    return m[n] = maxV;
}

int solve(vector<int> & v, int n) {
    if (n < 0) return 0;
    vector<int> a, b;
    int minV = 0;
    
    for (int num: v) {
        if (num & (1 << n)) a.push_back(num);
        else b.push_back(num);
    }
    
    
    if (a.size() && b.size()) minV += (1 << n);
    
    if (a.size() && b.size()) minV += min(solve(a, n - 1), solve(b, n - 1));
    else if (a.size()) minV += solve(a, n - 1);
    else if (b.size()) minV += solve(b, n - 1);
    
    return minV;
    
}

int main() {
//    ifstream fin("read.txt");
    li h, n, k, num, s = 0;
    vector<li> v;
    
    cin >> n >> k;

    for (li i = 0; i < n; i++) {
    	cin >> num;
    	v.push_back(num);
    }

    sort(v.begin(), v.end());

    while(k > 0 && !v.empty()) {
    	v.pop_back();
    	k--;
    }

    for (li nn : v) s += nn;

   	
    cout << s << endl;

    return 0;
}




Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll N,x,y;
    cin>>N;
    rep(1,i,sqrt(N)+1){
        if(N%i==0){
            x=N/i;
            y=i;
        }
    }
    cout<<x+y-2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int L, R, d;
  cin >> L >> R >> d;
  int count = 0;
  int x = L;
  while(x <= R){
    if(x % d == 0){
      count++;
    }
    x++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
int main(void){
  int r=0,c=0,n,m,*a,*b;
  scanf("%d %d",&n,&m);
  a=(int*)calloc(n*(m+1),sizeof(int));
  b=(int*)calloc(m,sizeof(int));
  for(;r<n;r++)for(c=0;c<m;c++)scanf(" %d",&a[r*(m+1)+c]);
  for(c=0;c<m;c++)scanf(" %d",&b[c]);
  for(r=0;r<n;r++){
    for(c=0;c<m;c++)a[(r+1)*(m+1)-1]+=a[r*(m+1)+c]*b[c];
    printf("%d\n",a[(r+1)*(m+1)-1]);
  }
  free(a);
  free(b);
  return 0;
}

Measured memory_bytes: 652
def main():

    N, M = map(int, input().split())
    A = [True] * (N + 1)
    for i in range(M):
        a = int(input())
        A[a] = False

    dp = [0] * (N + 1)
    dp[0] = 1

    for i in range(0, N - 1):
        if not A[i]:
            continue
        if A[i+1]:
            dp[i+1] += dp[i]
        if A[i+2]:
            dp[i + 2] += dp[i]
        dp[i] %= 1000000007

    if A[N-1]:
        dp[N] += dp[N - 1]

    print(dp[N] % 1000000007)


main()


Measured memory_bytes: 7796
object Main extends App {
  val sc = new java.util.Scanner(System.in) 
  var x = sc.nextInt()
  val num = Stream.iterate(x){x => x + 1}
  val ans = num.filter(x => !calc(x)).head
  println(ans)

  def calc(n: Int): Boolean = {
    for (i <- 2 until n) {
      if (n % i == 0) {
        return true
      }
    }
    false
  }
}

Measured memory_bytes: 55424
#include <iostream>
#include <vector>

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

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

    vector<int> a(N + 1);
    vector<int> b(N + 1, -1);
    int M = 0;

    rep(i, N) {
        cin >> a[i + 1];
    }

    for(int i = N; i >= 1; i--) {
        IFD cout << "i: " << i << endl;
        int c = 0;
        for(int j = N / i; j >= 1; j--) {
            int v = j * i;
            IFD cout << v << endl;
            if(i == v) {
                b[v] = (a[v] + c) % 2;
                if(b[v] == 1) {
                    M++;
                }
            } else {
                c = (c + b[v]) % 2;
            }
        }
    }
    IFD cout << endl;

    IFD {
        rep(i, N) {
            cout << b[i + 1] << " ";
        }
        cout << endl << endl;
    }

    cout << M << endl;
    if(M != 0) {
        rep(i, N) {
            if(b[i + 1] == 1) {
                cout << i + 1 << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


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


int n;
vector <int> par;     //親
vector <int> ran;    //木の深さ

//n要素で初期化
void inti(int n){
    for(int i=0; i<n; i++){
        par.push_back(i);
        ran.push_back(0);
    }
}

//木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(ran[x] < ran[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(ran[x] == ran[y]) ran[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x) == find(y);
}

int main(){
    int m;
    cin >> n >> m;
    inti(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        unite(a,b);
    }

    vector <int> ans(n,0);
    rep(i,n){
        int oya = find(i);
        ans[oya] = 1;
    }

    int SUM = 0;
    rep(i,n){
        SUM += ans[i];
    }

    cout << SUM - 1 << endl;
}

Measured memory_bytes: 4584
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M=map(int, raw_input().split())
al=[ [] for i in range(N+1) ]
edge=[]

for i in range(M):
	a,b=map(int, sys.stdin.readline().split())
	al[a].append(b)
	edge.append((a,b))


def bfs(start,end):
	Visit=[ 0 for _ in range(N+1) ]	#訪問
	d=[ float("inf") for _ in range(N+1)]	#距離
	prev=[ None for _ in range(N+1)]	#経路復元
	d[start]=0
	q=deque()
	q.append(start)
	Visit[start]=1

	while q:
		fro=q.popleft()
		for to in al[fro]:
			if Visit[to]==0:
				Visit[to]=1
				alt=d[fro]+1
				if alt<d[to]:
					d[to]=alt
					prev[to]=fro
				q.append(to)
	return d[end],prev


K=float("inf")
v=[]
start=None
end=None

for x,y in edge:
	kyori,keiro=bfs(y,x)
	if kyori<K:
		K=kyori+1
		v=keiro
		start=y
		end=x

if K==float("inf"):
	print -1
else:
	print K
	print end
	fro=end
	while fro!=start:
		fro=v[fro]
		print fro

Measured memory_bytes: 35100
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (h, a) = (v[0], v[1]);
    let ans = (h + a - 1) / a;
    println!("{}", ans);
}

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> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+c >= 22)
        cout << "bust";
    
    else
    {
        cout << "win";
    }
    

    return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ????????¢?´¢ '''

# n??????????´??????????????????????q????????¢?´¢????????£?????´???
# ?¨??????????O(qlogn)


def binary_search(key, A):
    imin, imax = 0, len(S)

    while imin < imax:
        mid = int((imin + imax) / 2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            imax = mid
        else:
            imin = mid + 1
    return False


if __name__ == '__main__':
    NS = int(input())
    S = list(map(int, input().split()))
    NT = int(input())
    T = list(map(int, input().split()))

    count = 0

    for t in T:
        if binary_search(t, S):
            count += 1
    print(count)

Measured memory_bytes: 18712
#include<stdio.h>
#define N 2000000
#define I 1000000

int h,a[N+1];

void maxheap(int i){
  int l,r,max,t;
  l=2*i;
  r=2*i+1;

  if(l<=h && a[l]>a[i])max=l;
  else max=i;
  if(r<=h && a[r]>a[max])max=r;

  if(max != i){
    t=a[i];
    a[i]=a[max];
    a[max]=t;
    maxheap(max);
  }
}

int extract(){
  int max;
  if(h<1)return -I;
  max=a[1];
  a[1]=a[h--];
  maxheap(1);
  return max;
}

void increasekey(int i, int key){
  int t;
  if(key<a[i])return;
  a[i]=key;
  while(i>1 && a[i/2]<a[i]){
 t=a[i];
    a[i]=a[i/2];
    a[i/2]=t;
    i=i/2;
  }
}

void insert(int key){
  h++;
  a[h]=-I;
  increasekey(h,key);
}

int main(){
  int key;
  char c[10];

  while(1){
    scanf("%s",c);
    if(c[0]=='e' && c[1]=='n')break;
    if(c[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else printf("%d\n",extract());
  }

  return 0;
}



Measured memory_bytes: 5648
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
int pt[2][10];
int ans[2];
int main(){
	FOR(i,0,2){
		FOR(j,0,10)cin>>pt[i][j];
		sort(pt[i],pt[i]+10);
	}
	FOR(i,0,2)FOR(j,0,3)ans[i]+=pt[i][9-j];
	cout<<ans[0]<<" "<<ans[1]<<endl;
	return 0;
}

Measured memory_bytes: 1180
#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()
{
    ll x;
    cin >> x;
    ll y = 100;
    ll count = 0;
    while (y < x) {
        y *= 1.01;
        count++;
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

const int N = 1e6 + 5;

int v[103], w[103];
long long dp[103][N];

int main()
{
	int n, W;
	cin >> n >> W;

	for(int i = 1; i < 103; i++)
		for(int j = 1; j < N; j++)
			dp[i][j] = 1e9 + 5;

	for(int i = 1; i <= n; i++)
		cin >> w[i] >> v[i];

	for(int i = 1; i <= v[1]; i++)
		dp[1][i] = w[1];

	for(int i = 2; i <= n; i++){
		for(int j = 1; j < N; j++){
			dp[i][j] = dp[i - 1][j];
			if(j >= v[i])
				dp[i][j] = min(dp[i][j], dp[i - 1][j- v[i]] + w[i]);			
		}
	}

	int ans = 0;
	for(int j = 1; j < N; j++)
		if(dp[n][j] <= W)
			ans = j;

	cout << ans << "\n";
}

Measured memory_bytes: 798848
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K,*X=map(int,open(0).read().split())
    ans = 0
    for x in X:
        ans += min(abs(x-K), abs(x))
    print(2 * ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int n;
    double a;
    while(1) {
        cin >> n;
        if ( n == 0) break;
        int s[n],tl = 0;
        double m, z = 0;
        rep(i, n) cin >> s[i];
        rep(i, n) tl += s[i];
        m = 1.0 * tl / n;
        rep(i, n) {
            z += ( s[i] - m ) * ( s[i] - m );
        }
        a = sqrt( z / n);
        printf("%lf\n", a);
    }

    return 0;
}



Measured memory_bytes: 3196
#include <stdio.h>
int main(){
  int i=0;
  char s[1200]={'\0'};
  fgets(s,1200,stdin);
  for(;i<1200;i++){
    if(s[i]=='\n'){
      s[i]='\0';
      break;
    }
    if(s[i]-'A'>=0&&'Z'-s[i]>=0)s[i]+='a'-'A';
    else if(s[i]-'a'>=0&&'z'-s[i]>=0)s[i]+='A'-'a';
  }
  puts(s);
  return 0;
}

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

int main() {
    int N,input,stair=0;
    int data[110];
    cin >> N;

    for(int i=0;i<N;i++){
      cin >>input;
      data[i]= input;
    }
    sort(data, data+N,greater<int>());

    for(int i=1;i<=N;i++){
      if(data[i-1]!=data[i]){
        stair++;
      }
    }

    cout<<stair<<"\n";
    return 0;
}


Measured memory_bytes: 256
values = input().split(' ')
value = int(values[0])
#print(value)
sum = 0
for x in reversed(range(1, value+1)):
  if( len(list(str(x))) % 2 == 0): ## even digit
    continue
    print("hoge")
  sum = sum + 1
#  print(x)
#  print(len(list(str(x))) % 2 )
print(sum)

Measured memory_bytes: 3060
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        ab: [(usize, usize); n],
    }

    let mut a = vec![0; n];
    let mut b = vec![0; n];

    for i in 0..n {
        let (ae, be) = ab[i];
        a[i] = ae * 2;
        b[i] = be * 2;
    }

    a.sort();
    b.sort();

    let mut ans = 0;
    if n % 2 == 1 {
        ans = (b[n / 2] + 2 - a[n / 2]) / 2;
    } else {
        let aa = (a[n / 2] + a[n / 2 - 1]) / 2;
        let bb = (b[n / 2] + b[n / 2 - 1]) / 2;
        ans = bb + 1 - aa;
    }

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


Measured memory_bytes: 12960
N=int(input())
res = 0
def checkOdd(N):
  k = 0
  for i in range(1,N+1):
    if N % i ==0:
      k += 1
  if k == 8:
    return True
  else:
    return False
 
if N<104:
  print(res)
else:
  for i in range(105,N+1,2):
    if checkOdd(i):
      res += 1
  print(res)

Measured memory_bytes: 9092
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N, K;
    cin >> N >> K;
    
    vector<ll> pos(0);
    vector<ll> neg(0);
    for(int i=0; i<N; i++){
        ll a;
        cin >> a;
        if(a>=0){
            pos.push_back(a);
        }else{
            neg.push_back(-a);
        }
    }

    sort(pos.rbegin(),pos.rend());
    sort(neg.rbegin(),neg.rend());

    int i=0;
    int j=0;
    for(int k=0; k<K; k++){
        if(i==(int)pos.size()){
            j++;
        }else if(j==(int)neg.size()){
            i++;
        }else if(pos[i]>neg[j]){
            i++;
        }else{
            j++;
        }
    }

    ll ans=1;
    //cout << i << ' ' << j << endl;
    if(j%2==1){
        if((int)pos.size()==0 || (i==(int)pos.size() && j==(int)neg.size())){
            ans=MOD-1;
            for(int k=0; k<i; k++){
                ans*=pos[k];
                ans%=MOD;
            }
            for(int k=0; k<K-i; k++){
                ans*=neg[(int)neg.size()-1-k];
                ans%=MOD;
            }
            cout << ans << endl;
            return 0;
        }else if(i==(int)pos.size()){
            i--;
            j++;
        }else if(j==(int)neg.size()){
            i++;
            j--;
        }else if(i==0){
            i++;
            j--;
        }else if(pos[i-1]*pos[i]>neg[j-1]*neg[j]){
            i++;
            j--;
        }else{
            i--;
            j++;
        }
    }

    for(int h=0; h<i; h++){
        ans*=pos[h];
        ans%=MOD;
    }
    for(int h=0; h<j; h++){
        ans*=neg[h];
        ans%=MOD;
    }
    cout << (ans+MOD)%MOD << endl;
}

Measured memory_bytes: 5528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.next();
		String[] s = sc.next().split("");
		int x = 0, max = 0;
		for (int i = 0; i < s.length; i++)
			if (s[i].equals("I")) {
				x++;
				if (x > max)
					max = x;
			}
			else
				x--;
		System.out.println(max);
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main(){
    int k,x,max,min;
    cin >> k >> x;
    min = x-k+1;
    max = x+k;
    for(int i=min; i<max; i++){
        cout << i << " ";
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

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

constexpr double EPS = 1e-7;

template <typename T>
constexpr T INF = numeric_limits<T>::max();

template <class T>
constexpr T PI = static_cast<T>(3.14159265358979323846);

constexpr int MOD = 1e9 + 7;

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

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

template <typename T>
std::vector<T> table(int n, T v) { return std::vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
	auto val = table(args...);
	return std::vector<decltype(val)>(n, std::move(val));
}

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	string S;
	cin >> S;
	for (auto &&s : S) {
		cout << "x";
	}
	cout << endl;

	return 0;
}


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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	// keisan
	for(int i=1;i<=n;i++){
		int ans = 0;
		LL k = 0;
		for(int x=1;x<=100;x++){
			for(int y=x;y<=100;y++){
				for(int z=y;z<=100;z++){
					k = x*x+ y*y + z*z + x*y + y*z + z*x;
					if(k > i){
						break;
					}
					if(k == i){
						int count = 0;
						if(x == y){
							count++;
						}
						if(y == z){
							count++;
						}
						if(z == x){
							count++;
						}
						if(count == 3){
							ans += 1;
						}else if(count == 1){
							ans += 3;
						}else{
							ans += 6;
						}
					}
				}
				if(3*x*x+3*y*y > i){
					break;
				}
			}
			if(6*x*x > i){
				break;
			}
		}
		cout << ans << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newline '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template
int n,a[200100],BIT[200100],s[200100];
ll getsum (int idx){
    int sum = 0;
    idx++;
    while(idx>0){
        sum += BIT[idx];
        idx -= idx & (-idx);
    }
    return sum;
}
void update (int idx, int val){
    idx ++ ;
    while(idx<=200005){
        BIT[idx]+=val;
        idx += idx & (-idx);
    }
}
bool check (int x){
    int pre[200000];
    pre[0]=0;
    si sr;
    sitr it;

    for(int i=1;i<=n;i++){
        int temp;
        if(a[i]<x){temp=-1;}
        else{temp=1;}
        pre[i]=pre[i-1]+temp;
    }


    for(int i=0;i<=200004;i++)BIT[i]=0;

    ll num=0;
    for(int i=0;i<=n;i++){
        int temp = pre[i] + 100000;
        num += getsum(temp);
        update(temp,1);
    }

//    ll M = ( n * (n+1) )/2;
//    ll half = M/2;
//    if(M%2==1){half++;}
    ll half = (n*(n+1))/4;

    return num>=1LL*(n+1)*n/4;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];s[i]=a[i];
    }
    sort(s+1,s+1+n);
    int l=1;
    int r=n;
    ll ans;
    while(l<=r){
        int mid = (l+r)/2;
        if(check (s[mid])){ans=s[mid];l=mid+1;}
        else{r=mid-1;}
    }

    cout<<ans<<newline;



}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main(void) {
    int N,t=0,i=0,tmp=0,pos=0;
    cin>>N;
    int arrival[N],C[N],S[N], F[N];
        for(int i=0;i<N-1;i++){
              cin>>C[i]>>S[i]>>F[i];
        }

      for(int i=0;i<N-1;i++){
        while(pos<N-1){
          t++;
          if((t>=S[pos])&&(t%F[pos]==0)){
            t+=C[pos]-1;
            pos++;
          }
        }
        arrival[i] = t+1;
        t=0,pos=i+1;
      }

    for(int i=0;i<N;i++){
      if(i==N-1){
        cout<<0<<endl;
        return 0;
      }
          cout<<arrival[i]<<endl;
    }

    return 0;
}


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

int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

int main(){
	int a;
	cin >> a;
	long long int sum=0;
	//三項gcdの総和を返す
	for(int i = 1; i <= a; i++){
		for(int j = 1; j <=a; j++){
			for(int k = 1; k <= a; k++){
				sum += gcd(gcd(i,j),k);
			}
		}
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sum = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            sum += (a[i]*a[j]);
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  Vi a(x),b(y),c(z),d(x*y);
  rep(i,0,x) cin >> a[i];
  rep(i,0,y) cin >> b[i];
  rep(i,0,z) cin >> c[i];
  
  int ct = 0;
  rep(i,0,x){
    rep(j,0,y){
      d[ct] = a[i]+b[j];
      ct++;
    }
  }
  sort(ALL(d));
  reverse(ALL(d));
  
  ct = d.size();
  int l = min(k,ct);
  Vi ans(l*z);
  ct = 0;
  
  rep(i,0,l){
    rep(j,0,z){
      ans[ct] = d[i]+c[j];
      ct++;
    }
  }
  sort(ALL(ans));
  reverse(ALL(ans));
  
  rep(i,0,k) cout<<ans[i]<< endl;
  return 0;
}


Measured memory_bytes: 31616
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    string str;
    str = to_string(N);

    int _N = 0;
    for(int i = 0; i < str.length(); i++)
        _N += str[i] - '0';

    if(N % _N == 0){
        cout <<"Yes" << std::endl;
    }
    else cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    string s; cin >> s;
    _LL k; cin >> k;
    int l = s.length();
    bool pre = false;
    _LL count = 0;
    _LL c1 = 0;
    rep(i, l)
    {
        if(i == 0) continue;
        if( pre )
        {
            pre = false;
            continue;
        }
        if(s[i - 1] == s[i]) 
        {
            pre = true;
            count++;
        }
    }
    if( pre || s[l - 1] != s[0] || k == 1)
    {
        cout << count * k;
    }
    else
    {
        c1 = count;
        pre = true;
        count = 1;
        rep(i, l)
        {
            if(i == 0) continue;
            if( pre )
            {
                pre = false;
                continue;
            }
            if(s[i - 1] == s[i]) 
            {
                pre = true;
                count++;
            }
        }

        if( pre )
        {
            cout << (count + c1) * (k / 2) + c1 * (k % 2);
        }
        else
        {
            cout << c1 + (k - 1) * count;
        }       
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int d, n;
    cin >> d >> n;
    if(n==100)n++;
    ll ans = pow(100, d);
    ans *= n;
    outline(ans);
    return 0;
}

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

int main() {
	int a, b, c, k, x, y, z;
	cin >> a >> b >> c >> k;
	x = max(max(a, b), c);
	y = a + b + c - x;
	for(int i = 0; i < k; i++){
		x = x * 2;
	}
	cout << x + y << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
3 3
1 3 4
1 3 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll a[maxn],b[maxn];

int main()
{
	//IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) cin>>a[i];
	REP(i,m) cin>>b[i];

	ll tta=0,ttb=0; 
	REP(i,n-1){
		ll meow=a[i+1]-a[i];
		tta+=meow*(i+1)%MOD*(n-1-i)%MOD;
		if(tta>=MOD) tta-=MOD;
	}
	REP(i,m-1){
		ll meow=b[i+1]-b[i];
		ttb+=meow*(i+1)%MOD*(m-1-i)%MOD;
		if(ttb>=MOD) ttb-=MOD;
	}
	cout<<tta*ttb%MOD;

	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+2;
const int M=1e6+2;
const int mod=998244353;
int ar[N],cnt[M],w[M];
int binpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1){
			ans*=x;
			ans%=mod;
		}
		x*=x;
		x%=mod;
		y>>=1;
	}
	return ans;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,ans=0,num,sum;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		cnt[ar[i]]++;
	}
	for(i=1;i<=M-2;i++){
		w[i]+=binpow(i,mod-2);
		if(w[i]>=mod){
			w[i]-=mod;
		}
		for(j=2;j*i<=M-2;j++){
			w[i*j]-=w[i];
			if(w[i*j]<0){
				w[i*j]+=mod;
			}
		}
//		cout<<cnt[i]<<endl;
	}
	for(i=1;i<=M-2;i++){
		sum=0;
		num=0;
		for(j=1;j*i<=M-2;j++){
			sum+=(((cnt[i*j]-1)*cnt[i*j])/2)%mod*((i*j*i*j)%mod)+((i*j*num)%mod*cnt[i*j])%mod;
			num+=cnt[i*j]*i*j;
			num%=mod;
			sum%=mod;
			//cout<<i<<' '<<i*j<<' '<<sum<<' '<<num<<endl;
		}
		ans+=w[i]*sum;
		//cout<<w[i]<<' '<<i<<' '<<sum<<endl;
		ans%=mod;
	}
	cout<<ans;
}

Measured memory_bytes: 17408
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

map<string, int> price;
map<string, vector<string> > resipi;

map<string, int> memo;

int solve(string str)
{
	if(memo.count(str))
		return memo[str];
	
	memo[str] = -1;
	
	if(!resipi.count(str))
		return memo[str] = price[str];
	
	int cost = 0;
	rep(i, resipi[str].size()){
		int a = solve(resipi[str][i]);
		if(a == -1)
			return memo[str] = price[str];
		
		cost += a;
	}
	
	return memo[str] = min(price[str], cost);
}

int main()
{
	int n;
	while(scanf("%d", &n), n){
		price.clear();
		resipi.clear();
		memo.clear();
		
		rep(i, n){
			char name[128];
			int p;
			scanf("%s%d", name, &p);
			price[string(name)] = p;
		}
		
		int m;
		scanf("%d", &m);
		rep(i, m){
			char name[128];
			int k;
			scanf("%s%d", name, &k);
			rep(j, k){
				char factor[128];
				scanf("%s", factor);
				resipi[string(name)].push_back(string(factor));
			}
		}
		
		char name[128];
		scanf("%s", name);
		printf("%d\n", solve(string(name)));
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 10005;
int T,n,m;
ll dp[maxn];
struct node{
	ll a,b;
}num[maxn];
bool cmp(node q,node p){
	if(q.a!=p.a)
		return q.a<p.a;
	else 
		return q.b>p.b;
}
int main() { 
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>num[i].a>>num[i].b;
	sort(num+1,num+1+n,cmp);
	ll maxx = 0;
		for(int j=1;j<=n;j++){
				for(int v = m+num[j].a-1;v>=num[j].a;v--){
					dp[v] = max(dp[v],dp[v-num[j].a]+num[j].b);
					maxx = max(maxx,dp[v]);
				}		
					
		}
	cout<<maxx<<endl;
    return 0;
}



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

using namespace std;

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

  int N,K; cin>>N>>K;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int h; cin>>h;
    if (h >= K) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

const int MAX_V  = 100000;
const int MAX_E  = 500000;
int r;
long long INF = 10e15;
//??????fromk???????????????to???????????????cost??????
struct edge {int from, to, cost; };

edge es[MAX_E];

long long d[MAX_V];   //???????????¢
int V, E;       //V???????????°???E???????????°

//s???????????????????????????????????????????????¢????±???????
void shortest_path(int s) {
  for(int i = 0; i < V; i++) d[i] = INF;
  d[s] = 0;
  while (true) {
    bool update = false;
    for(int i = 0; i < E; i++) {
      edge e = es[i];
      if (d[e.from] != INF &&  d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if(!update) break;
  }
}

using namespace std;

int main() {
  cin >> V >> E >> r;

  for(int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    es[i].from = s;
    es[i].to = t;
    es[i].cost = d;
  }

  shortest_path(r);

  for(int i = 0; i < V; i++) {
    if(d[i] == INF) {
      cout << "INF" << endl;
    }else {
      cout << d[i] << endl;
    }
  }

  return 0;
}

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

using namespace std;

int main() {
	int n;
	int ans = 0;
	cin >> n;
	if (n >= 10)ans += 9;
	else ans += n;
	if (n > 99)
		ans += n > 999 ? 900 : n - 99;
	if (n > 9999)
		ans += n > 99999 ? 90000 : n - 9999;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod1 1000000007LL
#define mod2 1000000009LL
#define base1 19
#define base2 31
#define base3 137
#define MAX 1e12
#define MIN -10000000000
#define pi acos(-1)
#define esp 1e-6
#define memz(x) memset(x, 0, sizeof x)
#define memn(x) memset(x, -1, sizeof x)
#define pb push_back
#define nai string::npos
#define in1(a) scanf("%lld", &a)
#define in2(a,b) scanf("%lld%lld", &a, &b)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(i) printf("Case #%lld: ", ++i)
#define FILE    freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout);
using namespace std;
const ll N = 300010;
ll a, b, res;
int main()
{
    in1(a);
    for(int i=0;i<=a;i++)
    {
        ll cnt=0;
        b=i;
        while(b>0)
        {
            cnt++;
            b/=10;
        }
        if(cnt&1)
        {
            res++;
        }
    }
    printf("%lld\n", res);
    return 0;
}



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

int M;

int MOD(int a){
	return (a %= M) >= 0 ? a : a + M;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int pow10(int N){
	return N == 0 ? 1 : 10 * pow10(N - 1);
}

void mat_print(vector<vector<int>> X){
	int i, j;
	for(i = 0; i < X.size(); i++){
		for(j = 0; j < X[0].size(); j++){
			printf("%lld ", X[i][j]);
		}
		printf("\n");
	}
}

vector<vector<int>> mat_pro(vector<vector<int>> X, vector<vector<int>> Y){
	vector<vector<int>> ans(X.size(), vector<int>(Y[0].size(), 0));
	int i, j, k;
	for(i = 0; i < X.size(); i++){
		for(j = 0; j < Y[0].size(); j++){
			for(k = 0; k < Y.size(); k++){
				ans[i][j] = MOD(ans[i][j] + X[i][k] * Y[k][j]);
			}
		}
	}
	return ans;
}

vector<vector<int>> mat_power(int N, vector<vector<int>> X, int K){
	if(K == 0){
		vector<vector<int>> ans(N, vector<int>(N, 0));
		for(int i = 0; i < N; i++){
			ans[i][i] = 1;
		}
		return ans;
	}
	else if(K % 2 == 0){
		return mat_power(N, mat_pro(X, X), K / 2);
	}
	else{
		return mat_pro(X, mat_power(N, X, K - 1));
	}
}

vector<vector<int>> mat_series(int N, vector<vector<int>> X, int K){
	vector<vector<int>> XOII(2 * N, vector<int>(2 * N, 0)), IO(2 * N, vector<int>(N, 0));
	int i, j;
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			XOII[i][j] = X[i][j];
		}
		XOII[N + i][i] = 1;
		XOII[N + i][N + i] = 1;
		IO[i][i] = 1;
	}
/*	printf("XOII:\n");
	mat_print(XOII);
	printf("IO\n");
	mat_print(IO);
*/	vector<vector<int>> XS = mat_pro(mat_power(2 * N, XOII, K), IO);
/*	printf("XS\n");
	mat_print(XS);
*/	vector<vector<int>> S(N, vector<int>(N, 0));
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			S[i][j] = XS[N + i][j];
		}
	}
	return S;
}

int solve(int A, int B, int L, int led){
	A = MOD(A);
	B = MOD(B);
	led = MOD(led);
//	printf("(A, B, L, led) = (%lld, %lld, %lld, %lld)\n", A, B, L, led);
	vector<vector<int>> X(2, vector<int>(2, 0));
	X[0][0] = led;
	X[0][1] = MOD(-B * led);
	X[1][1] = led;
//	printf("X:\n");
//	mat_print(X);
	vector<vector<int>> S = mat_series(2, X, L);
//	printf("S:\n");
//	mat_print(S);
	return MOD(S[0][0] * A + S[0][1] * 1);
}

signed main(){
	int L, A, B, i, lO, ans = 0;
	scanf("%lld%lld%lld%lld", &L, &A, &B, &M);
	for(i = 17, lO = 1; i >= 0; i--){
//		printf("i = %lld\n", i);
		int l = pow10(i), u = pow10(i + 1), s, t;
		if(A + B * (L - 1) < l || u <= A) continue;
		if(l <= A){
			s = 0;
		}
		else{
			s = (l - A + B - 1) / B;
		}
		if(A + B * (L - 1) < u){
			t = L;
		}
		else{
			t = (u - A + B - 1) / B;
		}
//		printf("(l, u) = (%lld, %lld)\n", l, u);
//		printf("(s, t) = (%lld, %lld)\n", s, t);
		ans = MOD(ans + solve(A + B * (t - 1), B, t - s, u) * lO);
//		printf("lO = %lld\n", lO);
//		printf("ans = %lld\n", ans);
		lO = MOD(lO * power(MOD(u), t - s));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int dp[N][3];
int a[N][3];
int solve(int n,int j)
{
  if(n<=0)
return 0;
if(dp[n][j]!=-1)
return dp[n][j];
int ans=0;
for(int i=0;i<3;i++)
if(i!=j)
ans=max(ans,solve(n-1,i));
ans+=a[n][j];
return dp[n][j]=ans;
}
int main()
{
   int n;
  cin>>n;
for(int i=1;i<=n;i++)
for(int j=0;j<3;j++)
cin>>a[i][j];
memset(dp,-1,sizeof(dp));
cout<<max(solve(n,1),max(solve(n,0),solve(n,2)))<<endl;
}

Measured memory_bytes: 8704
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int N; cin >> N;
	cout << ceil(log(N) / log(3)) << endl;
	return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main () {
    int n;
    vector<int> a;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int f;
        cin >> f;
        a.push_back(f);
    }
    int maxt = 0;
    for (int i = 0; i < n; ++i) {
        int current;
        current = a[i];
        int times = 0;
        for (int j = 0; true; ++j) {
            int re = current % 2;
            if (re == 1)
                break;
            current = current / 2;
            ++times;
        }
        maxt += times;
    }
    cout << maxt;
}

Measured memory_bytes: 384
use std::str;
use std::io;

fn main() {
    let a = read_vec::<i32>();
    let n = a[0];
    let k = a[1];
    let ans = if n % k == 0 {
        0 
    }
    else {
        1
    };
    println!("{}", ans);

}

fn read<T: str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4476
#include <iostream>

using namespace std;

int main(int argc, char** argv){
    int N;
    cin >> N;
    int ans = 0;

    if (N <= 9){
        ans = N;
    }
    else if (N <= 99){
        ans = 9;
    }
    else if (N <= 999){
        ans = 9 + (N - 99);
    }
    else if (N <= 9999){
        ans = 9 + 900;
    }
    else if (N <= 99999){
        ans = 9 + 900 + (N - 9999);
    }
    else {
        ans = 9 + 900 + 90000;
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
dst = 0

for i in range(N):
    for j in range(i+1, N):
        dst = 0
        for k in range(D):
            dst += (X[i][k] - X[j][k]) ** 2
        x = dst ** 0.5
        if x.is_integer():
            cnt += 1
        
print(cnt)

Measured memory_bytes: 3064
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.size = [1]*size

    def find(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]
    
    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.size[y] += self.size[x]
            self.parent[x] = y
        else:
            self.size[x] += self.size[y]
            self.parent[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def sizeofset(self, x):
        return self.size[self.find(x)]

if __name__ == "__main__":
    N,K,L = map(int,input().split())
    uf_road = UnionFind(N)
    uf_rail = UnionFind(N)
    for _ in range(K):
        p,q = map(int,input().split())
        p -= 1
        q -= 1
        uf_road.unite(p,q)
    for _ in range(L):
        r,s = map(int,input().split())
        r -= 1
        s -= 1
        uf_rail.unite(r,s)
    roots = [None]*N
    for i in range(N):
        roots[i] = (uf_road.find(i), uf_rail.find(i))
    from collections import defaultdict
    d = defaultdict(int)
    for r in roots:
        d[r] += 1
    print(" ".join([str(d[roots[i]]) for i in range(N)]))


Measured memory_bytes: 65428
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<ll,int> mp;
int main() {
    ll x;
    cin>>x;
    for(int i=-1000;i<1000;i++){

        mp[pow(i,5)]=1;
    }
    for(auto k:mp){
        if(mp.find(k.first+x)!=mp.end()){
            ll a,b;
            for(int i=-1000;i<1000;i++){
                if(pow(i,5)==k.first+x)
                    a = i;
            }
            for(int i=-1000;i<1000;i++){
                if(pow(i,5)==k.first)
                    b=i;
            }
            cout<<a<<' '<<b;
            return 0;
        }
    }

}


Measured memory_bytes: 4108
#include <iostream>
#include <string>

using namespace std;

int main() {
  string S;
  cin >> S;

  int diff = 999;
  for (size_t i = 0; i < S.size()-2; ++i) {
    int n = stoi(S.substr(i, 3));
    diff = min(diff, abs(753 - n));
  }
  cout << diff << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	long long int X,K,D,ans;
	cin>>X>>K>>D;
	if(X<0)X=-X;
	
	if(ans<0)ans=-ans;
	if(K-X/D>=0){
		K=K-X/D;
		X%=D;
		if(K%2){
			ans=D-X;
		}else ans=X;
	}else{
		ans=X-D*K;
	}
	cout<<ans;
	return 0;
}

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

const int N=1e6+10;

int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	vector<int>b(n);
	for(int i=0;i<n;i++){
		int k=1,rm=-1;
		for(int j=0;j<n;j++){
			if(a[j]==k)
				rm=j;
			if(a[j])k++;
		}
		if(rm==-1){
			cout<<rm<<endl;return 0;
		}
		b[i]=a[rm];
		a[rm]=0;
		
	}
	reverse(b.begin(),b.end());
	
	for(auto x:b)
		cout<<x<<endl;
	
		
}
/*

1 2 1 2


1 2 3 3 2

1 2 2 3 3


*/


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

n = int(input())
a = [int(i) for i in readline().split()]


ans = [0]*n

for i, c in enumerate(a):
    ans[a[i]-1] = i+1

print(*ans)

Measured memory_bytes: 13876
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  map<int, int> zyun;
  for ( int i = 0; i<N; i++){
    int k;
    cin >> k;
    zyun[k] = i+1;
  }
  for ( int i = 1; i<N; i++ ){
    cout << zyun[i] << " ";
  }
  cout << zyun[N] << endl;
}

Measured memory_bytes: 5504
import sys
import copy

def main():
    ABCD = list(map(str, input()))
    b_digit = len(ABCD)-1

    for i in range(2 ** b_digit):
        signs = ["+"] * b_digit
        for j in range(b_digit):
            if ((i >> j ) & 1):
                signs[b_digit - 1 - j] = "-"

        ABCD_tmp = copy.deepcopy(ABCD)
        for k in range(len(signs)):
            ABCD_tmp.insert(1+k*2,signs[k])
        if(eval("".join(ABCD_tmp))==7):
            print("{}=7".format("".join(ABCD_tmp)))
            sys.exit()

main()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
//     for(int i=0; i<N;i++){
//     }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int A,B,C,D;cin>>A>>B>>C>>D;
    int ans = 0;

    ans = max(A*B, C*D);

    cout<<ans<<endl;
    return 0;
}


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

int main(){
string S; cin >> S;
vector<bool> alphabets(26);

for (int i = 0; i < 26; i++) {
    alphabets.at(i) = false;
}
for (char X = 'a'; X <= 'z'; X++) {
    for (int i = 0; i < S.size(); i++) {
        if(S.at(i) == X) {
            alphabets[X - 'a'] = true; 
        }
    }
}
for (int i = 0; i < 26; i++) {
    if (!alphabets.at(i)) {
        char ans =  'a' + i;
        cout << ans << endl;
        return 0;
    }
}

cout << "None" << endl;

}

Measured memory_bytes: 512