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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


void fall(vector<vector<int>>& board, int H, int W){
    REP(n,H){
        for(int i=H; i>=1; i--){
            REP(j,W){
                if(board[i][j]==0){
                    board[i][j]=board[i-1][j];
                    board[i-1][j]=0;
                }
            }
        }
    }
}

int main() {
    
    int H,W,K; cin >> H >> W >> K;

    vector<vector<int>> board_origin(H+1, vector<int>(W, 0));
    vector<vector<int>> board(H+1, vector<int>(W, 0));
    FOR(i,1,H+1){
        string S;
        cin >> S;
        REP(j,W){
            
            board_origin[i][j] = S[j] - '0';
        }
    }

    int ans_max = 0;

    FOR(i,1,H+1){
        REP(j,W){//はじめに消すモノを全探索

            FOR(x,0,H+1){
                REP(y,W){
                    board[x][y] = board_origin[x][y];
                }
            }

            board[i][j] = 0;
            fall(board,H,W);

            int counter = 1;
            int ans = 0;
            int ans_before = 0;


            while(1){
                FOR(i,1,H+1){
                    int num = 0;
                    int count = 0;
                    REP(j,W){
                        if(num == board[i][j]){
                            count++;
                            if(count >= K && j==W-1){
                                ans += pow(2,counter-1) * count * num;
                                for(int k= j; k>=j-count+1; k--){
                                    board[i][k] = 0;
                                }
                            }
                        }else{
                            if(count >= K){
                                ans += pow(2,counter-1) * count * num;
                                for(int k= j-1; k>=j-count; k--){
                                    board[i][k] = 0;
                                }
                            }
                            num = board[i][j];
                            count = 1;
                        }
                    }  
                }
                fall(board,H,W);

                if(ans == ans_before){
                    ans_max = max(ans_max, ans);
                    break;
                }
                ans_before = ans;
                counter ++;

                // FOR(i,1,H+1){
                //     REP(j,5){
                //         cout << board[i][j] << " ";
                //     }
                //     cout << endl;
                // }
            }
        }
    }
    cout << ans_max << endl;
    return 0;
}

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

int main(void)
{

  int x[10], i, j;


  for (i = 0; i < 5; i++) scanf("%d", &x[i]);

  for  (i = 0; i < 5; i++) if (x[i] == 0) j = i + 1;

  printf("%d\n", j);

  return 0;

}


Measured memory_bytes: 1672
k, n = list(map(int, input().split(' ')))
an = list(map(int, input().split(' ')))

df = [None] * n

for i in range(n - 1):
    df[i] = an[i + 1] - an[i]

df[n - 1] = k - an[n - 1] + an[0]

print(sum(df) - max(df))


Measured memory_bytes: 77788
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <utility>

using namespace std;

template<typename T>
T partition(T ar[], int p, int r){
    T pivot = ar[r];
    int i = p - 1;
    for (int j = p; j <= r - 1; j++) {
        if(ar[j] <= pivot){
            i++;
            swap(ar[i], ar[j]);
        }
    }
    i++;
    swap(ar[i], ar[r]);
    return i;
}

int main(int argc, char const* argv[])
{
    int n, ar[100000];

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &ar[i]);
    }

    int q = partition(ar, 0, n-1);

    for (int i = 0; i < n; i++) {
        if(i == q) putchar('[');
        printf("%d", ar[i]);
        if(i == q) putchar(']');
        if(i != n-1) putchar(' ');
    }
    putchar('\n');

    return 0;
}

Measured memory_bytes: 2964
#include <iostream>

using namespace std;

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}


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

