akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String args[]) throws IOException {
		int Ans = 0;
		int ans = 0;

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s1 = new String(in.readLine());

		int N = Integer.parseInt(s1);

		String s2 = new String(in.readLine());
		String[] a = s2.split(" +");

		List<Integer> A = new ArrayList<Integer>();

		A.add(0);
		for(int i = 0;i < N;i++) {
			if( i == 0 || A.get(A.size() - 1) != Integer.parseInt(a[i])) {
				A.add(Integer.parseInt(a[i]));
			}
		}
		A.add(0);

		List<St> li = new ArrayList<St>();

		for(int i = 0;i < A.size() ;i++) {
			li.add(new Main().new St(A.get(i),i));
		}

		li.sort((e1,e2)-> e1.getNum() - e2.getNum()	);

		//初期状態での島の数の確認
		//マイナスからプラスへの境目を見る
		for (int j = 0; j < A.size() - 1 ; j++) {
			if (A.get(j) == 0 && A.get(j + 1) > 0) {
				ans++;
			}
		}
		Ans = ans;

		int countNum = 0;
		int incNum = 0;
		int decNum = 0;
		//System.out.println("初期島数 = " + Ans);
		
		//島の最大数を確認する
		//見る数値がリストの数値の中で最大値になった場合、終了する。
		for (int i = 0; li.get(i).getNum() != li.get(li.size() - 1).getNum();i++) {
			St st = li.get(i);
			St nextst = li.get(i + 1);

			//初期状態は確認しているのでスキップ
			if (st.getNum() <= 0 ) {
				continue;
			}

			countNum++;

			//沈む陸地に対しその左右の陸地をみて
			//ansを操作する。
			int nl_num = A.get(st.getIndex() - 1) ;
			int nr_num = A.get(st.getIndex() + 1) ;


			if (nl_num - st.getNum() > 0 && nr_num - st.getNum() > 0) {
				ans++;
				incNum++;
				//System.out.print("[in]:");
			}
			if (nl_num - st.getNum() <= 0 && nr_num - st.getNum() <= 0) {
				ans--;
				decNum++;
				//System.out.print("[de]:");
			}
		

			//System.out.println("getNum = " + String.format("%2d",st.getNum()) +",i = " + String.format("%4d",i) + ",index = " + String.format("%4d",st.getIndex()) + ",left = " + String.format("%2d",(rnum + st.getNum())) + ",right = " + String.format("%2d",(nnum + st.getNum())) + ",ans = " + String.format("%3d",ans));

			//海面の高さが変化するタイミングで
			//ansの判定を行う。
			if (st.getNum() != nextst.getNum() ) {
				if (ans > Ans) {
					Ans = ans;
				}
				//System.out.println("浸水 = " +  String.format("%2d",st.getNum()) + ",対象 = " + String.format("%4d",countNum) + ",inc = " + String.format("%4d",incNum) + ",dec = " + String.format("%4d",decNum) + ",ans = " + String.format("%4d",ans) + ",Ans = " + String.format("%4d",Ans));
				countNum = 0;
			}
			//if(i > 1000) {
			//	break;
			//}
		}

		System.out.println(Ans);
	}
	public class St{
		private int num;
		private int index;

		public St(int num , int index) {
			this.num = num;
			this.index = index;
		}

		public int getNum() {
			return num;
		}

		public int getIndex() {
			return index;
		}
	}

}


Measured memory_bytes: 58128
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

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

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

VVI cnt(N, VI(13, 0));
if (S[0] == '?')
    for (int i = 0; i < 10; i++) cnt[0][i] = 1;
else
    cnt[0][S[0] - '0'] = 1;

for (int k = 0; k < N - 1; k++) 
    if (S[k + 1] == '?')  // 次の文字が自由に決められる
        for (int i = 0; i < 13; i++) 
            for (int j = 0; j < 10; j++) { // 全ての文字を試す
                cnt[k + 1][(i * 10 % 13 + j) % 13] += cnt[k][i];
                cnt[k + 1][(i * 10 % 13 + j) % 13] %= MOD;
            }
    else  // 次の文字が指定されている
        for (int i = 0; i < 13; i++) {
            cnt[k + 1][(i * 10 % 13 + (S[k + 1] - '0')) % 13] += cnt[k][i];
            cnt[k + 1][(i * 10 % 13 + (S[k + 1] - '0')) % 13] %= MOD;
        }

