akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline   #sys.std.readlineのほうが10倍速い
N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N-1)]
PX = [tuple(map(int, input().split())) for i in range(Q)]
es = [[] for _ in range(N)]  #グラフ配列

for a,b in AB:
  a -= 1
  b -= 1
  es[a].append(b)
  es[b].append(a)
ps = [0] * N   #処理配列(当該のものをプラスする)
for p,x in PX:
  ps[p-1] += x
  
#print(es)
#print(ps)

ans = [0] * N #回答配列
ans[0] = ps[0]
stack = [0]  #待ち配列
visited = [0] * N #訪れたかどうか配列、最初は0、訪れたら1
visited[0] = 1
while stack: #空であればFalse、中身が入ってればTrueを返す性質
  v = stack.pop()
  for i in es[v]:
    if visited[i]:
      continue
    visited[i] = 1
    ans[i] = ans[v] + ps[i]
    stack.append(i)
print(*ans)


Measured memory_bytes: 179408
// D - Lucky PIN
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

bool dp[30000+1][3+1][1000+9];

int main(){
	int N; string S; cin>>N>>S;
	dp[0][0][0] = true;
	rp(i, 0, N) rp(j, 0, 3+1) rp(k, 0, 1000){
		if(!dp[i][j][k]) continue;
		dp[i+1][j][k] = true;
		if(j<=2) dp[i+1][j+1][k*10+S[i]-'0'] = true;
	}
	int count = 0;
	rp(i, 0, 1000) if(dp[N][3][i]) count++;
	cout<< count <<endl;
}

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

int main(){
	ll n,k;
	cin>>n>>k;
	ll h[n];
	ll d[n],tmp[n];
	for(ll i=0;i<n;i++){
		cin>>h[i];
		d[i]=pow(10,18);
		//tmp[i]=pow(10,18);
	}

	/*for(ll i=1;i<n;i++){
		for(ll j=i;j<k+i;j++){
			tmp[j]=min(abs(h[j]-h[i]),tmp[j]);
		}
	}*/
	if(k>n)k=n-1;
	d[0]=0;
	for(ll i=1;i<=k;i++){
		d[i]=abs(h[i]-h[0]);
	}
	for(ll i=1;i<n;i++){
		for(ll j=i+1;j<=k+i;j++){
			if(j>n)break;
			d[j]=min(d[j],d[i]+abs(h[j]-h[i]));
		}
		d[i]=min(d[i],d[i-1]+abs(h[i]-h[i-1]));
	}
	cout<<d[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    int i, j,k,n,r;
   
    int data[4][3][10] = {{{0}}};
    int b,f,v;
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        data[b-1][f-1][r-1]= data[b-1][f-1][r-1]+v;
    }
     for(k = 0; k < 4; k++){
        for(j = 0; j < 3; j++){
            for(i = 0; i < 10; i++){
            printf(" %d",data[k][j][i]);
            }
        printf("\n");
        }
   if(k == 3)break;
   
   printf("####################\n");
   }
   
   return 0;
 }
 


Measured memory_bytes: 2060
#include <vector>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int H, W, N, A, B;

long long LX, LY, RX, RY; // rotate

vector<int> X;
vector<int> Y;
vector<int> EX; // sorted X
vector<int> EY; // sorted Y
vector<int> UX; // unique X
vector<int> UY; // unique Y

vector<long long> SX; // accumulation sum X
vector<long long> SY; // accumulation sum Y
vector<long long> DX; // distance sum from UX
vector<long long> DY; // distance sum from UY

long long sumx(int l, int r)
{
	return SX[r] - SX[l];
}

long long sumy(int l, int r)
{
	return SY[r] - SY[l];
}

