akhauriyash/Code-Regression huggingface dataset:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
    return ret


S = list(input())
if len(set(S)) == 2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner cin = new Scanner();

    internal static void Main(string[] args) {
        var N = cin.nextInt();
        var a = ReadLine().Split(' ');
        var ans = new LinkedList<string>();
        for (int i = 0; i < N; i++) {
            if (i % 2 == 0) {
                ans.AddLast(a[i]);
            } else {
                ans.AddFirst(a[i]);
            }
        }

        if (N % 2 == 1) {
            WriteLine(string.Join(" ", ans.Reverse()));
        } else {
            WriteLine(string.Join(" ", ans));
        }
    }
}




class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 57500
#include <stdio.h>
#define N 100

int main()
{

  int A[N], i, j, k, n, v;

  /* input data */
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);

    /* output 1st data */
    if(i != n-1) printf("%d ", A[i]);
    else printf("%d",A[i]);
  }
  printf("\n");

  /* sort */
  for(i = 1; i <= n-1; i++){  
    v = A[i];
    j = i-1;
    while(j >=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;

    /* output 2,3,,,,nth data */
    for(j = 0; j < n; j++){
      if(j != n-1) printf("%d ", A[j]);
      else printf("%d", A[j]);
    }
    printf("\n");
  }
  return 0;
}

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

using namespace std;

int main()
{
	string S , T;
	while(getline(cin , S))for(size_t i = 0; i < 26; i++)
	{
		for(auto &x : S)if('a' <= x&&x <= 'z')if(++x > 'z')x -= 26;
		stringstream SS;
		SS << S;
		vector<string>VS;
		while(SS >> T)if(T == "the" || T == "this" || T == "that" || T == "ths." || T == "this." || T == "that.")
		{
			cout << S << endl;
			break;
		}
	}
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
int n,ans,sum,Mod,c[3030][3030],f[3030],g[3030][3030];
IN Pow(int x,int y,int p){
	re res=1;
	while(y){
		if(y&1)res=(ll)res*x%p;
		x=(ll)x*x%p;
		y>>=1;
	}
	return res;
}
I add(int &x,int y){(x+=y)>=Mod?x-=Mod:0;}
IN Plus(int x,int y){(x+=y)>=Mod?x-=Mod:0;return x;}
int main(){
	read(n);read(Mod);
	c[0][0]=1;g[0][0]=1;
	F(i,1,n){
		c[i][0]=1;g[i][0]=1;
		F(j,1,i)c[i][j]=Plus(c[i-1][j],c[i-1][j-1]);
		F(j,1,i)g[i][j]=Plus(g[i-1][j-1],(ll)(j+1)*g[i-1][j]%Mod);
	}
	F(i,0,n){
		sum=(ll)c[n][i]*Pow(2,Pow(2,n-i,Mod-1),Mod)%Mod;
		F(j,0,i)add(f[i],(ll)g[i][j]*Pow(2,(ll)(n-i)*j%(Mod-1),Mod)%Mod);
		if(i&1)add(ans,Mod-(ll)sum*f[i]%Mod);else add(ans,(ll)sum*f[i]%Mod);
	}
	printf("%d",ans);
	return 0;
}



Measured memory_bytes: 58988
module app;

import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto input = parseInput();
    int count = 0;
	for (int i = 0; i < 3; i++)
    {
        if (input.s[i] == input.t[i])
            count++;
    }
    writefln("%d", count);
}

struct Input
{
	string s;
    string t;
}

Input parseInput()
{
	Input input = void;
	input.s = readln().strip();
	input.t = readln().strip();
	return input;
}


Measured memory_bytes: 256
import heapq


def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    if N <= K:
        V.sort()
        total = sum(V)
        ans = max(total, 0)
        for i in range(min(K-N, N)):
            total -= V[i]
            ans = max(ans, total)
        print(ans)
    else:
        left = [0] * (K+1)
        right = [0] * (K+1)
        for i in range(K, 0, -1):
            lv = V[:i]
            rv = V[-i:]
            left[i] = sum(lv)
            right[i] = sum(rv)
            lheap = list(lv)
            rheap = list(rv)
            heapq.heapify(lheap)
            heapq.heapify(rheap)
            lmsum = 0
            rmsum = 0
            for j in range(1, i):
                if i+j > K:
                    continue
                lmsum += heapq.heappop(lheap)
                left[i+j] = max(left[i+j], left[i] - lmsum)
                rmsum += heapq.heappop(rheap)
                right[i+j] = max(right[i+j], right[i] - rmsum)
        for i in range(1, K):
            left[i] = max(left[i], left[i-1])
            right[i] = max(right[i], right[i-1])
        ans = 0
        for i in range(K+1):
            ans = max(max(left[i], 0) + max(right[K-i], 0), ans)
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39408
from collections import defaultdict
MOD = 10 ** 9 + 7

