akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <iterator>
#include <bits/stdc++.h>

using namespace std;

bool isPerfectSquare(long double x) 
{   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
} 

int main()
{
    int n, d;
    vector<vector<int>> nums;
    cin >> n >> d >> ws;
    string line;
    for (int i = 0; i < n; i++) {
        getline(cin, line);
        stringstream ss(line);
        int ti;
        vector<int> tmp;
        while(ss >> ti)
            tmp.push_back(ti);
        nums.push_back(tmp);
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int dist = 0;
            for (int k = 0; k < d; k++) {
                dist += pow(nums[i][k] - nums[j][k],2);
            }
            if (isPerfectSquare(dist)) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a, b, c, d;
int main() {
	cin >> a >> b >> c >> d;
	if (a <= c && a + d >= c) {
		cout << "Yes";
	}
	else if(a >= c && a <= c+d){
		cout << "Yes";
	}
	else if (a <= b && a + d >= b && b <= c && b + d >= c) {
		cout << "Yes";
	}
	else if (c <= b && c + d >= b && b <= a && b + d >= a) {
		cout << "Yes";
	}
	else{
		cout << "No";
	}
}

Measured memory_bytes: 256
#include <iostream>


int main(){
  int n, m, l;
  std::cin >> n;
  std::cin >> m;
  int T[n], C[m];

  for(int j = 0; j < n+1; j++){
    T[j] =  50010;
  }
  T[0] = 0;

  for(int i = 0; i < m; i++){
    std::cin >> C[i];
  }

  for(int k = 0; k < m ; k++){
    for(l = C[k]; l < n+1; l++){
      T[l] = std::min(T[l], T[l - C[k]] + 1);
    }

  }

  std::cout << T[n] <<"\n";

  return (0);
}

Measured memory_bytes: 3284
N = int(input())
A,B = map(int,input().split())
NNN = map(int,input().split())
NN= list(NNN)
counta = 0
countb = 0
countc = 0
for i in NN:
  if i <= A:
    counta += 1
for i in NN:
  
  if A < i <= B:
    countb += 1
for i in NN:
  if B < i:
    countc += 1


print(min(counta,countb,countc))

Measured memory_bytes: 9068
def ok(a, n, k, p):
    t = 0
    t_cnt = 0
    for w in a:
        if p < w:
            return -1
        if t + w > p:
            t_cnt += 1
            if t_cnt >= k:
                return -1
            t = w
        else:
            t += w
    return 0


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

P_max = n * 10000 // k + 10001

l = 0
r = P_max
m = 0
while l < r - 1:
    m = (l + r) // 2
    if ok(a, n, k, m) == 0:
        r = m
    else:
        l = m

print(r)










Measured memory_bytes: 9560
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int main(){
    ll n, k, q;
    cin >> n >> k >> q;
    v1 a(n, 0);
    rep(i,q){
        int A;
        cin >> A;
        A--;
        a[A]++;
    }
    rep(i, n){
        if(q-a[i] >= k) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9+7;

int main(){

    int n, m; cin >> n >> m;

    vector< string > s(n);
    for(string &u : s) cin >> u;

    vector< vector<int> > dp;
    dp.assign(n, vector<int>(m,0));

    dp[0][0] = 1;
    for(int i=1; i<m; i++) if(s[0][i] != '#') dp[0][i] = 1; else break;
    for(int i=1; i<n; i++) if(s[i][0] != '#') dp[i][0] = 1; else break;
    for(int i=1; i<n; i++)
        for(int j=1; j<m; j++)
            if(s[i][j] != '#')
                dp[i][j] = ( dp[i][j-1] + dp[i-1][j] ) % md;
    cout << dp[n-1][m-1] << "\n";

    return 0;
}


Measured memory_bytes: 9356
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        const int NumberOfAntennas = 5;

        static void Main(string[] args)
        {
            var array = new int[NumberOfAntennas];

            for (var i = 0; i < NumberOfAntennas; i++)
            {
                array[i] = int.Parse(Console.ReadLine());
            }

            var minIndex = 0;

            // 1桁目が最も小さいインデックスを抽出する
            for (var i = 1; i < NumberOfAntennas; i++)
            {
                if (array[i] % 10 == 0) continue; // 1桁目が0の時は対象外

                if (array[minIndex] % 10 == 0 || array[i] % 10 < array[minIndex] % 10)
                    minIndex = i;
            }

            // 最も小さい値を末尾と入れ替える
            var tmp = array[NumberOfAntennas - 1];
            array[NumberOfAntennas-1] = array[minIndex];
            array[minIndex] = tmp;

            var total = 0;
            for (var i = 0; i < NumberOfAntennas; i++)
            {
                total += array[i] % 10 == 0 || i == NumberOfAntennas-1 ? array[i] : (int) Math.Ceiling(array[i]/10.0)*10;
            }

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>

using namespace std;

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

    int posc=(int)str.find("C"), posf=(int)str.rfind("F");

    if(posc!=-1&&posf!=-1&&posc<posf){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int hill[10] = {};
    int higher[3] = {};
    int i, j;
    
    for(i=0;i<10;++i){
        scanf("%d", &hill[i]);
    }
    
    for(i=0;i<10;++i){
        if(hill[i] > higher[2]){
            higher[2] = hill[i];
        }
        
        if(higher[2] > higher[1]){
            int tmp = higher[1];
            higher[1] = higher[2];
            higher[2] = tmp;
        }
        
        if(higher[1] > higher[0]){
            int tmp = higher[0];
            higher[0] = higher[1];
            higher  [1] = tmp;
        }
    }
    
    for(i=0;i<3;++i){
        printf("%d\n", higher[i]);
    }
    
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> v(n+4, -1);
        for (int i = 0; i < n; ++i) {
            scanf("%d", &v[i+2]);
        }
        v[0] = 100; v[n+3] = 100;
        int ans = 0;
        for (int i = 2; i <= n+1; ++i) {
            for (int j = 1; j <= 3; ++j) {
                int t = v[i];
                v[i] = j;
                int valid = 1, l = i, r = i, c = 0;
                while(valid){
                    valid = 0;
                    while(v[l-1] == v[l]) l--;
                    while(v[r+1] == v[r]) r++;
                    if(r-l+1-c >= 4){
                        valid = 1;
                        c += r-l+1-c;
                        l--; r++;
                    }
                    if(v[l] != v[r]) break;
                }
                v[i] = t;
                ans = max(ans, c);
            }
        }
        cout << n-ans << "\n";
    };
    return 0;
}



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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  int ans = 0;
  for(int i = N; i >= 1; i--){
    int cnt = 0;
    for(int yak = 1; yak <= N; yak++){
      if(i % yak == 0) cnt++;
    }
    if(cnt == 8 && i % 2 == 1) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 256
def calc_min_diff(h, K):
        h.sort()
        min_h = h[K - 1] - h[0]
        for i in range(K, len(h)):
                min_h = min(min_h, h[i] - h[i - K + 1])
        return min_h


N, K = [int(v) for v in input().split()]
h = [int(input()) for _ in range(N)]
print(calc_min_diff(h, K))

Measured memory_bytes: 7488
using System;
using System.Linq;
using System.Collections.Generic;

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var n = N.ToString().Length;
            var res = 0;
            for(var i = 0; i < n; i++)
            {
                if((i+1) % 2 == 1)
                {
                    if (i == 0 && n == 1) res += N;
                    else if (i == 0 && n != 1) res += 9;
                    else if ((i+1) == n) res += N - (int)Math.Pow(10, i) + 1;
                    else res += (int)Math.Pow(10, i + 1) - (int)Math.Pow(10, i);
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[5];
		for (int i = 0; i < 5; i++) {
			x[i] = sc.nextInt();
		}
		sc.close();

		for (int i = 0; i < x.length; i++) {
			if (x[i] == 0) {
				System.out.println(i + 1);
				return;
			}
		}
	}
}


Measured memory_bytes: 35672
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str[];
		int cup[];

		cup = new int[3];
		cup[0] = 1;
		while (sc.hasNext()) {
			str = sc.next().split(",");
			int swap = cup[str[0].charAt(0) - 'A'];
			cup[str[0].charAt(0) - 'A'] = cup[str[1].charAt(0) - 'A'];
			cup[str[1].charAt(0) - 'A'] = swap;
		}
		for (int i = 0; i < 3; i++) {
			if (cup[i] == 1) {
				System.out.println((char)('A' + i));
			}
		}
	}
}

Measured memory_bytes: 12000
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
  for i in range(4):
    t = list(last4)
    if i >= 1:
      t[i-1], t[i] = t[i], t[i-1] 
    if ''.join(t).count('AGC') >= 1:
      return False
  return True

def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == N:
    return 1
  ret = 0
  for c in 'ACGT':
    if ok(last3 + c):
      ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
  memo[cur][last3] = ret
  return ret

print(dfs(0, 'TTT'))

Measured memory_bytes: 9420
n=int(input())
a=[int(x) for x in input().split()]
s=0
m=1000
for i in range(0,n-1):
    #print(i)
    if(a[i]>a[i+1] and s>0):
        m=m+s*a[i]
        s=0
    elif(a[i]<a[i+1] and m>=a[i]):
        s=m//a[i]
        m=m%a[i]
if(s>0):
    m=m+s*a[n-1]
print(m)
    
        

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

#define ll long long 
#define ff(i, a, b) for(int i = a; i <= b; i++)
#define fo(i, a, b) for(int i = a; i < b; i++)
#define fod(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int INF = 1e9, N = 100010;
const ll INFL = 1e18;

typedef pair <int, int> ii;
typedef pair <int, ii> II;
typedef vector <int> vi;
typedef vector <ii> vii;

int n, m, k, q, par[N], p[20][N], Min[20][N];
vector <int> d, l;
bool fes[N], vis[N];
vector <vii> G;
vii edge;
vector <II> E;

int anc(int p) { return p == par[p] ? p : par[p] = anc(par[p]); }
void join(int p, int q) { par[anc(p)] = anc(q); }

void dijkstra() {
	priority_queue < ii, vii, greater <ii> > pq;
	ff(i, 1, n) if (fes[i]) pq.push(ii(0, i)), d[i] = 0;
	while(!pq.empty()) {
		int u = pq.top().se, du = pq.top().fi; pq.pop();
		if (du != d[u]) continue;
		fo(i, 0, G[u].size()) {
			int v = G[u][i].se, w = G[u][i].fi;
			if (d[v] > d[u] + w) { d[v] = d[u] + w; pq.push(ii(d[v], v)); }
		}
	}
}

void changeGraph() {
	fo(i, 0, edge.size()) {
		int u = edge[i].fi, v = edge[i].se;
		int w = min(d[u], d[v]);
		E.pb(II(w, ii(u, v)));
	}
}	

void Kruskal() {
	G.assign(n + 1, vii());
	sort(E.begin(), E.end(), greater <II> ());
	fo(i, 0, E.size()) {
		int w = E[i].fi, u = E[i].se.fi, v = E[i].se.se;
		if (anc(u) != anc(v)) { join(u, v); G[u].pb(ii(w, v)) ; G[v].pb(ii(w, u)); }
	}
}

void dfs(int u) {
	vis[u] = 1;
	fo(i, 0, G[u].size()) {
		int v = G[u][i].se;
		if (vis[v]) continue;
		l[v] = l[u] + 1; p[0][v] = u; 
		Min[0][v] = G[u][i].fi;
//		cout << l[v] << ' ' << v << ' ' << Min[0][v] << "\n";
		dfs(v);
	}
}

int get(int u, int v) {
	int res = INF;
	if (l[u] < l[v]) swap(u, v);
	fod(i, 19, 0) if (l[p[i][u]] >= l[v]) { res = min(res, Min[i][u]); u = p[i][u]; } 
	if (u == v) return res;
	fod(i, 19, 0) if (p[i][u] != p[i][v]) { res = min(res, Min[i][u]); res = min(res, Min[i][v]); u = p[i][u]; v = p[i][v]; }
	if (u != v) { res = min(res, Min[0][u]); res = min(res, Min[0][v]); }
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> k >> q; 
	G.assign(n + 1, vii()); d.assign(n + 1, INF); l.assign(n + 1, 0);
	ff(i, 1, n) par[i] = i;
	while(m--) {
		int u, v, w; cin >> u >> v >> w;
		G[u].pb(ii(w, v)); G[v].pb(ii(w, u));
		edge.pb(ii(u, v));
	}
	ff(i, 1, k) { int x; cin >> x; fes[x] = 1; }
	dijkstra();
//	ff(i, 1, n) cout << i << ' ' << d[i] << "\n";
	changeGraph();
	Kruskal();
//	cout << "\n";
	ff(i, 1, n) {
//		cout << i << " Adj List:\n";
//		fo(j, 0, G[i].size()) cout << G[i][j].se << ' ' << G[i][j].fi << "\n";
	}
	ff(i, 1, n) ff(k, 1, 19) Min[k][i] = INF;
	p[0][1] = 0; l[1] = 1; dfs(1);
	ff(k, 1, 19) ff(i, 1, n) {
		p[k][i] = p[k - 1][p[k - 1][i]];
		Min[k][i] = min(Min[k - 1][i], Min[k - 1][p[k - 1][i]]);
	}
	while(q--) {
		int u, v; cin >> u >> v;
		printf("%d\n", get(u, v));
	}
}

Measured memory_bytes: 31884
#include <iostream>
#include <string>
using namespace std;
int numberdigit [10000][10000];
int main(){
    string s;
    int i=1; 
    while(1){
        int answer = 0;
        if(getline(cin, s)){
            if(s == "0"){
                break;
            }
            int n=s.size();
            for(int j=0;j<n;j++){
                numberdigit[i][j] = s[j] - '0';
                answer += numberdigit[i][j];
            }
            i+=1;
            cout << answer << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3496
def resolve():
    s_x, s_y, t_x, t_y = map(int, input().split())

    d_x = t_x - s_x
    d_y = t_y - s_y
    p_1 = 'U'*d_y + 'R'*d_x
    p_2 = 'D'*d_y + 'L'*d_x
    p_3 = 'L' + 'U' * (d_y+1) + 'R' * (d_x+1) + 'D'
    p_4 = 'R' + 'D' * (d_y+1) + 'L' * (d_x + 1) + 'U'

    print(p_1+p_2+p_3+p_4)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3060
import sys
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n=int(input())
a=[]
s=int(input())
if s!=0:
  print(-1)
  sys.exit()
a.append(s)
ans=0
prev=0
for i in range(n-1):
  x=int(input())
  if x-prev>1:
    print(-1)
    sys.exit()
  if x-prev==1:
    ans+=1
  else:
    ans+=x
  prev=x
print(ans)

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

constexpr int mod = 1e9 + 7;

#define dump(x) ([&](){auto y = (x); cout << #x << " = " << (y) << endl; })();
// #define dump(x) ;


template<class T>
ostream&operator<<(ostream &os, vector<T>v) {
  os << "{";
  for(size_t i = 0; i < v.size(); i++) os << v[i] << ", ";
  os << "}";
  return os;
}

template<class T, class U>
ostream&operator<<(ostream &os, pair<T, U>v) {
  os << "(" << v.first << " , " << v.second << ")";
  return os;
}

template<class T, class U>
ostream&operator<<(ostream &os, map<T, U>v) {
  os << "(map: \n";
  for(auto e : v) os << e << ", \n";
  os << ")";
  return os;
}

using Vec = vector<int>;
using Mat = vector<Vec>;

ll modpow(ll x, ll k, ll mod) {
  x %= mod;
  ll r = 1;
  assert(k >= 0);
  while(k) {
    if(k & 1) r = r * x % mod;
    x = x * x % mod;
    k >>= 1;
  }
  return r;
}

ll toint(string s) {
  ll res = 0;
  int n = s.size();
  for(int i = 0; i < n; i++) res |= (ll(s[n - 1 - i] - '0')) << i;
  return res;
}

string tostr(ll x, int n) {
  string res = "";
  for(int i = 0; i < n; i++) {
    res += '0' + ((x >> i) & 1);
  }
  reverse(begin(res), end(res));
  return res;
}

bool mul_OF(ll a, ll b) {
  // a * b > 4e18
  // a > floor(4e18 / b)
  return a > ll(1e18) / b;
}

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

  while(1) {
    ll n;
    cin >> n;
    if(n == 0) break;
    string b;
    cin >> b;

    ll e = 0;
    ll k = toint(b) + (1ll << 52);
    // dump(e);
    // dump(k);

    ll G = 1ll << 53;
    assert(k < G);

    ll now = k;
    int shift = 0;
    // dump(n);
    // dump(e);
    // dump(k);
    while(n) {
      ll ok = 0, ng = n + 1;
      ll s = (k >> shift);
      while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) >> 1;
        if(mul_OF(s, mid)) {
          ng = mid;
        } else {
          if(s * mid < G - now) ok = mid; else ng = mid;
        }
      }
      // dump(ok);
      now += s * ok;
      n -= ok;
      if(n) {
        now += s;
        assert(now >= G);
        assert(now < G * 2);
        now >>= 1;
        e++;
        shift++;
        if(shift > 53) shift = 53;
        n--;
      }

    }
    assert(k >= (1ll << 52));
    cout << tostr(e, 12) << tostr(now - (1ll << 52), 52) << "\n";
  }
}





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

const ll MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    vector<int> prime;
    vector<bool> isPrime(N + 1, true);
    isPrime.at(0) = false;
    isPrime.at(1) = false;
    for (int i = 2; i <= N; ++i) {
        if (isPrime.at(i)) {
            prime.push_back(i);
            for (int j = 2 * i; j <= N; j += i) {
                isPrime.at(j) = false;
            }
        }
    }

    vector<ll> cnt(prime.size(), 0);
    for (int x = 1; x <= N; ++x) {
        int num = x;
        for (int i = 0; i < prime.size(); ++i) {
            while (num % prime.at(i) == 0) {
                num /= prime.at(i);
                ++cnt.at(i);
            }
        }
    }
    ll ans = 1;
    for (auto &x : cnt) {
        ans = ans * (x + 1) % MOD;
    }
    cout << ans << endl;

    return 0;
}

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

using std::cin;
using std::cout;
using std::endl;
using std::string;;

int main(void) {
  int num = 0;
  int N;
  string S;

  cin >> S;

  for (auto it = S.cbegin(); it != S.cend(); it++) {
    if (*it == '+') num++;
    if (*it == '-') num--;
  }
  
  cout << num << endl;
  return 0;
  
}


Measured memory_bytes: 760
import numpy as np
A,B,H,M = map(int,input().split())
pi = np.pi
h_angle = (H + M/60) * 2*pi / 12
m_angle = M * 2 * pi / 60
h_x = A * np.cos(h_angle)
h_y = A * np.sin(h_angle)
m_x = B * np.cos(m_angle)
m_y = B*np.sin(m_angle)
print(np.sqrt((h_x - m_x) ** 2 + (h_y - m_y) ** 2))

Measured memory_bytes: 27156
N, K = map(int, input().split())
x = list(map(int, input().split()))
L = []

for i in range(N-K+1):
    L.append(abs(x[i]) + x[K+i-1] - x[i])
    L.append(abs(x[K+i-1]) + x[K+i-1] - x[i])
    
if N != 1:
    print(min(L))
else:
    print(abs(x[0]))


Measured memory_bytes: 14384
q=list(map(int,input().split()))
grid=[]
def k1(x,y):
  z=[]
  if y[0]+1<x[0]:
    z.append([y[0]+1,y[1]])
    if y[1]+1<x[1]:#
      z.append([y[0]+1,y[1]+1])
    if y[1]-1>=0:
      z.append([y[0]+1,y[1]-1])
  if y[0]-1>=0:
    z.append([y[0]-1,y[1]])
    if y[1]+1<x[1]:#
      z.append([y[0]-1,y[1]+1])
    if y[1]-1>=0:
      z.append([y[0]-1,y[1]-1])    
  if y[1]+1<x[1]:
    z.append([y[0],y[1]+1])
  if y[1]-1>=0:
    z.append([y[0],y[1]-1])
  return(z)
for i in range(q[0]):
    y=input()

    grid.append([i for i in y])
  
for i in range(q[0]):
    for j in range(q[1]):
        if grid[i][j]=='.':
            
          
            kh=k1(q,[i,j])
            
            count=0
            
            for k in range(len(kh)) :
                
                
                if grid[kh[k][0]][kh[k][1]] == '#' :
                  count+=1
            grid[i][j]=count      
                
for i in range(q[0]):
    pr=''
    for j in range(q[1]):
        pr=pr+str(grid[i][j])
    print(pr)



Measured memory_bytes: 3188
N = int(input())
a = [[0, 0, 0]]
for i in range(N):
    a.append([int(x) for x in input().split()])

for i in range(N):
    dist = abs(a[i+1][1] - a[i][1]) + abs(a[i+1][2] - a[i][2])
    time = a[i+1][0] - a[i][0]
    if time < dist or (time - dist) % 2 != 0:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 21156
PROGRAM c168a

IMPLICIT NONE
INTEGER :: N

READ *, N

IF (MOD(N, 10) == 3) THEN
 PRINT *, 'bon'
ELSE IF (MOD(N, 10) == 0 .OR. MOD(N, 10) == 1 .OR. MOD(N, 10) == 6 .OR. MOD(N, 10) == 8) THEN
 PRINT *, 'pon'
ELSE
 PRINT *, 'hon'
END IF

END PROGRAM c168a

Measured memory_bytes: 2856
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def factorization(n):
    factors = []

    if n < 2:
        return [n]

    while n % 2 == 0:
        factors.append(2)
        n //= 2

    for i in range(3, int(n ** 0.5) + 5, 2):
        while n % i == 0:
            factors.append(i)
            n //= i

    if n != 1:
        factors.append(n)

    return factors


def main():
    from collections import Counter
    n, p = map(int, readline().split())
    factors = Counter(factorization(p))

    ans = 1
    for key, val in factors.items():
        ans *= key ** (val // n)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 66252
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseMap(split(readline()))
    ans=0
    for i in 1:n
        if i%2==a[i]%2==1
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 163620
#include <cstdio>
#include <stack>
using namespace std;
int main() {
	int n;
	stack<int> S;
	while(scanf("%d",&n)!=EOF) {
		if(n)S.push(n);
		else {
			printf("%d\n",S.top());
			S.pop();
		}
	}
}

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

int main()
{
    string t;
    cin >> t;
    for(int i =0; i<t.size(); i++){
        if(t[i] == '?') t[i] = 'D';
    }
    cout << t << endl;
    return 0 ;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n;
string s;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> s;
    if( n&1 ){
        cout << "No";
    }else{
        if( s.substr( 0 , n/2 )!=s.substr( n/2 , n/2 ) ){
            cout << "No";
        }else{
            cout << "Yes";
        }
    }

    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 repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

//--//--//--//--//--//--//--//--//--//--//--//



int main() {
	int n;
	ll ans = 0;
	cin >> n;
    vec<ll> a(n);
	vec<ll> s(n+1,0);
	
	rep(i, n){
		cin >> a[i];
		s[i+1] = s[i] + a[i];
	}
	rep(i, n){
		ans += a[i] * ((s[n] - s[i+1]) % MOD) % MOD;
	}
	cout << ans%MOD << endl;
}

Measured memory_bytes: 6340
n, m = map(int, input().split())
abc = []
dis = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
    abc.append(list(map(int, input().split())))

for a, b, c in abc:
    dis[a-1][b-1] = c
    dis[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j])

count = 0
for a, b, c in abc:
    if c > dis[a-1][b-1]:
        count += 1

print(count)

Measured memory_bytes: 3572
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static java.lang.System.out;
import java.util.List;
import java.io.File;
import java.util.Scanner;

public class Main extends BaseExe {

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

    @Override
    protected void execute() throws Exception {
        List<Integer> ab = asList(nextLine().split(" ")).stream().map(Integer::parseInt)
                .collect(toList());
        out.printf("%d %d %.5f", getDiv(ab), getMod(ab), getDivDouble(ab));
    }

    private int getDiv(List<Integer> ab) {
        return ab.get(0) / ab.get(1);
    }

    private int getMod(List<Integer> ab) {
        return ab.get(0) % ab.get(1);
    }

    private double getDivDouble(List<Integer> ab) {
        return (double) ab.get(0) / (double) ab.get(1);
    }
}

abstract class BaseExe {

    private Scanner scan;

    private String inData;

    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void exeCtrl(Scanner scan) throws Exception {
        this.scan = scan;
        execute();
    }

    protected abstract void execute() throws Exception;

    protected String nextLine() {
        return scan.nextLine();
    }

    protected boolean judgeInData() {
        return hasNextLine() && isNotEmptyInData();
    }

    protected boolean hasNextLine() {
        return scan.hasNextLine();
    }

    protected boolean isNotEmptyInData() {
        inData = nextLine();
        return !inData.isEmpty();
    }

    protected String getInData() throws Exception {
        if (inData.isEmpty())
            throw new Exception("inData is Empty.");
        return inData;
    }
}

Measured memory_bytes: 32892
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define get(a,t) get<a>(t)
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const int INF=1e18;
const int N=100005;
void solve()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k>a)
    {
        if(k>a+b)
        {
            cout<<a-(k-a-b)<<endl;
        }
        else
        {
            cout<<a<<endl;
        }
        
    }
    else
    {
        cout<<k<<endl;
    }
    
    
}
int32_t main()
{
    IOS;
    //int t; cin>>t;
    int t=1;
    for(int tc=1;tc<=t;tc++)
    {
        //cout<<"Case #"<<tc<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc161
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            var ans = sw[0] <= sw[1] ? "unsafe" : "safe ";
            Console.WriteLine(ans);


        }
    }
}

