akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	int n, aa;
  	vector<int> vec;
	cin >> n;
  	for (int i = 1; i <= n; i++) {
      	cin >> aa;
      	vec.push_back(aa - i);
    }
  
  	sort(vec.begin(), vec.end());
  	auto mid = vec[(n - 1) / 2];
  	
  	long long sum = 0;
  	for (int i = 0; i < n; i++) {
    	sum += abs(vec[i] - mid);
    }
  
  	cout << sum << endl;
}

Measured memory_bytes: 1400
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
B = inpl()

C = 0
D = 0

for a, b in zip(A, B):
    if b - a > 1:
        C += (b-a) - ((b-a)%2)
    else:
        D += (a-b)

if C >= 2*D:
    print("Yes")
else:
    print("No")

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

int main() {
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) { continue; }
    ans += i;
  }

  cout << ans;
}

Measured memory_bytes: 3652
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    k=int(input())
    for i in range(min(100,k)):
        if s[i]!='1':
            print(s[i])
            break
    else:print(1)

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
long mod=1e9+7,dp[51][51][2505];
int N,K;
main()
{
	cin>>N>>K;
	dp[0][0][0]=1;
	for(int i=0;i<N;i++)for(int j=0;j<=i;j++)
	{
		for(int k=0;k<=K-2*j+2;k++)
		{
			if(dp[i][j][k]==0)continue;
			(dp[i+1][j][k+2*j]+=dp[i][j][k]*(2*j+1)%mod)%=mod;
			if(j>0)(dp[i+1][j-1][k+2*j-2]+=dp[i][j][k]*j*j%mod)%=mod;
			(dp[i+1][j+1][k+2*j+2]+=dp[i][j][k])%=mod;
		}
	}
	cout<<dp[N][0][K]<<endl;
}

Measured memory_bytes: 48512
#include<stdio.h>

int main(){
  int i;
  int A[3];

  for(i=1;i<=3;i++){
    scanf("%d", &A[i-1]);
  }

  if(A[0] + A[1] + A[2] >= 22){
    printf("bust");
  }else{
    printf("win");
  }

  return 0;
}

Measured memory_bytes: 128
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    R = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 2*math.pi*R
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

using namespace std;
const long nmax=100005;
int n,a[nmax],t,k,s;
int main()
{
    cin>>n; s=0; t=0; k=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]==i){
            t++;
            k++;
        }
        else t=0;
        if(t==2){
            k=k-1;
            t=0;
        }
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int sum[15][1005];
int get(int row1, int row2, int col){
	return sum[row2][col] - sum[row1-1][col] - sum[row2][col-1] + sum[row1-1][col-1];
}

int main(void)
{
	int ans = 987654321;
	int H, W, K; cin >> H >> W >> K;
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			scanf("%1d", &sum[i][j]);
			sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
		}
	}
	for(int bit = 0; bit<(1<<(H-1)); bit++){
		int b = bit<<1;
		int tmp = 1;
		vector<pii> v;
		for(int i=2;i<=H;i++){
			if((b>>(i-1))&1 != (b>>(i-2))&1){
				v.pb({tmp, i-1});
				tmp = i;
			}
		}
		v.pb({tmp, H});
		int n = v.size();
		int ans_ = n - 1;
		vector<int> cnt(n);
		bool imp = false;
		for(int j=1;j<=W;j++)
		{
			bool ok = true;
			for(int i=0;i<v.size();i++) {
				if(get(v[i].first, v[i].second, j) > K) {
					imp = true;
					break;
				}
				cnt[i] += get(v[i].first, v[i].second, j);
				if(cnt[i] > K) ok = false;
			}
			if(!ok) {
				ans_ ++;
				for(int i=0;i<v.size();i++) 
					cnt[i] = get(v[i].first, v[i].second, j);
			}
		}
		if(imp) continue;
		ans = min(ans, ans_);
	}
	cout << ans << endl;
	return 0;
}



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

bool f(int n) {
	int k[5];
	for (int i = 0; i < 5; i++) {
		k[i] = n % 10;
		n /= 10;
	}
	if (k[0] == k[4] && k[1] == k[3]) return true;
	else return false;
}