n = int(input())

prime_cnt = defaultdict(int)
for num in range(2, n + 1):
    i = 2
    while i * i <= num:
        if num % i == 0:
            cnt = 0
            while num % i == 0:
                cnt += 1
                num //= i
            prime_cnt[i] += cnt
        i += 1

    if num != 1:
        prime_cnt[num] += 1

ans = 1
for v in prime_cnt.values():
    ans *= v + 1
    ans %= MOD

print(ans)


Measured memory_bytes: 3316
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
h = [int(i) for i in input().split()]

dp = np.zeros(N, dtype=int)
h = np.array(h)

for i in range(1, N):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))

print(dp[N-1])

Measured memory_bytes: 23048
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    tuple<int,int,int> t[n - 1];
    for(int i = 0;i < n - 1;i++)
    {
        int c,s,f;
        cin >> c >> s >> f;
        t[i] = make_tuple(c,s,f);
    }
    for(int i = 0;i < n - 1;i++)
    {
        int ans = 0;
        for(int j = i;j < n - 1;j++)
        {
            ans = max(ans,get<1>(t[j]));
            while(ans % get<2>(t[j]) != 0)
            {
                ans++;
            }
            ans += get<0>(t[j]);
        }
        cout << ans << "\n";
    }
    cout << "0\n";

    return 0;
}

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

public class Main {

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

		ArrayList<String> lines = new ArrayList<String>();
		int c = 0;

		while (true) {
			String next = sc.nextLine();

			if (next.equals("0")) {
				break;
			}
			lines.add(next);
			c++;
		}

		for (int i = 0; i < c; i++) {
			String s = lines.get(i);
			int sum = 0;
			for (int j = 0; j < s.length(); j++) {
				int in = Integer.parseInt(s.substring(j, j + 1));
				sum += in;
			}
			System.out.println(sum);
		}

	}

}

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

using namespace std;

using int64 = long long;

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

  int a, b;
  cin >> a >> b;
  int ans = b;
  if (a <= 12) ans = b / 2;
  if (a <= 5) ans = 0;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> V(N);
  vector<int64_t> sum(N+1);
  for(int i=0;i<N;i++){
    cin>>V.at(i);
  }
  sum.at(0)=0;
  for(int i=1;i<N+1;i++){
    sum.at(i)=sum.at(i-1)+V.at(i-1);
  }
  sort(sum.begin(),sum.end());
  int64_t ans=0;
  int64_t num=0;
  for(int i=1;i<N+1;i++){
    if(sum.at(i)==sum.at(i-1)){
      num++;
    }
    else{
      ans=ans+num*(num+1)/2;
      num=0;
    }
  }
  ans=ans+num*(num+1)/2;
  cout<<ans;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>

using namespace std;
int a, b, c;
int main(){
	cin >> a >> b >> c;
	if (a + b + c <= 21) {
		cout << "win" << endl;
		return 0;
	}
	cout << "bust" << endl;
	return 0;
}

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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 710;

int g[mxN][mxN];
int C[mxN];
int N;

int W,B;

bool dfs(int u) {
	if(C[u] == 1) W++; else B++;
	for(int v = 0;v < N;v++) {
		if(!g[u][v]) {
			if(!C[v]) {
				C[v] = !(C[u] - 1) + 1;
				if(!dfs(v)) return false;
			} else if(C[v] == C[u]) return false;
		}
	}
	return true;
}

vector<pair<int,int> > in;

long long dp[mxN][mxN];

long long bt(int ind,int w,int b) {
	if(ind >= (int)in.size()) return (w * (w-1ll) + b * (b-1ll)) / 2ll;
	long long & ref = dp[ind][w];
	if(ref != -1) return ref;
	ref = min(bt(ind+1,w+in[ind].first,b+in[ind].second),bt(ind+1,w+in[ind].second,b+in[ind].first));
	return ref;
}

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

	int M,u,v;
	cin>>N>>M;
	for(int i = 0;i < M;i++) {
		cin>>u>>v;
		u--,v--;
		g[u][v] = g[v][u] = 1;
	}
	for(int i = 0;i < N;i++) g[i][i] = 1;
	for(int i = 0;i < N;i++) {
		if(!C[i]) {
			W = B = 0;
			C[i] = 1;
			if(!dfs(i)) {
				cout<<"-1\n";
				return 0;
			}
			in.push_back({W,B});
		}
	}
	memset(dp,-1,sizeof dp);
	cout<<bt(0,0,0)<<'\n';
	return 0;
}


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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"

ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n,k,i;
	cin>>n>>k;
	vector<ll> v(n);
	for(i=0;i<n;i++)cin>>v[i];
	sort(all(v));
	if(n<=k)
		cout<<0;
	else
	{
		ll sum=0;
		for(i=0;i<n-k;i++)
			sum+=v[i];
		cout<<sum;
	}

	return 0;
}