int main()
{
	// ------ Input ------ //

	scanf("%d", &W);
	scanf("%d", &H);
	scanf("%d", &N);

	X = vector<int>(N);
	Y = vector<int>(N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &X[i]);
		scanf("%d", &Y[i]);
	}


	// ------ Sort & Unique ------ //

	EX = X;
	EY = Y;

	sort(EX.begin(), EX.end()); UX.push_back(EX[0]);
	sort(EY.begin(), EY.end()); UY.push_back(EY[0]);

	for (int i = 1; i < N; i++)
	{
		if (EX[i] != EX[i - 1])
		{
			UX.push_back(EX[i]);
		}

		if (EY[i] != EY[i - 1])
		{
			UY.push_back(EY[i]);
		}
	}

	A = UX.size();
	B = UY.size();

	
	// ------ Accumulation ------ //

	SX.push_back(0);
	SY.push_back(0);

	for (int i = 0; i < N; i++) SX.push_back(SX[i] + EX[i]);
	for (int i = 0; i < N; i++) SY.push_back(SY[i] + EY[i]);


	// ------ Rotate ------ //

	LX = 999999999999999999LL;
	LY = 999999999999999999LL;
	RX = -999999999999999999LL;
	RY = -999999999999999999LL;

	for (int i = 0; i < N; i++)
	{
		long long tx = X[i] + Y[i];
		long long ty = X[i] - Y[i];

		LX = min(LX, tx);
		LY = min(LY, ty);
		RX = max(RX, tx);
		RY = max(RY, ty);
	}


	// ------ Distance Calculation ------ //

	for (int i = 0; i < A; i++)
	{
		int ptrl = lower_bound(EX.begin(), EX.end(), UX[i]) - EX.begin();
		int ptrr = upper_bound(EX.begin(), EX.end(), UX[i]) - EX.begin();

		long long suml = 1LL * UX[i] * ptrl - 1LL * sumx(0, ptrl);
		long long sumr = 1LL * sumx(ptrr, N) - 1LL * UX[i] * (N - ptrr);

		DX.push_back(sumr + suml);
	}

	for (int i = 0; i < B; i++)
	{
		int ptrl = lower_bound(EY.begin(), EY.end(), UY[i]) - EY.begin();
		int ptrr = upper_bound(EY.begin(), EY.end(), UY[i]) - EY.begin();

		long long suml = 1LL * UY[i] * ptrl - sumy(0, ptrl);
		long long sumr = 1LL * sumy(ptrr, N) - 1LL * UY[i] * (N - ptrr);

		DY.push_back(sumr + suml);
	}


	// ------ Calculate ------ //

	long long ret = 999999999999999999LL;

	int x = -1, y = -1, pl = 0, pr = B, l, r;

	for (int i = 0; i < A; i++)
	{
		long long res = 999999999999999999LL;

		for (int j = pl; j < pr; j++)
		{
			long long rx = UX[i] + UY[j];
			long long ry = UX[i] - UY[j];

			long long maxs = max(max(rx - LX, RX - rx), max(ry - LY, RY - ry));

			long long sum = 2LL * (DX[i] + DY[j]) - maxs;

			if (sum < res)
			{
				res = sum;

				l = j;
				r = j + 1;

				if (sum < ret)
				{
					x = UX[i];
					y = UY[j];
				}
			}
			else if (sum == res)
			{
				r++;
			}
		}

		pl = max(l - 1, 0);
		pr = min(r + 1, B);

		ret = min(ret, res);
	}


	// ------ Output ------ //

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

	printf("%d %d\n", x, y);

	return 0;
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int main(){
	int n,K;cin>>n>>K;
	string s;cin>>s;
	vector<pair<char,int>>v;
	for(char c:s){
		if(v.empty()||v.back().first!=c)v.push_back({c,1});
		else v.back().second++;
	}
	int ans=n-v.size();
	int cnt=max(0,((int)(v.size()-1)/2));
	cnt=min(cnt,K);
	K-=cnt;
	if(K&&v.size()%2==0)ans++;
	cout<<ans+cnt*2<<endl;
}

Measured memory_bytes: 1528
s=input()

mozisuu=len(s)

def hanteiki(s):
    hantei=True
    mozisuu=len(s)
    for i in range(len(s)):
        if s[i]!=s[mozisuu-i-1]:
            hantei=False
    return hantei
            
