akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<utility>
using namespace std;

void bubble_sort(vector<pair<char, int> >& c){
    bool flag = true;
    for (int i = c.size() - 1; flag; i--) {
        flag = false;
        for (int j = 0; j < i; j++) {
            if (c[j].second > c[j+1].second) {
                swap(c[j], c[j+1]);
                flag = true;
            }
        }
    }
}
void selection_sort(vector<pair<char, int> >& c) {
    for (int i = 0; i < c.size() - 1; i++) {
        int minj = i;
        for (int j = i + 1; j < c.size(); j++) {
            if (c[j].second < c[minj].second) minj = j;
        }
        if (i != minj) swap(c[i], c[minj]);
    }
}
bool is_same(vector<pair<char, int> >& c1, vector<pair<char, int> >& c2){
    for (int i = 0; i < c2.size(); i++) {
        if (c1[i].first != c2[i].first) return false;
    }
    return true;
}

int main(){
    int N;
    cin >> N;
    vector<pair<char, int> > card1(N);
    vector<pair<char, int> > card2(N);
    for (int i = 0; i < N; i++) {
        cin >> card1[i].first >> card1[i].second;
        card2[i].first  = card1[i].first;
        card2[i].second = card1[i].second;
    }
    bubble_sort(card1);
    for (int i = 0; i < N; i++) {
        cout << card1[i].first << card1[i].second << (i < N - 1 ? " " : "\n");
    }
    cout << "Stable" << endl;
    selection_sort(card2);
    for (int i = 0; i < N; i++) {
        cout << card2[i].first << card2[i].second << (i < N - 1 ? " " : "\n");
    }
    if (is_same(card1, card2)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }


    return 0;
}

Measured memory_bytes: 3076
#!/usr/bin/env python3
import sys

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def solve(N: int, A: "List[int]"):
    tmp = A[0]
    l = []
    for a in A:
        tmp = gcd(tmp, a)
        l.append(tmp)
    tmp = A[-1]
    r = []
    for a in A[::-1]:
        tmp = gcd(tmp, a)
        r.append(tmp)
    r.reverse()
    ret = 0
    for i in range(N):
        if i < 1:
            tmp = r[i + 1]
        elif i >= N - 1:
            tmp = l[i - 1]
        else:
            tmp = gcd(l[i - 1], r[i + 1])
        ret = max(ret, tmp)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18308
def main():
    n = int(input())
    A = list(map(int, input().split()))

    A_sorted = sorted(A)[::-1]
    teams = list([] for _ in range(n))
    idx = 0
    count = 0

    for score in A_sorted:
        teams[idx].append(score)
        
        count += 1

        if count == 2:
            if idx == n -1:
                idx = 0
            else:
                idx += 1
            
            count = 0
    
    res = 0

    for team in teams:
        res += team[1]
    
    print(res)

if __name__ == '__main__':
    main()

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
struct edge { int v, w; };

int c[2010][2010], sum[2010][2010];

int solve(int N, vector<bool> a, vector<bool> b) {
	vector<int> dp(N);
	rep(d, N) rep(i, N) if (a[(i + d) % N] != b[i]) dp[d]++;
	vector<i_i> p;
	rep(i, N) if (a[i]) {
		int l, r;
		for (l = 0; !b[(i + l + N) % N]; l++);
		for (r = 0; !b[(i - r + N) % N]; r++);
		p.pb(i_i(l, r));
	}
	int mi = INT_MAX / 2;
	rep(l0, N * 2) {
		int r0 = -1;
		for (i_i z: p) if (z.first > l0) r0 = max(r0, z.second);
		int i0, ans;
		if (r0 == -1) i0 = -l0, ans = l0;
		else i0 = r0, ans = l0 + l0 + r0;
		rep(i, N) {
			int d = abs(i - i0) % N;
			d = min(d, N - d);
			mi = min(mi, ans + d + dp[i]);
		}
	}
	return mi;
}