Measured memory_bytes: 1792
n = int(input())
a=list(map(int,input().split()))

b = sorted(a,reverse=True)

def binary_search(x):
    l,r = 0,n-1
    while l+1<r:
        i = (l+r)//2
        if b[i] > x:
            l = i
        else:
            r = i
    if abs(b[l]-x)>=abs(b[l+1]-x):
        l += 1
    return b[l]

def comb(n,r):
    r = min(r,n-r)
    ret = 1
    for i in range(1,r+1):
        ret *= (n+1-i)
        ret /= i
    return int(ret)

ans = ""
m = 0
for c in b[:1]:
    r = binary_search(c/2)
    #comb_c_r = comb(c,r)
    #if m < comb_c_r:
        #m = comb_c_r
    ans = str(c)+" "+str(r)
print(ans)

Measured memory_bytes: 14052
/*
 *  I wish I could travel by the road that crosses baby's mind,
 *  and out beyond all bounds;
 *  Where messengers run errands for no cause
 *  between the kingdoms of kings of no history;
 *  Where Reason makes kites of her laws and flies them,
 *  and Truth sets Fact free from its fetters.
 *                                           Rabindranath Tagore
 */

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

#ifndef ORZ_EVERYBODY_BUT_ME
#define ORZ_EVERYBODY_BUT_ME
#endif

#ifndef SOCIALISM
#define SOCIALISM
#endif

unsigned long long operator "" _love(unsigned long long literal) {
    return literal;
}

int main() {
    string s; int w;
    cin >> s >> w;
    for (int i = 0; i < s.size(); i += w) putchar(s[i]);
    return 0;
}


Measured memory_bytes: 256
import copy
import bisect
import math

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

s = [a[0]]
for i in range(1, N):
    s.append(s[i-1] + a[i])
ps = copy.copy(s)
for i in range(N):
    ps = [ps[j] - ps[0] for j in range(1, N-i)]
    s += ps

ans = 0
s.sort()

while s[-1] != 0:
    n = int(math.log2(s[-1]))
    ind = bisect.bisect_left(s, 2**n)
    if len(s) - ind == K:
        temp = s[-1]
        for i in range(1, K):
            temp &= s[-i-1]
        print(ans + temp)
        exit()
    elif len(s) - ind > K:
        ans += 2**n
        s = [x & (2**n-1) for x in s[ind:]]
    else:
        s = [x & (2**n-1) for x in s]
    s.sort()
print(ans)

Measured memory_bytes: 28812
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    }
}


Measured memory_bytes: 23764
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
num = [0] * 100010
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

for i in a:
    num[i] += 1

s = sum(a)

#print(num)
#print(b)
#print(c)


for i in range(q):
    s += (c[i]-b[i])*num[b[i]]
    num[c[i]] += num[b[i]]
    #print(num)
    num[b[i]] = 0
    #print(num,"\n")
    print(s)


Measured memory_bytes: 22084
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, a, b = map(int, input().split())
    r = 0
    for i1 in range(1, n + 1):
        i1sum = 0
        i1org = i1
        while i1:
            i1sum += i1 % 10
            i1 = i1 // 10
        if a <= i1sum <= b:
            r += i1org
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1e6;
const ll LINF = (ll)1e19;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<double> v(N);
    REP(i, N){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double ans = v[0];
    for(int i = 1; i < N; i++){
        ans += v[i];
        ans /= 2;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int a, answer;
map<string, int> m;

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

	cin >> a;
	for (int i = 0; i < a; i++) {
		string s;
		cin >> s;
		if (m[s] == 0) {
			m[s]++;
			answer++;
		}
		else m[s]++;
	}
	cout << answer;
	return 0;
}

Measured memory_bytes: 19288
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 62;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll p(n);
  rep(i,n) cin>>p[i];
  vll a(n);
  rep(i,n){
    a[p[i]-1]=i;
  }
  ll k=1;
  ll ans=0;
  for(int i=1;i<n;i++){
    if(a[i]>a[i-1])k++;
    else{
      ans=max(k,ans);
      k=1;
    }
  }
  ans=max(ans,k);
  COUT(n-ans);
}

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<int> nums(10);
  for (int i = 0; i < 10; i++) {
    cin >> nums[i];
  }

  sort(nums.begin(), nums.end(), greater<int>());
  for (int i = 0; i < 3; i++) {
      cout << nums[i] << endl;
  }
}


Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    vector<P> v;
    for(int i=0;i<n;++i){
      int d,p;
      cin >> d >> p;
      v.push_back(P(p,d));
    }
    sort(v.begin(), v.end(), greater<P>());
    int s = 0;
    for(int i=0;i<n;++i) s+=v[i].first*v[i].second;
    for(int i=0;i<n;++i){
      m-=v[i].second;
      s-=v[i].first*v[i].second;
      if(m<0){
	s+=v[i].first*(-m);
	m=0;
	break;
      }
    }
    cout << s << endl;
  }
  return 0;
}

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