Measured memory_bytes: 28232
#解法1
w = input()
ls = []
#s = list(w)などとすることで省略できる
for i in range(len(w)):
  ls.append(w[i])
ls.sort()
#文字列ソート
now_str = ls[0]
#nowは現在の参照対象の文字列
now = 1
#nowは現在の文字の連続数、1から数える
flag = 0
#条件を満たしているかを考えるflag関数
for i in range(1,len(ls)):
  if ls[i] == now_str:
    now += 1
  else:
    #連続数が偶数ならば
    if now%2 == 0:
      now = 1
      now_str = ls[i]
      continue
    else:
      #連続数が奇数ならば
      flag += 1
      break
#最終処理
if now% 2 == 0:
  flag += 0
else:
  flag += 1
if flag == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
def solve() :
    x, y = map(int, input().split())

    flag = False
    for i in range(0, x+1) :
        if i*4 + (x-i)*2 == y :
            flag = True
            break

    if flag :
        print("Yes")
    else :
        print("No")


if __name__ == "__main__":
    solve()

Measured memory_bytes: 61680
n = int(input())
a = list(map(int,(input().split())))
b = list(map(int,(input().split())))
c = list(map(int,(input().split())))

sum1 = sum(b)
tmpsum = 0
for i in range(len(c)):
  if(a[i+1] == a[i]+1):
    tmpsum += c[a[i]-1]