int main (void) {
    int n_switch, n_bulb, i, j;
    scanf("%d%d", &n_switch, &n_bulb);
    /* number of connected switch to a bulb */
    int n_con_switch;
    /* connected switch No. */
    int switch_no;
    /* switch connection to bulb No.
     *     if switch No.1 is connected to bulb No.1 and 2,
     *     then switch_con[0] = 11b (= 3 in decimal) */
    int switch_con[n_switch];
    memset(switch_con, 0, n_switch*sizeof(int));
    /* for all bulb */
    for ( i=0; i<n_bulb; i++ ) {
        scanf("%d", &n_con_switch);
        /* for all connected switch */
        for ( j=0; j<n_con_switch; j++ ) {
            scanf("%d", &switch_no);
            switch_no--; /* switch index start from 0 */
            /* bulb No. <i> is connected to switch No. <switch_no> */
            switch_con[switch_no] |= (1 << i);
        }
    }
    int p=0, tmp_p;
    for ( i=0; i<n_bulb; i++ ) {
        scanf("%d", &tmp_p);
        p |= (tmp_p << i);
    }

    int ans=0, bulb_st;
    /* for all switch pattern */
    for ( i=0; i<(1<<n_switch); i++ ) {
        bulb_st = 0;
        /* for all switch */
        for ( j=0; j<n_switch; j++ ) {
            /* if a switch on,
             * condition of the bulb connected to the switch is changed.
             *     bulb on  -> bulb off
             *     bulb off -> bulb on */
            if ( i >> j & 1 )
                bulb_st ^= switch_con[j];
        }
        if ( bulb_st == p )
            ans++;
    }

    printf("%d\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

struct Sushi
{
    int kind;
    u_int64_t score;
};

bool isPicked[100'000];
Sushi sushi[100'000];

int main()
{
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> sushi[i].kind >> sushi[i].score;
        sushi[i].kind--;

        isPicked[i] = false;
    }

    sort(sushi, sushi + N, [](const auto &lh, const auto &rh) {
        return lh.score > rh.score;
    });

    u_int64_t kinds = 0;
    u_int64_t base = 0;
    auto cmp = [](const Sushi &lh, const Sushi &rh) {
        return lh.score > rh.score;
    };
    auto rcmp = [](const Sushi &lh, const Sushi &rh) {
        return lh.score < rh.score;
    };
    priority_queue<Sushi, vector<Sushi>, decltype(cmp)> cands(cmp);
    priority_queue<Sushi, vector<Sushi>, decltype(rcmp)> noCands(rcmp);

    for (int i = 0; i < N; i++)
    {
        if (i < K)
        {
            if (!isPicked[sushi[i].kind])
            {
                kinds++;
            }
            else
            {
                cands.push(sushi[i]);
            }
            base += sushi[i].score;
            isPicked[sushi[i].kind] = true;
            continue;
        }

        noCands.push(sushi[i]);
    }

    u_int64_t totalMax = base + kinds * kinds;
    while (!cands.empty())
    {
        Sushi nextCand;
        bool found = false;

        while (!noCands.empty())
        {
            Sushi top = noCands.top();
            noCands.pop();
            if (!isPicked[top.kind])
            {
                nextCand = top;
                found = true;
                break;
            }
        }

        if (!found)
        {
            break;
        }

        Sushi worstCand = cands.top();
        cands.pop();
        base -= worstCand.score;
        base += nextCand.score;
        kinds++;
        isPicked[nextCand.kind] = true;

        u_int64_t total = base + kinds * kinds;
        totalMax = max(totalMax, total);
    }

    cout << totalMax << endl;
}


Measured memory_bytes: 4212
n=int(input())
m=n
lst=[]
while n%2==0:
    lst.append(2)
    n//=2
f=3
while f*f<=n:
    if n%f==0:
        lst.append(f)
        n//=f
    else:
        f+=2
if n!=1:
    lst.append(n)
print("{}:".format(m),*lst)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define ll long long
#define ff first 
#define ss second
#define MP make_pair
#define PB push_back
#define pri 1000000007
using namespace std;

int main() {
	
	string k;
	cin>>k;
	
	ll d;
	cin>>d;
	
	ll z=k.length();
	ll dp[z+1][d]={0};
	
	dp[z][0]=1;
	for(ll i=z-1;i>=0;i--){

		for(ll ze=0;ze<=9;ze++)
		  {
		  	
		  	for(ll za=0;za<d;za++)
		  	dp[i][(za+ze)%d]=(dp[i][(za+ze)%d]+dp[i+1][za])%pri;
		  	
		  }              
		
	                      }
		
						  
	ll za=0,ans=0;
	
	for(ll i=0;i<z;i++){
		      ll e=k[i]-'0';
	
		for(ll z=0;z<e;z++){
			ans=(ans+dp[i+1][(d-(za+z)%d)%d])%pri;}
		
		za=(za+e)%d;
						}
	if(za%d==0)ans++;	
		
	cout<<(ans-1+pri)%pri<<endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <string>

int main(){
    std::string W;
    std::cin >> W;
    int size = W.size();
    bool check =false;
    int counter = 0;
    for(int i = 0; i < size; i++){
        for(int j = 0; j < size; j++){
            if(W[i] == W[j]){
                counter++;
                if(counter%2 == 0){
                    check = true;
                }
                else{
                    check = false;
                }
            }
        }
        if(!check){
            break;
        }
    }
    if(!check){
        std::cout << "No";
    }
    else{
        std::cout << "Yes";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    ll n, m;
    cin >> n >> m;
    ll ans;
    if (n == 1 and m == 1) {
        ans = 1;
    } else if (n == 1 or m == 1) {
        ans = max(n, m) - 2;
    } else {
        ans = n * m - (n + m - 2) * 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
K = int(input())


cand = [[str(i)] for i in range(10)]


k = 9
end = 0

if K <= 9:
    print(K)
else:
    for j in range(10000000):
        new_cand = [[] for i in range(10)]
        for top in range(10):
            if top == 0:
                new = []
                new += [str(top) + rest for rest in cand[0]]
                new += [str(top) + rest for rest in cand[1]]
                new_cand[top] = new
            elif top != 0 and top != 9:
                new = []
                new += [str(top) + rest for rest in cand[top-1]]
                new += [str(top) + rest for rest in cand[top]]
                new += [str(top) + rest for rest in cand[top+1]]
                new_cand[top] = new
                if k + len(new) >= K:
                    print(new[K-k-1])
                    end = 1
                    break
                k += len(new)
            elif top == 9:
                new = []
                new += [str(top) + rest for rest in cand[8]]
                new += [str(top) + rest for rest in cand[9]]
                new_cand[top] = new
                if k + len(new) >= K:
                    print(new[K-k-1])
                    end = 1
                    break
                k += len(new)
        cand = new_cand
        if end == 1:
            break


Measured memory_bytes: 10228
#include <iostream>
#include <algorithm>
#include <climits>
#define ll long long

using namespace std;

const ll NMAX = 105, WMAX = 1e5 + 15;
struct OBJECT {
    ll v, w;
} v[NMAX];
ll matrix[NMAX][WMAX];

ll n, w;

ll solve(ll pos, ll weight) {
    if(weight > w)
        return INT_MIN;
    if(pos > n)
        return 0;
    if(matrix[pos][weight] != 0)
        return matrix[pos][weight];
    ll val;
    val = max(solve(pos + 1, weight + v[pos].w) + v[pos].v, solve(pos + 1, weight));
    matrix[pos][weight] = val;
    return val;
}

int main()
{
    cin >> n >> w;
    for(ll i = 1; i <= n; i++) {
        cin >> v[i].w >> v[i].v;
    }
    cout << solve(1, 0);
    return 0;
}


Measured memory_bytes: 75624
i = list(map(int, input().split()))
A = i[0]
B = i[1]

a = 0
s = 0
m = 0

def add(a, b):
  return a + b

def sub(a, b):
  return a - b

def mul(a, b):
  return a * b

a = add(A, B)
s = sub(A, B)
m = mul(A, B)

print(max(a, s, m))


Measured memory_bytes: 3060
#ABC085C
N,Y=map(int,input().split())
d=(Y-N*1000)//1000 #if all 1000yen
if d%9==0 and d//9>=0 and N-d//9>=0:
	print(d//9,0,N-d//9)
	exit()
for n in range(N):
	if d%4==0 and d//4>=0 and N-n-d//4>=0:
		print(n,d//4,N-n-d//4)
		exit()
	d-=9
print('-1 -1 -1')

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val N = nextInt()
    val L = listOfInt().sorted().toIntArray()
    var ans = 0
    for (a in 0 until N - 2) {
        for (b in a + 1 until N - 1) {
            for (k in b + 1 until N) {
                if (L[a] + L[b] > L[k]) ans += 1
                else break
            }
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)


Measured memory_bytes: 48380
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll n,x;
ll A[N+5];
int main()
{
  finp;
  cin>>n>>x;
  afor(i,1,n)cin>>A[i];
  ll ans = 0;
  afor(i,2,n)
  {
  	ll diff = max(0LL,(A[i] + A[i-1]) - x);
  	ans+=diff;
  	ll val = min(diff,A[i]);
  	A[i]-= val;
  	diff-=val;
  	A[i-1]-=diff;

  }
  cout<<ans;
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  int x,n;
  cin>>x>>n;
  vector<int> list(200);
 rep(i,n){
   int p;
   cin>>p;
   list[p+1]++;
 }
  int ans1=inf;
  int ans2=inf;
  rep(j,100){
    if(list[x-j+1]==0){
      ans1=x-j;
      break;
    }
  }
   rep(l,100){
    if(list[x+l+1]==0){
      ans2=x+l;
      break;
    }
  }
  if(abs(x-ans1)<=abs(ans2-x)) cout<<ans1<<endl;
else  cout<<ans2<<endl;
return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (ll i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (ll i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    int n;
    cin>>n;
    string st = to_string(n);
    for (auto elem : st)
    {
        if (elem == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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


namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine()
                .Select(x => int.Parse(x.ToString()))
                .ToList();
            str.RemoveAll(x => x == 0);
            Console.WriteLine(str.Count);
        }
    }

}

Measured memory_bytes: 11348
/*
 * Author       : YangDavid
 * Created Time : 2019年07月15日 星期一 17时10分20秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 555555, MOD = 998244353;
int muln(int x, int y) { return 1LL * x * y % MOD; }
int qpow(int x, int y) {
    int ret = 1;
    for(; y; y >>= 1, x = muln(x, x))
        if(y & 1) ret = muln(ret, x);
    return ret;
}
int mo(int x) {
    if(x < 0) return x + MOD;
    if(x >= MOD) return x - MOD;
    return x;
}
int fac[maxn], ifac[maxn];
int C(int n, int m) {
    if(n < m) return 0;
    return muln(fac[n], muln(ifac[m], ifac[n - m]));
}

int main() {
    fac[0] = ifac[0] = 1;
    for(int i = 1; i <= 555000; ++i) {
        fac[i] = muln(fac[i - 1], i);
        ifac[i] = qpow(fac[i], MOD - 2);
    }

    int n, m, Min, ans = 0;
    scanf("%d%d", &n, &m);
    Min = min(n, m);
    for(int k = 0; k <= Min; ++k) {
        ans = mo(ans + ((k&1)?-1:1) * muln(C(n,k),muln(C(m,k),muln(fac[k],muln(qpow(m+1,n-k),qpow(n+1,m-k))))));
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4608
#include<stdio.h>

int main(){
    int N, i;
    char c;
    scanf("%d", &N);
    for(i=0;i<N;i++){
        scanf("%c", &c);
        if(c == 'Y'){
            printf("Four");
            return 0;
        }
    }
    printf("Three");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main () {

    int n;
    scanf("%d", &n);

    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        b[i] = a[i];
    }

    sort(b.begin(), b.end());
    int x = b[n/2 - 1], y = b[n/2];

    for (int i = 0; i < n; i++) {
        printf("%d\n", (a[i] < b[n/2])? y : x);
    }

    return 0;
}

Measured memory_bytes: 3712
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

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

	cin >> N;
	string s;
	cin >> s;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		if (s[i] == '#')v[i]++;
		if (i)v[i] += v[i - 1];
	}
	int ans = N - v.back();
	ans = min(ans, v.back());
	for (int i = 1; i < N; i++) {
		ans = min(ans, v[i - 1] + ((int)N - i) - (v.back() - v[i - 1]));
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1428
#include <stdio.h>
#include <string.h>


int main()
{
	int n,i,money = 100000,a;
	scanf("%d",&n);
	for(i = 0; i < n; i++){
		money = money * 1.05;
		a = money % 1000;
		if(a != 0){
		money = money +1000;
		money = money - a;
		}
	}
	printf("%d\n",money);
	return 0;
}

Measured memory_bytes: 592
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
a=~~input[0]
b=~~input[1]
	console.log(a<9&&b<9?"Yay!":":(");
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, A, B;
    cin >> N >> A >> B;
    ll res = 0;

    res += (N/(A+B)) * A;

    res += min(N%(A+B), A);

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200001],n,k,m,ans,i,j,g;
int main(){
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&m);
		a[m]++;
	}
	sort(a+1,a+n+1);
	for(i=1;i<=n-k;i++)
		ans+=a[i];
	printf("%d",ans);
	return 0;
}

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

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    
    map<char, int> cnt;
    for (char c: s)
        cnt[c]++;
    
    li answer = 0;
    for (auto it: cnt)
        answer += it.second * (li)(s.length() - it.second);
    answer /= 2;
    answer++;
    
    cout << answer << endl;
    
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

class UnionFindTree {
private:
    vector<int> parent;
    vector<int> count;
public:
    UnionFindTree(int n) : parent(n), count(n, 1) {
        // 最初は全てを根として初期化
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int get_root(const int x) {
        // データxが属する木の根を取得する
        if (parent[x] == x) return x;
        // 取得したものは直接木の根をつなぐ(経路圧縮)
        return parent[x] = get_root(parent[x]);
    }

    void unite(const int x, const int y) {
        // xとyの木を併合する
        int rx = get_root(x);
        int ry = get_root(y);
        // 元から同じ木に属している場合は何もしない
        if (rx == ry) return;
        // xの属する木をyの属する木につける
        parent[rx] = ry;
        count[ry] += count[rx];
        count[rx] = 0;
    }

    bool is_same_root(const int x, const int y) {
        return get_root(x) == get_root(y);
    }

    int get_size(const int x) {
        return count[get_root(x)];
    }

    void print() {
        for(auto elm : parent) cout << elm << " ";
        cout << endl;
        for(auto elm : count) cout << elm << " ";
        cout << endl;
    }
};

int main(){
    int n, m;
    cin >> n >> m;

    UnionFindTree tree(n);

    vector<int> p(n);
    map<int, int> op;
    for (auto i = 0; i < n; i++) {
        cin >> p[i]; p[i]--;
    }
    for (auto i = 0; i < m; i++) {
        int x, y; cin >> x >> y; x--; y--;
        tree.unite(x, y);
    }

    int ans = 0;
    for (auto i = 0; i < n; i++) {
        if(tree.is_same_root(p[i], i)) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4584
W, H, N = map(int, input().split())
xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    xmin = max(xmin, x)
  if a == 2:
    xmax = min(xmax, x)
  if a == 3:
    ymin = max(ymin, y)
  if a == 4:
    ymax = min(ymax, y)
if xmax <= xmin or ymax <= ymin:
  print(0)
else:
  print((xmax-xmin)*(ymax-ymin))
  

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
	static char s[5];

	scanf("%s", s);
	printf((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
const int mod = 1000000007;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
int main(){
  string s;
  cin >> s;
  sort(all(s));
  cout << (s == "abc" ? "Yes":"No") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = Integer.parseInt(in.next());
        int b = Integer.parseInt(in.next());
        System.out.println(gcd(a,b));

        in.close();
    }
}


Measured memory_bytes: 26048
# -*- coding: utf-8 -*-
dishes = [0]*5
last_order = 0
lo_mod = 10
for i in range(5):
    dishes[i] = int(input())
    tmp_mod = dishes[i] % 10
#    print(tmp_mod)
    if (tmp_mod != 0) & (tmp_mod < lo_mod):
        last_order = i
        lo_mod = tmp_mod
count = 0
for i in range(5):
    if i == last_order:
        count += dishes[i]
    else:
        mod = dishes[i] % 10
        if mod != 0:
            count += dishes[i] // 10 * 10 + 10
        else:
            count += dishes[i]
print(count)

Measured memory_bytes: 3064
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::collections::VecDeque;

fn main() {
    let (N, M) = get!(usize, usize);
    let (u, v): (Vec<_>, Vec<_>) = get!(usize, usize; M).into_iter().unzip();
    let (S, T) = get!(usize, usize);

    // 何歩目かを含めた状態グラフを作成し、BFSにより解を求める
    let mut G = vec!(vec!(); 3 * N + 1);
    for (x, y) in u.into_iter().zip(v.into_iter()) {
        G[x].push((y + N, 0));
        G[x + N].push((y + 2 * N, 0));
        G[x + 2 * N].push((y, 1));
    }
    let mut q = VecDeque::new();
    let mut dp = vec!(-1; 3 * N + 1);
    q.push_back(S);
    dp[S] = 0;
    while !q.is_empty() {
        let i = q.pop_front().unwrap();
        for &(x, w) in G[i].iter() {
            if dp[x] == -1 {
                q.push_back(x);
                dp[x] = dp[i] + w;
            }
        }
    }
    let ans = dp[T];

    println!("{}", ans);
}


Measured memory_bytes: 35036
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n,tmp) vector<tmp> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,10e9));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);

int n;

signed main(){
    int h;
    cin >> h >> n;
    Vec(a,n,P);
    REP(i,n){
        int x,y;
        cin >> x >> y;
        a[i] = P(x,y);
    }
    twovec(dp,n,h+1);
    P p = a[0];
    int cnt1 = p.first;
    int cnt2 = p.second;
    while(true){
        if(cnt1 >= h){
            dp[0][h] = cnt2;
            break;
        }
        dp[0][cnt1] = cnt2;
        cnt1 += p.first;
        cnt2 += p.second;
    }
    dp[0][0] = 0;
    FOR(i,1,n){
        p = a[i];
        /*
        if(p.first >= h){
            dp[i][h] = min(dp[i-1][h],p.first);
            continue;
        }
        */
        //dp[i][p.first] = min(dp[i-1][p.first],p.second);
        REP(j,h+1){
            if(dp[i-1][j] == 10e9 && dp[i][j] == 10e9) continue;
            dp[i][j] = min(dp[i-1][j],dp[i][j]);
            int tmp = j + p.first;
            if(tmp>=h) tmp = h;
            dp[i][tmp] = min(dp[i][tmp],dp[i][j] + p.second);
        }
    }
    /*
    REP(i,n){
        Debug(dp[i]);
    }
    */
    print(dp[n-1][h]);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 78464
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k,c = LI()
s = input()

cnt = 0
i = n-1
d = defaultdict(int)
tmp = k
while i >= 0:
    if s[i] == 'o':
        cnt += 1
        d[i] = tmp
        tmp -= 1
        i -= c
    i -= 1
i = 0
f = defaultdict(int)
tmp = 1
while i < n:
    if s[i] == 'o':
        f[i] = tmp
        tmp += 1
        i += c
    i += 1
for i,j in sorted(f.items()):
    if j == d[i]:
        print(i+1)


     



Measured memory_bytes: 85716
import numpy as np


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))
    pow_2_k = 1
    ans = 0
    for k in range(30):
        MA = A % (2 * pow_2_k)
        MB = B % (2 * pow_2_k)
        MB.sort()
        # [2**k, 2 * (2**k)) か [3 * (2**k), 4 * (2**k)) の中に入るとk-bit目が1。
        # この a + b の数をカウントする。
        # → [2**k - a, 2 * (2**k) - a) か [3 * (2**k) - a, 4 * (2**k) - a) の中に入る b の数をカウント。
        cnt = 0
        indices_1 = np.searchsorted(MB, pow_2_k - MA, side='left')
        indices_2 = np.searchsorted(MB, 2 * pow_2_k - MA, side='left')
        indices_3 = np.searchsorted(MB, 3 * pow_2_k - MA, side='left')
        cnt += ((N - indices_1) - (N - indices_2) + (N - indices_3)).sum()
        if cnt % 2 == 1:
            ans += pow_2_k
        pow_2_k *= 2
    print(ans)


if __name__ == '__main__':
    main()

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

const ll INF = 1LL << 60;

int main() {
    ll x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  int ans = 0;
  rep(i, N) ans += a[i] - 1;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import static java.lang.Integer.parseInt;

/**
 * ICPC Calculator
 */
public class Main {

	static final char NOOP = ' ';
	static final char PLUS = '+';
	static final char MULTI = '*';

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		Main main = new Main();

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			Exp exp = main.new Exp(null, -1, PLUS);
			Exp parent = exp;

			for (int i = 0; i < n; i++) {
				line = br.readLine();

				int lv = 0;
				for (char c : line.toCharArray()) {
					if (c == '.') {
						lv++;
					} else {
						while (parent.lv >= lv) {
							parent = parent.parent;
						}
						Exp sub = main.new Exp(parent, lv, c);
						parent.exps.add(sub);
						if (c == PLUS || c == MULTI) parent = sub;
					}
				}
			}
			System.out.println(exp.value());
		} //end while
	} //end main

	class Exp {
		int lv;
		char op;
		int value;
		//
		Exp parent;
		List<Exp> exps;

		Exp(Exp parent, int lv, char c) {
			this.parent = parent;
			this.lv = lv;
			if (c != PLUS && c != MULTI) {
				this.op = NOOP;
				this.value = c - '0';
			} else {
				this.op = c;
				exps = new ArrayList<Exp>();
			}
		}

		int value() {
			if (op == PLUS) {
				value = 0;
				for (Exp exp : exps) value += exp.value();
			} else if (op == MULTI) {
				value = 1;
				for (Exp exp : exps) value *= exp.value();
			}
			return value;
		}
	}
}

Measured memory_bytes: 24820
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] res = new int[N+1];
		for (int i = 0; i < N-1; i++) {
			int tmp = sc.nextInt();
			res[tmp]++;
		}
		for (int i = 1; i < res.length; i++) {
			System.out.println(res[i]);
		}
	}
}

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

using namespace std;

bool cmp(pair<int,int>A, pair<int,int>B){
    if(A.second == B.second)
       return  A.first < B.first;
    return A.second < B.second;
}
int main(){
    int n, m;
    vector < pair<int,int> > v(m);
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(),v.end(), cmp);
    int ans = 1;
    int cur = v[0].second;
    for (int i = 1; i < m; i++){
        if (v[i].first >= cur){
            ans++;
            cur = v[i].second;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
int MOD=1000000000+7;
int INF=1e6;
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int r,c,n;
    cin>>r>>c>>n;
    vector<pair<int,int>> v;
    rep(i,n){
        int x1,y1,x2,y2;
      cin>>x1>>y1>>x2>>y2;
        if((x1==0||x1==r||y1==0||y1==c)&&(x2==0||x2==r||y2==0||y2==c)){
            pair<int,int> p;
            if(y1==0||x1==r){
                p.first=x1+y1;
                p.second=i;
            }
            else {
                p.first=(r+c)*2-x1-y1;
                p.second=i;
                
            }
            v.push_back(p);
            if(y2==0||x2==r){
                p.first=x2+y2;
                p.second=i;
            }
            else {
                p.first=(r+c)*2-x2-y2;
                p.second=i;
            }
            v.push_back(p);
        }
    }
    sort(v.begin(),v.end());
    deque<int> d;
    bool flag[120000]={};
    rep(i,v.size()){
        if(!flag[v[i].second]){
            flag[v[i].second]=true;
            d.push_front(v[i].second);
        }
        else if(d.front()!=v[i].second){
            cout<<"NO";
            return 0;
        }
        else {d.pop_front(); }
    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using ll = long long;
const ll MOD=1e9+7;
const long long INF = 1LL<<60;

int main() {
    int a,b,c;
    cin >> a >> b >> c;

    if (a==b && a!=c){
        cout << "Yes" << endl;
    }else if (a==c && a!=b){
        cout << "Yes" << endl;
    }else if (b==c && b!=a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main() { 
    int n;
    cin >> n;
    vector<int> a(n);
    for(int& x : a) {
        cin >> x;
    }
    int res = 0;
    for(int i = 1; i < n - 1; ++i) {
        vector<int> v = {a[i - 1], a[i], a[i + 1]};
        sort(v.begin(), v.end());
        if(a[i] == v[1]) ++res;
    }
    cout << res << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	vector<int> v(5);
	for (int i = 0; i < 5; i++)cin >> v[i];
	for (int i = 0; i < 5; i++)if (v[i] == 0) {cout << i + 1; return ;}


}

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

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3652
N = int(input())
a = []
b = []

for i in range(N):

    an , bn = map(int,input().split())

    a.append(an)
    b.append(bn)

a.sort()
b.sort()

a.append(1000000)
b.append(1000000)

lis = [0]

for i in range(N+1):

    i += 1
    now = lis[i - 1]

    while a[0] == i:

        now += 1
        del a[0]

    while b[0] == i-1:

        now -= 1
        del b[0]

    lis.append(now)

ans = 0
#print (lis)
for i in range(len(lis)):

    if i <= lis[i]+1 and ans < i:
        ans = i

print (ans - 1)
        



Measured memory_bytes: 14292
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int main(){
int n;
cin>>n;
cout<<n*n*n<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <math.h>
using namespace std;


int main()
{
	string s;
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		cout << "Bad" << endl;
	} else {
		cout << "Good" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    @lru_cache(None)
    def f(i, j):
        if i < 0 or j < 0:
            return -INF
        if i == 0:
            return -INF
        if abs(j - i // 2 - 1) >= 2:
            return -INF
        if j == 0:
            return 0
        if j == 1:
            return max(A[:i])
        return max(A[i - 1] + f(i - 2, j - 1), f(i - 1, j))

    print(f(N, math.floor(N / 2)))


if __name__ == "__main__":
    main()

    

Measured memory_bytes: 263600
#include<bits/stdc++.h>
using namespace std;
int a[35];

int main(){
	signed long long n,k,i;
	cin>>n>>k,i=0;
	
	while(n!=0){
		a[i]=n%k;
		n/=k,i++;
	}
	
	cout<<i;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N, M;
list<int>edge[5001];
int num[5001];
queue<int>Q;
bool flag;
bool used[5001];

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	for (int i = 0; i < N; i++) {

	}
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		num[b]++;
	}
	for (int i = 1; i <= N; i++) {
		if (!num[i] && !used[i])Q.push(i);
		while (!Q.empty()) {
			for (auto j : edge[Q.front()]) {
				num[j]--;
				if (!num[j])Q.push(j);
			}
			cout << Q.front() << endl;
			used[Q.front()] = true;
			Q.pop();
			if (Q.size() > 1)flag = true;
		}
	}
	cout << flag << endl;
	return 0;
}

Measured memory_bytes: 6320
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    char S[107],T[107];
    cin >> S >> T;
    sort(S,S+strlen(S));
    sort(T,T+strlen(T));
    reverse(T,T+strlen(T));
    cout << (strcmp(S,T)<0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a; cin >> n >> a;
	if (n + a > 0) {
		cout << 1 << endl;
	}
	if (n + a == 0) {
		cout << 0 << endl;
	}
	if (n + a < 0) {
		cout << -1 << endl;
	}
}


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

void reconstruct(int pb, int pe, int ib, int ie, int* left, int* right, int* preorder, int* inorder) {
    if (pe != pb) {
        for (int i=ib; i<=ie; i++) {
            if (inorder[i] == preorder[pb]) {
                if (i==ib) {
                    left[preorder[pb]] = -1;
                } else {
                    left[preorder[pb]] = preorder[pb+1];
                    reconstruct(pb+1, pb+i-ib, ib, i-1, left, right, preorder, inorder);
                }
                if (i==ie) {
                    right[preorder[pb]] = -1;
                } else {
                    right[preorder[pb]] = preorder[pb+1+i-ib];
                    reconstruct(pb+i+1-ib, pe, i+1, ie, left, right, preorder, inorder);
                }
            }
        }
    } else {
        left[preorder[pb]] = -1;
        right[preorder[pb]] = -1;
    }
}

void postorder(int root, int id, int* left, int* right) {
    if (left[id] >= 0) {
        postorder(root, left[id], left, right);
    }
    if (right[id] >= 0) {
        postorder(root, right[id], left, right);
    }
    std::cout << id;
    if (id != root) {
        std::cout << " ";
    }
}

int main() {
    int n;
    int left[41], right[41], preorder[41], inorder[41];
    std::cin >> n;
    
    for (int i=0; i<n; i++) {
        std::cin >> preorder[i];
    }
    for (int i=0; i<n; i++) {
        std::cin >> inorder[i];
    }

    reconstruct(0, n-1, 0, n-1, left, right, preorder, inorder);

    postorder(preorder[0], preorder[0], left, right);
    std::cout << "\n";

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a<b)cout << 0<<endl;
    else cout<< 10<<endl;
    return 0;
}



Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

S = input()

print("No" if (S == "AAA" or S == "BBB") else "Yes")


Measured memory_bytes: 43376
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = (int) Math.floor(a/3600);
        if((a - 3600*b) > 0){
            int c = (int)Math.floor((a-3600*b)/60);
            if(a-3600*b- c*60 > 0){
                int d = a-3600*b - c*60;
                System.out.println(b + ":" + c + ":" + d);
            }else{
                System.out.println(b + ":" + c + ":" + 0);
            }

        }else{
            System.out.println(b + ":" + 0 + ":" + 0);
        }

    }
}



Measured memory_bytes: 26340