if hanteiki(s):
    if hanteiki(s[0:(mozisuu-1)//2]):
        if hanteiki(s[(mozisuu+3)//2-1:]):
            print("Yes")
            exit()

print("No")

Measured memory_bytes: 9008
n, x, y = map(int,input().split())
ls = [0] * n
for u in range(1, n):
    for v in range(u, n+1):
        u2x = abs(u-x)
        v2y = abs(v-y)

        d = min(v-u, u2x + 1 + v2y)
        ls[d] += 1

for k in range(1, n):
    print(ls[k])

Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    string s = "Sunny";
    string r = "Rainy";
    string c = "Cloudy";
    string input;
    
    cin >> input ;
    if(input == s)cout << c;
    else if (input == c ) cout << r;
    else if (input == r ) cout << s; 
    
}

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

int main(void)
{
    std::string S;
    std::cin >> S;

    int64_t remain = 15 - S.size();

    int64_t win = 0;
    for (auto c : S) {
        if (c == 'o') win++;
    }

    std::cout << (remain - (8-win) >= 0 ? "YES" : "NO") << std::endl;

    return 0;
}

Measured memory_bytes: 256
import 'dart:io';
 
void main(List<String> args) {
  int N = int.parse(stdin.readLineSync());
  int ans = 0;
  for(int i=1; i<=N; ++i){
  	if(i%3!=0&&i%5!=0) ans = ans + i;
  }
  print(ans);
}

Measured memory_bytes: 13100
package main

import (
	"fmt"
)

func main() {

	count := 0
	fmt.Scan(&count)
	odd := 0
	even := 0
	for i := 0; i < count; i++ {
		x := 0
		fmt.Scan(&x)
		if x % 2 == 0 {
			if even == 1 {
				continue
			} else {
				even = 1
			}
		} else {
			if odd == 1 {
				odd = 0
				if even == 1 {
					continue
				} else {
					even = 1
				}
			} else {
				odd = 1
			}
		}

	}
	if odd+even == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


Measured memory_bytes: 5504
from collections import deque

N, K = map(int, input().split())
D = input().split()

nums = list("0123456789")
for d in D:
    nums.remove(d)


def dfs(N, nums):
    ans = 10 ** 9
    if "0" in nums:
        queue = deque(nums[1:])
    else:
        queue = deque(nums)

    while queue:
        tmp = queue.pop()
        if int(tmp) >= N:
            if int(tmp) < ans:
                ans = int(tmp)
        else:
            for n in nums:
                queue.append(tmp + n)

    return ans


print(dfs(N, nums))


Measured memory_bytes: 3316
while 1:
    if input() == '0':
        break
    s = list(map(int, input().split()))
    m = sum(s) / len(s)
    m_2 = sum(i ** 2 for i in s) / len(s)
    print('{0:f}'.format((m_2 - m ** 2) ** 0.5))

Measured memory_bytes: 7732
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	string peach, apple;
	peach = "peach";
	apple = "apple";
	getline(cin, s);
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'p'){
			int flag = 0;
			for (int i2 = i,j=0; i2 < i + 5; i2++,j++){
				if (peach[j] != s[i2]){
					flag = 1;
					break;
				}
			}
			if (!flag){
				for (int i2 = i,j=0; i2 < i + 5; i2++,j++){
					s[i2] = apple[j];
				}
			}
		}
		else if (s[i] == 'a'){
			int flag = 0;
			for (int i2 = i, j = 0; i2 < i + 5; i2++, j++){
				if (apple[j] != s[i2]){
					flag = 1;
					break;
				}
			}
			if (!flag){
				for (int i2 = i, j = 0; i2 < i + 5; i2++, j++){
					s[i2] = peach[j];
				}
			}
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string S;cin >> S;
    vector<LL> ct;
    char tmp = S[0];
    LL p = 1;
    LL N = S.size();
    rep(i,N){
        if(i == 0)continue;
        if(tmp == S[i]){
            p++;
            if(i == N-1)ct.push_back(p);
        }
        else{
            ct.push_back(p);
            p = 1;
            tmp = S[i];
            if(i == N-1)ct.push_back(p);
        }
    }

 //   rep(i,ct.size())cout << ct[i] << " ";
 //   cout << endl; 

    LL ans = 0;
    LL lim = ct.size();
    if(N == 1){
        ans = 1;
    }
    else{
        rep(i,lim){

        if(S[0] == '<'){
            if(i == lim-1){
                LL a = ct[i];
                ans += a*(a+1)/2;
            }
            else{
                LL a = ct[i];
                LL b = ct[i+1];
                if(a < b)ans += a*(a-1)/2 + b*(b+1)/2;
                else ans += a*(a+1)/2 + b*(b-1)/2;
            }
            i++;
        }
        else{
            if(i == 0){
                LL a = ct[i];                
                ans += a*(a+1)/2;
            }
            else{
                if(i == lim-1){
                    LL a = ct[i];                
                    ans += a*(a+1)/2;
                }
                else{
                    LL a = ct[i];
                    LL b = ct[i+1];
                    if(a < b)ans += a*(a-1)/2 + b*(b+1)/2;
                    else ans += a*(a+1)/2 + b*(b-1)/2;
                }
                i++;
            }
    //        cout << ans << " ";
        }

    }
    //cout << endl;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3068
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0 for i in range(n)]
z=set(a)
y=len(z)
for x in a:
    s[x-1]+=1
b=sorted(s)
f=0
ans=0
for x in b:
    if x!=0:
        f+=1
        ans+=x
    if f>=y-k:
      	break
print(ans)


Measured memory_bytes: 26812
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "queue"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll S, W;
  cin >> S >> W;
  if (W >= S) {
    cout << "unsafe"
         << "\n";
  } else {
    cout << "safe"
         << "\n";
  }
  return 0;
}


Measured memory_bytes: 3652
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new MyInputStream(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(MyInputStream cin)
        {
            var S = cin.Read();
            WriteLine(S.ToCharArray().Distinct().Count() == S.Length ? "yes" : "no");
        }
    }

    public class MyInputStream
    {
        private readonly System.IO.TextReader _stream;
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(System.IO.TextReader s, char separator = ' ')
        {
            this.separator = separator;
            this._stream = s;
            inputStream = new Queue<string>();
        }
        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return _stream.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}

Measured memory_bytes: 13280
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
#define SIZE 1005
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll k, n;

int main() {
	io(); cin >> n >> k;
	cout << min(n % k, k - n % k);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int num = 3*n;
    long[] strong = new long[num];
    long sum = 0;
    for (int i = 0; i < num; i++){
      strong[i] = sc.nextLong();
    }
    Arrays.sort(strong);
    for(int j = 0; j < n;j++){
      sum += strong[num-2*(1+j)];
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 97564
#include <bits/stdc++.h>
using namespace std;
pair <pair <string, int>, int> p [110];
int main () {
int a; cin>>a;
for (int i = 0; i <a; i ++) {
int t; string in;
cin>>in>>t;
//string tmp = in;
p [i] = make_pair (make_pair (in, -t), i);
}
std :: sort (p, p + a);
for (int i = 0; i <a; i ++) 
  cout<<(p [i]. second + 1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  string s;
  cin >> s;
  while (1) {
    s.pop_back();
    string t1 = s.substr(0, s.size()/2), t2 = s.substr(s.size()/2);
    if (t1 == t2) break;
  }
  dump(s.size());
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  if((int)(sqrt(1+8*n))*(int)(sqrt(1+8*n))!=1+8*n){cout<<"No";return 0;}
  cout<<"Yes"<<endl;
  int num=(1+sqrt(1+8*n))/2;
  cout<<num<<endl;
  vector<int> v[1000];
  int i=1;
  for(int x=1;x<=num;x++){
    for(int y=x+1;y<=num;y++){
      v[x].push_back(i);
      v[y].push_back(i);
      i++;
    }
  }
  for(int i=1;i<=num;i++){
    cout<<v[i].size()<<" ";
    for(int k=0;k<v[i].size();k++){
      cout<<v[i][k]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

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

typedef long long ll;

int main(){
	const int MOD = 1e9+7;
	ll N,K;
	cin >> N >> K;

	ll ans = 0;
	ll l = 0;
	ll r = 0;
	l = K * (K-1) / 2;
	r = l + (N-K+1)*K;
	ll rr = N-K+1;
	ans = r-l+1;
	for(int i=K; i<=N; i++){
		l = (l+i);
		rr--;
		r = (r+rr);
		ans += (r-l)+1 % MOD;
		ans %= MOD;
	}

	cout <<ans<<endl;
}



Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
	int N;
	int D;
	cin >> N >> D;
	int A[15][15];
	int sum;
	int tmp;
	int ans;
	
	for(int i=0;i<N; i++){
		for(int j=0; j<D; j++){
			cin >> A[i][j];
		}
	}
	
	for(int i=0; i<N; i++){
		for(int k=i+1; k<N; k++){
			for(int j=0; j<D; j++){
				sum +=(A[i][j]-A[k][j])*(A[i][j]-A[k][j]);
			}
			for(int p=1; p*p<=sum; p++){
				if(p*p==sum){
					ans++;
				}
			}
			sum = 0;
			tmp = 0;
		}
	}
	
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 256
import itertools

while True:
	n, x = map(int, input().split()) # n = 5, x = 9

	if (n == 0 and x == 0):
		break

	count = 0
	num_sequence = [i + 1 for i in range(n)] # [1, 2, 3, 4, 5]
	for guess in itertools.combinations(num_sequence, 3):
		sum = 0
		for i in guess:
			sum += i
		if (sum == x):
			# (1, 3, 5)
			# (2, 3, 4)
			count += 1

	print(count)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const ll INF = 1e18;


ll rec(int left, int right, vector<ll>& A, vector<vector<ll>>& memo) {
  if (left + right == A.size()) {
    return 0;
  }
  if (memo[left][right] != INF) {
    return memo[left][right];
  }

  if ((left + right) % 2 == 0) {
    memo[left][right] = max(rec(left + 1, right, A, memo) + A[left],
                            rec(left, right + 1, A, memo) + A[A.size()-1-right]);
  } else {
    memo[left][right] = min(rec(left + 1, right, A, memo) - A[left],
                            rec(left, right + 1, A, memo) - A[A.size()-1-right]);
  }
  return memo[left][right];
}


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  vector<vector<ll>> memo(N, vector<ll>(N, INF));
  cout << rec(0, 0, A, memo) << endl;
  return 0;
}


Measured memory_bytes: 70912
n = int(input())
c = 0
while 1:
    c += 1
    if n == 0:
      break
    if n > 0:
        if c%2 == 1: 
            if (4**(c//2+1)-1)//3 >= n:
                break
    elif n < 0:
        if c%2 == 0:
            if abs(2*(4**(c//2)-1))//3 >= abs(n):
                break
if n == 0:
    ans = ["0"]
else:
    k = 0
    ans = []
    while k < c:
        ans.append(str(n%2))
        n = (-1)* (n//2)
        k += 1
print("".join(ans[::-1]))

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

using namespace std;

using int64 = long long;

struct Task {
  int64 cost;
  int64 deadline;
};

int main() {
  int n;
  cin >> n;
  vector<Task> tasks;
  for (int i = 0; i < n; i++) {
    int64 cost, deadline;
    cin >> cost >> deadline;
    tasks.push_back(Task({cost, deadline}));
  }
  sort(
    tasks.begin(), tasks.end(),
    [](Task t1, Task t2) { return t1.deadline < t2.deadline; });
  int64 t = 0;
  for (const auto& task : tasks) {
    t += task.cost;
    if (t > task.deadline) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 6384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if(a>=13){
		cout<<b<<endl;
	}
	else if(a>=6){
		cout<<b/2<<endl;
	}
	else{
		cout<<0<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define LL long long
#define LD long double
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
int const MAXN = 2e6 + 9;
int a[MAXN];
int main(){
    ios_base::sync_with_stdio (0),cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++)
            for(int k = j + 1; k < n; k++){
                vector<int> v;
                v.push_back(a[i]);
                v.push_back(a[j]);
                v.push_back(a[k]);
                sort(all(v));
                if(v[0] == v[1] or v[1] == v[2]) continue;
                ans += (v[0] + v[1] > v[2]);
                
            }
    }
    cout << ans << endl;
}

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

int main()
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  
  int backet5 = 0, backet7 = 0;
  
  for (int i = 0; i < 3; i++) {
		if (a[i] == 5) backet5++;
    	if (a[i] == 7) backet7++;
  }
  
  if (backet5 == 2 && backet7 == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;

int main() {
	int n, m, l, k, a, h;
	while (cin >> n >> m >> l >> k >> a >> h) {
		if (n == 0 && m == 0 && l == 0 && k == 0 && a == 0 && h == 0) {
			break;
		}
		vector<int> p(l);
		for (int i = 0; i < l; i++) {
			cin >> p[i];
		}
		int x, y, t;
		vector< vector<P> > mp(n);
		for (int i = 0; i < k; i++) {
			cin >> x >> y >> t;
			mp[x].push_back(P(y, t));
			mp[y].push_back(P(x, t));
		}
		int ans = 300000;
		priority_queue<Q, vector<Q>, greater<Q> > pq;
		pq.push(Q(0,P(m, a)));
		vector<int> ss(n, -1);
		while (!pq.empty()) {
			Q q = pq.top();
			pq.pop();
			int time = q.first;	
			int mlim = (q.second).first;
			int pos = (q.second).second;
			if (ss[pos] >= mlim) {
				continue;
			}
			else {
				ss[pos] = mlim;
			}
			bool isr = false;
			for (int i = 0; i < l; i++) {
				if (pos == p[i]) {
					isr = true;
				}
			}
			for (int i = 0; i < mp[pos].size(); i++) {
				int to = mp[pos][i].first;				
				int cost = mp[pos][i].second;				
				if (cost > mlim || ss[to] >= mlim - cost) {				
				} else {
					if (to == h) {
						ans = min(ans, time + cost);
					} else {
						pq.push(Q(time + cost, P(mlim - cost, to)));
					}
				}
			}
			if (isr) {
				if (mlim < m) {
					pq.push(Q(time + 1, P(mlim + 1, pos)));
				}
			}
		}
		if (ans == 300000) {
			cout << "Help!" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct UnionFind
{
	const int n;
	vector<int> rank;
	vector<int> par;
	UnionFind(int _n): n(_n)
	{
		rank.assign(n, 0);
		par.assign(n, -1);
	}
	
	int find(int i)
	{
		if (par[i] == -1) return i;
		else return par[i] = find(par[i]);
	}
	
	void unite(int i, int j)
	{
		i = find(i);
		j = find(j);
		if (i == j) return;
		
		if (rank[i] == rank[j])
		{
			par[i] = j;
			++rank[j];
		}
		else
		{
			if (rank[i] > rank[j]) swap(i, j);
			par[i] = j;
		}
	}
	bool is_same(int i, int j)
	{return find(i) == find(j);}
};



void ending(bool status)
{
	if (status)
	cout << "Yes" << endl;
	else
		cout << "No" << endl;
	exit(0);
}

int main()
{
	int n;
	cin >> n;
	vector<pii> a(n), b(n);

	for (int i=0; i<n; ++i)
    {
        int v;
        cin >> v;
        a[i] = make_pair(v, i);
    }
	for (int i=0; i<n; ++i)
    {
        int v;
        cin >> v;
        b[i] = make_pair(v, i);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
	
	// check
	for (int i=0; i <n; ++i)
 	if (a[i].first > b[i].first) ending(false);

	// check spanning 
	UnionFind uf(n);
	for (int i=0; i<n; ++i)
		uf.unite(a[i].second, b[i].second);
	
	int cnt = 0;
	for (int i=0; i<n; ++i)
	if (uf.par[i] == -1) ++cnt;

	if (cnt > 1)
		ending(true);

	for (int i=0; i<n-1; ++i)
	if (a[i+1].first < b[i].first) ending(true);
	
    ending(false);
}


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

const static int MAX_N = 300030;
int parK[MAX_N];
int rnkK[MAX_N];
int parL[MAX_N];
int rnkL[MAX_N];
int N;

void init(){
  for (int i=1; i<=N; i++){
    parK[i] = i;
    rnkK[i] = 0;
    parL[i] = i;
    rnkL[i] = 0;
  }
}

int find(int x, char state) {
  if (state=='K'){
    if (parK[x] == x) {
      return x;
    } else {
      return parK[x] = find(parK[x],'K');
    }
  } else {
    if (parL[x] == x) {
      return x;
    } else {
      return parL[x] = find(parL[x],'L');
    }
  }
}

void unite(int x, int y, char state){
  if (state=='K'){
    x = find(x,state);
    y = find(y,state);
    if (x==y) return;
    if (rnkK[x]<rnkK[y]){
      parK[x] = y;
    } else {
      parK[y] = x;
      if (rnkK[x]==rnkK[y]) rnkK[x]++;
    }
  } else {
    x = find(x,state);
    y = find(y,state);
    if (x==y) return;
    if (rnkL[x]<rnkL[y]){
      parL[x] = y;
    } else {
      parL[y] = x;
      if (rnkL[x]==rnkL[y]) rnkL[x]++;
    }
  }
}

bool same(int x, int y, char state){
  return find(x,state) == find(y,state);
}

int main(){
  int K, L;
  cin >> N >> K >> L;
  init();
  for (int i=0; i<K; i++){
    int p, q;
    cin >> p >> q;
    unite(p, q, 'K');
  }
  for (int i=0; i<L; i++){
    int r, s;
    cin >> r >> s;
    unite(r, s, 'L');
  }
  map<pair<int,int>, int> mp;
  for (int i=1; i<=N; i++){
    mp[make_pair(find(i,'K'),find(i,'L'))]++;
  }
  for (int i=1; i<=N; i++){
    if (i>1) cout << ' ' ;
    cout << mp[make_pair(find(i,'K'),find(i,'L'))];
  }
  cout << endl;
}


Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i;
	ll ans = 0;
	cin >> num;
	vector<int> d(num + 1, 0);
	for (i = 0; i < num; i++)
		cin >> d[i];
	for (i = num - 1; i >= 0; i--) {
		if (d[i] > i || d[i] + 1 < d[i + 1]) {
			ans = -1;
			break;
		}
		if (d[i] + 1 == d[i + 1])
			continue;
		ans += d[i];
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#line 2 "codes/header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "codes/solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    int n;cin>>n;
    vec<ll> a(n);
    ll s = 0;
    map<int, int> cnt;
    rep(i, n){
        cin>>a[i];
        s += a[i];
        cnt[a[i]]++;
    }

    int Q;cin>>Q;
    rep(q, Q){
        int b,c;cin>>b>>c;
        s -= (ll)cnt[b] * b;
        s += (ll)cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << s << endl;
    }

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 8544
import math
n = int(input())
total = 0
word = str(n)
val1 = len(word)
ans = 0
if val1==1:
	ans = n
elif val1==2:
    ans = 9
elif val1==3:
	ans = 9+n-99
elif val1==4:
	ans = 909
elif val1==5:
	ans = 909+n-9999
else:
	ans = 90909
print(ans)


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

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

//足したり引いたりすると勝手にmodをとってくれる
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619

//コンビネーションのライブラリ
struct combination {
    //factのなかに階乗を求めている
    //ifactのなかに階乗逆元を求めている
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int x, y;
  cin >> x >> y;
  
  //移動回数 (x+y) / 3 回である
  //移動回数が3の倍数にならないとき, 不適である
  if ((x+y)%3) {
    cout << 0 << endl;
    return 0;
  }
  
  int n = (x+y)/3;
  
  //目標地点は, (x - n, y - n)になる
  //ここへ 長さ１の矢印を組み合わせて到達する経路の数を求める
  //これは有名問題である
  //a+b C a　により求めることができる　・・・　コンビネーションの問題となる
  //移動回数が求まる, というのは比較的ありうる
  //図を書いてみると、格子点っぽい
  //うまく変換すると, 格子点上を動く問題へ帰着できるのでは？と疑うことが大切である
  x -= n; y -= n;
  
  //xは負になることもあるため, 注意せよ
  //ex. x = 1, y = 5
  if (x < 0 || y < 0) {
    cout << 0 << endl;
    return 0;
  }
  
  //コンビネーションの構造体の初期化をする
  //左側に来る最大値を入れておく
  combination c(x+y);
  
  //x+y C x　を計算する
  mint ans = c(x+y,x);
  
  
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  string a,b;
  cin >> a >> b;
  
  int s = a.size();
  int t = b.size();

  if(s > t) cout << "GREATER" << endl;
  else if(s < t) cout << "LESS" << endl;
  else {
    if(a[0] > b[0]) cout << "GREATER" << endl;
    else if(a[0] < b[0]) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 3632
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int n,col[MAXN],Ok;
vector<int>P[MAXN];
void dfs(int u,int fa){
	int cnt[2]={0,0},p;
	int size=P[u].size();
	for(int i=0;i<size;i++){
		int v=P[u][i];
		if(v==fa)continue;
		dfs(v,u);
		cnt[col[v]]++;
	}
	if(u==1&&cnt[1]==size)Ok=1;
	if(cnt[0]>=2)Ok=1;
	if(cnt[0])col[u]=1;
	else col[u]=0;
}
int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		P[u].push_back(v);
		P[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(P[i].size()>1){
			dfs(1,0);
			break;
		}
	if(Ok)printf("First\n");
	else printf("Second\n");
}
/*
6
1 2
2 3
3 4
4 5
5 6

7
1 2
2 3
3 4
4 5
5 6
6 7
*/

Measured memory_bytes: 6144
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	while(1){
		int n; cin >> n;
		if (!n)break;
		int t[16][16] = {};
		for (int i = 0; i < 16; i++)
			for (int j = 0; j < 16; j++)
				if (i == j)continue;
				else t[i][j] = 9999999;
		bool f[15][15] = {};
		bool F[15] = {};
		for (int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			t[a][b] = c;
			t[b][a] = c;
			
			F[a] = 1, F[b] = 1;
		}

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					t[j][k] = min(t[j][k], t[j][i] + t[i][k]);
				}
			}
		}

		int ans = 0, an = 9999999;
		for (int i = 0; i < 10; i++) {
			if (!F[i])continue;
			int dd = 0;
			for (int j = 0; j < 10; j++) {
				if (!F[j])continue;
				dd += t[i][j];
			}
			if (an > dd) {
				ans = i, an = dd;
			}
		}


		
			cout << ans << " " << an << endl;
	
}

	
	return 0;

}

Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,n;
  cin>>h>>n;
  int a[n];
  int sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  if(sum>=h) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;

int main(){
  int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
  int H,W;
  int maxD=0;
  cin>>H>>W;
  H--;W--;
  string S;
  char maze[W+1][H+1];
  int D[W+1][H+1];
  
  for(int i=0;i<=H;i++){
    for(int j=0;j<=W;j++){
      D[j][i]=1000;
    }
  }

  for(int i=0;i<=H;i++){
    cin>>S;
    for(int j=0;j<=W;j++){
      maze[j][i]=S.at(j);
    }
  }
  
  for(int wi=0;wi<=W;wi++){
    for(int hi=0;hi<=H;hi++){
      if(maze[wi][hi]=='#') continue;
       
      for(int i=0;i<=H;i++){
        for(int j=0;j<=W;j++){
          D[j][i]=1000;
        }
      }
      
      D[wi][hi]=0;
      queue<P>que;
      que.push(P(wi,hi));
      
      while(que.size()){
        P p=que.front();que.pop();
        for(int i=0;i<4;i++){
          int nx=p.first+dx[i],ny=p.second+dy[i];
          if(0<=nx && nx<=W && 0<=ny && ny<=H && maze[nx][ny]=='.' && D[nx][ny]==1000){
            que.push(P(nx,ny));
            D[nx][ny]=D[p.first][p.second]+1;
          }
        }
      }
      
      for(int i=0;i<=H;i++){
        for(int j=0;j<=W;j++){
          if(maze[j][i]=='.'){
            maxD=max(maxD,D[j][i]);
          }
        }
      }
    }  
  }
  cout<<maxD<<endl;
  return 0;
}
  


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define MAX_N 1000000007
#define INF 100000000000000

int main(){
  int a,b;
  cin >> a >> b;
  if(min(a,b) < 1){
    cout << -1 << endl;
    return 0;
  }
  if(max(a,b) > 9){
    cout << -1 << endl;
    return 0;
  }
  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <cstdlib>
#include <vector>
#include <iostream>
using namespace std;


int main() {
    long long x;
    scanf("%lld", &x);
    int cnt = 0;
    long long n = 100;
    while(n < x) {
        n += n / 100;
        cnt++;
    }
    printf("%d\n", cnt);
    
    return 0;
}

Measured memory_bytes: 3764
from collections import Counter

N = int(input())
A = list([int(i) for i in input().split()])

cA = Counter(A)
pairsumc = 0
for k, v in cA.items():
    #print(k, v, v*(v-1)/2)
    pairsumc += v*(v-1)/2
#print(pairsumc)
for a in A:
    print(int(pairsumc - cA[a]+1))

Measured memory_bytes: 26780
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> express[510];
    for(int i = 1; i <= m; i++){
        int l, r;
        cin >> l >> r;
        express[l].push_back(r);
    }
    for(int i = 1; i <= n; i++){
        sort(express[i].begin(), express[i].end());
    }
    for(int i = 1; i <= q; i++){
        int p, q;
        cin >> p >> q;
        int ans = 0;
        for(int i = p; i <= q; i++){
            ans += distance(express[i].begin(), upper_bound(express[i].begin(), express[i].end(), q));
        }
        cout << ans << endl;
    }
    //cout.precision(10);
    return 0;
}

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

string s[505];
int n, ans;
bool check(int v){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(s[i][j] != s[(v+j)%n][(n+i-v)%n])return false;
		}
	}
	return true;
}

signed main(){
	cin>>n;
	for(int i = 0; i < n; i++)cin>>s[i];
	for(int i = 0; i < n; i++)
		if(check(i))
			ans += n;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int main(){
	int H,W;
	int N;
	cin>>H>>W>>N;

	vector<vint> vv;
	initvv(vv,H,W);
	pii pos;
	rep(i,H){
		rep(j,W){
			char t;
			cin>>t;
			if(t=='S'){
				vv[i][j]=0;
				pos.F=i;
				pos.S=j;
			}
			else if(t=='.') vv[i][j]=10;
			else if(t=='X') vv[i][j]=-10;
			else vv[i][j]=t-'0';
		}
	}
	// queue<pii> q;
	ll ans=0;
	rep(i,N){
		queue<pair<pii,int> > q;
		q.push(mkp(pos,0));
		vector<vint> vis;
		initvv(vis,H,W);
		rep(k,H) rep(j,W) vis[k][j]=1;
		while(!q.empty()){
			pair<pii,int> tmp=q.front();
			q.pop();
			if(vv[tmp.F.F][tmp.F.S]==i+1){
				pos=tmp.F;
				ans+=tmp.S;
				break;
			}
			rep(j,4){
				int x=tmp.F.F+dx[j];
				int y=tmp.F.S+dy[j];
				if(x<H&&y<W&&x>=0&&y>=0&&vis[x][y]&&vv[x][y]!=-10){
					q.push(mkp(mkp(x,y),tmp.S+1));
					vis[x][y]=0;
				}
			}
		}
	}
	cout<<ans<<endl;
	// rep(i,H){
		// rep(j,W){
			// cout<<vv[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	// cout<<endl;
}

Measured memory_bytes: 8924
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
//#define int LL
using namespace std;
const int N   = 233;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,a[N];
signed main()
{
	read(n)	;
	rep(i,1,n) 
	{
		read(a[i]);
	}
	int ans=0;
	rep(i,1,n-1) if (a[i]==a[i+1]) a[i+1]=-1,++ans;
	printf("%d",ans);
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
vector<pii> ab;
//=============================
void input()
{
    cin>>N>>K;
    ab.resize(N);
    rep(i,0,N-1){
        cin>>ab[i].first>>ab[i].second;
    }
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    sort(all(ab));

    int ans;
    rep(i,0,N-1){
        int num = ab[i].second;

        if (K > num){
            K -= num;
        }
        else {
            ans = ab[i].first;
            break;
        }
    }
    cout<<ans<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#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 = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        String t=sc.next();
        
        int len=s.length();
        
        for(int i=0;i<len;i++){
            if(s.charAt(i)!=t.charAt(i)){
                System.out.println("No");
                return ;
            }
        }
        
        System.out.println("Yes");
    }
}


Measured memory_bytes: 35728
#include <stdio.h>

int main()
{
	int i, N, h[102] = {};
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(h[i]));
	
	int sum = 0, flag, count;
	while (1) {
		flag = 0;
		count = 0;
		for (i = 0; i <= N + 1; i++) {
			if (h[i] > 0) {
				h[i]--;
				if (flag == 0) {
					count++;
					flag = 1;
				}
			} else flag = 0;
		}
		sum += count;
		if (count == 0) break;
	}
	
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n;
string s;
int ans;
int br[214514];
signed main() {
	cin >> n >> s;
	rep(i, n) {
		if (i)br[i] = br[i - 1];
		if (s[i] == '#')br[i]++;
	}
	ans = n - br[n - 1];
	rep(i, n) {
		int memo = 0;
		memo += br[i];
		memo += (n - i - 1) - (br[n - 1] - br[i]);
		ans = min(ans, memo);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2688
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = input()
T = input()

lis = list(T)

max_count = 0
for i in range(len(S) - len(T)+1):
    subS = list(S[i:i+len(T)])
    count = 0
    for j in range(len(T)):
        if subS[j] == T[j]:
            count += 1
    # print(subS, count)
    max_count = max(max_count, count)

print(len(T) - max_count)





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

ll INF = 1e+18;

int 
main()
{
  ll N; cin >> N;
  vector<char> ans;
  int plus = 96;

  while(N > 0){
    int tmp = N % 26;
    if(tmp == 0){
      tmp = 26;
      N = N / 26 - 1;
    } else {
      N /= 26;
    }
    ans.push_back((char)(tmp + plus));
  }

  for(int i = (int)(ans.size() - 1); i >= 0; --i){
    cout << ans[i];
  }
  cout << endl;

}


Measured memory_bytes: 3588