print(sum1+tmpsum)

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

string a,b;
vector<char> s,t;

main() {
    cin >> a >> b;
    int n=a.size(),m=b.size();
    rep(i,n) s.pb(a[i])
    rep(i,m) t.pb(b[i])
    sort(all(s));
    sort(rall(t));
    rep(i,min(n,m)) {
        if (s[i] < t[i]) {
            ct("Yes")
            return 0;
        } else if (s[i] > t[i]) {
            ct("No")
            return 0;
        }
    }
    if (n>=m) ct("No")
    else ct("Yes")

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n, k;
    char s[15];
    cin >> n >> s >> k;
    
    for (int i = 0; i < n; i++) {
        if (s[i] == s[k - 1]) cout << s[i];
        else cout << "*";
    }
    cout << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	int x,y,z;
	cin >> x >> y >> z;
	cout << z << " " << x << " "<< y;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

ll n, m, q;
vector<array<ll, 4>> abcd;

ll solve(vector<ll>& tmp){
    if(tmp.size() == n){ return 0; }

    ll last = 1;
    if(tmp.size()){
        last = tmp.back();
    }

    ll maxval = 0;
    for(ll x = last; x <= m; ++x){
        tmp.push_back(x);
        ll ret = 0;
        for(auto y : abcd){
            if(y.at(1) == tmp.size() - 1 &&
               tmp.at(y.at(1)) - tmp.at(y.at(0)) == y.at(2)){
                ret += y.at(3);
            }
        }
        ret += solve(tmp);
        maxval = max(ret, maxval);
        tmp.pop_back();
    }
    return maxval;
}

int main(){
    cin >> n >> m >> q;
    REP(i, q){
        ll ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        ai--; bi--;
        abcd.push_back({ai, bi, ci, di});
    }
    vector<ll> tmp;
    cout << solve(tmp) << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
//#include "lib/bigint2.h"

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ if(a>b) a=b;}


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll d, a;
	cin >>n >>d >>a;
	vector<pii> x(n);
	rep(i, n) cin >>x[i].first >>x[i].second;
	
	sort(all(x));
	ll ans = 0, cdg =0;
	priority_queue<pii, vector<pii>, greater<pii> > q;
	rep(i, n){
		ll h, ps; tie(ps, h) = x[i];
		while(!q.empty() && q.top().first < ps){
			cdg -= q.top().second;
			q.pop();
		}
		if(h - cdg <=0) continue;
		ll su = (h - cdg + a -1) /a;
		ans += su;
		cdg += a * su;
		q.emplace(ps + 2LL*d, a*su);
	}
	cout << ans <<"\n";
	return 0;
}


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

