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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int H,W,K;
vector<string> S;
bool vis [800] [800];
const int dx [] = {0,1,0,-1};
const int dy [] = {-1,0,1,0};

bool in_range(int y,int x)
{
	return y >= 0 && y < H && x >= 0 && x < W;
}

void bfs(int y,int x)
{
	queue< pair< pair<int,int>,int > > q;
	q.push(make_pair(make_pair(y,x),0));
	vis [y] [x] = true;

	while(q.empty() == false){
		auto curr = q.front();
		q.pop();

		if(curr.second >= K) continue;
		FOR(i,0,4){
			int ny = curr.first.first + dy [i],nx = curr.first.second + dx [i];
			if(in_range(ny,nx) == false) continue;
			if(S [ny] [nx] == '#' || vis [ny] [nx]) continue;
			vis [ny] [nx] = true;
			q.push(make_pair(make_pair(ny,nx),curr.second + 1));
		}
	}
}

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

	cin >> H >> W >> K;
	S.assign(H,"");
	FOR(i,0,H){
		cin >> S [i];
	}

	FOR(i,0,H) FOR(j,0,W) if(S [i] [j] == 'S'){
		bfs(i,j);
		break;
	}
	
	int ans = 1e9;
	FOR(i,0,H) FOR(j,0,W) if(vis [i] [j]){
		chmin(ans,(i + (K - 1)) / K + 1);
		chmin(ans,(H - 1 - i + (K - 1)) / K + 1);
		chmin(ans,(j + (K - 1)) / K + 1);
		chmin(ans,(W - 1 - j + (K - 1)) / K + 1);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1536
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    long L = sc.nextLong();
    long R = sc.nextLong();
    long n = 0;
    while(n < L) n += 2019;
    int cnt = 0;
    while(n <= R){
      cnt++;
      n += 2019;
    }
    if(cnt == 0){
      long ans = 3000;
      for(long i=L; i<R; i++){
        for(long j=i+1; j<=R; j++){
          long first = i % 2019;
          long second = j % 2019;
          long tmp = first * second % 2019;
          ans = Math.min(tmp, ans);
        }
      }
      out.println(ans);
    }else{
      out.println(0);
    }
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    string w;
    cin >> w;
    int t,u=0;
    for(int i=0;i<w.size();i++){
      t=count(w.begin(),w.end(),w[i]);
      if(t%2==1){
        u=1;
        break;
      }
    }
    if(u==0){
      cout << "Yes" << endl;
    }else{
      cout << "No"  << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int i;
	char s[20];
	cin >> s;
	for (i = 0; i < 4; i++)
		cout << s[i];
	cout << " ";
	for (i = 4; i < 12; i++)
		cout << s[i];
	cout << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib> 

using namespace std;

int main() {
	int n,l;
	cin >>n>>l;
	int sum=0;
	for (int i = l; i < n+l; i++)
	{
		sum += i;
	}
	if(l>0) sum -= l;
	else if(n+l-1<0) sum -= (n+l-1);

	cout << sum;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

vector<string> split(string s, string t) {
	vector<string> ret;
	for(int i=0, n; i<=s.length(); i=n+1) {
		n = s.find_first_of(t, i);
		if(n == -1) n = s.length();
		string tmp = s.substr(i, n-i);
		ret.push_back(tmp);
	}
	return ret;
}
map<string, vector<string> > group;
set<string> se;

int solve(string now) {
  if (group.count(now) == 0) return 1;
  int res = 0;
  FOR(it, group[now]) {
    if (se.count(*it)) continue;
    se.insert(*it);
    res += solve(*it);
  }
  return res;
}

int main() {
  int n;
  while(cin >> n, n) {
    group.clear();
    string s;
    REP(i, n) {
      string line;
      cin >> line;
      line = line.substr(0, line.size()-1);
      vector<string> v = split(line, ":");
      vector<string> member = split(v[1], ",");
      group[v[0]] = member;
      if (i==0) s = v[0];
    }
    se.clear();
    cout << solve(s) << endl;
  }
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}
const int V = 100005;
vector<int> to[V * 2];
bool visited[V * 2];

vector<int> cnt;
void dfs(int v)
{
    if (visited[v])
        return;
    visited[v] = true;
    cnt[v / V]++;
    for (int u : to[v])
    {
        dfs(u);
    }
}

int main()
{
    int n;
    ll ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        y += V;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    for (int i = 0; i < V * 2; i++)
    {
        if (visited[i])
            continue;
        cnt = vector<int>(2);
        dfs(i);
        ans += (ll)cnt[0] * cnt[1];
    }
    cout << ans - n << endl;
    return 0;
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

ll n,m,d[100010]={};
V<ll> v[100010];

int main(void){
	cin>>n>>m;
	rep(i,m){
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	reg(i,1,n)d[i]=1e9;
	d[1]=0;
	queue<ll> q;
	q.push(1);
	while(!q.empty()){
		ll p = q.front();q.pop();
		rep(i,v[p].size()){
			ll r=v[p][i];
			if(d[r]>d[p]+1){
				d[r]=d[p]+1;
				q.push(r);
			}
		}
	}
	cout<<"Yes"<<endl;
	reg(i,2,n){
		rep(j,v[i].size()){
			ll r=v[i][j];
			if(d[r]==d[i]-1){
				cout<<r<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 12932
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		int[] A = new int[N];
		int[][] BC = new int[M][2];

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < M; i++) {
			BC[i][0] = sc.nextInt();
			BC[i][1] = sc.nextInt();
		}

		Arrays.sort(A);
		Arrays.sort(BC, (a, b) -> Integer.compare(b[1], a[1])); //降順

		int bci = 0;
		for (int ai = 0; ai < A.length; ai++) {
			if (A[ai] >= BC[bci][1]) {
				break;
			}
			A[ai] = BC[bci][1];
			BC[bci][0]--;
			if (BC[bci][0] <= 0) {
				bci++;
			}
			if (bci >= BC.length) {
				break;
			}
		}

		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += A[i];
		}

		out.println(ans);

		sc.close();

	}

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

}


Measured memory_bytes: 98920
A, B, C, X, Y = map(int, input().split())
price = [0]*(max(X, Y)+1)
price[0] = A*X+B*Y
for i in range(1, max(X, Y)+1):
  price [i] = 2*C*i+A*max(0, X-i)+B*max(0,Y-i)
print(min(price))

Measured memory_bytes: 39920
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

struct Node{
	int y1,x1,y2,x2;
	Node(int a,int b,int c,int d){y1=a+1,x1=b+1,y2=c+1,x2=d+1;}
};

int H,W,N=0;
int A[510][510];
int mode=0;
std::vector<Node> ans;

int main(){
	cin>>H>>W;
	REP(i,H)REP(j,W){
		cin>>A[i][j];
	}
	REP(i,H){
		if(mode==0){
			REP(j,W-1){
				if(A[i][j]%2==1){
					A[i][j+1]++;
					A[i][j]--;
					ans.push_back(Node(i,j,i,j+1));
				}
			}
			if(i!=H-1&&A[i][W-1]%2==1){
				A[i+1][W-1]++;
				A[i][W-1]--;
				ans.push_back(Node(i,W-1,i+1,W-1));
			}
			mode=1;
		}
		else{
			for(int j=W-1;0<j;j--){
				if(A[i][j]%2==1){
					A[i][j-1]++;
					A[i][j]--;
					ans.push_back(Node(i,j,i,j-1));
				}
			}
			if(i!=H-1&&A[i][0]%2==1){
				A[i+1][0]++;
				A[i][0]--;
				ans.push_back(Node(i,0,i+1,0));
			}
			mode=0;
		}
	}
	cout<<ans.size()<<endl;
	for(auto x:ans){
		cout<<x.y1<<" "<<x.x1<<" "<<x.y2<<" "<<x.x2<<endl;
	}
	return 0;
}


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

constexpr int N_MAX = 3001;
ll dp[4][N_MAX][N_MAX] = {};

struct item{
    int r;
    int c;
    ll v;
};

int main()
{
    int r, c, k;
    cin >> r >> c >> k;
    vector<item> vitem;
    for(int i=0; i<k; ++i){
        int ri, ci;
        ll vi;
        cin >> ri >> ci >> vi;
        vitem.emplace_back(item{ri, ci, vi});
    }
    sort(vitem.begin(), vitem.end(), [](item &a, item &b){
        return a.r < b.r || (a.r == b.r && a.c < b.c);
    });
    int item_itr = 0;
    auto &itm = vitem[item_itr];
    for(int ri=1; ri<=r; ++ri){
        for(int ci=1; ci<=c; ++ci){
            // 上から来る場合
            dp[0][ri][ci] = 0;
            for(int n=0; n<=3; ++n)dp[0][ri][ci] = max(dp[0][ri][ci], dp[n][ri-1][ci]);
            // 左から来る
            for(int n=1; n<=3; ++n){
                dp[n][ri][ci] = max(dp[n][ri][ci], dp[n][ri][ci - 1]);
            }
            // 乗せる
            if(itm.r == ri && itm.c == ci){
                for(int n=3; n>=1; --n){
                    dp[n][ri][ci] = max(dp[n][ri][ci], dp[n-1][ri][ci] + itm.v);
                }
                ++item_itr;
                if(item_itr < k)itm=vitem[item_itr];
            }
        }
    }
    ll ans=0;
    for(int n=0; n<=3; ++n){
        ans = max(ans, dp[n][r][c]);
    }
    cout << ans;
    return 0;
}


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

using namespace std;

constexpr int N = 3010;
long long dp[N][N][4];

int main() {
    #ifdef LOCAL
    freopen("in", "r", stdin);
    #endif // LOCAL
    ios::sync_with_stdio(0); cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> s(h, vector<int>(w));
    for (int i = 0; i < k; i++) {
        int r, c, v;
        cin >> r >> c >> v;
        r--; c--;
        s[r][c] = v;
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 3; k >= 0; k--) {
                if (j < w - 1) dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                if (k && j < w - 1) dp[i][j + 1][k - 1] = max(dp[i][j + 1][k - 1], dp[i][j][k] + s[i][j]);
                if (i < h - 1) dp[i + 1][j][3] = max(dp[i + 1][j][3], dp[i][j][k]);
                if (k && i < h - 1) dp[i + 1][j][3] = max(dp[i + 1][j][3], dp[i][j][k] + s[i][j]);
            }
        }
    }
    long long ans = 0;
    for (int k = 1; k < 4; k++) ans = max(ans, dp[h - 1][w - 1][k] + s[h - 1][w - 1]);
    ans = max(ans, dp[h - 1][w - 1][0]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 320664
N = int(input())
S = [input() for _ in range(N)]
T = ["".join(s) for s in zip(*S)]

ans = 0
for _ in range(N):
    ans += (S == T)
    S = [s[-1] + s[:-1] for s in S]
    T = T[-1:] + T[:-1]

print(N * ans)

Measured memory_bytes: 9284
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int W = sc.nextInt();
		int H = sc.nextInt();
		int N = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int d = 0;
		for (int i = 0; i < N - 1; ++i) {
			int nx = sc.nextInt();
			int ny = sc.nextInt();
			d += dist(x, y, nx, ny);
			x = nx;
			y = ny;
		}
		System.out.println(d);
	}

	static int dist(int x1, int y1, int x2, int y2) {
		if (x1 > x2) {
			int tmp = x1;
			x1 = x2;
			x2 = tmp;
			tmp = y1;
			y1 = y2;
			y2 = tmp;
		}
		if (y1 < y2) {
			int diag = Math.min(x2 - x1, y2 - y1);
			x1 += diag;
			y1 += diag;
			return diag + x2 - x1 + y2 - y1;
		} else {
			return x2 - x1 + Math.abs(y2 - y1);
		}
	}

}

Measured memory_bytes: 25484
#include <stdio.h>
#define N 200010
#define NoAnswer {puts("-1");return 0;}
int n,a[N],b[N];
long long ans=0;
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;++i) {
		scanf("%d",a+i);
		if(a[i]>i) NoAnswer;
	}
	for(int i=1;i<n;++i) {
		if(a[i]>a[i-1]) {
			if(a[i]==a[i-1]+1) ++ans;
			else NoAnswer;
		} else ans+=a[i];
	}
	printf("%lld",ans);
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	string s, t;
  cin >> s >> t;
  rep(i, s.size() + 1) {
    if(s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    char ch = s[0];
    s.erase(s.begin());
    s += ch; 
  }
  cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<sstream>
#include<fstream>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
/*freopen{"input.txt","r",stdin};
freopen{"output.txt","w",stdout};*/
#define mp make_pair
#define pb push_back
const int INF=1000*1000*1000;
const int maxn=2e5; 
typedef long long ll;
typedef long double ld;
typedef pair<int,int>PII;
//priority_queue <int,vector<int>,greater<int> > q1;  //从小到大 
//priority_queue <int,vector<int>,less<int> >q2;  //从大到小 

//set multiset vector queue priority_queue map multimap pair string structure 

//枚举 思维 贪心 搜索 模拟 预处理 二分 排序 

int main(){
	//ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
	ll n;
	cin>>n;
	cout<<n*(n-1)/2;
	
	
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long ans = sc.nextLong() + sc.nextLong();
        if(ans%2==1)
            System.out.println("IMPOSSIBLE");
        else
        System.out.println(ans/2);
    }
}

Measured memory_bytes: 22100
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    res = 0
    for i in range(n):
        l, r = map(int, input().split())
        res += r - l + 1

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

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

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

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

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

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

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

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

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

    let n: usize = sc.read();
    let mut list: VecDeque<u32> = VecDeque::with_capacity(n + n);

    for _ in 0..n {
        let com: String = sc.read();
        match com.as_str() {
            "insert" => {
                let x = sc.read();
                list.push_front(x);
            },
            "delete" => {
                let x: u32 = sc.read();
                let pos = list.iter().position(|&e| e == x).unwrap_or(list.len());
                let mut tail = list.split_off(pos);
                tail.pop_front();
                list.append(&mut tail);
            },
            "deleteFirst" => {
                list.pop_front();
            },
            "deleteLast" => {
                list.pop_back();
            },
            _ => panic!(),
        }
    }

    println!("{}", list.iter().join(" "));
}



Measured memory_bytes: 21304
n=int(input())
a=list(map(int,input().split()))
def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b
b=Csum(a)
c=sum(a)
d=[]
for i in range(1,n):
    d.append(abs((c-b[i])-b[i]))
print(min(d))

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s; cin >> s;
  ll n = s.size();
  auto check = [&]() -> ll {
    if (s[n-1] == '1') return -1;
    if (s[0] == '0') return -1;
    ll p = 0;
    ll q = n - 2;
    ll last_p = 0;
    while (p <= q) {
      if (s[p] != s[q]) return -1;
      if (s[p]) last_p = p;
      p++;
      q--;
    }
    return last_p + 1;
  };
  ll t1 = check();
  if (t1 < 0) {
    cout << "-1" << endl;
    return 0;
  }
  ll idx = 2;
  auto build = [&](auto rF, ll i, ll k) -> void {
    ll m = k - 1;
    while (m-1 >= 0 && s[m-1] == '0') m--;
    cout << i << " " << idx++ << "\n";
    if (m > 1) rF(rF, idx - 1, m);
    for (ll j = m; j < k - 1; j++) {
      cout << i << " " << idx++ << "\n";
    }
  };
  build(build, 1, n);
  

  return 0;
}



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