int main(){

  ll n,k,cnt=1;
  cin >> n >> k;

  while(n >= k){
    n = n/k;
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc142/tasks/abc142_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

auto Eratosthenes(const int n)
{
    vector<ll> result;
    result.emplace_back(1); //特殊
    vector<bool> is_prime(n+1,true); //trueで初期化
    for(ll i = 2; i <= n; ++i){
        if (is_prime.at(i)) {
            for(ll j = 2 * i; j <= n; j += i){
                is_prime[ j ] = false;
            }
            result.emplace_back( i );
        }
    }
    return result;
}
bool is_prime(const ll n){
    switch(n){
        case 0: // fall-through
        case 1: return true;//false;
        case 2: return true;
    } // n > 2 が保証された

    if(n%2 == 0) return false;

    // 上で i=2 相当は調べたので、i=3から奇数のみ調べる
    for(ll i=3;i*i<=n;i+=2){
        if(n%i == 0) return false;
    }

    return true;
}

int main() {
#if LOCAL&01
    //std::ifstream in("./test/sample-2.in"); //input.txt
    std::ifstream in("./input.txt"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll A,B; cin>>A>>B;
    //if(A>B) swap(A,B); //A小さい
    auto gcdv = __gcd(A,B);
    //auto al = divisor(A);
    //auto bl = divisor(B);
#if LOCAL
    cout<<"gcd"<<gcdv<<endl;
#endif
    vector<ll> tyou = divisor(gcdv);
#if LOCAL
    cout<<tyou.back()<<endl;
#endif
    // for(auto a:al){
    //     auto it = lower_bound(bl.begin(),bl.end(), a);
    //     if(*it==a){ tyou.push_back(a);}
    // }

    //素数は判定
//    auto sosu = Eratosthenes(tyou.back());
#if LOCAL
//    cout<<sosu.size()<<endl;
#endif
    ll ans=0;
    for(auto v:tyou){
        if (is_prime(v)) {
#if LOCAL
            cout<<v<<endl;
#endif
            ++ans;
        }
        //else break;
    }
    // for(auto v:tyou){
    //     auto it = lower_bound(sosu.begin(),sosu.end(),v);
    //     if(*it==v) ++ans;
    // }
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int a[1000010];
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    int curr = a[0];
    int ans = 1;
    for (int i = 1; i < n; ++i)
    {
        if (curr <= a[i])
        {
            ans++;
            curr = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Given an array of integers of size ‘n’.
// Our aim is to calculate the maximum sum of ‘k’
// consecutive elements in the array.

/*{{{*/
#include<bits/stdc++.h>
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, A, B) for (int I = (A); I <= (B); ++I)
#define repr(I, A, B) for (int I = (A); I >= (B); --I)
#define fors(I, S) for (int I = 0; S[I]; ++I)
#define get_pos(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define mp make_pair
#define pb emplace_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define in insert
#define cn count
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef set<int> si;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T, class U> void _W(const pair<T, U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
/*}}}*/

const int SIZE = 1e6 + 10;

void solve() {
	int n;
	string s;
	R(n, s);
	int ans = 0;
	rep(i, 0, n - 3) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			ans++;
	}
	W(ans);
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

#define MULTITEST 0
#if MULTITEST
	CASET {
		solve();
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 3736
require 'set'

def count_paths(graph, idx, visited = Set.new, count = 0)
  return count if visited.include?(idx)

  visited.add(idx)
  return count + 1 if visited.size == graph.size

  graph[idx].inject(count) do |cnt, node|
    count_paths(graph, node, visited.dup, cnt)
  end
end

n_nodes, n_edges = gets.chomp.split.map(&:to_i)
graph = Array.new(n_nodes) { [] }
n_edges.times do
  a, b = gets.chomp.split.map { |n| n.to_i - 1 }
  graph[a].push(b)
  graph[b].push(a)
end

graph.each { |nodes| nodes.uniq! }

p count_paths(graph, 0)

Measured memory_bytes: 2556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);
        Arrays.sort(str);
        System.out.println(String.join(" ", str));

    }
}

Measured memory_bytes: 24372
# import sys
import math

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize

# ===CODE===

m, n = map(int, input().split())

res = 1
mod = 10 ** 9 + 7
while n > 0:
    if n & 1 == 1:
        res = res * m % mod
    m = m * m % mod

    n >>= 1

print(res)



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

const int N=1e4+10;
vector<pair<ll,ll>> v(N);
int n;
ll dp[N];
ll solve(ll health){
	if(health<=0){
		return 0;
	}
	if(dp[health]!=-1){
		return dp[health];
	}
	ll ans=1000000000;
	for (int i =0;i<n;i++){
		ans=min(ans,v[i].second+solve(health-v[i].first));
	}
	return dp[health]=ans;
}
int main() {
   ll health;
 
    cin>>health>>n;
     for(int i=0;i<n;i++){
     	 cin>>v[i].first>>v[i].second;
     }
     memset(dp,-1,sizeof dp);
    ll anss=solve(health);
  cout<<anss<<endl;
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

const ll MOD = 998244353;
const int MN = 2010;

inline void add(ll &x, ll y) { x += y; if (x >= MOD) x -= MOD; }

ll dp[MN][MN];
ll comb[MN][MN];
ll pf[MN][2];

int main() {
	rep(i, MN) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
		}
	}

	string S; cin >> S;
	int N = S.size();

	rep(i, N) {
		pf[i+1][0] = pf[i][0];
		pf[i+1][1] = pf[i][1];
		if (S[i] == '0') {
			pf[i+1][0] += 2;
		} else if (S[i] == '1') {
			pf[i+1][0]++;
			pf[i+1][1]++;
		} else {
			pf[i+1][1] += 2;
		}
	}

	dp[0][0] = 1;
	rep(i, N) {
		rep(j, i+1) if (dp[i][j] != 0) {
			int n0 = pf[i][0] + (S[i] != '2');
			int n1 = pf[i][1] + (S[i] != '0');
			int u0 = j, u1 = i - j;
			if (n0 >= u0 + 1) {
				add(dp[i + 1][u0 + 1], dp[i][j]);
			}
			if (n1 >= u1 + 1) {
				add(dp[i + 1][u0], dp[i][j]);
			}
		}
	}

	ll ans = 0;
	for (int i = 0; i <= N; ++i) {
		int z0 = pf[N][0] - i;
		int z1 = N - z0;
		if (z0 >= 0 && z1 >= 0) {
			ll t = dp[N][i] * comb[N][z0] % MOD;
			add(ans, t);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 61824
def main():
  n = int(input())
  a = [int(s) - 1 for s in input().split()]
  res = 0
  for i in range(n):
    if a[i] != (i-res):
      res += 1
  if res == n:
    print(-1)
  else:
    print(res)
    
if __name__ == '__main__':
  main()

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

int main(){

    int a,b,c;
    cin >> a >>b >>c;

    cout << min(b/a,c) <<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b = 0; cin >> n;
	int dp[123456] = { 0 }, test[123456] = { 0 };
	for (int h = 0; h <n; h++) {
		cin >> a; test[h] = a;
	}
	for (int h = 1; h < n; h++) {
		if (h == 1) {
			dp[h] = abs(test[h - 1] - test[h]);
		}
		else {
			dp[h] = min(dp[h - 1] + abs(test[h - 1] - test[h]), dp[h - 2] + abs(test[h - 2] - test[h]));
		}
	}
	cout << dp[n - 1] << endl;
	cin >> n;
}


Measured memory_bytes: 1152
/*
	Mbak Sana Dong
	Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll arr[100100];
int main()
{
	int n,i,j,k,x,y,ans,curr,temp,m;
	int tc;
	cin >> n >> m;
	bool odd = 0;
	for(i=1;i<=n;i++)
	{
		cin >> arr[i];
	}
	ll lcm = arr[1];
	ll gcd = arr[1];
	bool can = 1;
	for(i=2;i<=n;i++)
	{
		gcd = __gcd(lcm, arr[i]);
		lcm = (lcm*arr[i]) / gcd;
		if(lcm > 1LL*2*m)
		{
			can = 0;
			break;
		}
	}
	for(i=1;i<=n;i++) if((lcm/arr[i])%2==0) odd = 1;
	if(!can || odd)
	{
		printf("0\n");
		return 0;
	}
	ll sana = 0;
	ll start = lcm / 2;
	sana = 1;
	ll low, mid, high;
	low = 0;
	ll maxi = 1e10;
	high = maxi / lcm;
	mid = (low + high) / 2;
	ll chaeng = 0;
	while(low <= high)
	{
		if(start + mid*lcm <= m)
		{
			chaeng = mid;
			low = mid + 1;
		}
		else
		{
			high = mid - 1;
		}
		mid = (low + high) / 2;
	}
	sana += chaeng;
	cout << sana <<endl;
	return 0;
}

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

using namespace std;

int main()
{
  int N, M, C; cin >> N >> M >> C;
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> B(M);

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

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

  int counter = 0;
  for (int n_i = 0; n_i < N; ++n_i) {
    int sum = 0;
    for (int m_i = 0; m_i < M; ++m_i) {
      sum += A[n_i][m_i] * B[m_i];
    }

    if (sum > -C)
      counter++;
  }

  cout << counter << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const int maxA = 60, maxN = 60;
  int N;
  while (cin >> N) {
    vector<int> a(N), b(N);
    for (int i = 0; i < N; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> b[i];
    }
    bool reachable[maxA][maxA][maxA];
    memset(reachable, false, sizeof(reachable));
    for (int i = 0; i < maxA; i++) {
      for (int j = 0; j < maxA; j++) {
        reachable[0][i][i] = true;
      }
    }
    for (int k = 1; k < maxA; k++) {
      for (int i = 0; i < maxA; i++) {
        for (int j = 0; j < maxA; j++) {
          reachable[k][i][j] =
              reachable[k - 1][i][j] | reachable[k - 1][i % k][j];
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < N; i++) {
      ok &= reachable[maxA - 1][a[i]][b[i]];
    }
    if (!ok) {
      cout << -1 << endl;
      continue;
    }
    bool available[maxN][maxA];
    memset(available, false, sizeof(available));
    for (int i = 0; i < N; i++) {
      available[i][a[i]] = true;
    }
    ll res = 0;
    for (int k = maxA - 1; k >= 1; k--) {
      bool need = false;
      for (int i = 0; i < N; i++) {
        bool found = false;
        for (int a = 0; a < maxA; a++) {
          if (available[i][a] && reachable[k - 1][a][b[i]]) {
            found = true;
            break;
          }
        }
        if (!found) {
          need = true;
          break;
        }
      }
      if (need) {
        res += 1ll << k;
        for (int i = 0; i < N; i++) {
          for (int a = 0; a < k; a++) {
            for (int t = a + k; t < maxA; t += k) {
              available[i][a] |= available[i][t];
            }
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  while(cin>>str,str!="0"){
    int a[2]={};
    for(int i=1;i<str.size();i++){
      if(str[i]!=str[i-1]){
	a[str[i]-'A']++;
      }else{
	a[str[i]-'A']++;
      }
    }
    if(a[0]>a[1])
      a[0]++;
    else
      a[1]++;
    cout<<a[0]<<" "<<a[1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,alf='Z';
  string s;
  cin>>n;
  cin>>s;
  int str =s.size();
  for(int i=0;i<str;i++){
    s[i]+=n;
    if(s[i] > alf)
      s[i]-=26;

    cout<<s[i];
  }
  cout<<endl;
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++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 ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll a,b;
    cin >> a >> b;
    ll c = b-a;
    cout << (c)*(c+1)/2-b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll INF = 1<<29;
int main(){
    int n;cin>>n;
    double v[n];
    rep(i,n){
        cin>>v[i];
    }
    sort(v,v+n);
    double ave=0.0;
    ave=(v[0]+v[1])/2;
    for(int i=2;i<n;i++){
      ave=(v[i]+ave)/2;
    }
    cout<<ave<<endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb push_back
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
	a = a%mod;
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}
template <typename T>
void max_self(T &a, T b ){
	a = max(a, b);
}

template <typename T>
void min_self(T &a, T b){
	a = min(a, b);
}

int main()
{
    fast;
    int t;
    //~ cin>>t;
    t=1;
    while(t--){
		ll n,W;
		cin>>n>>W;
		ll val[n],weight[n];
		ll sum=0;
		for(int i=0;i<n;i++){
			cin>>weight[i]>>val[i];
			sum+=val[i];
		}
		
		vector<ll> dp(sum+1, inf);
		dp[0]=0;
		for(int i=0;i<n;i++){
			for(int cur_val = sum-val[i]; cur_val>=0;cur_val--){
				min_self(dp[cur_val+val[i]], dp[cur_val]+weight[i]);
			}
		}
		ll answer = 0;
		for(int i=0; i<sum+1;i++){
			if(dp[i]<=W)
				max_self(answer,(ll)i);
			//~ cout<<dp[i]<<endl;
		}
		cout<<answer;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
using namespace std;
int main(){
    string str;
    int i=0,j=0,num;
    int a[250][200];
    int b[250][200];
    while(getline(cin,str)){
        istringstream is(str);
        j=0;
        while(is>>num){
            is.ignore();
            a[i][j]=num,j++;
        }
        i++;
    }
    b[0][0]=a[0][0],i--;
    for(int k=1;k<=i/2;k++){
        for(int l=0;l<=k;l++){
            if(!l)b[k][l]=a[k][l]+b[k-1][l];
            else if(k==l)b[k][l]=a[k][l]+b[k-1][l-1];
            else b[k][l]=a[k][l]+max(b[k-1][l-1],b[k-1][l]);
        }
    }
    for(int k=i/2+1;k<=i;k++){
        for(int l=0;l<=i-k;l++){
            b[k][l]=a[k][l]+max(b[k-1][l],b[k-1][l+1]);
        }
    }
    cout<<b[i][0]<<endl;
    return 0;
}

Measured memory_bytes: 1384
N = int(input())
h = list(map(int,input().split()))
DP = [float('inf') for i in range(N)]
DP[0]=0
DP[1]=abs(h[1]-h[0])
for i in range(N-2):
    DP[i+2]=min(DP[i+1]+abs(h[i+2]-h[i+1]),DP[i]+abs(h[i+2]-h[i]))
print(DP[-1])

Measured memory_bytes: 13928
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]

    ans = 10 ** 9

    for bit in range(1 << (H-1)):
        canSolve = True
        ord = [0] * (H + 1)
        N = 0
        for i in range(H):
            if bit & 1 << i:
                ord[i+1] = ord[i] + 1
                N += 1
            else:
                ord[i+1] = ord[i]
        nums = [0] * (H + 1)
        for w in range(W):
            one = [0] * (H + 1)
            overK = False
            for h in range(H):
                one[ord[h]] += int(S[h][w])
                nums[ord[h]] += int(S[h][w])
                if one[ord[h]] > K:
                    canSolve = False
                if nums[ord[h]] > K:
                    overK = True
            if not canSolve:
                break
            if overK:
                N += 1
                nums = one
        if canSolve and ans > N:
            ans = N
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 43100
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, H) {
    string s;
    cin >> s;
    a[i] = "#";
    a[i] += s;
    a[i] += "#";
  }
  rep(i, W+2) cout << '#';
  cout << endl;
  rep(i, H) cout << a[i] << endl;
  rep(i, W+2) cout << '#';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define IN 3

int main(void)
{
    int data[IN];
    int temp;
    int i,j;
    
    scanf("%d %d %d",&data[0],&data[1],&data[2]);
    
    for(i=0 ; i < IN-1 ; i++)
    {
        for(j=IN-1 ; i < j ; j--)
        {
            if(data[j-1] > data[j])
            {
                temp = data[j-1];
                data[j-1] = data[j];
                data[j] = temp;
            }
        }

    }
    
    printf("%d %d %d\n",data[0],data[1],data[2]);
    
    return 0;
}



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


int main() {
  string s;
  cin >> s;
  if (s == "ARC") {
    cout << "ABC";
  } else {
    cout << "ARC";
  }
}

Measured memory_bytes: 3624
s = input()
state = False
if s.startswith('A'):
    if s[2:-1].count('C') == 1:
        if s.lstrip('A').replace('C', 'c') == s.lstrip('A').replace('C', 'c').lower():
            state = True

if state:
    print('AC')
else:
    print('WA')


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

#define ll long long
#define inf 1e18 + 5

int dp[3003][3003];
string s, t;

int solve (int i, int j) {
	if (i == -1 || j == -1) {
		return 0;
	}
	if (dp[i][j] != -1) {
		return dp[i][j];
	}

	//dp[i][j] = 0;

	if (s[i] == t[j]) {
		dp[i][j] = 1  + solve (i - 1, j - 1);
	}
	else {
		dp[i][j] = max (solve(i - 1, j), solve(i, j - 1));
	}
	return dp[i][j];
}


int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	cin >> s >> t;
	memset (dp, -1, sizeof dp);
	int i = s.length() - 1, j = t.length() - 1;
	int len = solve (i, j), len_ptr = len;
	//cout << len ;
	if (len == 0) {
		cout << "" ;
		return 0;
	}
	string ans = "";

	while (i != -1 && j != -1) {
		if (s[i] == t[j]) {
			//ans[len_ptr] = s[i];
			ans.push_back(s[i]);
			i--; j--; len_ptr--;
		}
		else {
			if (i == 0) {
				j--;
				continue;
			}
			if (j == 0) {
				i--;
				continue;
			}
			if (dp[i - 1][j] >= dp[i][j - 1]) {
				i--;
			}
			else {
				j--;
			}
		}
	}

	reverse (ans.begin(), ans.end());
	cout << ans;
	return 0;
}

Measured memory_bytes: 35712
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



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

    if (p[2] == p[3] && p[4] == p[5])cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

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

using namespace std;

int n, m, q, ans;
int a[50], b[50], c[50], d[50];

vector<int> sb;

int score(vector<int> v){
	int res = 0;
	for(int i = 0; i < q; ++i){
		if(sb[b[i]-1]-sb[a[i]-1] == c[i]) res += d[i];
	}
	return res;
}

void rec(int k){
	if(sb.size() == n){
		ans = max(ans, score(sb));
	}else{
		for(int i = k; i <= m; ++i){
			sb.push_back(i);
			rec(i);
			sb.pop_back();
		}
	}
}

int main(){
	cin >> n >> m >> q;
	for(int i = 0; i < q; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i];
	rec(1);
	cout << ans << endl;
}

Measured memory_bytes: 3596
/// 1行の文字を空白で分割してVec<T>にする。
fn read_split<T : std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

fn main() {
    let mut input : Vec<i64> = read_split();
    input.sort();
    let small = input[0] % 2 == 0;
    let large = input[1] % 2 == 0;
    if small == large {
        
        println!("{}", input[1] - ((input[1] - input[0]) / 2));
    } else {
        println!("IMPOSSIBLE");
    }

}



Measured memory_bytes: 4352
N = int(input())

A = []
B = []
for _ in range(N):
    a, b = [int(_) for _ in input().split()]
    A.append(a)
    B.append(b)
A.sort()
B.sort()

if N % 2 == 1:
    print(B[N//2] - A[N//2] + 1)
else:
    sa, ea = A[N//2 - 1], B[N//2 - 1]
    sb, eb = A[N//2], B[N//2]
    print(eb+ea - (sa+sb) + 1)


Measured memory_bytes: 25552
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String[] strs = sc.nextLine().split(" ");
      	int d = Integer.valueOf(strs[0]);
      	int t = Integer.valueOf(strs[1]);
      	int s = Integer.valueOf(strs[2]);
      	if(d<=t*s){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
	}
}


Measured memory_bytes: 35820
package MyApp;
use utf8;
use 5.016;

say func(map { chomp; $_ } <>);

sub func {
    my ($line1, @lines) = @_;
    my ($n, $m) = split / /, $line1;
    my %hash;
    for my $line (@lines) {
        my ($k, @k) = split / /, $line;
        $hash{$_}++ for @k;
    }
    my $answer = 0;
    for my $key (keys %hash) {
        $answer++ if $hash{$key} == $n;
    }
    return $answer;
}

1;
__END__


Measured memory_bytes: 512
module Matrix =
  struct
    type t = {a: float; b: float; c: float; d: float}
    let init a b c d = {a = a; b = b; c = c; d = d}
    let mul m1 m2 = init (m1.a *. m2.a +. m1.b *. m2.c) (m1.a *. m2.b +. m1.b *. m2.d) (m1.c *. m2.a +. m1.d *. m2.c) (m1.c *. m2.b +. m1.d *. m2.d)
    let inv m =
      let det = m.a *. m.d -. m.b *. m.c in
      init (m.d /. det) ((-1.0) *. m.b /. det) ((-1.0) *. m.c /. det) (m.a /. det)
  end

let id x = x

let solve x1 y1 x2 y2 x3 y3 =
  let stm = Matrix.mul (Matrix.inv (Matrix.init (y1 -. y2) (y3 -. y1) (x2 -. x1) (x1 -. x3))) (Matrix.init (0.5 *. (x3 -. x2)) (0.0) (0.5 *. (y3 -. y2)) (0.0)) in
  let cx = x1 +. 0.5 *. (x2 -. x1) +. stm.Matrix.a *. (y1 -. y2) in
  let cy = y1 +. 0.5 *. (y2 -. y1) +. stm.Matrix.a *. (x2 -. x1) in
  let r = sqrt ((cx -. x1) ** 2.0 +. (cy -. y1) ** 2.0) in
  (cx, cy, r)

let _ = 
  let n = Scanf.scanf "%d\n" id in
  let rec loop n = 
    if n = 0 then ()
    else
      begin
        let cx, cy, r = Scanf.scanf "%f %f %f %f %f %f\n" solve in
        Printf.printf "%.3f %.3f %.3f\n" cx cy r;
        loop (n - 1)
      end
  in loop n

Measured memory_bytes: 2368