int main(){
  int a,b,c,d,i,j,array[4];
  string s;
  cin>>array[0]>>array[1]>>array[2];
  sort(array,array+3);
  cout<<abs(array[0]-array[1])+abs(array[1]-array[2])<<endl;
}

Measured memory_bytes: 256
a,b,q = map(int, input().split())
inf=10**18
s=[-inf]+[int(input()) for _ in range(a)]+[inf]
t=[-inf]+[int(input()) for _ in range(b)]+[inf]
x=[int(input()) for _ in range(q)]
from bisect import bisect_left,bisect_right
for i in range(q):
    idx_s=bisect_right(s,x[i])
    idx_t=bisect_right(t,x[i])
    ans=inf
    for ss in [s[idx_s-1],s[idx_s]]:
        for tt in [t[idx_t-1],t[idx_t]]:
            d1,d2=abs(ss-x[i])+abs(ss-tt),abs(tt-x[i])+abs(tt-ss)
            ans=min(ans,d1,d2)
    print(ans)

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

using namespace std;

typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	int n, tcnt = 0;
	cin >> s;
	n = sz(s);
	stack<int> stc;
	for(int i = 0; i < n; i++){
		if(s[i] == 'S')
			stc.push(i);
		else if(sz(stc))
			stc.pop();
		else
			tcnt++;
	}
	int scnt = sz(stc);
	cout << scnt + tcnt << endl;
	return 0;
}

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