int main() {
	string s, t; cin >> s >> t;
	int N = s.length();
	vector<bool> a(N), b(N);
	rep(i, N) a[i] = (s[i] == '1'), b[i] = (t[i] == '1');
	bool ok = false;
	rep(i, N) if (b[i]) ok = true;
	if (!ok) {
		cout << (a == b ? 0 : -1) << endl;
		return 0;
	}
	int ans = solve(N, a, b);
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	ans = min(ans, solve(N, a, b));
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
      int n;
      cin>>n;
      int a[n],b[n],x,y;
      for(int i=0;i<n;i++){
           cin>>x>>y;
           a[i]=x+y;
           b[i]=x-y;
      }
      sort(a,a+n);
      sort(b,b+n);
      cout<<max(a[n-1]-a[0],b[n-1]-b[0]);
}


Measured memory_bytes: 5168
#include <iostream>
#include <cstdlib>
#include <vector>
#include <set>
using namespace std;
const static int N_MAX = 110;
const static int N_A = 0;
const static int ERR = -9999;

int main() {
  while( 1 ) {
    int n;
    vector< set<int> > table;
    bool possible[ N_MAX ];
    
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }

    set<int> dummy;
    table.push_back( dummy );
    for( int i = 1; i <= n; i++ ) {
      int m;
      cin >> m;
      set<int> s;
      possible[ i ] = true;
      for( int j = 0; j < m; j++ ) {
        int p;
        cin >> p;
        s.insert( p );
      }
      table.push_back( s );
    }


    int k;
    cin >> k;
    for( int i = 0; i < k; i++ ) {
      int l;
      cin >> l;
      for( int j = 1; j <= n; j++ ) {
        if( !possible[ j ] ) { continue; }
        if( table[ j ].find( l ) == table[ j ].end() ) {
          possible[ j ] = false;
        }
      }
    }
    
    int ans = -1;
    
    for( int i = 1; i <= n; i++ ) {
      if( possible[ i ] ) {
        if( ans == -1 ) {
          ans = i;
        } else {
          ans = ERR;
        }
      }
    }

    if( ans == ERR ) { ans = -1; };

    cout << ans  << endl;
  }
}

Measured memory_bytes: 1740
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
a,b,n = readInts()
th = b-1
if n >= th:
    print(int(math.floor(a*th/b) - a * math.floor(th/b)))
else:
    print(int(math.floor(a*n/b) - a * math.floor(n/b)))


Measured memory_bytes: 10232
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    n = I()
    v = list(IL())
    v.sort(reverse=True)
    while 1<len(v):
        tmp = v.pop()+v.pop()
        v.append(tmp/2)
        v.sort(reverse=True)
    print(v.pop())
    exit()

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

int main()
{
    int n, count = 0, now = 1;
    cin >> n;
    rep(i,n) {
        int v;
        cin >> v;
        if (v == now) {
            count++;
            now++;
        }
    }
    cout << (count != 0 ? n - count : -1) << endl;
    return 0;
}


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

#define ll long long

int main()
{
	int n;
	cin>>n;
	ll a[n];
	ll cnt = 0LL;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++)
	{
		cnt += a[i] / 2;
		a[i] %= 2;
		if(a[i] && a[i+1] && i + 1 < n)
		{
			--a[i];
			--a[i+1];
			++cnt;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int a[10],v[2],all;
int main(){
while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&v[0],&v[1])!=EOF){
    all=0;
    int v2=v[0]+v[1];
    for(int i=0;i<10;i++){
        all+=a[i];
    }
    double dis=(double)all*v[0]/v2;
    for(int i=0;i<10;i++){
        dis-=a[i];
        if(dis<=0){
            cout<<i+1<<endl;
            break;
        }
    }
}
return 0;
}

Measured memory_bytes: 1208
<?php
fscanf(STDIN, '%s', $str);
$rev = strrev($str);
if ($str !== $rev) {
    echo "No";
    exit;
}
$len = strlen($str);
$check1End = ($len-1)/2;
$check2Start = ($len+3)/2;
$check1Valid = true;
$check1Str = substr($str, 0, $check1End);
$check1Rev = strrev($check1Str);
if ($check1Str !== $check1Rev) {
    echo "No";
    exit;
}
$check2Str = substr($str, $check2Start-1, $len);
$check2Rev = strrev($check2Str);
if ($check2Str !== $check2Rev) {
    echo "No";
    exit;
}
echo "Yes";