cout << cnt[N-1][5] << endl;

}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

int main(){
  int n,a,b;
  bool ans=1,f=0;
  cin>>n>>a;
    
  if(n>2) REP(i,n-1){
    cin>>b;
    if(a<b) f=0;
    else if(a-1==b && !f) f=1;
    else if(a!=b){
      ans=0;
      break;
    }
    a=b;
   }

  if(ans) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
#include<set>
#include<map>
using namespace std;
int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		if (n % 10 == 2)ans++;
		n /= 10;
	}
	cout << ans << endl;
	return 0;
}

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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)



using namespace std;
typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

using namespace std;


int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }

    ll a, b;
    char ch;
    cin >> a >> ch >> b;

ll rs;

switch(ch) {
case '+':
    rs = a + b;
    break;
case '-':
    rs = a - b;
    break;

}

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


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

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)
#define input_c(x) scanf("%c", &x);

#define BS 101

int main(int argc, char const *argv[]) {
    char S[BS];
    input_s(S);
    int i, s_len= strlen(S);
    for(i= 0; i < s_len; i++) {
        if((i % 2 == 0 && S[i] == 'L') || (i % 2 == 1 && S[i] == 'R')) {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
long a[200005];
pair<long,long>b[200005];
long c[200005];
int main()
{
    long n;
    cin>>n;
    for(long i=0;i<n;i++){scanf("%ld",&a[i]);b[i].first=a[i];b[i].second=i;}
    sort(b,b+n);
    for(long i=0;i<n;i++)c[b[i].second]=i;
    long l=n/2;
    for(long i=0;i<n;i++){
        if(c[i]<l)printf("%ld\n",b[l].first);
        else printf("%ld\n",b[l-1].first);
    }
	return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1};
int dx[] = {1, -1, 0, 0};

int n, q;
class UnionFind {
public:
    vector<int> Parent;
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    int size(int A) {
        return -Parent[root(A)];
    }
    bool connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) {
            return false;
        }
        if (size(A) < size(B)) swap(A, B);
        Parent[A] += Parent[B];
        Parent[B] = A;
        return true;
    }
};
int main() {
    cin >> n >> q;
    UnionFind uni(n + 1);
    rep(i, q) {
        int com, x, y; cin >> com >> x >> y;
        if (com == 0) {
            uni.connect(x, y);
        } else {
            if (uni.root(x) == uni.root(y)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
}



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

int main(){
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    int i = s.size();
    vector<int> ans;

    int now = n;

    while(now > 0){
        int p = min(now, m);
        bool tmp = 0;
        for(int i = p; i >= 1; i--){
            if (s[now-i] == '0'){
                tmp = 1;
                now -= i;
                ans.push_back(i);
                break;
            }
        }
        if (!tmp) {
            cout << -1 << endl;
            return 0;
        }
    }

    rrep(i, ans.size()) cout << ans[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1144
#include<stdio.h>
int main(){
  int i,j;//i:モンスターの体力　j:攻撃一回につき減らせる体力
  scanf("%d %d",&i,&j);
  int n=i;
  int t=0;
  while(n>0){
    n-=j;
    t++;
  }
  printf("%d\n",t);
  return 0;
}
    

Measured memory_bytes: 128
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

int n,a[N],x;
signed main(){
    FastIO;
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
        x^=a[i];
    }
    rep(i,1,n){
        cout<<(x^a[i])<<' ';
    }
    return 0;
}


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

int main(){
  int a, b;
  string s, t, u;
  cin >> s >> t >> a >> b >> u;
  
  if(u==s){
    cout << a-1 << " " << b;
  }else{
    cout << a << " " << b-1;
  }
  
  return 0;
}


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



int main(){
	cin.tie(0)->sync_with_stdio(0);
	vector<vector<int>> next(1, vector<int>(26, -1));
	vector<int> cnt(1);
	auto insert = [&](const string &s){
		int u = 0;
		for(auto c: s){
			c -= 'a';
			if(!~next[u][c]){
				next[u][c] = int(next.size());
				next.push_back(vector<int>(26, -1));
				cnt.push_back(0);
			}
			u = next[u][c];
		}
		++ cnt[u];
	};
	int n;
	cin >> n;
	vector<string> a(n);
	for(auto &s: a){
		cin >> s;
		reverse(s.begin(), s.end());
		insert(s);
	}
	long long res = 0;
	for(auto &s: a){
		array<int, 26> lastpos;
		lastpos.fill(-1);
		int m = int(s.size());
		for(auto i = 0; i < m; ++ i){
			lastpos[s[i] - 'a'] = i;
		}
		for(auto u = 0, i = 0; ~u && i < m; ++ i){
			for(auto c = 0; c < 26; ++ c){
				if(i <= lastpos[c] && ~next[u][c]){
					res += cnt[next[u][c]];
				}
			}
			u = next[u][s[i] - 'a'];
		}
	}
	sort(a.begin(), a.end());
	for(auto i = 0; i < n; ){
		int j = i;
		while(j < n && a[i] == a[j]){
			++ j;
		}
		res -= (j - i) * 1LL * (j - i + 1) / 2;
		i = j;
	}
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 140780
def gcd(LIST):
    ans=LIST[0]
    for member in LIST[1:]:
        x=max(ans,member)
        y=min(ans,member)
        if x%y==0:
            ans=y
        else:
            while x%y!=0:
                z=x%y
                x=y
                y=z
            ans=z
    return ans
N=int(input())
A=list(map(int,input().split()))
print(gcd(A))

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
int main(){
    string s; cin >> s;
    int n = s.size();
    string ans = "";
    rep(i, n){
        if(s[i] == '0')ans += s[i];
        else if(s[i] == '1')ans += s[i];
        else{
            if(!ans.empty())ans.erase(ans.size() - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ GRL_3_B Bridges
// 2018.5.7 bal4u
// https://everysick.hatenablog.com/entry/2016/06/13/120033 を参考にした
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_V 100002
#define MAX_E 100002

typedef struct { int s, t; } EDGE;		// ブリッジ（橋）になる辺
EDGE bridge[MAX_E]; int sz;				// s < t となっている

int  hi[MAX_V], *to[MAX_V];
int  low[MAX_V], pre[MAX_V];
int  cnt;

int dfs(int cur, int from)
{
	int i, e, t;
	
	low[cur] = pre[cur] = ++cnt;
	for (i = 0; i < hi[cur]; i++) {
		e = to[cur][i];

		if (!pre[e]) {
			t = dfs(e, cur);
			if (t < low[cur]) low[cur] = t;
			if (pre[e] == low[e]) {
				if (cur < e) bridge[sz].s = cur, bridge[sz].t = e; // 出力に合わせる
				else         bridge[sz].s = e,   bridge[sz].t = cur;
				sz++;
			}
		} else if (from != e) {
			t = low[e];
			if (t < low[cur]) low[cur] = t;
		}
	}
	return low[cur];
} 

void check_bridge(int V)
{
	int i;
	for (i = 0; i < V; i++) {
		if (!pre[i]) dfs(i, i);
	}
}

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
}

int cmp(EDGE *a, EDGE *b) { if (a->s - b->s) return a->s - b->s; return a->t - b->t; }

int main()
{
    int E, V, s, t, i, j;
    int *memo;
 
    V = in(), E = in();
    memo = malloc(E<<3);
    j = 0; for (i = 0; i < E; i++) {
        memo[j++] = s = in(), memo[j++] = t = in();
        hi[s]++, hi[t]++;
     }
    for (i = 0; i < V; i++) {
        if (hi[i]) to[i] = malloc(hi[i]<<2);
    }
    memset(hi, 0, V<<2);
 
    j = 0; while (E--) {
        s = memo[j++], t = memo[j++];
		to[s][hi[s]++] = t, to[t][hi[t]++] = s;
    }
 
    check_bridge(V);
 
	qsort(bridge, sz, sizeof(EDGE), cmp);

	for (i = 0; i < sz; i++) {
		out(bridge[i].s), pc(' '), out(bridge[i].t), pc('\n');
	}
    return 0;
}


Measured memory_bytes: 3360
import java.util.Scanner;
class Main{
    public static void main(String args[]){
	int A[] = new int[100000];
	int i,j,n,l,count=0;
	Scanner scan = new Scanner(System.in);
	
	n = scan.nextInt();
	
	for(i=0;i<n;i++){
	    A[i] = scan.nextInt();
	}
	
	l = partition(A,0,n-1);
	for(i=0;i<n;i++){
	    if(A[l]==A[i]){
		count++;
	    }
	}
	
	for(i=0;i<n;i++){
	    if(A[l]==A[i]){
		if(count>1){
		    System.out.print(A[i]+" ");
		    count--;
		    continue;
		}
		if(count==1){
		System.out.print("["+A[i]+"] ");
		continue;
		}
	    }
	    if(i==n-1){
		System.out.println(A[i]);
		break;
	    }
	    System.out.print(A[i]+" ");
	}
    }
    
    public static int partition(int A[],int p,int r){
	int i,j,x,temp=0;
	
	x = A[r];
	i = p-1;
	for(j=p;j<r;j++){
	    if(A[j]<=x){
		i++;
		temp = A[i];
		A[i] = A[j];
		A[j] = temp;
	    }
	}
	temp = A[i+1];
	A[i+1] = A[r];
	A[r] = temp;
	return i+1;
    }
}



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

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

    int n;
    cin >> n;
    int p;
    int sum = 0;
    int max_p = 0;
    for (int i = 0; i < n; ++i) {
        cin >> p;
        sum += p;
        max_p = max(max_p, p);
    }
    
    sum -= max_p / 2;
    
    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  ll d;
  cin >> d;
  vector<ll> c(26);
  ll s[d][26];
  vector<ll> t(d);
  rep(i, 0, 26) cin >> c[i];
  rep(i, 0, d) rep(j, 0, 26) cin >> s[i][j];
  rep(i, 0, d){
    cin >> t[i];
    t[i]--;
  }

  ll ans = 0;
  vector<ll> last(26, 0);
  rep(i, 0, d){
    ll day = i+1;
    ans += s[i][t[i]];
    last[t[i]] = day;

    rep(j, 0, 26){
      if(t[i] == j) continue;
      ans -= c[j] * (day - last[j]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>


using namespace std;



int main() {

	int N, max = 0, x = 0;
	string S;
	
	cin >> N;
	cin >> S;

	for (int i = 0; i < N ; i++) {
		
		if (S[i] == 'I') {
			x += 1;
		}
		else {
			x -= 1;
		}

		if (max < x) {
			max = x;
		}
	}

	cout << max;

	return 0;

}

Measured memory_bytes: 888
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333
#define Mo 998244353

using namespace std;
int i,j,m,n,p,k,a[N],ans,Max[N],fa[N];
vector<int>v[N];
void dfs(int x)
{
		int i;
		Max[x]=1;
		for (i=0;i<(int)v[x].size();++i)
		{
				int p=v[x][i];
				fa[p]=x;
				dfs(p);
				Max[x]=max(Max[x],Max[p]+1);
		}
		if (x!=1&&Max[x]>=k&&fa[x]!=1) 
		{
				Max[x]=-1;
				++ans;
		}
}
int main()
{
		scanf("%d%d",&n,&k);
		for (i=1;i<=n;++i) scanf("%d",&a[i]);
		if(a[1]!=1) ++ans;
		for (i=2;i<=n;++i) v[a[i]].pb(i);
		dfs(1);
		printf("%d\n",ans);
}


Measured memory_bytes: 14720
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input_values = sc.nextInt();
        String values[] = new String[input_values];
        values[0] = sc.next();
        for (int i = 1; i < input_values; i++) {
            
            values[i] = sc.next();
            for (int j = 0; j < i; j++) {
                if (values[j].equals(values[i])) {
                    System.out.println("No");
                    System.exit(0);
                }
            }
            if (values[i - 1].charAt(values[i - 1].length() - 1) != values[i].charAt(0)) {
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");

    }
}


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

using namespace std;

int main()
{
    int n,q,l,r,cnt;
    int a[100005];

    char s[100005];
    scanf("%d%d%s",&n,&q,s);
        a[0]=0;
    cnt=0;
    for(int i=1; i<n; i++)
    {
        if(s[i]=='C' && s[i-1]=='A')
            cnt++;
        a[i]=cnt;
    }
    while(q--)
    {

        scanf("%d%d",&l,&r);

        printf("%d\n",a[r-1]-a[l-1]);
    }
    return 0;
}


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

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

  int n, k;
  cin >> n >> k;
  if (k == 1) {
    puts("0");
  } else {
    int ans = n - k;
    cout << ans << '\n';
  }
  return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int ans(string s) {
    if (s.length() == 1) return 0;
    int mv = 0;
    rep(i, 1, s.length()) {
        mv = max(mv, stoi(s.substr(0, i)) * stoi(s.substr(i)));
    }
    return ans(to_string(mv)) + 1;
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    int n; cin >> n;
    rep(i, 0, n) {
        string s; cin >> s;
        cout << ans(s) << endl;
    }
}



Measured memory_bytes: 3324
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

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

int main()
{
    long a, b, x;
    cin >> a >> b >> x;

    long first = a;
    if (first % x != 0)
    {
        first += x - a%x;
    }
    long end   = b - (b%x);

    long count = (end - first) / x + 1;

    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
    int w,a,b;
    scanf("%d%d%d",&w,&a,&b);
    if (b>a+w)
        printf("%d\n",b-(a+w));
    else if (b+w<a)
        printf("%d\n",a-(b+w));
    else printf("0\n");
    return 0;
}


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

int main(){

    int X, N;
    cin >> X >> N;
    if(N == 0){
        cout << X << endl;
        return 0;
    }

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

    bool flag;
    flag = false;
    for (i=0; i<N; i++){
        if(P[i] == X){
            flag = true;
            break;
        }
    }
    if(flag == false){
        cout << X << endl;
        return 0;
    }


    int abs_num_p, abs_num_n;
    abs_num_p = X + 1;
    abs_num_n = X - 1;

    //int iter;
    bool flag_p;
    bool flag_n;
    //iter = 0;
    
    while(true){
        flag_p = false;
        flag_n = false;
        for (i=0; i<N; i++){
            if(P[i] == abs_num_p){
                flag_p = true;
            }
            if(P[i] == abs_num_n){
                flag_n = true;
            }
        }
        if((     flag_p ==  true) && (flag_n ==  true)){
            abs_num_p += 1;
            abs_num_n -= 1;
            continue;
        }
        else if((flag_p ==  true) && (flag_n == false)){
            cout << abs_num_n << endl;
            return 0;
        }
        else if((flag_p == false) && (flag_n ==  true)){
            cout << abs_num_p << endl;
            return 0;
        }
        else if((flag_p == false) && (flag_n == false)){
            cout << abs_num_n << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
def cal(A,B,x):
    return int((A*x)/B) - A*int(x/B)

def main():
    A,B,N = map(int,input().split())
    if N <= B-1:
        ans = cal(A,B,N)
    else:
        ans = cal(A,B,B-1)
    print(ans)

if __name__ == "__main__":
    main()


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

int main(void){
    ll n,q,a;
    cin>>n;
    vector<ll> x(100001,0);
    rep(i,n){
        cin>>a;
        x[a]++;
    }
    cin>>q;
    vector<ll> b(q+1),c(q+1),s(q+1,0);
    rep(i,100000)s[0]+=i*x[i];
    ll A,B,C;
    rep(i,q){
        cin>>b[i]>>c[i];
        B=b[i];
        C=c[i];
        A=x[B];
        x[B]=0;
        x[C]+=A;
        s[i]=s[i-1]+A*(C-B);
    }
    rep(i,q)cout<<s[i]<<endl;
}

Measured memory_bytes: 6312
program arc067
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,a,b,i
    integer(int64),allocatable:: x(:)
    integer(int64):: ans=0

    read*, n,a,b
    allocate(x(n))
    read*, x(:)

    do i=2,n
        ans=ans+min(b,a*(x(i)-x(i-1)))
    end do

    print'(i0)', ans
end program arc067

Measured memory_bytes: 1536
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (l, r) = scan!(i64, i64);
    if r - l > 2019 {
        println!("0");
        return;
    }

    let mut ans = (l * r) % 2019;
    for i in l..r {
        for j in i + 1..r + 1 {
            ans = min(ans, (i * j) % 2019)
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	string A, S, C;
	cin >> A >> S >> C;
	cout << "A";
	cout << S.front();
	cout << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
import math
ans = 0
k = int(input())
for a in range(1, k + 1):
    for b in range(1, k + 1):
        x = math.gcd(a, b)
        for c in range(1, k + 1):
            y = math.gcd(x, c)
            ans += y
print(ans)


Measured memory_bytes: 8980
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int k = Integer.parseInt(br.readLine());
        int n = 0;
        if (k%2 == 1) {
            System.out.println((k/2) * (k/2+1));
        }
        else System.out.println((k/2)*(k/2));
        
        
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size() - 1; i++){
        if (s[i] == s[i + 1]){
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }
    for (int i = 0; i < (int) s.size() - 2; i++){
        if (s[i] == s[i + 2]){
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] atoz = new int[26];
  
        do {
            String s = sc.nextLine();
            for (char c : s.toCharArray()){
                if ((c < 'A' || 'Z' < c) && (c < 'a' || 'z' < c)) continue;
                atoz[Character.toLowerCase(c)- 'a']++;
            }
        } while (sc.hasNext());
  
        for (char c = 'a'; c <= 'z'; c++){
            System.out.println(c + " : " + atoz[c - 'a']);
        }
    }
}



Measured memory_bytes: 26040
#include<iostream>
#include<cstdio>
#include<string>
#define MAX 100000
using namespace std;

int main(){
    int N, Q, l, r;
    char S[MAX+1];
    cin >> N >> Q;
    cin >>  S;
    int ans = 0, k = 0; //答え
    int A[MAX+1];
    A[0] = 0;
    for(int i = 1; i <= N; i++){
        if(S[i-1] == 'A' && S[i] == 'C' && i + 1 <= N) {
            A[i] = k + 1;
            k++;
        }
        else A[i] = k;
    }

    for(int i = 0; i < Q; i++){
        cin >> l >> r;
        ans = A[r] - A[l];
        if(A[l-1] != A[l]) ans += 1;
        if(A[r-1] != A[r]) ans -= 1;
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(){
  int n,m,ans=0;
  cin >> n >> m;
  int a[n][m],k[n];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      a[i][j]=0;
  
  for(int i=0; i<n; i++){
    cin >> k[i];
    for(int j=0; j<k[i];j++){
      cin >> a[i][j];
    }}
  for(int c=0; c<k[0]; c++){
   int counter=0;
   for(int i=1;i<n;i++)
     for(int j=0;j<m;j++)
       if(a[0][c]==a[i][j]) counter++;
   if(counter==n-1) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    ll k,n;
    std::cin >> k>>n;
    VEC(ll,a,n);
    std::vector<ll> b(n);
    b[0]=a[0];
    rep(i,n-1){
        b[i+1]=a[i+1]-a[i];
    }
    b.pb(a[0]+k-a[n-1]);
    sort(all(b),greater<ll>());
    std::cout << k-b[0] << std::endl;
}

Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		int z;
		cin >> z;
		a.push_back(z-1);
	}
	int x = 0, c = 0;
	for (;;) {
		if (x == 1) {
			cout << c << endl;
			break;
		}
		if (c >= n) {
			cout << "-1" << endl;
			break;
		}
		c++;
		x = a[x];
	}
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
using namespace std;
int main(){
  	long int N,A,B,ans;
  	cin >> N >> A >> B;
	if (N%(A+B)<=A){
      ans = A*(long int)(N/(A+B))+N%(A+B);
    }
  	else{ 
      ans = A*(long int)(N/(A+B))+A;
     }
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC044C
{
  class Program
  {

    // After reading editorial
    static void Main(string[] args)
    {
      string[] bufs = Console.ReadLine().Split(' ');
      int N = int.Parse(bufs[0]);
      int A = int.Parse(bufs[1]);

      int[] y = new int[N];

      bufs = Console.ReadLine().Split(' ');
      for (int i = 0; i < N; i++) {
        y[i] = int.Parse(bufs[i]) - A;
      }

      int X = 50;
      long[,] dp = new long[N + 1, 2 * N * X + 1];
      dp[0, N * X] = 1;

      for (int j = 1; j <= N; j++) {
        for (int t = 0; t <= 2 * N * X; t++) {
          int k = t - y[j - 1];
          if (k >= 0 && k <= 2 * N * X) {
            dp[j, t] = dp[j - 1, t] + dp[j - 1, k];
          }
          else {
            dp[j, t] = dp[j - 1, t];
          }

        }
      }

      Console.WriteLine(dp[N, N * X] - 1);
    }
  }
}


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

"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6

output:
5
"""

import sys
import heapq as hp

WHITE, GRAY, BLACK = 0, 1, 2


def generate_adj_table(v_table):
    for each in v_table:
        v_from, v_to, edge_weight = map(int, each)
        init_adj_table[v_from][v_to] = edge_weight
        init_adj_table[v_to][v_from] = edge_weight

    return init_adj_table


def prim_span_tree():
    distance[init_v] = 0
    parent[init_v] = -1
    path_heap = []
    hp.heappush(path_heap, (0, init_v))

    while len(path_heap) >= 1:
        current_vertex = hp.heappop(path_heap)[1]

        color[current_vertex] = BLACK

        for adj_vertex, adj_weight in adj_table[current_vertex].items():
            if color[adj_vertex] is not BLACK:
                if adj_weight < distance[adj_vertex]:
                    distance[adj_vertex] = adj_weight
                    parent[adj_vertex] = current_vertex
                    color[adj_vertex] = GRAY
                    hp.heappush(path_heap, (adj_weight, adj_vertex))

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    parent = [-1] * vertices
    distance = [float('inf')] * vertices
    color = [WHITE] * vertices
    init_v = 0

    init_adj_table = tuple(dict() for _ in range(vertices))
    adj_table = generate_adj_table(v_info)
    print(sum(prim_span_tree()))

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int N = input(), K = input();
    int ans = 0;
    while (N) {
        ans++;
        N /= K;
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool operator==(const mint& a, const mint& b) { return a.x == b.x;}

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

    int n;
    cin >> n;
    vector<int> cnt(n);
    rep(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    if (n % 2 == 0) {
        for (int i = 1; i < n; i += 2) {
            if (cnt[i] != 2) {
                puts("0");
                return 0;
            }
        }
        cout << mint(2).pow(n/2) << endl;
    } else {
        for (int i = 0; i < n; i += 2) {
            if ((i == 0 && cnt[i] == 1) || (i != 0 && cnt[i] == 2)) continue;
            puts("0");
            return 0;
        }
        cout << mint(2).pow(n/2) << endl;
    }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a=0,w=0,t=0,r=0;
    for(int i=0;i<n;i++){
        string s;
		cin>>s;
		if(s=="AC")	a++;
		else if(s=="WA")	w++;
		else if(s=="TLE")	t++;
		else if(s=="RE")	r++;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<w<<endl;
	cout<<"TLE x "<<t<<endl;
	cout<<"RE x "<<r<<endl;
	return 0;
}

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

int main() {
    ll X, K, D; cin >> X >> K >> D;
    ll ans;
    if (abs(X) / D > K) {
        if (X > 0) {
            ans = abs(X - D * K);
        } else {
            ans = abs(X + D * K);
        }
    } else {
        if (X >= 0) {
            if ((X / D) % 2 == K % 2) {
                ans = X % D;
            } else {
                ans = D - (X % D);
            }
        } else {
            if (abs(X / D) % 2 == K % 2) {
                ans = abs(X) % D;
            } else {
                ans = D - (abs(X) % D);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int D;
    cin >> D;
    string ans = "Christmas";

    for ( int i = 0; i < 25-D; i++ ) {
        ans += " Eve";
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 764
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};

int main(){
  ll L, R;
  cin >> L >> R;
  ll ans = 2019;

  for(ll i = L; i <= min(R, L + 3000); i++){
    for(ll j = i + 1; j <= min(R, L + 4000); j++){
      ll I = i % 2019;
      ll J = j % 2019;
      ans = min(ans, (I*J)%2019);
    }
  }
  cout << ans << endl;













}


Measured memory_bytes: 256