using namespace std;

const int MAX_N = 1e2+10;
const int MAX_W = 1e4+10;

struct Item
{
	int v, w;
};

int N, W;
int dp[MAX_N][MAX_W];
Item items[MAX_N];

void solve() {
	for (int i = 0; i < N; ++i) {
		Item item = items[i];
		for (int w = 0; w <= W; ++w) {
			if (w < item.w) {
				dp[i+1][w] = dp[i][w];
			}
			else {
				dp[i+1][w] = max(dp[i][w], dp[i+1][w-item.w] + item.v);
			}
		}
	}
}


int main(int argc, char const *argv[])
{
	cin >> N >> W;
	for (int i = 0; i < N; ++i) {
		cin >> items[i].v >> items[i].w;
	}

	solve();

	cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 7020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int k = Integer.parseInt(chr[0]);
			int x = Integer.parseInt(chr[1]);
			 System.out.println(500*k>=x? "Yes" : "No");
		}
	}
}

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

void trace(int A[], int N){
    for(int i=0; i<N; i++){
        cout << A[i];
        if(i==(N-1)) cout << endl;
        else cout << " ";
    }
}

void insertionSort(int A[], int N){

    for(int i=1; i<N; i++){
        int v=A[i];
        int j=i-1;
        while(j>=0 and A[j]>v){
            A[j+1]=A[j];
            j--;
        }
    A[j+1]=v;
    trace(A, N);
    }
}

