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

#define fi first
#define se second
#define pb push_back
 
#define limit (int) (2e5 + 5) 
#define mod (long long int) (1e9 + 7)
 
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

int l[102];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    lli x,k,d;
    cin >> x >> k >> d;

    x = abs(x);

    if (x/d >= k)
    {
        cout << x - k*d;
        return 0;
    }


    k -= x/d;

    if (k%2 == 0)
    {
        cout << x%d;
    } else {
        cout << d-x%d;
    }

    return 0;
}














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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a % k == 0 || b % k == 0){
      System.out.println("OK");
      return;
    }

      int rem = a % k;
      int temp = a-rem;
      temp += k;
      for(int i=temp; i<b; i+=k){
        if(temp > a){
          System.out.println("OK");
          return;
        }
      }
      System.out.println("NG");
  }
}


Measured memory_bytes: 35792
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    string s = readln.chomp;

    while (!s.empty) {
        s.popBack();
        s.popBack();

        if (s[0 .. $ / 2] == s[$ / 2 .. $]) {
            writeln(s.length);
            return;
        }
    }
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

const int INF = 100000000;

const int M = 5000;

int main()
{
    string s[3];
    for(int i = 0; i < 3; i++) cin >> s[i];
    int n[3];
    for(int i = 0; i < 3; i++) n[i] = s[i].size();
    bool ab[10000], bc[10000], ac[10000];
    for(int i = -4000; i <= 4000; i++){
        ac[M + i] = true;
        if(i < 0){
            for(int j = 0; j < min(n[0], n[2] + i); j++){
                if(s[0][j] != '?' && s[2][j - i] != '?' && s[0][j] != s[2][j - i]) ac[M + i] = false;
            }
        }
        else{
            for(int j = i; j < min(n[0], n[2] + i); j++){
                if(s[0][j] != '?' && s[2][j - i] != '?' && s[0][j] != s[2][j - i]) ac[M + i] = false;
            }
        }
    }
    for(int i = -4000; i <= 4000; i++){
        ab[M + i] = true;
        if(i < 0){
            for(int j = 0; j < min(n[0], n[1] + i); j++){
                if(s[0][j] != '?' && s[1][j - i] != '?' && s[0][j] != s[1][j - i]) ab[M + i] = false;
            }
        }
        else{
            for(int j = i; j < min(n[0], n[1] + i); j++){
                if(s[0][j] != '?' && s[1][j - i] != '?' && s[0][j] != s[1][j - i]) ab[M + i] = false;
            }
        }
    }
    for(int i = -4000; i <= 4000; i++){
        bc[M + i] = true;
        if(i < 0){
            for(int j = 0; j < min(n[1], n[2] + i); j++){
                if(s[1][j] != '?' && s[2][j - i] != '?' && s[1][j] != s[2][j - i]) bc[M + i] = false;
            }
        }
        else{
            for(int j = i; j < min(n[1], n[2] + i); j++){
                if(s[1][j] != '?' && s[2][j - i] != '?' && s[1][j] != s[2][j - i]) bc[M + i] = false;
            }
        }
    }
    int ans = INF;
    for(int i = -4000; i <= 4000; i++){
        for(int j = -4000; j <= 4000; j++){
            if(i - j > 4000) continue;
            if(ab[M + i] && ac[M + j] && bc[M + j - i]){
                ans = min(ans, max(n[0], max(n[1] + i, n[2] + j)) - min(0, min(i, j)));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#define MAX 100010
#define L 15
using namespace std;

vector<int> v[MAX];
int mem[L][MAX];
vector<pair<int,int> > P[L];

int n,m,q,c[MAX];

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}

	for(int i=0;i<L;i++){
		for(int j=0;j<n;j++){
			mem[i][j]=-1;
		}
	}

	cin>>q;
	for(int i=0;i<q;i++){
		int x,y;cin>>x>>y>>c[i];x--;
		pair<int,int> z;
		z.first=x,z.second=i;
		P[y].push_back(z);
	}
	//****
	for(int l=L-1;l>0;l--){

		for(int i=0;i<P[l].size();i++){
			mem[l][P[l][i].first]=max(mem[l][P[l][i].first],P[l][i].second);
		}

		for(int i=0;i<n;i++){
			if(mem[l][i]>-1){
				for(int j=0;j<v[i].size();j++){
					mem[l-1][v[i][j]]=max(mem[l][i],mem[l-1][v[i][j]]);
				}
			}
		}
	}
	for(int i=0;i<P[0].size();i++){
		mem[0][P[0][i].first]=max(mem[0][P[0][i].first],P[0][i].second);
	}

	for(int i=0;i<n;i++){
		int ans=-1;
		for(int j=0;j<L;j++)ans=max(ans,mem[j][i]);
		if(ans==-1)cout<<"0"<<endl;
		else cout<<c[ans]<<endl;
	}
	return 0;
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
int n,cd=0,tot=0;
string a,b,c,d;
int main(){
	cin>>n;
	cin>>a;
	cin>>b;
	for(int i=0;i<n;i++){
		c=a.substr(i,n);
		d=b.substr(0,n-i);
		if(c==d){
			cd=c.length();
			break;
		}
	}
	cout<<2*n-cd;
	return 0;
}

Measured memory_bytes: 256
def f(x):
    if 1<=x<=9:
        return 1
    if x%10==0:
        return 0
    x = str(x)
    a = x[0]
    b = x[-1]
    k = len(x)
    if int(a)<int(b):
        if k==2:
            return 0
        else:
            return 2*(10**(k-2)-1)//9
    elif int(a)>int(b):
        return 2*(10**(k-1)-1)//9
    else:
        if k==2:
            return 3
        else:
            return (1+(10**(k-2)-1)//9+int(x[1:k-1]))*2+1

N = int(input())
dp = [0 for _ in range(N+1)]
for i in range(min(N,9)+1):
    dp[i] = i
for i in range(10,N+1):
    dp[i] = dp[i-1]+f(i)
print(dp[N])
        

Measured memory_bytes: 10980
A = int(input())
B = int(input())

if   (A == 1 and B == 2) or (B == 1 and A == 2):
    print(3)
elif (A == 2 and B == 3) or (B == 2 and A == 3):
    print(1)
elif (A == 1 and B == 3) or (B == 1 and A == 3):
    print(2)


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

using namespace std;

using ll = long long;

ll n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	ll ans = 0;
	for(ll i=1; i*i<=n; ++i){
		if(n%i==0){
			ll m=n/i-1;
			if(m>i) ans += m;
		}
	}
	cout << ans <<"\n";
}

Measured memory_bytes: 256
#include <iostream>

auto main () -> int
{
	for (int x = 1; x <= 9; ++ x)
	{
		for (int y = 1; y <= 9; ++ y)
		{
			std::cout << x << 'x' << y << '=' << (x * y) << std::endl;
		}
	}
}

Measured memory_bytes: 3076
n=input()
ans=0
a=len(n)
c_lst=[6, 42, 192, 732, 2538, 8334, 26484]
if int(n)>777777777:
    print(c_lst[-1])
    exit()
elif a<=2:
    print(0)
    exit()
elif a>=4:
    ans=c_lst[a-4]

from itertools import product
l_lst=["3","5","7"]
for i in product(l_lst,repeat=a):
    s="".join(i)
    if "3" in s and "5" in s and "7" in s:
        if int(s)<=int(n):
            ans+=1
print(ans)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N, M = list(map(int, input().split()))
    requests = []
    for i in range(M):
        a_i, b_i = list(map(int, input().split()))
        requests.append((a_i, b_i))

    return N, M, requests


def main(N: int, M: int, requests: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 島の数(2 <= N <= 10^5)
        M (int): 要望の数(1 <= M <= 10^5)
        requests (list): 要望(1 <= a_i < b_i <= N)
    """
    # 求解処理
    requests = sorted(requests, key=lambda x: x[1])
    bridge = 0
    ans = 0
    for i in range(M):
        a_i, b_i = requests[i]
        if a_i > bridge:
            bridge = b_i - 1
            ans += 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, M, requests = get_input()

    # メイン処理
    main(N, M, requests)


Measured memory_bytes: 24788
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] ch = sc.next().toCharArray();

        sc.close();

        for (int i = 0; i < ch.length - 1; i++) {
            for (int j = i + 1; j < ch.length; j++) {
                if (ch[j] == ch[i]) {
                    System.out.println("no");
                    return;
                }
            }
        }

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

Measured memory_bytes: 22612
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	string s;
	cin >> s;
	int ans = (int)s.size(), cur = 0;
	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == 'S')
			cur++;
		else
		{
			if (cur)		
				ans -= 2, cur--;
		}
	}
	cout << ans << endl;

	return 0;
}



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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<24];
char bit_count[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(((bit>>i)&1)==0)continue;
            if(((bit>>j)&1)==0)continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(c[i]==c[j]&&ok(i,bit)&&ok(j,bit)&&!memo[to_bit]){
                ret=max(ret,dfs(to_bit));
            }
        }
    }


    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}
/*
void init(){
    for(int i=0;i<(1<<24);i++){
        for(int j=0;j<24;j++)if((i>>j)&1){
            bit_count[i]++;
        }
    }
}*/

int main(){
    //init();
    while(input())solve();
    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  string T;
  cin >> T;
  char pre = 'T';
  ll ans = 0;
  int N = T.size();
  REP(i, N){
    if(T[i] == 'P'){

    }
    else{
      T[i] = 'D';
      ans++;
      if(pre == 'P'){
        ans++;
      }
    }
    pre = T[i];
  }
  // cout << ans << endl;
  cout << T << endl;
  return 0;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,a;int fa=0; 
	cin>>s>>a;
	if(s[0]==a[0])
        fa++;
    if(s[1]==a[1])
    	fa++;
    if(s[2]==a[2])
    	fa++;
    cout<<fa;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
red = n-k
mod=10**9+7

kai = [1]*2005
for i in range(2,2005):
    kai[i] = kai[i-1]*i #%mod

def nCk(n,k):
    return (kai[n]*pow(kai[n-k],mod-2,mod)%mod)*pow(kai[k],mod-2,mod)%mod if n>=k else 0

for i in range(1,k+1):
    print(nCk(k-1,i-1)*nCk(red+1,i)%mod)


Measured memory_bytes: 5748
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    double possibility=0;
    
    int counter=0;
    for(int j=1;j<n+1;j++){
    for(int i=j;i<k;i=i*2){
        counter++;
    }
    
        double n1=1;
        for(int y=0;y<counter;y++){
             n1=n1*2;
    }
        possibility = possibility + (1 / (n*n1));
        
        counter = 0;
    
    }
    
    
   
    cout << setprecision(11) << possibility << endl;
}

Measured memory_bytes: 3724
#include <iostream>
#include <cstdio>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
 
ull pow(ull x,ull n) {
  ull res = 1;
  while(n > 0) {
    if(n&1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14])
{
  int j;
  long long f = 1;
  long long g = 0;
  for(j = 0;;j++) {
    if(str[j] == 'A')
      g += f * 1;
    else if(str[j] == 'C')
      g += f * 2;
    else if(str[j] == 'G')
      g += f * 3;
    else if(str[j] == 'T')
      g += f * 4;
    else break;
    f *= 5;
  }
  return g; 
}
 
int main()
{
  int i,j,k,l;
  int n;
  long ans = 0;
  static char dic[10000000];
  char opstr[7];
  char str[13];
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s",opstr,str);
    if(opstr[0] == 'i') {
      dic[dic_op(str)] = 1;
    }
    else if(opstr[0] == 'f') {
      if(dic[dic_op(str)] == 1)
        puts("yes");
      else
        puts("no");
      j++;
    }
  }
  return 0;
}

Measured memory_bytes: 9496
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int cnt = 0;
		for(int i = 0 ; i <= K ; i++) {
			for(int j = 0 ; j <= K ; j++) {
				if(S - i - j >= 0 && S - i - j <= K) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 25044
#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(){
    int N, K;
    cin>>N>>K;
    int A[N];
    int max=0;
    rep(i, N){
        cin>>A[i];
        max=fmax(max, A[i]);
    }
    //binary search
    int now=max;
    int up=N;
    int low=0;
    int ans=0;

    while(true){
        int cut_num=0;
        rep(i, N) if(A[i]>=now) cut_num+=((A[i]+now-1)/now)-1;
        if(cut_num>K){
            low=now;
            now=(up+low)/2;
        }else{
            ans=now;
            up=now;
            now=(up+low)/2;
        }

        if(abs(up-low)==1) break;
    }

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

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

int main() {
  int n;
  cin >> n;
  int a[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (i = 0; i < n; i++) {
    while (a[i] % 2 == 0) {
      count++;
      a[i] /= 2;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n, w; cin >> n >> w;
	mk(wt, n + 1, int);
	mk(val, n + 1, int);

	int sum = 0;

	for (int i = 1; i <= n; i++) {
		cin >> wt[i] >> val[i];
		sum += val[i];
	}

	int dp[n + 1][sum + 1];
	int ans = 0;

	for (int i = 0; i <= n; i++) {
		for (int v = 0; v <= sum; v++) {
			if (v == 0)
				dp[i][v] = 0;

			else if (i == 0)
				dp[i][v] = inf;

			else if (val[i] > v)
				dp[i][v] = dp[i - 1][v];

			else {
				dp[i][v] = min(dp[i - 1][v], wt[i] + dp[i - 1][v - val[i]]);

				if (dp[i][v] <= w)
					ans = max(ans, v);
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 82508
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;

    while (1)
    {
        cin >> h >> w;
        if(h == 0 && w == 0)
            break;
        for(int i = 0 ; i < h ; i++){
            for (int j = 0; j < w; j++)
            {
                if(i == 0 || i == h - 1)
                    cout << "#";
                else{
                    if(j == 0 || j == w - 1)
                        cout << "#";
                    else
                        cout << ".";
                }

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


Measured memory_bytes: 3076
import numpy as np


A,B = map(int,input().split())
point = 0
for i in range(1,1001):
    
    if np.floor(i * 0.08) == A and np.floor(i * 0.1) == B:
        print(i)
        point = 1
        break
        
if point == 0:
    print('-1')

Measured memory_bytes: 13052
import java.util.*;

public class Main{
  
  public static void main (String[] args){
    
    Main main = new Main ();
    
    main.solve();
  }
  
  private void solve(){
    
    Scanner scanner = new Scanner(System.in);
    
    int N = scanner.nextInt();
    int[] list = new int[N];
    int sum = 0;
    boolean flag =true;
    
    for (int index=0; index<N; index++){
      int temp=scanner.nextInt();
      list[index]=temp;
      sum+=temp;
    }
    
    for (int index=0; index<N; index++){
      int temp=list[index];
      if (temp>=sum-temp){
        flag=false;
      }
    }
    
    if (flag==true){
      System.out.println("Yes");
  } else {
      System.out.println("No");
    }
  }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>


int main(){
    int K; cin>>K;
    string s; cin>>s;
    int N = s.size();
    if(N<=K){ cout << s << "\n"; }
    else{ cout << s.substr(0,K) << "...\n"; }
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
//イントとダブルが入り乱れるときはどちらかに統一しよう。

int max(int x,int y){
  if(x>y) return x;
  return y;
}

int min(int x,int y){
  if(x<y) return x;
  return y;
}

int sumofdigits(int n){
  int sum=0;
  while(n>0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int n,k;
  int l[110];
  cin >> n >> k;
  for(int i=0; i <n ; ++i)cin >> l[i];
  sort(l,l+n,greater<int>());
  int length=0;
  for(int i=0;i<k; ++i)length+=l[i];
  cout << length << endl;
}


Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val Ps = Array.fill(N)(in.nextInt)
  val (_, count) = Ps.foldLeft((N + 1, 0)){ case ((min, count), i) =>
    if (i < min) (i, count + 1) else (min, count)
  }
  println(count)
}

Measured memory_bytes: 68588
#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 ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==ans+1)
		{
			ans++;
		}
	}
	if(ans==0)
	cout<<-1<<endl;
	else
	cout<<n-ans<<endl;
}

Measured memory_bytes: 4352
puts [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][gets.to_i-1]


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    int n,w;cin >> n >> w;
    vector<ll> width(n);vector<ll> value(n);
    REP(i,n){
        ll a,b;cin >> a >> b;
        width[i] = b;value[i]=a;
    }
    vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
    REP(i,n){
        ll origin=width[i];
        REP(j,w+1){
            if(j-origin>=0){
                dp[i+1][j]=max(dp[i][j],dp[i+1][j-origin] + value[i]);
            } else {
                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            }
        }
    }
    cout << dp[n][w] << endl;
}


Measured memory_bytes: 10692
N, K = gets.chomp.split(" ").map(&:to_i)
M = Array.new(N).map!{
  gets.chomp.split(" ").map(&:to_i)
}

M.sort_by!{|a, b| a}
ans, wk = [0, K]
M.each{|a, b|
  wk -= b
  (ans = a; break) if wk <= 0
}

puts ans


Measured memory_bytes: 12664
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();


        int syou = a / k;
        
        if( a % k == 0 ){
            System.out.println("OK");
        }else{
            if( (syou + 1)*k > b ){
                System.out.println("NG");
            }else{
                System.out.println("OK");
            }
        }
       

    }
}

Measured memory_bytes: 27068
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    int N, A;
    cin >> N;
    vector<int> s(N, -1);
    cin >> A;
    s[N - 1] = A;
    rep(i, N - 1) {
        cin >> A;
        auto iter = lower_bound(s.begin(), s.end(), A) - s.begin();
        s[iter - 1] = A;
    }
    rep(i, N) {
        if (s[i] > -1) {
            cout << N - i << endl;
            return 0;
        }
    }
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int score = 0;
    rep(i, n-1){
        if(s[i] == s[i+1]) score++;
    }
    int ans = min(score+2*k, n - 1);
    cout << ans << endl;
    
}

Measured memory_bytes: 3760
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  $ans = 0;
  for ($i=0; $i<$n; $i++) {
    if($i % 2 == 0){
      if($a[$i] % 2 != 0){
        $ans++;
      }
    }
  }

  echo $ans;

Measured memory_bytes: 16200
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(int argc, const char * argv[]) {
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<ll> a(A), b(B), c(C);
    for (int i = 0; i < A; i++) cin >> a[i];
    for (int i = 0; i < B; i++) cin >> b[i];
    for (int i = 0; i < C; i++) cin >> c[i];
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    sort(c.begin(), c.end(), greater<int>());
    int tmp_a = X - 1;
    int tmp_b = Y - 1;
    ll ans = 0;
    for (int i = 0; i < C; i++) {
        if (tmp_a < 0 || tmp_b < 0) {
            if (tmp_a < 0 && tmp_b < 0) {
                break;
            } else if (tmp_a < 0) {
                if (c[i] > b[tmp_b]) {
                    tmp_b -= 1;
                    ans += c[i];
                }
            } else if (tmp_b < 0) {
                if (c[i] > a[tmp_a]) {
                    tmp_a -= 1;
                    ans += c[i];
                }
            }
            continue;
        }
        if (a[tmp_a] > b[tmp_b]) {
            if (c[i] > b[tmp_b]) {
                tmp_b -= 1;
                ans += c[i];
            } else {
                break;
            }
        } else {
            if (c[i] > a[tmp_a]) {
                tmp_a -= 1;
                ans += c[i];
            } else {
                break;
            }
        }
    }
    if (tmp_a >= 0) {
        for (int i = 0; i <= tmp_a; i++) ans += a[i];
    }
    if (tmp_b >= 0) {
        for (int i = 0; i <= tmp_b; i++) ans += b[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
n = int(input())
x = 0

for i in range(1,n+1):

    if i%3 == 0:
            print(" %d"%i,end = "")

    else:
        x = i
        while (x):
          if x%10 == 3:
              print(" %d"%i,end = "")
              break
          x //= 10

print()


Measured memory_bytes: 5876
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int T = sc.nextInt();

		int minC = 1001;
		for (int i=0; i<N; i++){
			int c = sc.nextInt();
			int t = sc.nextInt();
			if (minC > c && T >= t){
				minC = c;
			}
		}
		if (minC == 1001){
			System.out.println("TLE");
		} else {
			System.out.println(minC);
		}
	}
}

Measured memory_bytes: 23124
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
B = [int(input()) for i in range(n)]
C = [[0,0,0] for _ in range(3)]

for b in B:
    for i in range(3):
        for j in range(3):
            if(A[i][j] == b):
                C[i][j] = 1

for i in range(3):
    if(C[i][0] == 1 and C[i][1] == 1 and C[i][2] == 1):
        print("Yes")
        exit()
    elif(C[0][i] == 1 and C[1][i] == 1 and C[2][i] == 1):
        print("Yes")
        exit()
if(C[0][0] == 1 and C[1][1] == 1 and C[2][2] == 1):
    print("Yes")
    exit()
elif(C[0][2] == 1 and C[1][1] == 1 and C[2][0] == 1):
    print("Yes")
    exit()
print("No")
exit()


Measured memory_bytes: 9192
#include <iostream>

int main()
{
	int N;
	std::cin >> N;
	if (N == 1)
	{
		std::cout << "Hello World";
	}
	else if (N == 2)
	{
		int A, B;
		std::cin >> A;
		std::cin >> B;
		std::cout << (A + B);
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	bool result = false;
	if (W >= (x + r) && H >= (y + r))
	{
		if (0 <= (x - r) && 0 <= (y - r))
		{
			result = true;
		}
	}
	if (result)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3112
import numpy as np
a = [int(x) for x in input().split()]

count = 0
while True:
    if (a[0] == a[1] and a[1] == a[2]):
        break
    elif (max(a) - min(a) >= 2):
        a[np.argmin(a)] += 2
        count += 1
        #print(a)
    else:
        a = [x+1 if i != np.argmax(a) else x for i, x in enumerate(a)]
        count += 1
        #print(a)
print(count)

Measured memory_bytes: 12776
import java.util.Scanner;

public class Main {

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

		int dishes[] = new int[5];

		for(int i = 0; i < 5; i++) {
			 dishes[i] = Integer.parseInt(sc.nextLine());
		}

		int diffmax = 0;
		int diffmaxindex = 0;
		int diff = 0;
		for(int i = 0; i < 5; i++) {
			if(dishes[i]%10 != 0) {
				diff = (dishes[i]/10 + 1) * 10 - dishes[i];
			}

			if(diffmax < diff) {
				diffmax = diff;
				diffmaxindex = i;
			}
		}

		int sumTime = 0;

		for(int i = 0; i < 5; i++) {
			if(i != diffmaxindex) {
				if(dishes[i]%10 != 0) {
					sumTime = sumTime + ((dishes[i]/10 + 1) * 10);
				}else {
					sumTime = sumTime + dishes[i];
				}

			}
		}

		sumTime = sumTime + dishes[diffmaxindex];

		System.out.println(sumTime);
	}

}

Measured memory_bytes: 22868
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int l,r;
int main()
{
	l=read(); r=read();
	ll ans=0x3f3f3f3f;
	for(int i=l;i<=r&&i<=l+2019;i++)
		for(int j=i+1;j<=r&&j<=l+2019;j++)
			ans=std::min(ans,(ll)i*j%2019);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;

long long power(long long x,long long n){
    long long res = 1;
    while(n > 0) {
        if(n & 1) res *= x;
        x *= x;
        n>>=1;
    }
    return res;
}

vector<ll> ans;
void dfs(ll n){
    ans.push_back(n);
    if(n/power(10,9)!=0){
        return;
    }
    else{
        if (n % 10 == 0) {
            dfs(n * 10);
            dfs(n * 10 + 1);
        } else if (n % 10 == 9) {
            dfs(n * 10 + 8);
            dfs(n * 10 + 9);
        } else {
            dfs(n * 10 + (n % 10) - 1);
            dfs(n * 10 + (n % 10));
            dfs(n * 10 + (n % 10) + 1);
        }
    }
}
int main() {
    ll k;
    cin >> k;
    k--;
    for (ll i = 0; i < 9; i++) {
        dfs(i + 1);
    }
    sort(ans.begin(), ans.end());
    cout << ans[k] << endl;
}

Measured memory_bytes: 5352
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.next();
    let ds: Vec<u32> = sc.vec(n);

    let mut sum = 0;
    for (i, di) in ds.iter().enumerate() {
        for (j, dj) in ds.iter().enumerate() {
            if i < j {
                sum += di * dj;
            }
        }
    }
    println!("{}", sum);
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define inf 100000000000000001
#define PI 3.14159265
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

// string to integer stoi() Remember: it takes string not character
// string to long long stol()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll n;
ll a[200001];
vector<ll> adj[200001];
bool vis[200001];
ll ans[200001];
vector <ll> v1;

void dfs(ll u){

    ll fg=1;
    ll po=0;
    ll ori=0;
    auto it = lower_bound(v1.begin(), v1.end(), a[u]);
    if(it==v1.end()){
        fg=1;
        v1.push_back(a[u]);
    }
    else{
        fg=0;
        ll pos = it-v1.begin();
        po=pos;
        ori=v1[pos];
        v1[pos]=a[u];
    }
    ans[u]=v1.size();

    for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
    {
        if(!vis[*i]){
            vis[*i]=true;
            dfs(*i);
        }   
    }

    if(fg==1){
        v1.pop_back();
    }
    else{
        v1[po]=ori;
    }
}

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    cin>>n;
    for (int i = 1; i<=n; ++i)
    {
        cin>>a[i];
        vis[i]=false;
        ans[i]=0;
    }
    for (int i = 0; i < n-1; ++i)
    {
        ll a1, b1;
        cin>>a1>>b1;
        adj[a1].push_back(b1);
        adj[b1].push_back(a1);
    }

    ans[1]=1;
    vis[1]=true;
    dfs(1);

    for (int i = 1; i<=n; ++i)
    {
        cout<<ans[i]<<endl;
    }

    return 0;
} 


Measured memory_bytes: 29296
#include<bits/stdc++.h>
using namespace std;
#define N 100000
int visit[N+5],color[N+5];
int n,ans;
void dfs(vector<vector<int> >&v,int index){
	if(visit[index]==1)return;
	visit[index]=1;
	int s=v[index].size();
	ans=max(ans,s);
	unordered_set<int>notuse;
	notuse.insert(color[index]);
	int k=1;
	for(int i:v[index]){
		if(visit[i]==1)continue;
		while(notuse.count(k)>0)k++;
		color[i]=k;
		notuse.insert(k);
	}
	for(int i:v[index]){
		if(visit[i]==0)dfs(v,i);
	}	

	notuse.clear();
}
/*void dfs_a(vector<vector<int> >&v,int index,vector<tuple<int,int,int> >&a){
	if(visit[index]==1)return;
	visit[index]=1;
	for(int i:v[index]){
		if(visit[i]==1)continue;
		a.emplace_back(make_tuple({index,i,color[i]}));
	}
	for(int i:v[index]){
		dfs_a(v,i,a);
	}	
}*/
main(){
	ios::sync_with_stdio(false);
	//cin.tie(0);
	memset(visit,0,sizeof(visit));
	memset(color,0,sizeof(color));
	cin>>n;
	vector<vector<int> >v(n+1);
	int x,y;
	vector<int>p;
	for(int i=1;i<n;i++){
		cin>>x>>y;
		p.emplace_back(y);
		v[x].emplace_back(y);
		v[y].emplace_back(x);
	}
	dfs(v,1);
	cout<<ans<<"\n";
	for(int i:p){
		cout<<color[i]<<"\n";
	}
}

Measured memory_bytes: 21884
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    xs = concatMap f [0, 2, 4, 6] :: [Int]
    f k = (+) <$> ((* (10 ^ k)) <$> [1..9]) <*> [0..(10 ^ k - 1)]
    m = length . takeWhile (<= n) $ xs
  print m

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* テ・ツ淞コテヲツ慊ャティツヲツ?ァツエツ?*/
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double EPS = 1e-7; // ティツィツアテ・ツョツケティツェツ、テ・ツキツョ^2
const double INF = 1e9;
#define X real()
#define Y imag()
// #define LE(n,m) ((n) < (m) + EPS)
#define LE(n,m) ((n) - (m) < EPS)
// #define GE(n,m) ((n) + EPS > (m))
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// テ・ツ??ァツゥツ催」ツ??ot(a,b) = |a||b|cosテ篠ク
double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// テ・ツ、ツ姪ァツゥツ催」ツ??ross(a,b) = |a||b|sinテ篠ク
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// テァツつケテ」ツ?ョテゥツ?イティツ。ツ古ヲツ鳴ケテ・ツ青?
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

// テァツキツ堙・ツ按?」ツ?ィテァツつケ
bool isecSP(Point a1, Point a2, Point b) {
  return !ccw(a1, a2, b);
}

// テァツつケpテ」ツ?ョテァツ崢エテァツキツ啾テ」ツ?クテ」ツ?ョテ・ツーツ?・ツスツアテァツつケテ」ツつ津ィツソツ氾」ツ??
Point proj(Point a1, Point a2, Point p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

double distSP(Point a1, Point a2, Point p) {
  Point r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  //= !ccw(a1, a2, r)
  return min(abs(a1-p), abs(a2-p));
}

const int N = 5001;
double minc[N], minp[N];
int id[N];
bool used[N];

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

    VP p(n);
    rep(i,n)
    {
        int x,y;
        cin >>x >>y;
        p[i] = Point(x,y);
    }

    fill(minc,minc+N,INF);
    fill(minp,minp+N,INF);
    fill(id,id+N,0);
    fill(used,used+N,false);

    double ans = 0;
    minc[0] = 0;
    minp[0] = 0;

    rep(_,m+1)
    {
        int v = -1;
        rep(i,n)
        {
            if(!used[i] && (v==-1 || minc[i]<minc[v])) v = i;
        }

        // rep(i,n) printf("%d : minp %f minc %f, id %d\n", i,minp[i],minc[i],id[i]);

        if(v==-1) break;
        // dbg(v);
        used[v] = true;
        ans += minp[v];
        rep(i,n)
        {
            // printf("%d - %d  -> %d\n", id[v],v,i);
            minc[i] = min({minc[i],abs(p[v]-p[i]),distSP(p[id[v]],p[v],p[i])});
        }

        rep(i,n)
        {
            if(minp[i] > abs(p[v]-p[i]))
            {
                minp[i] = min(minp[i],abs(p[v]-p[i]));
                id[i] = v;
            }
        }
    }

    printf("%.10f\n", ans);
    return 0;
}

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

inline int hight(int cx, int cy, int x, int y, int h){
  return h + abs(cx - x) + abs(cy - y);
}

struct Pos{
  int x, y, h;
};

int main(){
  int n; cin >> n;
  vector<Pos> v(n);
  for(auto&&e:v){
    cin >> e.x >> e.y >> e.h;
    if(e.h > 0)swap(e, *v.begin());
  }

  int cx, cy;
  for(int x = 0; x <= 100; ++x){
    for(int y = 0; y <= 100; ++y){
      bool fin = true;
      int ch = -1;
      for(auto&&e:v){
	int h = hight(x, y, e.x, e.y, e.h);
	cx = x; cy = y;
	if(ch == -1){
	  ch = h;
	} else if(ch != h && !(h >= ch && e.h == 0)){
	  fin = false;
	  break;
	}
      }
      if(fin){
	cout << cx << ' ' << cy << ' ' << ch << endl;
	return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<ul, ul> puu;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define ls (i << 1)
#define rs (i << 1 | 1)
#define mid (l + r >> 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define mfil(x, k) memset(x, k, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y, true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y, true) : false; }
struct __init { __init()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(16); cout << fixed;
    srand(time(0) ^ ui(ul(new char)));
} } static __init__;
/* default code ends here */
const int maxn = 6010;
int n;
bool A[maxn], B[maxn];
int pre[maxn], suc[maxn];
vector<pii> vec;
int main()
{
	string foo;
	cin >> foo;
	n = foo.length();
	enum(i, 1, n)
		A[i] = foo[i - 1] - '0';
	cin >> foo;
	enum(i, 1, n)
		B[i] = foo[i - 1] - '0';
	bool flag = true;
	enum(i, 1, n)
		if(B[i])
		{
			flag = false;
			break;
		}
	if(flag)
	{
		enum(i, 1, n)
			if(A[i])
				return cout << -1 << '\n', 0;
		return cout << 0 << '\n', 0;
	}
	memcpy(A + n + 1, A + 1, sizeof (bool) * n);
	memcpy(A + 2 * n + 1, A + 1, sizeof (bool) * n);
	memcpy(B + n + 1, B + 1, sizeof (bool) * n);
	memcpy(B + 2 * n + 1, B + 1, sizeof (bool) * n);
	enum(i, 1, 3 * n)
		pre[i] = B[i] ? i : pre[i - 1];
	dec(i, 3 * n, 1)
		suc[i] = B[i] ? i : suc[i + 1];
	int ans = INT_MAX;
	enum(i, -n, n)
	{
		vec.clear();
		int res = 0;
		enum(j, n + 1, 2 * n)
			if(A[j] == 1 && B[j + i] == 0)
			{
				if(i >= 0 && suc[j] <= i + j || i < 0 && pre[j] >= i + j)
					continue;
				if(i >= 0)
					vec.pb(pii(j - pre[j], suc[j] - (i + j)));
				else
					vec.pb(pii(i + j - pre[j], suc[j] - j));
			}
		sort(vec.begin(), vec.end());
		if(!vec.empty())
		{
			res = INT_MAX;
			int Max = 0;
			dec(i, vec.size() - 1, 0)
			{
				chkmin(res, vec[i].fi + Max);
				chkmax(Max, vec[i].se);
			}
			chkmin(res, Max);
			//cerr << res << endl;
			res *= 2;
		}
		enum(j, n + 1, 2 * n)
			if(A[j] != B[i + j])
				res ++;
		res += abs(i);
		chkmin(ans, res);
		//cerr << i << ' ' << vec.size() << ' ' << res << endl;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define modd               1e9+7
#define ff                 first
#define ss                 second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define rep(i,l,r)         for(int i=l;i<r;i++)
#define rer(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
using namespace std;
int32_t main(){

	
     int n;
     cin >> n;
     if(n%2!=0){
     	cout << "0\n";
     }
     else{
     	n/=2;
     	int count = 0;
     	for(int i=5;n/i>=1;i*=5){
     		count+=n/i;
     	}
     	cout << count;
     }
    return 0;

}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n, t, a;
    cin >> n;
    ll x = 1, y = 1;
    REP(i,n){
        cin >> t >> a;
        ll p = max((x+t-1)/t, (y+a-1)/a);
        x = p*t;
        y = p*a;
    }
    cout << x+y << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
#define int long long
#define mod 1000000007
using namespace std;

int dp[62][3];
signed main() {
	int n; cin >> n;
	dp[61][0] = 1;
	for (int i = 61; i > 0; i--) {
		int a = (n >> (i-1)) & 1;
		dp[i - 1][2] += dp[i][2]*3;
		if (a) {
			dp[i - 1][2] += dp[i][1] * 2;
			dp[i - 1][1] += dp[i][1];
			dp[i - 1][1] += dp[i][0];
			dp[i - 1][0] += dp[i][0];
		}
		else {
			dp[i - 1][2] += dp[i][1];
			dp[i - 1][1] += dp[i][1];
			dp[i - 1][0] += dp[i][1];
			dp[i - 1][0] += dp[i][0];
		}
		dp[i - 1][0] %= mod;
		dp[i - 1][1] %= mod;
		dp[i - 1][2] %= mod;
	}
	cout << (dp[0][0] + dp[0][1] + dp[0][2]) % mod << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
b = True
s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i] = map(int, input().split())


ans = [-1] * N

if M == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    elif N == 3:
        print(100)
        
else:
    
    if N == 1:
        for i in range(M-1):
            if c[i] != c[i + 1]:
                b = False
        ans[0] = c[0]
    
    elif N == 2:
        
        for i in range(M):
            if s[i] == 1 and c[i] == 0:
                b = False
        
        for i in range(M):
            for j in range(N):
                if s[i] == j + 1:
                    if ans[j] == c[i] or ans[j] == -1:
                        ans[j] = c[i]
                    else:
                        b = False
        
        if ans[0] == -1:
            ans[0] = 1
        if ans[1] == -1:
            ans[1] = 0
                        
    elif N == 3:
        
        for i in range(M):
            if s[i] == 1 and c[i] == 0:
                b = False
        
        for i in range(M):
            for j in range(N):
                if s[i] == j + 1:
                    if ans[j] == c[i] or ans[j] == -1:
                        ans[j] = c[i]
                    else:
                        b = False
        
        if ans[0] == -1:
            ans[0] = 1
        if ans[1] == -1:
            ans[1] = 0
        if ans[2] == -1:
            ans[2] = 0
                    
    if b:
        if N == 1:
            print(ans[0])
        elif N == 2:
            print(ans[0] * 10 + ans[1])
        else:
            print(ans[0] * 100 + ans[1] * 10 + ans[2])
    else:
        print(-1)

Measured memory_bytes: 3192
n, a, b, c, d = map(int, input().split())

s = input()

if s.find('##',a,c) < 0 and s.find('##',b,d) < 0:
    if c<d :
        print('Yes')
    else :
        if s.find('...',b-2,d+1)>=0:
            print('Yes')
        else :
            print('No')
else :
    print('No')

Measured memory_bytes: 3572