int main() {
	int a, b;
	cin >> a >> b;
	int cnt = 0;
	for (int i = a; i <= b; i++) {
		if (f(i))cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> b(m);
    rep(i,m) cin >> b[i];
    rep(i, n) rep(j, m){
        cin >> a[i][j];
    }
    int ans = 0;
    rep(i,n) {
        int sum = c;
        rep(j, m){
            sum += a[i][j] * b[j];
        }
        if (sum > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40"""
        output = """3
4
6
1
5
2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100"""
        output = """10
9
8
7
6
5
4
3
2
1"""
        self.assertIO(input, output)
def resolve():
    n=int(input())
    towns=[]
    for i in range(n):
        x=input().split()
        towns.append([x[0],-int(x[1]),i+1])
    towns.sort()
    for i in towns:
        print(i[2])

if __name__ == "__main__":
    resolve()

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

const int MAX_PRIME = 1005;
vector<int> primes;
vector<bool> is_prime;
// 小さい素数(MAX_PRIMEまで)は先に用意しとく
void init_primes() {
  is_prime = vector<bool>(MAX_PRIME + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= MAX_PRIME; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i*2; j <= MAX_PRIME; j+=i) {
        is_prime[j] = false;
      }
    }
  }
}

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

  init_primes();

  int n;
  ll mod = pow(10,9)+7;
  ll res=1;
  cin>>n;
  map<ll, ll> factors;
  for(int i=2;i<=n;i++){
    int t = i;
    for(int j=0;j<primes.size();j++){
      if(t==1)break;
      int p = primes[j];
      while(t % p == 0){
        t /= p;
        factors[p]++;
      }
    }
  }
  for (auto& kv : factors) {
    res = (res * (kv.second + 1)) % mod;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int sum;
int n,d;

int main(void) {
    int i=0;
    cin >> n >> d;

    sum += n/(2*d+1);
    if (n%(2*d+1)) sum++;
    cout << sum << endl;
    return 0;
}


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

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> h(n);
  rep(i,n) {
	cin >> h.at(i);
  }
  sort(h.begin(), h.end());
  long long ans = 0;
  rep(i,n-k) {
	ans += h.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<algorithm>
using namespace std;
int n,a,b;


int main(){
  cin>>n;
  a=n;b=0;
  while(a!=0){
    b+=a%10;
    a/=10;
  }
  if(n%b==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main(){
  int a,b,c,d,e,k; 
  cin >>a>>b>>c>>d>>e>>k;
  
  string ans;
  if(e-a>k){
    ans = ":(";
  }else{
    ans = "Yay!";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def calc_gcd(x, y):
    
    if x < y:
        x, y = y, x

    while y > 0:
        x, y = y, x % y

    return x



n = int(input())
A = list(map(int, input().split()))


a_last = None

for a in A:
    if a_last == None:
        a_last = a
        continue

    gcd = calc_gcd(a, a_last)
    
    a_last = a * a_last / gcd


print(int(a_last))


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

int main(){
  int N, T;
  cin >> N >> T;
  int c, t;
  int mc = 1001;
  for(int i = 0; i < N; i++){
    cin >> c >> t;
    if(t <= T) mc = min(mc, c);
  }
  if(mc == 1001) cout << "TLE" << endl;
  else cout << mc << endl;
  return 0;
}


Measured memory_bytes: 256
A=int(input())
B=int(input())
if A == 1:
    if B == 2:
        print(3)
    else:
        print(2)
if A == 2:
    if B == 1:
        print(3)
    else:
        print(1)
if A == 3:
    if B == 1:
        print(2)
    else:
        print(1)


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

int main(){

    int N;
    cin >> N;

    int repdigit[10];

    repdigit[0] = 100;
    for( int i = 1; i <= 9; i++ ){
        repdigit[i] = 100*i + 10*i + i;
    }

    for( int i = 1; i <= 9; i++ ){
        if( repdigit[i-1] <= N && N <= repdigit[i] ){
            cout << repdigit[i] << endl;
            break;
        }
    }

    return 0;

}

Measured memory_bytes: 256
/*||>>>> Praveen Ojha <<<<>>>> 09 August 2019 <<<<>>>> 20:57:36 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(0LL,c-(a-b))<<"\n";
return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    // 一巡目
    for (int i = 0; i < ty - sy; ++i) {
        cout << "U";
    }

    for (int i = 0; i < tx - sx; ++i) {
        cout << "R";
    }

    // 二巡目
    for (int i = 0; i < abs(sy - ty); ++i) {
        cout << "D";
    }

    for (int i = 0; i < abs(sx - tx); ++i) {
        cout << "L";
    }

    // 三巡目
    for (int i = 0; i < ty - sy + 2; ++i) {
        if(!i) cout << "L";
        else cout << "U";
    }

    for (int i = 0; i < tx - sx + 2; ++i) {
        if(i==tx-sx+2-1) cout << "D";
        else cout << "R";
    }

    // 四巡目
    for (int i = 0; i < abs(sy - ty) + 2; ++i) {
        if(!i) cout << "R";
        else cout << "D";
    }

    for (int i = 0; i < abs(sx - tx) + 2; ++i) {
        if(i==abs(sx-tx)+2-1) cout << "U";
        else cout << "L";
    }

    cout << endl;


}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  ll x,y;cin>>x>>y;
  if(x%y==0){
    out(-1);
    return 0;
  }
  for(ll i=x;i<10e18;i+=x){
    if(i%y!=0){
      out(i);
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int maxn=100005;
int dp[maxn],a[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        dp[i]=mod;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        if(i+1<n)
            dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        if(i+2<n)
            dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}



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

int main()
{
  int n,W;
  cin >> n >> W;
  int wt[n],val[n]; 
  ll K[n+1][W+1] = {0};
  
  for (int i=0; i<n; i++) cin >> wt[i] >> val[i];
  for (int i=0; i<=n; i++)
  {
    for (int j=0; j<=W; j++)
    {
        if (i==0 || j==0) K[i][j] = 0;
      else if (wt[i-1] <= j)
      	K[i][j] = max(val[i-1] + K[i-1][j-wt[i-1]], K[i-1][j]);
      else
        K[i][j] = K[i-1][j];
    }
  }
   cout << K[n][W] << endl;
 
  return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

int pw(int a, int b, int m = MOD) {
    if (b == 0)
        return 1;
    if (b & 1)return a * pw(a, b - 1) % m;
    return pw(a * a % m, b / 2);
}

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> ans(k + 1);
    int pans = 0;
    for (int i = k; i >= 1; i--) {
        ans[i] = pw(k / i, n);
        for (int j = 2; j * i <= k; j++) {
            ans[i] = (ans[i] - ans[i * j] + MOD) % MOD;
        }
        pans = (pans + ans[i] * i % MOD) % MOD;
    }
    cout << pans << endl;
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3984
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,n,k,m[150][150];
  for(int i=0;i<150;i++)for(int j=0;j<150;j++)m[i][j]=1000000;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>k;
    for(int j=0;j<k;j++){
      cin>>a;
      cin>>m[i][a];
    }
  }
  int dist[100]={};
  int visited[100]={};
  for(int i=1;i<100;i++)dist[i]=1000000;
  while(1){
    int i=-1;
    for(int j=0;j<n;j++){
      if(visited[j]==0){
	if(i==-1||dist[i]>dist[j]){
	  i=j;
	}
      }
    }
    if(i==-1)break;
    visited[i]=1;
    for(int j=0;j<n;j++){
      int A=dist[i]+m[i][j];
      if(dist[j]>A){
	dist[j]=A;
      }
    }
  }
  for(int i=0;i<n;i++)printf("%d %d\n",i,dist[i]);
  return 0;
}

Measured memory_bytes: 3304
def main():
    n, a, b, c = map(int, input().split())
    s = [input() for _ in range(n)]
    if a+b+c == 0:
        print("No")
        return
    num = dict(A=a, B=b, C=c)
    ans = []
    if a+b+c == 1:
        for si in s:
            if num[si[0]] == 1:
                ans.append(si[1])
                num[si[0]], num[si[1]] = 0, 1
            elif num[si[1]] == 1:
                ans.append(si[0])
                num[si[0]], num[si[1]] = 1, 0
            else:
                print("No")
                return
        print("Yes")
        print("\n".join(ans))
    else:
        for i in range(n):
            si = s[i]
            if num[si[0]] >= 1 and num[si[1]] >= 1:
                if i < n-1:
                    sii = s[i+1]
                    if sii[0] == si[0] or sii[1] == si[0]:
                        ans.append(si[0])
                        num[si[0]] += 1
                        num[si[1]] -= 1
                    else:
                        ans.append(si[1])
                        num[si[0]] -= 1
                        num[si[1]] += 1
                else:
                    ans.append(si[0])
            elif num[si[0]] >= 1 and num[si[1]] == 0:
                ans.append(si[1])
                num[si[1]] += 1
                num[si[0]] -= 1
            elif num[si[1]] >= 1 and num[si[0]] == 0:
                ans.append(si[0])
                num[si[0]] += 1
                num[si[1]] -= 1   
            else:
                print("No")
                return
        print("Yes")
        print("\n".join(ans))
            
                
        
    
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 85440
def main():
    # n, m = map(int, input().split())
    # a = [int(input()) for i in range(m)]
    # n, m = map(int, readline().split())
    # a = set(map(int, read().split()))
    n, m = map(int, input().split())
    a = set(int(input()) for i in range(m))
    mod = 1000000007

    # フィボナッチ数列を作る要領で行う
    d = [0] * (n+1)
    # 2回0が続く状況aに連番があったら即座に終了する
    cnt = 0 
    # d[0]とd[1]を規定。aに1が含まれていることを考慮して場合分けしておく
    d[0] = 1
    if 1 not in a:
        d[1] = 1
    # else:
    #     d[1] = 1
    # 階段番号は2~nまでを見る必要がある
    for i in range(2, n+1):
        if i in a:
            d[i] = 0
            cnt += 1
            if cnt == 2:
                print('0')
                exit()
        else:
            d[i] = (d[i-1] + d[i-2]) % mod
            cnt = 0
    # print(d)  
    ans = d[n]        
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11884
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
#define pb push_back
#define F first
#define S second

const int MX=1e5+100;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a, b;
	string s, t;
	cin>>a>>b>>s>>t;
	int c=__gcd(a,b);
	int aa=a, bb=b;
	a/=c;
	b/=c;
	int cnta=0, cntb=0;
	for(int i=0 ;i<c; i++){
		if(s[cnta]!=t[cntb]){
			cout<<-1;
			return 0;
		}
		cnta+=a;
		cntb+=b;
	}
	cout<<(ll)aa*bb/c;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin>>N>>K;
  int i = 0;
  int S = 0;
  while (i < N) {
    int x;
    cin>>x;
    if (x <= K / 2) {
      S += x;
    }
    else {
      S += K - x;
    }
    i++;
  }
  cout<<2 * S<<endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = Integer.parseInt(in.nextLine());
		String line = in.nextLine();
		List<Character> inputs = new ArrayList<>();
		for (int i = 0; i < num; ++i) {
			inputs.add(new Character(line.charAt(i)));
		}
		System.out.println(calc(inputs));
		in.close();
	}

	private static int calc(List<Character> inputs) {
		int righterChangeNum = countWestChange(inputs.subList(1, inputs.size()));
		int lefterChangeNum = 0;
		int result = lefterChangeNum + righterChangeNum;
		for (int i = 1; i < inputs.size(); ++i) {
			Character prev = inputs.get(i - 1);
			Character next = inputs.get(i);
			if (prev.equals('E') && next.equals('E')) {
				righterChangeNum--;
			} else if (prev.equals('E') && next.equals('W')) {
				// None
			} else if (prev.equals('W') && next.equals('E')) {
				lefterChangeNum++;
				righterChangeNum--;
			} else {// prev.equals('W') && next.equals('W')
				lefterChangeNum++;
			}
			result = Math.min(result, lefterChangeNum + righterChangeNum);
			// System.out.println(i + ", " + result);
		}
		// 最後

		result = Math.min(result, countEastChange(inputs.subList(0, inputs.size() - 1)));
		return result;
	}

	private static int countEastChange(List<Character> dirs) {
		int result = 0;
		for (Character dir : dirs) {
			if (dir.equals('W')) {
				result++;
			}
		}
		return result;
	}

	private static int countWestChange(List<Character> dirs) {
		int result = 0;
		for (Character dir : dirs) {
			if (dir.equals('E')) {
				result++;
			}
		}
		return result;
	}
}


Measured memory_bytes: 38820
program main
  integer :: N
  integer :: A(3,3)
  integer,allocatable :: b(:)
  integer :: i,j 
  read(*,*) A(1,:)
  read(*,*) A(2,:)
  read(*,*) A(3,:)
  read(*,*) N
  allocate(b(N))
  do i = 1,N
     read(*,*) b(i)
  end do

  do i =1,N
     where(A==b(i)) A = 0
  end do

  do i = 1,3
     if ( all(A(i,:) == 0 )) then
        write(*,'(a)') 'Yes'
        stop
     end if
  end do

  do i = 1,3
     if ( all(A(:,i) == 0 )) then
        write(*,'(a)') 'Yes'
        stop
     end if
  end do

  if ( (A(1,1) == 0 .and. A(2,2) == 0 .and. A(3,3) == 0) ) then
     write(*,'(a)') 'Yes'
     stop
  end if
  
  if ( (A(1,3) == 0 .and. A(2,2) == 0 .and. A(3,1) == 0) ) then
     write(*,'(a)') 'Yes'
     stop
  end if
  write(*,'(a)') 'No'
end program main


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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N), d(N);
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < N; i++){
        cin >> c[i] >> d[i];
    }
    
    vector<pair<int, int>> red(N), blue(N);
    for(int i = 0; i < N; i++){
        red[i] = make_pair(a[i], b[i]);
        blue[i] = make_pair(c[i], d[i]);
    }
    
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    
    vector<bool> used(N, false);
    
    int cnt = 0;

    for(int i = 0; i < N; i++){
        int now = -1;       // index
        int ele = -1;       // now番目の赤い点のy座標（最大値）
        for(int j = 0; j < N; j++){
            if(blue[i].first <= red[j].first || blue[i].second <= red[j].second){
                continue;
            }
            
            if(!used[j] && red[j].second > ele){
                now = j;
                ele = red[j].second;
            }
        }
        
        if(now != -1){
            cnt++;
            used[now] = true;
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  string a;
  cin >> a;
  int b = a.size();
  int ans[111];
  int sum = 0,tmp=0;
  for(int i = b-1;i>=0;i--){
    if(a.at(i)=='B')sum++;
    else if(sum==0){
      ans[tmp] =  a.at(i)-'0';
      tmp++;
    }
    else sum=max(0,sum-1);
  }
  for(int i = tmp-1;i>=0;i--){
    cout << ans[i];
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int A, B;
    cin >> A >> B;
    int ret = 0, cur = 1;
    while (cur < B)
        ret++, cur += A - 1;
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

#define MAXR 1000005

//以下、MAXR(=10^5)です。詳しくはテンプレートを参照してください。
#define PN 1 //素数のマークは1

//MAXRまでの整数は素数であると仮定する
vector<ll> PN_chk(MAXR+1,PN);//0indexでi番目が整数iに対応(0~MAXR)

//素因数分解結果に含まれるそれぞれの素数の個数を保存するmap
map<ll,ll> prime;

//O(MAXR)
void se(){
    ll MAXRR=sqrt(MAXR)+1;
    //2以上の数の素因数分解をするので無視して良い
    PN_chk[0]=0;PN_chk[1]=0;
    for (int i = 2; i < MAXRR; i++){
        //たどり着いた時に素数と仮定されているなら素数
        //ある素数の倍数はその素数で割り切れるのでマークづけ
        if(PN_chk[i]==1) for (int j = i; j < ll(MAXR/ i); j++){PN_chk[j*i]=i;}
    }
}

//O(logn)
//mapなのでprimeは整列されている！！！
void prime_factorize(ll n){
    if(n<=1) return;
    //1の場合はnは素数
    if(PN_chk[n]==1){prime[n]+=1;return;}
    //マークされている数は素数
    prime[PN_chk[n]]+=1;
    //マークされている数でnを割った数を考える
    prime_factorize(ll(n/PN_chk[n]));
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N ;i++) cin >> A[i];
    se();

    map<int, int> m;
    for (int i= 0; i < N; i++) {
        prime.clear();
        prime_factorize(A[i]);
        for (auto it = prime.begin(); it != prime.end(); it++) {
            m[it->first]++;
        }
    }

    bool is_pair = true;
    bool is_set = true;
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second >= 2) is_pair = false;
        if (it->second == N) is_set = false;
    }

    if (is_pair) {
        cout << "pairwise coprime" << endl;
    } else if (is_set) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }

    return 0;
}

Measured memory_bytes: 23644
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  set<int> st1, st2;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    st1.insert(x);
    st2.insert(x);
  }
  vector<int> a;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    st1.insert(x);
    if (st2.count(x)) a.push_back(x);
  }
  sort(a.begin(), a.end());
  cout << (int) a.size() << " " << st1.size() << endl;
  for (int i = 0; i < (int) a.size(); i++) {
    cout << a[i] << endl;
  }
  for (int i : st1) {
    cout << i << endl;
  }
  return 0;	
}


Measured memory_bytes: 19544
#include<stdio.h>
#define N 100
#define INF 2000000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dij(void);

int n,A[N][N];

int main(){
  int i,j,k,c,u,v;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      A[i][j] = INF;
    }
  }

  for(i = 0;i < n;i++){
    scanf("%d%d",&u,&k);
    for(j = 0;j < k;j++){
      scanf("%d%d",&v,&c);
      A[u][v] = c;
    }
  }

  dij();
  
  return 0;
}

void dij(){
  int i,u,v,min;
  int B[N],col[N];

  for(i = 0;i < n;i++){
    B[i] = INF;
    col[i] = WHITE;
  }

  B[0] = 0;
  col[0] = GRAY;

  while(1){
    min = INF;
    u = -1;

    for(i = 0;i < n;i++){
      if(min > B[i] && col[i] != BLACK){
	u = i;
	min = B[i];
      }
    }
    if(u == -1)break;
    col[u] = BLACK;

    for(v = 0;v < n;v++){
      if(col[v] != BLACK && A[u][v] != INF){
	if(B[v] > B[u] + A[u][v]){
	  B[v] = B[u] + A[u][v];
	  col[v] = GRAY;
	}
      }
    }
  }

  for(i = 0;i < n;i++){
    if(B[i] == INF){
      B[i] = -1;
    }
    printf("%d %d\n",i,B[i]);
  }
}



Measured memory_bytes: 2104
//https://blog.csdn.net/hesorchen
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define lowbit(a) (a & (-a))
#define INF 0x3f3f3f3f
#define MAX 1010
#define mod 1000000007
#define PI 3.1415926
#define test_ printf("*************\n")

int main()
{
    ll a, b, n;
    cin >> n >> a >> b;
    ll temp = n / (a + b);
    ll ans = temp * a;
    ans += min(a, n % (a + b));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

num_r, num_g, num_b = 0, 0, 0
for i in range(n):
    if s[i] == 'R': num_r += 1
    elif s[i] == 'G': num_g += 1
    else: num_b += 1

hiku = 0
for i in range(n-2):
    s_i = s[i]
    for j in range(i+1, n-1):
        if s[j] == s_i: continue
        s_j = s[j]
        j_i = j-i
        if j+j_i < n:
            miru = s[j+j_i]
            if miru != s_i and miru != s_j:
                hiku += 1
        else:
            break

print(num_r*num_g*num_b-hiku)

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

ll a,b;
int main() {
	cin >> a >> b;
    if(a > 0){
        cout<<"Positive"<<endl;
        return 0;
    }
    if(b >= 0){
        cout<<"Zero"<<endl;
        return 0;
    }
    if((b-a) % 2==0){
        cout<<"Negative"<<endl;
    }else{
        cout<<"Positive"<<endl;
    }
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    string S;
    cin >> N >> K >> S;
    if(S[K-1]=='A')S[K-1]='a';
    if(S[K-1]=='B')S[K-1]='b';
    if(S[K-1]=='C')S[K-1]='c';
    cout << S;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = str(input())
num_list=[]
white=0
black=0
#一番左が境界の場合
num_list.append([0,0])
for i in range(0,N):
    if(S[i]=="."):
        white+=1
    elif(S[i]=="#"):
        black+=1
    num_list.append([white,black])

#左から0,1,.....Nのところに境界を持ってきたときのしろと黒の個数がnum_listに入っている
ans=N
tmp=0
for i in range(0,N+1):
    tmp=num_list[i][1]+white-num_list[i][0]
    if(ans>tmp):
        ans=tmp
print(ans)

Measured memory_bytes: 30056
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

long a, b, c, k;

int main(){
	scanf("%ld%ld%ld%ld", &a, &b, &c, &k);
	if(k%2 == 0){
		printf("%ld\n", a-b);
	}else{
		printf("%ld\n", b-a);
	}
	return 0;
}


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

using namespace std;

string s;
vector<int> fs;

int main() {
    cin >> s;
    s += 'N';
    s = string("N") + s;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != 'x') {
            fs.push_back(i);
        }
    }

    bool is_pd = true;

    for(int i = 0; i < fs.size() / 2; i++) {
        if(s[fs[i]] != s[fs[fs.size() - i - 1]]) {
            is_pd = false;
            break;
        }
    }

    if(!is_pd) {
        cout << -1 << endl;
        return 0;
    }

    int p1, p2;

    if(fs.size() % 2 == 0) {
        p1 = fs.size() / 2 - 1;
        p2 = p1 + 1;

        p1 = fs[p1];
        p2 = fs[p2];
    } else {
        p1 = fs.size() / 2;
        p2 = p1;

        p1 = fs[p1];
        p2 = fs[p2];
    }

    int cnt = 0;

    while(p1 >= 0 && p2 < s.size()) {
        if(
            (s[p1] == 'x' && s[p2] == 'x')
            || (s[p1] != 'x' && s[p2] != 'x')
        ) {
            p1--;
            p2++;
            continue;
        }

        if(s[p1] == 'x') {
            cnt++;
            p1--;
        }

        if(s[p2] == 'x') {
            cnt++;
            p2++;
        }
    }

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


Measured memory_bytes: 1016
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vl = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define vsort(xx) sort(xx.begin(),xx.end())
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll W,H,x,y; cin>>W>>H>>x>>y;
    long double s=(W*H)/2.0;
    bool f=0;
    if(W/2.0==(long double)x && H/2.0==(long double)y) f=true;
    
    cout<<s<<" "<<f<<endl;
   
    return 0;
}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

	ll N, M;
	ll ans = 0;

	cin >> N >> M;

	multiset<ll> Lg, Rg;
	ll L, R;
	rep(i, M) {
		cin >> L;
		cin >> R;
		Lg.insert(L);
		Rg.insert(R);
	}

	ans = max((ll)0,*Rg.begin() - *Lg.rbegin() + 1);

	cout << ans << "\n";

	return 0;
}

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

int main()
{
	int n, k, q, i, x;
	cin >> n >> k >> q;
	int a[n];
	memset(a, 0, sizeof(a));
	for(i=0; i<q; i+=1)
	{
		cin >> x;
		a[x-1]+=1;
	}
	for(i=0; i<n; i+=1)
	{
		if(a[i]+k-q<=0)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
}

Measured memory_bytes: 1024
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	//input = input.split("\n");
	tmp = input.split("");
	//文字列から10進数に変換するときはparseIntを使います
	var count=0;
	for (var i=0;i<tmp.length;i++){
		if(tmp[i]==1) count++;
	}
	//出力
	console.log(count);
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int N;
  cin>>N;
  long long int num = 0;
  for (int i = 0; i < N; i++) {
    long long int tmp1;
    long long int tmp2;
    cin>>tmp1;
    cin>>tmp2;
    num += tmp2 - tmp1 + 1;
  }
  cout<<num;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8

# In[17]:

import sys
#input = sys.stdin.readline
N = int(input())
S = [input() for i in range(N)]


# In[18]:

b_cnt = 0
a_cnt = 0
ab_cnt = 0
for i in range(N):
    if S[i][0]=='B'and S[i][-1]=='A':
        ab_cnt += 1
    elif S[i][0]=='B':
        b_cnt += 1
    elif S[i][-1]=='A':
        a_cnt += 1
#print(b_cnt, a_cnt)
#print(ab_cnt, a_cnt, b_cnt, '/'.join(S).count('AB') )

#if abs(a_cnt-b_cnt) >= 1 and ab_cnt > 0:
ans = 0
if ab_cnt > 0:
    ans += ab_cnt - 1
    if b_cnt > 0:
        b_cnt -= 1
        ans += 1
    if a_cnt > 0:
        a_cnt -= 1
        ans += 1
ans += min(a_cnt, b_cnt)

"""
if max(a_cnt, b_cnt) == 0 and ab_cnt > 0:
    ab_cnt -= 1
elif min(a_cnt, b_cnt) > 0 and ab_cnt > 0:
    ab_cnt += 1
elif abs(a_cnt-b_cnt) == 0 and ab_cnt > 0:
    ab_cnt += 1
elif abs(a_cnt-b_cnt) > 0 and ab_cnt > 0:
    ab_cnt += 0
"""
    
#if ab_cnt < 0:
#    ab_cnt = 0
#ab_cnt = ab_cnt-1 if ab_cnt!=0 else ab_cnt
print('/'.join(S).count('AB') + ans)


# In[ ]:





Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N,K;

void solve()
{
	int res = 0;
	while(N){
		res++;
		N/=K;
	}
	cout << res << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N >> K;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 505000;
int n,m,a[N];
bool ck(int k){//1..2k 2k+1..2n
	rep(i,1,k)if(a[i]+a[2*k-i+1]>=m)return 1;
	rep(i,1,n-k)if(a[2*n-i+1]+a[2*k+i]<m)return 0;
	return 1;
}
int main() {
	read(n);read(m);rep(i,1,n*2)read(a[i]);
	sort(a+1,a+n*2+1);
	int l=0,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(ck(mid))r=mid;else l=mid+1;
	}
	int res=0,k=l;//cerr<<k<<endl;
	rep(i,1,k)umax(res,(a[i]+a[2*k-i+1])%m);
	rep(i,1,n-k)umax(res,(a[2*n-i+1]+a[2*k+i])%m);
	cout<<res;
	return 0;
}


Measured memory_bytes: 1024
def func():
    pass


def main():
    n, k = map(int, input().split())
    if k % 2 == 1:
        a_c = n // k
        print(a_c ** 3)
    else:
        p1 = (n // k) ** 3

        kh = k // 2
        p2 = ((n // kh) - (n // k)) ** 3
        print(p1 + p2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int a,b,c,d;cin >> a >> b >> c >> d;
    int ans = min(a,b) + min(c,d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
const int N=305*305;
int n,m,dp[N],f[N];
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    scanf("%d",&n);
    dp[0]=f[0]=1;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);m+=x;
        for(int j=m;j>=x;j--)
        {
            dp[j]=((ll)dp[j]*2+dp[j-x])%mod;
            f[j]=(f[j]+f[j-x])%mod;
        }
        for(int j=x-1;j>=0;j--)
            dp[j]=(ll)dp[j]*2%mod;
    }
    int ans=0;
    for(int i=(m+1)>>1;i<=m;i++)
        ans=(ans+(ll)dp[i]*3)%mod;
    if(m%2==0) ans=(ans-(ll)f[m/2]*3)%mod;
    ans=(qpow(3,n)-ans+mod)%mod;
    printf("%d\n",ans);
}

Measured memory_bytes: 896
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().calc();
	}

	public void calc() {
		char[] s = in.next().toCharArray();
		char before = s[0];
		int ans = 999999;

		for (int i = 1; i < s.length; i++) {
			if (before != s[i]) {
				before = s[i];
				ans = Math.min(ans, Math.max(i, s.length-i));
			}
		}

		if (ans == 999999) {
			ans = s.length;
		}

		out.println(ans);

		out.close();
	}            

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}


Measured memory_bytes: 23508
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a,maxx;
ll ans;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);in(maxx);
	for(int i=1;i<n;i++){
		in(a);
		if(a<maxx)ans+=(1ll)*(maxx-a);
		maxx=max(maxx,a);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3728