int main(void){
    int N; cin >> N;
    int A[N];
    for(int i=0; i<N; i++) cin >> A[i];

    trace(A,N);
    insertionSort(A, N);
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F(i,a,b) for(int i=a;i<=b;++i)
const int maxn=2e5+5;
int n,a[maxn];
LL ans=0;
int main()
{
	scanf("%d",&n);
	F(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	ans=a[n];
	if(n&1){
		int i,sum;
		for(i=n-1,sum=n-2;sum>1;--i,sum-=2)
		{
			ans+=2*a[i];
		}
		ans+=a[i];
	} else {
		int i,sum;
		for(i=n-1,sum=n-2;sum;--i,sum-=2)
		{
			ans+=2*a[i];
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4596
class RMQ
  INFINITY = 2**31 - 1
  def initialize(size)
    @index = 1
    @index *= 2 while @index < size
    @array = Array.new(@index * 2 - 1, INFINITY)
  end

  def find(x, y, k = 0, l = 0, r = @index)
    if r <= x || y <= l
      INFINITY
    elsif x <= l && r <= y
      @array[k]
    else
      ml = find(x, y, k * 2 + 1, l, (l + r) / 2)
      mr = find(x, y, k * 2 + 2, (l + r) / 2, r)
      [ml, mr].min
    end
  end

  def update(x, y)
    x += @index - 1
    @array[x] = y
    while x > 0
      x = (x - 1) / 2
      @array[x] = @array[(x * 2) + 1, 2].min
    end
  end
end

n, q = gets.split.map(&:to_i)
rmq = RMQ.new(n)
q.times do
  com, x, y = gets.split.map(&:to_i)
  com == 0 ? rmq.update(x, y) : puts(rmq.find(x, y + 1))
end



Measured memory_bytes: 8936
import java.util.Scanner;

public class Main {
    public static void main(String[] ar) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt(), b = sc.nextInt();
            if (a == 0 && b == 0)
                break;
            if(a>b) {
                a+=b;
                b=a-b;
                a-=b;
            }
            System.out.println(a+" "+b);
        }    
    }
}


Measured memory_bytes: 37240
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<long> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end(), greater<long>());
  vector<long> v;
  for(int i = 0; i < n; i++){
    if(a[i] == a[i + 1]){
      v.push_back(a[i]);
      i++;
    }
    if(v.size() == 2) break;
  }
  if(v.size() == 2) cout << v[0] * v[1] << endl;
  else cout << 0 << endl;
  return 0;
}


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

ll powmod(ll a, ll k, ll m) {
  if (k == 0) return 1;
  ll t = powmod(a, k / 2, m);
  t = (t * t) % m;
  if (k % 2 == 1) t = (t * a) % m;
  return t;
}

const ll mod = 1000000007;
int main() {
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll, ll>, pair<int, int>> vct;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zero++;
      continue;
    }
    ll g = gcd(a, b);
    a /= g, b /= g;
    if (b < 0) a = -a, b = -b;
    if (a > 0)
      vct[make_pair(a, b)].first++;
    else {
      ll tmp = -a;
      a = b, b = tmp;
      vct[make_pair(a, b)].second++;
    }
  }
  ll prod = 1;
  for(auto it : vct) {
    ll sum = powmod(2, it.second.first, mod) + powmod(2, it.second.second, mod) - 1;
    sum %= mod;
    prod = (prod * sum) % mod;
  }
  prod += zero - 1;
  if (prod < 0) prod += mod;
  prod %= mod;
  cout << prod << endl;
  return 0;
}