Measured memory_bytes: 4728
#include<stdio.h>

static int N = 1000;

void sort(int A[],int n);

int main(){
  int n,i,j;
  int A[N+1];
  
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  
  sort(A,n);
  
  for(j=2;j<=n;j++){
    int key = A[j];
    int i = j-1;
    
    while(i > 0 && A[i]>key){
      A[i+1] = A[i];
      i--;
    }
    A[i+1] = key;

    sort(A,n);
  }
  return 0;
}

void sort(int A[],int n){
  int i;
  
  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}



Measured memory_bytes: 2128
using System;
using System.Collections.Generic;
					
public class Program
{
	public static void Main()
	{
		var stk = new Stack<int>();
		
		string s;

		while( null != ( s = Console.ReadLine()) ) {
			var n = int.Parse(s);
			
			if(n==0) Console.WriteLine(stk.Pop());
			else	stk.Push(n);
		}
	}
}

Measured memory_bytes: 10004
#include<iostream>
#include<set>

using namespace std;

int main()
{
	
	set <int> s;

	for (int i = 0; i < 2; i++)
	{
		int input;
		cin >> input;
		s.insert(input);
	}

	for (int i = 1; i <= 3; i++)
	{
		if (s.count(i)) continue;
		else
		{
			cout << i;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
typedef long long ll; 
ll seq[1000005]; 
inline int sum(ll n)
{
	int res = 0; 
	while (n)
	{
		res += n % 10; 
		n /= 10; 
	}
	return res; 
}
int main()
{
	// freopen("ARC099-D.in", "r", stdin); 
	int cnt = 0, n;
	scanf("%d", &n);
	for (int i = 1; i <= 999; i++)
	{
		ll cur = i; 
		while (cur <= 1e15)
		{
			seq[cnt++] = cur; 
			cur = cur * 10 + 9; 
		}
	}
	std::sort(seq, seq + cnt); 
	cnt = std::unique(seq, seq + cnt) - seq; 
	for (int i = 0; i < cnt; i++)
	{
		bool f = true; 
		for (int j = i + 1; j < cnt && f; j++)
		{
			int x = sum(seq[i]), y = sum(seq[j]); 
			if (seq[i] * y > seq[j] * x)
				f = false; 
		}
		if (f && n)
		{
			printf("%lld\n", seq[i]);
			n--; 
		}
	}
	return 0; 
}


Measured memory_bytes: 256
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)


m = 0
tot = 0
for i in A:
    if i > m:
        m = i
    else:
        tot += m - i
print(tot)

Measured memory_bytes: 32932
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True


mo=998244353

ans=0

n,s=LI()
a=LI()

A=3000



def dyn(n,A,a):
    dp=[[0]*(A+1) for i in range(n+1)]
    
    for i in range(n):
        x=a[i]
        dp[i+1]=dp[i][:]
        dp[i+1][x]+=1+i
        for j in range(x,A+1):
            #show(i,j,x)
            dp[i+1][j]+=dp[i][j-x]
            dp[i+1][j]%=mo
    return dp

dp=dyn(n,A,a)

ans=0
for i in dp:
    ans+=i[s]
    ans%=mo
    #show(i)

print(ans)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vll>;
using vb = vector<bool>;

const int INF = 2e9+5;
const ll LLINF = (1LL << 60) + 5;

/*
  filippos
  Contest : AtCoder DP contest
  Task : H - Grid 1
*/

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

  int h, w; cin >> h >> w;

  vector<string> a(h);
  for(string &s : a)
    cin >> s;

  const int MOD = 1e9 + 7;

  vvi dp(h, vi(w, -1));

  function<int(int, int)> ways = [&](int r, int c){    
    if(r >= h || c >= w) return 0;
    if(dp[r][c] != -1) return dp[r][c];
    if(a[r][c] == '#') return 0;
    if(r == h-1 && c == w-1) return 1;
    return dp[r][c] = (ways(r+1, c) + ways(r, c+1)) % MOD;
  };

  cout << ways(0, 0);

  return cout << endl, 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a+b+c > 21) cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;



public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		
		char cs[] = s.toCharArray();
		char ct[] = t.toCharArray();
		
		Arrays.sort(cs);
		Arrays.sort(ct);
		
		String ss = new String(cs);
		String tt = new String(ct);
		
		StringBuilder a = new StringBuilder(tt);
		a.reverse();
		String ttt = new String(a);
		
		
		if(ss.compareTo(ttt) < 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 21844
"use strict";
function body(a, b){
    return [a*b, (a+b)*2];
}

(function (){
    var s = require("fs").readFileSync("/dev/stdin", "utf8");
    var ary = s.split(' ').map(Number);

    var ans=body(ary[0], ary[1]);
    
    console.log("%d %d",ans[0], ans[1]);

})();


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll gcd(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	while(ll r=(a%b)){
		a = b;
		b = r;
	}
	return b;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	auto N=in();
	auto A=vecin(N);
	auto l=lcm(A[0],A[1]);
	for(int i=2;i<N;i++){
		l = lcm(l,A[i]);
	}
	
	out(l);
	return 0;
}


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

void push(int x);
int pop();

int S[1000],top;

int main(){
  int x,i,j;
  char s[100];
  top = 0;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      i = pop();
      j = pop();
      push(i+j);
    } else if ( s[0] == '-' ){
      i = pop();
      j = pop();
      push(j-i);
    } else if ( s[0] == '*' ){
      i = pop();
      j = pop();
      push(i*j);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}
void push(int x){
      top++;
    S[top] = x;
}
int pop(){
    top--;
    return S[top+1];
}


Measured memory_bytes: 2108
#include<stdio.h>

int main() {
	int N, K, X, Y;
	scanf("%d", &N);
	scanf("%d", &K);
	scanf("%d", &X);
	scanf("%d", &Y);

	if (N <= K) printf("%d\n", X*N);
	else printf("%d", X*K + Y*(N - K));

	return 0;
}

Measured memory_bytes: 128
if __name__ == '__main__':
    s = int(input())
    A = []
    for i in range(0, 10**6):
        if i == 0:
            A.append(s)
        elif A[i-1]%2 == 0:
            new = A[i-1]//2
            if new in A:
                break
            A.append(new)
        elif A[i-1]%2 == 1:
            new = 3*A[i-1]+1
            if new in A:
                break
            A.append(new)
    print(i+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

ll f(ll n)
{
	ll tmp = (n+1)/2;
	ll res = tmp%2;
	if (n%2 == 0)
		res ^= n;
	return res;
}

int main(int argc, char **argv)
{
	ll A, B; cin >> A >> B;
	std::cout << (f(A-1)^f(B)) << std::endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

ans = 0
N += 1
# a = b * x + K'(K >= K)
for b in range(K+1, N):
    max_x = N // b
    ans += max_x * (b - K) + max(N-b*max_x-K, 0)
    if K == 0:
        ans -= 1
print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		
		int cnt = 1;
		while(true) {
			boolean flg = true;
			int N = s.length-cnt;
			if (N%2 == 0){
				for (int i=0; i<N/2; i++) {
					if (s[i] != s[i+N/2]) {
						flg = false;
						break;
					}
				}
				if (flg == true) {
					System.out.println(N);
					return;
				}
			}
			cnt++;
		}
	}
}


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

int h[123456];
int n, a, b;

int ck(LL x) {
  if (x > 1.0 * 1e10 / b) return 1;
  LL dec = x * b;
  LL need = 0;
  for (int i = 0; i < n; i ++) {
    LL r = max(0LL, (h[i] - dec + (a - b - 1)) / (a - b));
    need += r;
  }
  return need <= x;
}

int main() {
  scanf("%d %d %d", &n, &a, &b);
  for (int i = 0; i < n; i ++)
    scanf("%d", h + i);
  LL l = 0, r = 1e14;
  while (l < r) {
    LL md = l + r >> 1;
    if (ck(md)) r = md;
    else l = md + 1;
  }
  cout << l << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int i, k, n, cnt = 0;
	cin >> n >> k;
	map<int, int> acnt;
	multiset<int> avar;
	for (i = 0; i < n; i++){
		int a;
		cin >> a;
		acnt[a]++;
	}
	for (const auto k : acnt){
		avar.insert(k.second);
	}
	i = 0;
	for (set<int>::iterator it = avar.begin(); i < (int)avar.size() - k; i++, it++){
		cnt += *it;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 18944
#include<iostream>
using namespace std;
int main()
{
	int n,p;
	while(cin>>n>>p,n) 
	{
		int nums[n];
		for(int i = 0; i < n; ++i)
		{
			nums[i]=0;
		}
		int zero=n;
		int pos=0;
		while(1)
		{
			if(p>=1)
			{
				p--;
				if(nums[pos]==0) zero--;
				nums[pos]++;
			}
			else
			{
				p=nums[pos];
				if(nums[pos]!=0) zero++;
				nums[pos]=0;
			}	
			if(p==0&&zero==n-1) break;
			pos=(pos+1)%n;
		}
		cout<<pos<<endl;
	}
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;
	Array x(n);
	REP(i, n) cin >> x[i];

	ll ans = INF;
	for (int p = 1; p <= 100; p++) {
		ll xx = 0;
		REP(i, n) xx += (x[i] - p) * (x[i] - p);
		chmin(ans, xx);
	}
	cout << ans << en;

	return 0;
}

Measured memory_bytes: 256
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    int A[n],B[n];
    int fact=1;
    for(int i=2;i<=n;i++)
    fact=fact*i;
    for(int i=0;i<n;i++)cin>>A[i];

    for(int j=0;j<n;j++)cin>>B[j];

    string k ="";
    for(int i=1;i<=n;i++)
    k+=make_str(i);
    int id1=0,id2=0;
    for(int i=0;i<fact;i++)
    {
        
        //cout<<k<<'\n';
        bool flag1=true,flag2=true;
        for(int i=0;i<n;i++)
        {
            if(A[i]!=k[i]-'0')
            flag1=0;
        }
        for(int i=0;i<n;i++)
        {
            if(B[i]!=k[i]-'0')
            flag2=0;
        }
        if(flag1)
        id1=i;
        if(flag2)
        id2=i;

        next_permutation(all(k));
    }
    cout<<abs(id1-id2);
    

return 0;
}

Measured memory_bytes: 3676
function main(input){
    let lines = input.split("\n");
    let length = parseInt(lines[0]);
    let nums = lines[1].split(" ").map(x=>parseInt(x));

    console.log(Math.min(...nums)+" "+Math.max(...nums)+" "+nums.reduce((sum,x)=>sum+=x));

    
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 18928
#line 1 "template.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int array[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << array[k - 1] << endl;
}


Measured memory_bytes: 256
s = input()
n = len(s)
ans = [ 0 for i in range(n)]
for j in range(2):
    cnt = 0
    for k in range(n):
        if s[k] == 'R':
            cnt += 1
        else:
            ans[k] += cnt // 2 #切り捨て
            ans[k-1] += -( -cnt // 2 ) #切り上げ
            cnt = 0
    
    ans = ans[::-1]
    s = s[::-1]

    s_list = list(s)
    for l in range(n):
        if s_list[l] == 'L':
            s_list[l] = 'R'
        else:
            s_list[l] = 'L'
    s = ''.join(s_list)

print(*ans)

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

int main(){
    int p[3];
    std::cin >> p[0] >> p[1] >> p[2];
    std::vector<int> a;
    for(int i : p)a.push_back(i);
    std::sort(a.begin(),a.end());
    std::cout << a[0] + a[1] << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
vector<int>red,green,blue;
signed main(){
    int n;
    string s;
    cin>>n>>s;
    rep(i,n){
        if(s[i]=='R')red.push_back(i);
        else if(s[i]=='G')green.push_back(i);
        else blue.push_back(i);
    }
    int rlen=red.size(),glen=green.size(),blen=blue.size();
    int ans=rlen*glen*blen;
    rep(i,rlen){
        rep(j,glen){
            int l=red[i],r=green[j];
            if(l>r)swap(l,r);
            if(r+(r-l)<n&&s[r+(r-l)]=='B')ans--;
            if((r-l)%2==0&&s[(r+l)/2]=='B')ans--;
            if(l-(r-l)>=0&&s[l-(r-l)]=='B')ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define mem(a) memset(a,0,sizeof(a))
#define inf 0x7ffffff

using namespace std;
int GCD(int a,int b)
{
	if(b == 0)
		return a;
	return GCD(b,a%b);
}

int main()
{
    std::ios::sync_with_stdio(false);
    int n,old,x,newn;
    while(~scanf("%d",&n))
    {
        vector<int> s;
        scanf("%d",&old);
        while(n--)
        {
            scanf("%d",&newn);
            x=abs(newn-old);
            s.push_back(x);
            old=newn;
            //printf("!\n");
        }
        int temp = s[0];
        for ( int i = 0; i < s.size() ; i++)
        {
            temp = GCD(temp,s[i]);
        }
        printf("%d\n",temp);
    }
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
 
 
 
 
int main() {
    int n;
    cin>>n;

    int a[n],b[n],c[n-1];
    int manzoku=0;
    rep(i,n){
       cin>>a[i];
       a[i]--; 
    }
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n-1){
        cin>>c[i];
    }
    rep(i,n){
        manzoku+=b[a[i]];
        int j=a[i-1]+1;
        if(i>0&&a[i]==j){
            manzoku+=c[a[i]-1];
        }
    }
    cout<<manzoku<<endl;

}




Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
    long long int n;
    scanf("%lld",&n);
    long long int a=1;
    if(n<10)
    {
        printf("%lld",n);
        return 0;
    }
    n=n+1;
    while(n>=10)
    {
        n=n/10;
        a*=10;
    }
    a=a*n-1;
    //printf("%lld\n",a);
    int sum=0;
    while(a!=0)
    {
        sum=sum+(a%10);
        a=a/10;
    }
    printf("%d",sum);
}


Measured memory_bytes: 128
import java.util.*;

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

        int count = 0;
        for (int i = 0; i < n; i++) {
            int tmp = d - 1;
            count += tmp / a[i] + 1;
        }

        System.out.println(count + x);
    }
}

Measured memory_bytes: 36060
#include <iostream>
#include <utility>

using namespace std;
int a(int A, int B, int C){

    int max_c = B / A;

    return min(max_c, C);


}

int main(){
    int A,B,C; cin >> A >> B >> C;

    cout << a(A, B, C);

    return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2005,MAXM=4005;
int n,k,ncnt=0;
bool vis[MAXN];
struct edge
{
	int v,nxt;
	edge(){}
	edge(int vv,int nn)
	{
		v=vv,nxt=nn;
	}
}E[MAXM];
int w[MAXN];
void addedge(int u,int v)
{
	E[++ncnt]=edge(v,w[u]);
	w[u]=ncnt;
}
int dfs1(int u,int f,int d)
{
	int re=1;
	if(d==0)
		return re;
	for(int i=w[u];i;i=E[i].nxt)
	{
		int v=E[i].v;
		if(v!=f)
		{
			re+=dfs1(v,u,d-1);
		}
	}
	return re;
}
int dfs2(int u,int f,int d)
{
	int re=0;
	if(d==0)
		return 1;
	for(int i=w[u];i;i=E[i].nxt)
	{
		int v=E[i].v;
		if(v!=f)
		{
			re+=dfs2(v,u,d-1);
		}
	}
	return re;
}
int main()
{
	//freopen("shorten.in","r",stdin);
	//freopen("shorten.out","w",stdout);
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	int zans=0;
	for(int i=1;i<=n;i++)
	{
		int o=dfs1(i,0,(k/2));
		if(k&1)
		{
			int op=0;
			for(int j=w[i];j;j=E[j].nxt)
				op=max(op,dfs2(E[j].v,i,k/2));
			o+=op;
		}
		zans=max(zans,o);
	}
	printf("%d\n",n-zans);
	fclose(stdin);
	fclose(stdout);;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define rep(i,x,n) for(int (i)=(x);(i)<(n);(i)++)
using namespace std;

int main(){
    
    int n,c = 0;
    cin >> n;
    vi p(n),sw(2);
    rep(i,0,n){
        cin >> p[i];
        if(p[i] != i+1){
            c++;
        }
    }

    if(c < 3){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


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

int main(void){

    int A, B;

    scanf("%d%d", &A, &B);

    printf("%d\n", (A + B) % 24);

    return 0;
}

Measured memory_bytes: 1732
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    l = []

    for i in range(100):
        for j in range(100):
            if i * 4 + j * 7 <= 100:
                l.append(i * 4 + j * 7)

    N = int(input())

    if N in l:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 5016
#include <stdio.h>
int main(void){
    int W,H;
    int i,j;
    while(1){
        
        scanf("%d %d ",&H,&W);
         if(H==0&&W==0)
         break;
   
        
        for(i=1;i<=H;i++){
            for(j=1;j<=W;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
       
    }
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

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

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

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


void Main() {
	int N; cin >> N;
	vint A(N); cin >> A;
	int xd = 0;
	for (auto &v : A) xd ^= v;
	cout << (xd == 0 ? "Yes" : "No") << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n), y(n);
  vector<int> a(n);
  rep(i, n) cin >> x[i] >> y[i] >> a[i];
  
  int min_x = 0, min_y = 0, max_x = w, max_y = h;
  rep(i, n) {
    switch(a[i]) {
      case 1:
        if (x[i] > min_x) min_x = x[i];
        break;
        
      case 2:
        if (x[i] < max_x) max_x = x[i];
        break;
        
      case 3:
        if (y[i] > min_y) min_y = y[i];
        break;
        
      case 4:
        if (y[i] < max_y) max_y = y[i];
        break;

    }
  }
  
  if (max_x<min_x || max_y<min_y) {
    cout << 0 << endl;
    return 0;
  }
  int ans = (max_x - min_x) * (max_y - min_y);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort()
f.sort(reverse=True)

l = -1
r = 10**12

while l+1 < r:
  c = (l+r)//2
  s = 0
  for i in range(n):
    s += max(0, a[i] - c//f[i])
  if s <= k:
    r = c
  else:
    l = c
print(r)


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

using int64 = long long;
using uint64 = unsigned long long;

int64 f(int64 b, int64 n) {
    if (n < b) return n;
    else return f(b, n / b) + n % b;
}

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

    int64 n, s;
    std::cin >> n >> s;

    for (int64 b = 2; b <= 1000000LL; b++) {
        if (f(b, n) == s) {
            std::cout << b << std::endl;
            return 0;
        }
    }

    // b > 10^6
    int64 ans = (n == s) ? (n + 1) : -1;
    for (int64 d1 = 1; d1 <= std::min(s, 1000000LL); d1++) {
        int64 d2 = s - d1;
        if (n - d2 < 0 or (n - d2) % d1 != 0) continue;

        int64 b = (n - d2) / d1;
        if (b > std::max(d1, d2) and (ans < 0 or ans > b)) {
            ans = b;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

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

    ll s=0;
    vll a(n);
    each(&it,a)
    {
        cin>>it;
        s+=it;
    }

    ll ans=LONG_LONG_MAX;
    ll b=0,c=s;
    each(it,a)
    {
        ans=min(ans,abs(b-c));
        b+=it;
        c-=it;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define devugv(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define debugvp(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long i64; 
typedef vector< int > vi;
typedef vector< i64 > vi64;
typedef pair< int, int > pi;
typedef vector< pair< int, int > > vpi;
typedef vector< vector < int > > vvi;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in.txt", "r", stdin);
#endif

    int n; cin >> n;
    vi tt(n);
    i64 sum = 0;
    forn(i, n) {
        cin >> tt[i];
        sum += tt[i];
    }
    int m; cin >> m;
    int p, t;
    forn(i, m) {
        cin >> p >> t;
        --p;
        i64 ans = sum - tt[p] + t;
        cout << ans << '\n';
    }

#ifdef LOCAL_DEFINE
    cout << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

int n;
int a[100005];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a, a + n);
	a[n] = 0;
	int cur = 0, cnt = 0, ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (a[i] == cur) {
			++cnt;
		}
		else {
			if (cnt >= cur) ans += cnt - cur;
			else ans += cnt;
			cur = a[i];
			cnt = 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

    
    ll n;
    cin>>n;
    ll sum = 0;
    forn(i,1,n+1)
    {
        forn(j,1,n+1)
        {
            forn(k,1,n+1)
            {
                sum += __gcd(i,__gcd(j,k));
            }
        }
    }

    cout<<sum;


    return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3624