public class Main {

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

		int n = sc.nextInt();

		pr.println(n * (n + 1) / 2);

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9552
import std.stdio;
import std.string;
import std.algorithm;
import std.range;
import std.array;
import std.conv;


ubyte toNum(dchar e)
{
    if('a' <= e && e <= 'z')
        return cast(ubyte)(e - 'a');
    else
        return cast(ubyte)(e - 'A' + 26);
}

char toChar(ubyte u)
{
    if(u < 26)
        return cast(char)('a' + u);
    else
        return cast(char)('A' + u - 26);
}


void main()
{
    while(1){
        uint N = readln().chomp().to!uint;
        if(N == 0)
            break;

        auto kc = array(readln().chomp().split().map!(to!uint)).cycle;
        auto st = array(readln().chomp().map!toNum);
        foreach(i, ubyte e; st){
            e = (e + 52 - kc[i]) % 52;
            write(toChar(e));
        }

        writeln();
    }
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

bool calc(int x,int n,bool f){
  while(x>0){
    if(n>=x){
      n-=x;
      if(f)printf("%d\n",x);
    }
    --x;
  }
  if(n==0)return true;
  else return false;
}

int main(){
  int n;
  scanf("%d",&n);
  int low = 0, high = n;
  while(low+1<high){
    int mid = (low+high)/2;
    if(calc(mid,n,false)){
      high = mid;
    }else{
      low = mid;
    }
  }
  calc(high,n,true);
  return 0;
}


Measured memory_bytes: 256
from collections import deque
n=int(input())
a=list(map(int,input().split()))
ans=deque()
rev=False
if n&1:
   rev=True 
for i in a:
    if rev:
        ans.appendleft(i)
    else:
        ans.append(i)
    rev=not rev
print(*ans)

Measured memory_bytes: 32496
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 07/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s; cin>>s;
  if (s == "AAA" or s == "BBB")
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    A.push_back(0);
    
    long long ans = 0;
    long long sum = 0;
    for(int i = 0; i <= N; i++){
        if(A[i] == 0){
            ans += sum / 2;
            sum = 0;
        }else{
            sum += A[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

void solve() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	
	if (n < k){
		cout << x*n;
	}
	else{
		cout << x*k + y*(n-k);
	}

}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
u, d, c = [1], [1], [1]
for i in range(1, b + 1):
    u.append(u[-1] * (n - i + 1) % mod)
    d.append(d[-1] * i % mod)
    c.append(u[i] * pow(d[i], mod - 2, mod) % mod)
print((pow(2, n, mod) - 1 - c[a] - c[b]) % mod)

Measured memory_bytes: 32612
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/

#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define fo(x,y) for(int x = 1 ; x <= y ; ++x)
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;

typedef long long ll;
typedef unsigned int uint;
const int nmax = 200005;
const ll linf = LLONG_MAX;
const int mod = 1e9+7;
const int inf = INT_MAX;
#define pll pair<ll,ll>



int n , a;
set <int> s;
int main(){
    cin >> n;
    fo(i,n){
        cin >> a;
        s.insert(a);
    }
    cout << (n == s.size() ? "YES\n" : "NO\n");
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
using namespace std;
int c[20],a[20][20],b[20];
int main(void)
{
    int n,m,x,bc,mn=2e9;
    bool d=false;
    cin >> n >> m >> x;
    for(int i=0;i<n;i++)
    {
        cin >> c[i];
        for(int j=0;j<m;j++)
            cin >> a[i][j];
    }
    for(int k=0;k<(1<<n);k++)
    {
        int cnt=0;
        bc=0;
        for(int j=0;j<m;j++)
            b[j]=0;
        for(int i=0;i<n;i++)
        {
            if(k>>i & 1)
            {
                bc+=c[i];
                for(int j=0;j<m;j++)
                    b[j]+=a[i][j];
            }
        }
        for(int j=0;j<m;j++)
            if(b[j]>=x)
                cnt++;
        if(cnt==m)
        {
            d=true;
            mn=min(mn,bc);
        }
    }
    if(d==false)
        cout << "-1";
    else
        cout << mn;
    return 0;
}


Measured memory_bytes: 3648
n = int(input())

dp = [0] + [100000]*n

ptn = [1]
_ = 1
while 6**_ < 100000:
    ptn.append(6**_)
    _ += 1

_ = 1
while 9**_ < 100000:
    ptn.append(9**_)
    _ += 1

for i in range(1,n+1):
    for j in ptn:
        if i-j >= 0:
            dp[i] = min(dp[i], dp[i-j]+1)
print(dp[-1])

Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

vector<vector<int>> calcNext(const string& S, int types = 26, char base = 'a') {
	int n = (int)S.size();
	vector<vector<int>> res(n + 2, vector<int>(types, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < types; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - base] = i;
	}
	return res;
}

int main() {
	IOS;
	int n;
	string s;
	cin >> n >> s;
	auto cal = calcNext(s, 10, '0');
	int res = 0;
	REP(i, 10) {
		REP(j, 10) {
			REP(k, 10) {
				int l = -1;
				l = cal[l + 1][i];
				l = cal[l + 1][j];
				l = cal[l + 1][k];
				if (l < n) {
					res++;
				}
			}
		}
	}
	put(res);
	return 0;
}

Measured memory_bytes: 2432
///=======================///
/// coder: Andy - Tohrumi ///
///=======================///

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)

using namespace std;

typedef pair<ll, ll> pll;	typedef pair<int, int> ii;
typedef vector<pll> vll;	typedef vector<string> vs;		typedef vector<ii> vii;
typedef vector<int> vi; 	typedef vector<ll> vl;

///====code start here====///

bool dp[100005];

signed main() {
	fastio;
	int n, k; cin >> n >> k;
	int a[n];
	rep(i, 0, n) cin >> a[i];
	rep(i, 1, k + 1) {
		rep(j, 0, n) {
			if(i - a[j] < 0) continue;
			dp[i] |= (dp[i - a[j]] ^ 1); 
		}
	}
	if(dp[k]) cout << "First\n";
	else cout << "Second\n";
	return 0;
}


Measured memory_bytes: 3724
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	long long s = 0, cur = 0;
	for (int i = 0; i < N; ++i) s += A[i];
	for (int i = 1; i < N; i += 2) cur += A[i];
	vector<long long> ans(N);
	for (int i = 0; i < 2 * N; i += 2) {
		ans[i % N] = (s / 2 - cur) * 2;
		cur -= A[(i + 1) % N];
		cur += A[i % N];
	}
	for (int i = 0; i < N; ++i) {
		if (i) cout << ' ';
		cout << ans[i];
	}
	return 0;
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

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

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll N, A, B;
    cin >> N >> A >> B;

    ll d = B-A-1;
    if(d%2==1){
        p("Alice");
    }else{
        p("Borys");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const long long mod = 1e9 + 7;
long long dp[N] = {};
int main() {
    int n;
    cin >> n;
    if (n >= 3) fill(dp + 3, dp + n + 1, 1);
    for (int i = 4; i <= n; i++)
        for (int j = i - 3; j >= 0; j--)
            dp[i] = (dp[i] + dp[j]) % mod;
    cout << dp[n] << '\n';
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

        int mini = 0;
        for (int i = 0; i < cs.length; i++) {
            if (cs[i] == 'A') {
                mini = i;
                break;
            }
        }

        int maxi = 0;
        for (int i = cs.length - 1; i >= 0; i--) {
            if (cs[i] == 'Z') {
                maxi = i;
                break;
            }
        }
        System.out.println(maxi - mini + 1);
    }
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int mp[3][3];

int main(){

	REP(i,3)REP(j,3)cin >> mp[i][j];

	REP(i,101){
		REP(j,101){
			REP(k,101){
				bool flag = true;
				REP(ii,3){
					if(mp[ii][0] - i != mp[ii][1] - j)flag = false;
					if(mp[ii][1] - j != mp[ii][2] - k)flag = false;
					if(mp[ii][0] - i < 0)flag = false;
				}
				if(flag){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   int k = sc.nextInt();
   String a = Integer.toString(n, k);
   int l = a.length();

   System.out.println(l);
 }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
#define sp(x,y) cout<<fixed<<setprecision(y)<<x<<endl;
#define int ll
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=3e5+5;

int n,k;

vector<vi> mul(vector<vi> a, vector<vi> b){
	vector<vi> c(n, vector<int>(n,0));
	fo(i,n){
		fo(j,n){
			fo(l,n){
				c[i][j]=(c[i][j]+(a[i][l]*b[l][j])%MOD)%MOD;
			}
		}
	}
	return c;
}

vector<vi> matrix_power(vector<vi> a, int k){
	if(k==1)
		return a;
	if(k&1)
		return mul(a,matrix_power(a,k-1));
	else{
		vector<vi> b=matrix_power(a,k/2);
		return mul(b,b);
	}

}

signed main(){
	fastio();
	cin>>n>>k;
	vector<vi> a(n,vi(n));
	fo(i,n){
		fo(j,n){
			cin>>a[i][j];
		}
	}
	a=matrix_power(a,k);
	int ans=0;
	fo(i,n){
		fo(j,n){
			ans=(ans+a[i][j])%MOD;
		}
	}
	cout<<ans<<endl;
}

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


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

answer = sum(a)
a_num_cnt = {}

for i in range(n):
    num = a[i]

    if num in a_num_cnt:
        a_num_cnt[num] += 1
    else:
        a_num_cnt[num] = 1

for i in range(q):
    b, c = map(int, input().split())
    increament = c - b

    if b in a_num_cnt:
        cnt = a_num_cnt[b]
        answer += (increament * cnt)
        a_num_cnt[b] -= cnt

        if c in a_num_cnt:
            a_num_cnt[c] += cnt
        else:
            a_num_cnt[c] = cnt


    print(answer)
    

Measured memory_bytes: 20628
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int a[190];
    int n;
    rep(i,190) a[i] = i * i;

    while(cin >> n, n){
        int cnt = 0;
        range(i,1,190){
            if(a[i] == n) {
                cnt++;
                break;
            }
            range(j,i,190){
                if(a[i] + a[j] == n){
                    cnt++;
                    break;
                }
                range(k,j,190){
                    if(a[i] + a[j] + a[k] == n){
                        cnt++;
                        break;

                    }
                    range(l,k,190){
                        if(a[i] + a[j] + a[k] + a[l] == n){
                            cnt++;
                            break;
                        }
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3016
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n;
	cin >> n;
	cout << (1000 - (n % 1000)) % 1000;
}


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

int num[105];

bool cmp(int a,int b){
    if (a%10==0)
        return 0;
    if (b%10==0)
        return 1;
    return a<b;
}

int main()
{
    int n;
    cin>>n;
    int all=0;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
        all+=num[i];
    }
    sort(num,num+n,cmp);
    if (all%10==0)
        all-=num[0];
    if (all%10!=0)
        printf("%d\n",all);
    else
        printf("0\n");
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class Main{

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return str;
        }

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

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

        long nextLong() {

            return Long.parseLong(next());
        }

        BigInteger nextBigIntger() {
            BigInteger bb = new BigInteger(next());
            return bb;
        }
    }
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int n = sc.nextInt(),k =sc.nextInt(),ans=1,pre=1;
        for (int i=1;i<=n;i++){
             int dob = 2*pre;
             if(dob-pre<=k)
                 ans+=pre;
            else ans+=k;
            pre = dob;
        }
        System.out.println(ans);
        }

}




Measured memory_bytes: 22868
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		char str[260];
		char e[260];
		scanf("\n");
		gets(str);
		int leng=strlen(str);
			for(int i=1;i<26;i++){
				if(i%2!=0 && i%13!=0){
					for(int j=0;j<26;j++){
						string r;
						for(int y=0;y<leng;y++){
							if(str[y]-'a'>=0 && str[y]-'a'<26){
								int o=str[y]-'a';
								o=(o*i+j)%26;
								r.push_back(o+'a');
							}else{
								r.push_back(str[y]);
							}
						}
						int p=r.size();
						for(int i=0;i<p-3;i++){
							if(r[i]=='t' && r[i+1]=='h' && ((r[i+2]=='a' && r[i+3]=='t') || (r[i+2]=='i' && r[i+3]=='s'))){
								cout << r << endl;
								goto ri;
							}
					}
				}
			}
			}
ri:;
}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500;

int n;
int c[N], s[N], f[N];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	
	for (int i = 0; i < n; i++) {
		ll t = 0;
		for (int station = i; station < n - 1; station++) {
			if (t <= s[station]) {
				t = s[station];
				t += c[station];
			} else {
				int wait = (t - s[station]) % f[station];
				if (wait) wait = f[station] - wait;
				t += wait;
				t += c[station];
			}
		}
		cout << t << "\n";
	}
    return 0;
}


Measured memory_bytes: 256