Measured memory_bytes: 15920
#include<stdio.h>
int main(){
  int a,b,c,d,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d%d%d",&b,&c,&d);
    b*=b;
    c*=c;
    d*=d;
    if(b==c+d){
      printf("YES\n");
    }
    else if(c==b+d){
      printf("YES\n");
    }
    else if(d==b+c){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 576
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int n;
int a[200010];
int dp[200010];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		int b=a[i];
		dp[b]=dp[b-1]+1;
		if(ans<dp[b]){
			ans=dp[b];
		}
	}
		
	cout<<n-ans<<endl;
	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
    ll n, k;
    cin >> n >> k;

    ll sho = n % k;
    cout << min(sho, abs(sho - k)) << endl;
}

int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

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

int main(){
    int n,k;
    cin >> n >> k;
    int ans=0;
    while(n!=0){
        n=n/k;
        ans+=1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            long X = sc.nextLong();
            long x = 100;
            for (int i = 0;; i++) {
                if (x >= X) {
                    System.out.println(i);
                    return;
                }

                x += x / 100;
            }
        }
    }
}


Measured memory_bytes: 27016
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define INF 1e9


class monster{
public:
  long long int atk, SpellCounter;
  monster(){}
  monster(long long int atk_, int spell_)
    :atk(atk_),
     SpellCounter(spell_)
  {}
};


int main(void){
  int n;
  cin >> n;

  long long int hero_h, hero_a, hero_d, hero_s;
  cin >> hero_h >> hero_a >> hero_d >> hero_s;
  long long int orig_h = hero_h;

  long long int sum = 0;
  long long int input_h, input_a, input_d, input_s;
  vector<pair<double, int> > rate;
  vector<monster> enemy;
  for(int i = 0; i < n; i++){
    cin >> input_h >> input_a >> input_d >> input_s;
    long long int attack = max(input_a - hero_d, 0LL);
    
    // ????????¬????????????????????£???????????????????????¬????????????????????£?????????
    if(input_s > hero_s){ hero_h -= attack; }


    long long int SpellCounter;
    // ????????????????????????????\´????????????????????¶??????
    if(hero_a <= input_d){
      if(attack > 0){
        cout << -1 << endl;
        return 0;
      }
      attack = 0;
      SpellCounter = 1;
    }
    else{
      sum += attack;
      SpellCounter = ((input_h - 1) / (hero_a - input_d)) + 1;
    }
    
    rate.push_back(make_pair(attack / (double)SpellCounter, enemy.size()));
    enemy.push_back(monster(attack, SpellCounter));  
  }
  sort(rate.begin(), rate.end());
  reverse(rate.begin(), rate.end());

  for(int i = 0; i < n; i++){
    long long int sc = enemy[rate[i].second].SpellCounter - 1;
    hero_h -= sc * sum;
    sum -= enemy[rate[i].second].atk;
    hero_h -= sum;
    if(hero_h <= 0){
      cout << -1 << endl;
      return 0;
    }
  }

  cout << orig_h - hero_h << endl;  
  return 0;
}

Measured memory_bytes: 4384
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
 
using namespace std ;
 
typedef tree<pair<pll,lli>,null_type,less<pair<pll,lli>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
#define MAXN 200000

int main () 
{
/////////////////////////////////////
    
 
/////////////////////////////////////  
	
	lli n;
	string s;
	cin>>n;
	cin>>s;

	lli cnt=0;
	loopl(i,2,n)
	{
		if(s[i-2]=='A' && s[i-1]=='B' && s[i]=='C') cnt++;
	}

	cout<<cnt;


}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ifor(n) for(int i=0;i<n;i++) 
#define jfor(n) for(int j=0;j<n;j++)
#define Ifor(n) for(int i=1;i<n;i++) 
#define Jfor(n) for(int j=1;j<n;j++)
const int inf=0x3f3f3f3f;
int main(){
   ll n,a,b;
   cin>>n>>a>>b;
   ll w=a+b;
   ll ans=n/w*a;
   n%=w;
   ans+=min(n,a);
   cout<<ans<<endl;
} 

Measured memory_bytes: 256
A = {}
def fibonacci(n):
    global A
    if n == 0 or n == 1:
        A[n] = 1
        return A[n]
    if n in A:
        return A[n]
    else:
        A[n] = fibonacci(n - 2) + fibonacci(n - 1)
        return A[n]

n = int(input())
print(fibonacci(n))


Measured memory_bytes: 5600
#include <algorithm>
#include <queue>
#include <iostream>
#include <vector>
int main(){
  int N;
  int M;
  std::cin>>N>>M;
  std::vector<std::pair <int, int> > vp;
  for(int i=0;i<N;++i){
    int a, b;
    std::cin>>a>>b;
    vp.push_back(std::make_pair(a, -b));
  }
  std::sort(vp.begin(), vp.end());
  
  std::priority_queue<int> pq;

  long long ret=0;
  int p=0;
  for(int i=1;i<=M;++i){
    while(p<vp.size() && vp[p].first<=i){
      pq.push(-vp[p].second);
      ++p;
    }
    if(pq.size()>0){
      ret=ret+pq.top();
      pq.pop();
    }
  }
  std::cout<<ret<<std::endl;
  return 0;
}


Measured memory_bytes: 1908
cnt = 0
n = int(input())
p_lis = []
p_lis = list(map(int,input().split()))
for i in range(1,len(p_lis)-1):
    if p_lis[i+1] > p_lis[i] > p_lis[i-1]:
        cnt += 1
    elif p_lis[i-1] > p_lis[i] > p_lis[i+1]:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=1e5+10,mod=1e9+7;
#define int LL
LL fast(LL x,LL p){
	LL ret=1;
	for (;p;p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
int f[M],s[M],si[M],n;
bool vis[M];
LL Fd(int x){
	if (f[x]==x) return x;
	return f[x]=Fd(f[x]);
}
int dp[M],a[M],ct,cs;
signed main(){
	n=read();
	F(i,1,n) f[i]=i; 
	F(i,1,n){
		a[i]=read();
		if (a[i]!=-1) {
			int u=Fd(i),v=Fd(a[i]);
			if (u!=v) f[u]=v; 
		}
	}
	F(i,1,n){
		if (!s[Fd(i)]) ct++; 
		s[Fd(i)]++;
		if (a[i]==-1) si[Fd(i)]++,cs++;
	}
	int block=ct-cs;
	LL tot=fast(n-1,cs),ans=1ll*tot*n%mod,tbl=1ll*block*tot%mod,sv=0; 
	dp[0]=1;
	F(i,1,n){
		if (vis[Fd(i)] || !si[Fd(i)]) continue;
		int x=Fd(i); vis[x]=1; sv=(sv+(s[x]-1)*fast(n-1,cs-1))%mod;
		DF(i,n,1){
			dp[i]=(dp[i]+1ll*dp[i-1]*s[x])%mod;
		}
	}
	LL fac=1;
	F(i,2,cs){
		fac=1ll*fac*(i-1)%mod;
		sv=(sv+1ll*dp[i]*fac%mod*fast(n-1,cs-i))%mod; 
	}
//	cout<<tot<<" "<<sv<<" "<<tbl<<"   sb250\n";
	cout<<(ans-tbl-sv+mod)%mod<<"\n";
	return 0;
}




Measured memory_bytes: 3864
#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

bool existWord(string ring, string str) {
	int rlength = ring.length();
	int slength = str.length();

	for (int i = 0; i <= rlength - slength; i++) {
		if (ring.substr(i, slength) == str)return true;
	}
	return false;
}



int main(){
	string ring;
	string str;

	getline(cin, ring);
	getline(cin, str);

	ring = ring + ring;

	if (existWord(ring, str)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	cout << endl;



	//system("pause");
    return 0;
}




Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * fh;
}

int res = 0, cnt = 0;

typedef long long ll;
long long a, b;
int main () {
#ifdef zjp_shadow
	freopen ("d.in", "r", stdin);
	freopen ("d.out", "w", stdout);
#endif
	int cases = read();
	while (cases --) {
		cin >> a >> b;
		ll mult = a * b, res = sqrt(mult), ans = res * 2 - 1;
		if (res * res == mult && (a ^ b)) -- ans;
		if (res * (res + 1) >= mult) -- ans;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 384