akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n;
lint a[MAX];
vector<int> G[MAX];

lint dfs(int v, int pv){
    if(pv >= 0 && G[v].size() == 1) return a[v];
    vector<lint> c;
    lint csum = 0, X, Y;
    for(int nv: G[v])if(nv != pv){
        lint t = dfs(nv, v);
        if(t < 0) return -1;
        c.push_back(t);
        csum += t;
    }
    if(pv < 0){
        return csum == a[v] ? 1 : -1;
    }
    else{
        X = 2*a[v] - csum;
        Y = csum - X;
        if(X < 0 || Y < 0) return -1;
        lint tmp = 0;
        for(lint y: c) tmp += min(y, Y/2);
        return tmp >= Y ? X : -1;
    }
}

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%lld", &a[i]);
    rep(i, n-1){
        int u, v;
        scanf("%d%d", &u, &v);
        --u; --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    rep(i, n)if(G[i].size() == 1){
        puts(dfs(i, -1) >= 0 ? "YES" : "NO");
        return 0;
    }
}

Measured memory_bytes: 17408
#include <stdio.h>

int main(void){
  int A, B;
  char op;
  scanf("%d %c %d", &A, &op, &B);
  if (op == '+'){
    printf("%d\n", A+B);
  } else if  (op == '-'){
    printf("%d\n", A-B);
  } else {
    printf("%s\n", "Invalid!");
  }
  return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<vector<int>> G(N);
  vector<pair<int,int>> vp;
  for(int i=1;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a,b);
  }

  int K=0;
  map<pair<int,int>,int> I;
  vector<int> cs(N,0); // color of edge between its parent

  vector<int> used(N,0);
  queue<int> que;
  used[0]=1;
  que.emplace(0);
  while(!que.empty()){
    int v=que.front();que.pop();
    if(K<(int)G[v].size()) K=G[v].size();
    int cur=1;
    for(int u:G[v]){
      if(used[u]) continue;
      if(cur==cs[v]) cur++;
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
      used[u]=1;
      que.emplace(u);
    }
  }

  cout<<K<<endl;
  for(auto p:vp) cout<<I[p]<<endl;
  return 0;
}


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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;
	int a[105];
	rep(i, n) cin >> a[i];

	sort(a, a+n, greater<int>());

	f = 0;
	rep(i, n){
		if(i%2 == 0){
			f += a[i];
		}else{
			f -= a[i];
		}
	}

	cout << f;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    int [][] cards = new int [5][15];
    private  static String[] cards2 = {"0","S","H","C","D"};
    int n,j,i,k,cards4,Nu;
    String cards3;
    public void ca() {
        Scanner sc = new Scanner(System.in);
        for(j = 1;j <= 4;j++) {
            for(i = 1 ; i <= 13; i++) {
                k = i;
                cards[j][i] = k;
            }
        }
        n = sc.nextInt();
        for(k = 0 ; k < n ; k++) {
            cards3 = sc.next();
            cards4 = sc.nextInt();
            if(cards3.equals( "S" )) {
                Nu = 1;
            } else if(cards3.equals( "H" )) {
                Nu = 2;
            } else if(cards3.equals( "C" )) {
                Nu = 3;
            } else if(cards3.equals( "D" )) {
                Nu = 4;
            }
            switch(Nu) {
                case 1:
                    for(j = 1;j <= 13 ; j++) {
                        if(cards4 == cards[1][j]) {
                            cards[1][j] -= cards4;
                        }
                    }
                    break;
                case 2:
                    for(j = 1;j <= 13 ; j++) {
                        if(cards4 == cards[2][j]) {
                            cards[2][j] -= cards4;
                        }
                    }
                    break;
                case 3:
                    for(j = 1;j <= 13 ; j++) {
                        if(cards4 == cards[3][j]) {
                            cards[3][j] -= cards4;
                        }
                    }
                    break;
                case 4:
                    for(j = 1;j <= 13 ; j++) {
                        if(cards4 == cards[4][j]) {
                            cards[4][j] -= cards4;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        for(j = 1;j <= 4;j++) {
            for(i = 1;i <= 13;i++) {
                if(cards[j][i] != 0) {
                    System.out.printf("%S %d\n",cards2[j],cards[j][i]);
                }
            }
        }
    }
    public static void main(String[] agrs) {
        new Main().ca();
    }
}

Measured memory_bytes: 18132
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] arr = br.readLine().split(" ");
        Arrays.sort(arr);
        out.println(arr[0].equals("1") 
                    && arr[1].equals("4")
                    && arr[2].equals("7")
                    && arr[3].equals("9")
                    ? "YES" : "NO");
        out.close();
    }
}


Measured memory_bytes: 20948
N, A, B, C, D = map(int, input().split())
S = input()
for i in range(A - 1, max(C, D) - 1):
    if S[i] == S[i + 1] == '#':
        print("No")
        exit()

if C < D:
    print("Yes")
else:
    for i in range(B - 2, D - 1):
        if S[i:i + 3] == '...':
            print("Yes")
            exit()
    print('No')


Measured memory_bytes: 9452
import fractions
A,B,C,D = list(map(int,input().split()))
dis = B - A + 1

CD = C*D//(fractions.gcd(C,D))
#print(CD)
perCfromA = (A-1)//C
perDfromA = (A-1)//D
perCDfromA = (A-1)//(CD)


perCfromB = B//C
perDfromB = B//D
perCDfromB = B//(CD)

#print(perCfromA,perDfromA,perCDfromA,perCfromB,perDfromB,perCDfromB)
warikire = (perCfromB + perDfromB -perCDfromB) - (perCfromA + perDfromA -perCDfromA)
warikirenai = dis -warikire
print(warikirenai)

Measured memory_bytes: 5048
#include<stdio.h>
#include<map>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int p[80];
int main(){
   int n;
   scanf("%d",&n);
   for(int i=0;i<n;i++)
    scanf("%d",&p[i]);
    int s=0,x=0;
   for(int i=1;i<n-1;i++){
        x=0;
      if(p[i]<p[i-1])
      x++;
      if(p[i]<p[i+1])
        x++;
      if(x==1)
        s++;
   }
   printf("%d\n",s);
}


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

int main() {
    int x, y, gcd, temp1, temp2;
    bool flag = true;
    cin >> x >> y;
    if (x == y) {
        int gcd = x;
        cout << gcd << endl;
        return 0;
    }
    else if (x > y){
        temp1 = x % y;
        temp2 = y;
    }
    else if (y > x) {
        temp1 = y % x;
        temp2 = x;
    }
    while (flag) {
        if (temp1 == 0) {
            gcd = temp2;
            break;
        }
        temp2 = temp2 % temp1;
        if (temp2 == 0) {
            gcd = temp1;
            break;
        } 
        //この時点でtemp2<temp1
        temp1 = temp1 % temp2;
    }
    cout << gcd << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
  int n,ans,cnt;
   scanf("%d",&n);
  int i,j;
  int a[n];
  int b[n];

 
  for(j=0;j<n;j++){
    scanf("%d",&a[j]);
    scanf("%d",&b[j]);
  }
  ans=0;
  cnt=1;

  for(i=0;i<n-2;i++){
    if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
 return 0;
}

Measured memory_bytes: 1664
N = int(input())
S = input()

s = list(S)
for i in range(len(S)):
    if (ord(s[i]) - 64 + N) % 26 == 0:
        p = 90
    else:
        p = (ord(s[i]) - 64 + N) % 26 + 64

    s[i] = chr(p)

print("".join(s))

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  LL n;cin>>n;
  cout<<n*(n-1)/2<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys

s_prime, t = sys.stdin.read().split()
ls = len(s_prime)
lt = len(t)

def main():
    for i in range(ls-lt, -1, -1):
        t_prime = s_prime[i:i+lt]
        for j in range(lt):
            if not t_prime[j] in ['?', t[j]]:
                break
        else:
            s = (s_prime[:i] + t + s_prime[i+lt:]).replace('?', 'a')
            return s
    return 'UNRESTORABLE'
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
#include<cstdio>
int N,A[100010];
int diff(int i,int j){return i>j?i-j:j-i;}
int main(){
	scanf("%d",&N);
	int sum=0;
	for(int i=1;i<=N;i++)scanf("%d",A+i);
	for(int i=0;i<=N;i++)sum+=diff(A[i],A[i+1]);
	for(int i=1;i<=N;i++){
		printf("%d\n",sum-diff(A[i-1],A[i])-diff(A[i],A[i+1])+diff(A[i-1],A[i+1]));
	}
}

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;

void call(int n) {
	repi(i, 1, n+1) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
			continue;
		}
		while (x) {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << endl;
}
int main() {
	int a;
	cin >> a;
	call(a);
}


Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final String S = s.next();
			int aa = Integer.parseInt(S.substring(0, 2));
			int bb = Integer.parseInt(S.substring(2, 4));

			String ret;
			if (1 <= aa && aa <= 12) {
				// MMbb
				if (1 <= bb && bb <= 12) {
					ret = "AMBIGUOUS";
				} else {
					ret = "MMYY";
				}
			} else {
				// YYbb
				if (1 <= bb && bb <= 12) {
					ret = "YYMM";
				} else {
					ret = "NA";
				}
			}
			System.out.println(ret);
		}
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define LL long long int
using namespace std;

const int N = 5e5 + 5;
const int oo = 1e9 + 5;
const int MOD = 1e9 + 7;

LL A[N], B[N];
void solve() {
    int n, m;
    LL k;
    cin >> n >> m >> k;
    for (int i=0;i<n;++i) cin >> A[i];
    for (int i=0;i<m;++i) cin >> B[i];
    LL have = 0, go = 0;
    int j = 0;
    while(j<m && have + go + B[j] <= k) {
        go += B[j];
        ++j;
    }
    int ans = j;
    --j;
    for (int i=0;i<n;++i) {
        have += A[i];
        while(j >= 0 && have + go > k) {
            go -= B[j];
            --j;
        }
        if (have + go <= k) {
            ans = max(ans, i + 1 + j + 1);
        }
    }
    cout << ans << '\n';
} 

int main() {
    FASTIO;
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 6784
package main

import "fmt"

func main() {
	N, Q := 0, 0
	S := ""
	fmt.Scan(&N, &Q)
	fmt.Scan(&S)
	s := make([]int, N+1)
	s[0] = 0
	for i := 0; i < N; i++ {
		if i+1 < N && S[i] == 'A' && S[i+1] == 'C' {
			s[i+1] = s[i] + 1
		} else {
			s[i+1] = s[i]
		}
	}

	for i := 0; i < Q; i++ {
		l, r := 0, 0
		fmt.Scan(&l, &r)
		l--
		r--
		fmt.Println(s[r] - s[l])
	}
}


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

def main():
    N, S = map(str, open(0).read().split())
    N = int(N)

    S_rep = []
    for i in range(0, len(S)):
        n = ord(list(S)[i])
        if (n + N < 91):
            S_rep.append(chr(n + N))
        else:
            S_rep.append(chr(n + N + 6))
    
    S_rep = ''.join(S_rep)
    print(S_rep.upper())



main()

Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll k; cin >> k;
    vector<ll> dp(k, INF);
    dp[1] = 1;

    deque<pair<ll, ll>> q = {{dp[1], 1}};

    while (!q.empty()) {

        ll c = q.front().first;
        ll v = q.front().second;
        q.pop_front();

        ll n1 = (v + 1) % k;
        ll n2 =  v * 10 % k;
        if (chmin(dp[n1], dp[v] + 1))
            q.push_back(pair<ll, ll>(dp[n1], n1));
        if (chmin(dp[n2], dp[v]))
            q.push_front(pair<ll, ll>(dp[n2], n2));

    }

    cout << dp[0] << endl;
    
}

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

int main(){
    ll N, K; cin >> N >> K;

    ll ans = 0;
    rep(b, K+1, N + 1){
        ll t = N / b;
        ans += (b - 1 - (K-1)) * t;
        ll t1 = N % b;
        if(t1 >= K) ans += t1 - (K - 1);
        if(K == 0) ans--;
        cerr << b << " " <<  ans << endl;
    }
    cout << ans << endl;
}


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

ans = -float('inf')
v = []
for n in range(N):
    loop, score = 0, 0
    t = n
    for i in range(min(N, K)):
        n = P[n]-1
        score += C[n]
        ans = max(ans, score)
        if n == t:
            loop = i+1
            break
    v.append((loop, score))

for n in range(N):
    loop, score = v[n]
    if loop > 0 and score > 0:
        r = (K-1)//loop
        nscore = r*score
        for i in range(K-r*loop):
            n = P[n]-1
            nscore += C[n]
            ans = max(nscore, ans)
print(ans)


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

int main() {
  int n, t;
  cin >> n >> t;
  int ans = 10010;
  rep(i, n) {
    int c, T;
    cin >> c >> T;
    if(c < ans && T <= t) ans = c;
  }
  if(ans == 10010) cout << "TLE" << endl;
  else cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 3596
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    ml = l = 0
    ACTG = set('ACTG')
    for x in input():
        if x in ACTG:
            l += 1
            ml = max(ml, l)
        else:
            l = 0
    print(ml)

main()


Measured memory_bytes: 38256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
  /*int N, M; cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    int x, y; cin >> x >> y;
  }
  for (int i = 0; i < M; ++i) {
    int p, q; cin >> p >> q;
  }*/
  
  while (1) {
    int N; cin >> N;
    if (!N)break;

    vector<long long int>times(1000);
    int preminute = 0;
    vector<bool>isin(1000);
    for (int i = 0; i < N; ++i) {
      string day, time, inout, num; cin >> day >> time >> inout >> num;
      const int minute = stoi(time.substr(0, 2)) * 60 + stoi(time.substr(3, 2));
      const int prayer = stoi(num);
      bool in = inout == "I";
      if (isin[0]) {
        for (int i = 1; i < 1000; ++i) {
          if (isin[i])times[i] += minute - preminute;
        }
      }
      isin[prayer] = in;
      preminute = minute;
    }
    long long int ans = *max_element(times.begin(), times.end());
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int N, P; cin >> N >> P;
  string S; cin >> S;
  long long ans = 0;
  if (10 % P == 0) {
    for (int i = 0; i < N; i++) {
      if ((S.at(i) - '0') % P == 0) ans += i+1;
    }
  }
  else {
    vector<int> A(N+1, 0);
    int ten = 1;
    for (int i = N-1; i >= 0; i--) {
      int tmp = (S.at(i) - '0') * ten % P;
      A.at(i) = (A.at(i+1) + tmp) % P;
      ten *= 10;
      ten %= P;
    }
    map<int, long long> M;
    for (int i = 0; i < N+1; i++) {
      if (M.count(A.at(i))) M[A.at(i)]++;
      else M[A.at(i)] = 1;
    }
    for (auto p : M) ans += (p.second * (p.second - 1)) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1796
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long INF = 1<<31;

int ans;

int main(void) {
    ll x;
    cin >> x;
    ll sum = 100;

    while (sum<x) {
        sum = (ll)(sum*1.01);
        ans++;
    }
    

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
N, x = map(int, input().split())
a = list(map(int, input().split()))

cost = 0
for i in range(len(a)):
    if a[i] > x:  # そもそもx個より多い場合はx個に減らす
        cost += a[i] - x
        a[i] = x
    if i > 0 and a[i - 1] + a[i] > x:  # 1つ前との和がx個になるまで減らす
        cost += a[i - 1] + a[i] - x
        a[i] = x - a[i - 1]

print(cost)


Measured memory_bytes: 14540
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int c = 1;
	char last = s[0];
	for (int i = 1; i < n; i++) {
		if (last != s[i]) c++;
		last = s[i];
	}
	c = max(1, c - 2 * k);
	cout << n - c << endl;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, C; cin >> N >> C;
    int group[3][31];
    rep(i, 3) rep(j, 30) group[i][j] = 0;
    int dist[C][C]; rep(i, C) rep(j, C) cin >> dist[i][j];
    int grid[N][N]; rep(i, N) rep(j, N) cin >> grid[i][j];
    rep(i, N){
        rep(j, N){
            grid[i][j]--;
            group[(i+j)%3][grid[i][j]]++;
        }
    }
    int size[3] = {};
    rep(i, 3){
        rep(j, C){
            size[i] += group[i][j];
        }
    }
    // rep(i, 3){
    //     rep(j, C){
    //         cout << group[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // rep(i, 3) cout << size[i] << " "; cout << endl;
    int ans = mod;

    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            if(i == j) continue;
            for(int k = 0; k < C; k++){
                if(i == k || j == k) continue;
                //group[0]は色i, group[1]は色j, group[2]は色k
                int acc = 0;
                for(int col = 0; col < C; col++){
                    acc += group[0][col]*dist[col][i] + group[1][col]*dist[col][j] + group[2][col]*dist[col][k];
                }
                ans = min(ans, acc);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ans = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) <= K: ans.append(A[i]+B[j]+C[k])
            else: break
ans.sort(reverse=True)
for i in range(K): print(ans[i])

Measured memory_bytes: 8708
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a, b = li()

print((a+b) // 2 if (a+b) % 2 == 0 else "IMPOSSIBLE")

Measured memory_bytes: 3064
#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;
constexpr int mod2 = 998244353;
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>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

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) {
	if (v.size()) {
		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;
	vector<Pl> dat(N); cin >> dat;
	sort(rbegin(dat), rend(dat), [](Pl a, Pl b) { return (a.first+a.second < b.first+b.second); });

	ll point = 0;
	for (int i = 0; i < N; i++) {
		point += (i&1 ? -dat[i].second : dat[i].first);
	}
	cout << point << endl;
}

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



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

int main(){
   int H, W;
   std::cin >> H >> W;
   std::vector<std::string> s(H);
   for(int i=0; i<H; ++i){
      std::string tmp;
      std::cin >> tmp;
      s[i] = tmp;
   }

   std::vector<int> flags(H,0);
   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j){
	 if(flags[i] & (1<<j)) continue;
	 bool flag = false;
	 if(s[i][j]=='#'){
	    if(0<j && s[i][j-1]=='#'){
	       flag = true;
	       flags[i] |= (1<<(j-1));
	    }
	    if(j+1<W && s[i][j+1]=='#'){
	       flag = true;
	       flags[i] |= (1<<(j-1));
	    }
	    if(0<i && s[i-1][j]=='#'){
	       flag = true;
	       flags[i-1] |= (1<<j);
	    }
	    if(i+1<H && s[i+1][j]=='#'){
	       flag = true;
	       flags[i+1] |= (1<<j);
	    }

	 }else flag = true;
	 if(flag==false){
	    std::cout << "No" << std::endl;
	    return 0;
	 }
      }

   }
   std::cout << "Yes" << std::endl;

   return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
edges = [list() for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
visited = [0]*N
cnt = 0
def dfs(u,visited):
    visited = visited[:]
    global cnt
    visited[u] = True
    if all(visited):
        cnt += 1
        return
    for v in edges[u]:
        if not visited[v]:
            dfs(v,visited)
    return 0

dfs(0,visited)
print(cnt)

Measured memory_bytes: 42972
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <iomanip>
#include <functional>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
#define bit(n,k) ( (n>>k)&1 )

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end\n"<<endl;
}

template<class T>
void VPout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i].first<<" "<<V[i].second<<'\n';
    }
    cout<<"end\n"<<endl;
}


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout<<fixed<<setprecision(10);

    int N;
    cin>>N;
    vector<int> X(N);
    for(int i=0;i<N;i++) cin>>X[i];
    ll ans=INF;
    for(int x=0;x<=100;x++){
        ll t=0;
        for(int i=0;i<N;i++){
            t+=(X[i]-x)*(X[i]-x);
        }
        chmin(ans,t);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#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 a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + c <= 21 ? "win" : "bust") << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
S = [0]*(10**5)
ans = 0
for a in A:
    S[a-1] += 1
    ans += a
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    b = S[B-1]
    S[B-1] = 0
    S[C-1] += b
    ans += b*(C-B)
    print(ans)

Measured memory_bytes: 84124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

ll modP(ll x, ll y, ll MOD)
{
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
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...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}
ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}
void solve()
{
    ll ans = 0;
 ll n,k; 
 cin>>n>>k; 
 ll a[n]; 
 for(int i=0;i<n;i++)
 cin>>a[i];
 for(int i=k;i<n;i++)
  {
  if(a[i]>a[i-k]) 
  {
cout<<"Yes\n";
  }
  else 
  cout<<"No\n";
  }
    //cout << ans << "\n";
}int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t ;
    t = 1;
   
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}





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


using namespace std;


void white_cells()
{
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H * W) - (h * W) - (H * w) + (h * w) << "\n";
}


void double_helix()
{
  char b;
  cin >> b;

  if (b == 'A') cout << "T\n";
  else if (b == 'T') cout << "A\n";
  else if (b == 'C') cout << "G\n";
  else  cout << "C\n";

}


void five_antennas()
{
  vector<int> a(5);
  for (int i = 0; i < 5; ++i) cin >> a[i];
  int k;
  cin >> k;

  if (a[4] - a[0] > k)
  {
    cout << ":(\n";
    return;
  }
  cout << "Yay!\n";

}

void buttons()
{
  int a, b;
  cin >> a >> b;

  int v_max = 0;
  for (int i = 0; i < 2; ++i) {
    if (a > b) {
      v_max += a;
      --a;
    }
    else
    {
      v_max += b;
      --b;
    }
  }
  cout << v_max << "\n";
}


int main()
{
  //white_cells();
  //double_helix();
  //five_antennas();
  buttons();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const string com[4] = { "insert", "delete", "deleteFirst", "deleteLast" };


int main()
{
	ios_base::sync_with_stdio(0);
	deque<int> deq;

	int n; cin >> n;
	rep (i, n ){
		string op = ""; cin >> op;
		rep (j, 4 ){
			if (op == com[j] ){
				if (j == 0 || j == 1 ){
					int x; cin >> x;
					if (j == 0 ) deq.push_front (x );
					else{
						deque<int>::iterator it = deq.begin();
						for(; it != deq.end(); it++ ){
							int curr = (*it);
							if (curr == x ){
								deq.erase (it );
								break;
							} // end if
						} // end for
					} // end if
				}else
				if (j == 2 ){
					deq.pop_front();
				}else{	// if (j == 3 )
					deq.pop_back();
				} // end if
			} // end if
		} // end rep
	} // end rep

	rep (i, deq.size() ){
		cout << deq[i] << ( i != deq.size() - 1 ? ' ' : '\n' );
	} // end rep	

		
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = k;
    for (int i = 0; i < n - 1; ++i) {
        ans *= k - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3544
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    int gap = Integer.MAX_VALUE;

    for (int i = 0; i < (s.length() - 2); i++) {
      String t = s.substring(i, i + 3);
      int a = Integer.parseInt(t);
      if (Math.abs(753 - a) < gap) {
        gap = Math.abs(753 - a);
      }
    }

    System.out.println(gap);

  }
}

Measured memory_bytes: 35704
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
int dp[101][100010] = {0};
signed main(){

    int n,W;
    cin >> n >> W;
    int w[100010];
    int v[100010];
    rep(i,n){
        cin >> w[i] >> v[i];
    }
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j <= W;j++){
            if(i == 0 && j-w[i]>=0){
                dp[i][j] = v[i];
            }else if(j-w[i]>=0)dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            else if(i != 0)dp[i][j] = dp[i-1][j];
        }
    }
    // rep(i,n){
    //     rep(j,W+1)cerr << dp[i][j] << " ";
    //     cerr << endl;
    // }
    cout << dp[n-1][W] << endl;

    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://dp.contest.atcoder.jp/tasks/dp_a
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

Measured memory_bytes: 78336
k = int(input())
lun = [str(i) for i in range(1, 10)]
L = [str(i) for i in range(1, 10)]
nL = []
while len(lun) < 10 ** 5:
    for num in L:
        l = num[-1]
        lm = int(l) - 1
        lp = int(l) + 1
        nL.append(num + l)
        if lm >= 0:
            nL.append(num + str(lm))
        if lp < 10:
            nL.append(num + str(lp))
    lun.extend(nL)
    L = nL
    nL = []
lunlun = [int(x) for x in lun]
lunlun.sort()
print(lunlun[k-1])


Measured memory_bytes: 32464
#include<bits/stdc++.h>
using namespace std;
const int N = 2087, inf = 1e9 + 7;
int n,k,q;
int a[N],g[N],ct[N],si[N];
int solve(int bi)
{
    int mn = a[si[bi]];
    int m = 0;
    memset(ct,0,sizeof(ct));
    for (int i = 0; i < n; ++i) {
        if (a[i] < mn) {
            ++m;
            continue;
        }
        g[i] = m;
        ++ct[m];
    }
    int rm = q, mx = inf;
    for (int i = bi; i < n && rm; ++i) {
        int j = si[i];
        if (ct[g[j]] >= k) {
            --ct[g[j]];
            --rm;
            mx = a[j];
        }
    }
    return rm ? inf : mx - mn;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k >> q;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        si[i] = i;
    }
    sort(si,si+n,[&](int i,int j)->bool{return a[i] < a[j];});
    int ans = inf;
    for (int i = 0; i < n; ++i) {
        int v = solve(i);
        if (v == inf)
            break;
        ans = min(ans, v);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
MAX_N = 10 ** 5
p_lst = [0 for i in range(MAX_N+1)]


def is_prime():
    a = [0 for i in range(MAX_N+1)]
    for i in range(2, MAX_N+1):
        for j in range(2*i, MAX_N+1, i):
            a[j] += 1

    for i in range(2, MAX_N+1):
        if a[i] == 0:
            p_lst[i] = 1


def main():
    q = int(input())

    is_prime()
    s, idx = [0 for i in range(MAX_N+1)], 0
    for i in range(2, MAX_N+1):
        if p_lst[i] == 1 and p_lst[(i+1)//2] == 1:
            s[i] = s[i-1] + 1
        else:
            s[i] = s[i-1]

    for i in range(q):
        l, r = map(int, input().split())
        print(s[r]-s[l-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 5008
// Binary Search
#include <stdio.h>
#include <stdlib.h>

int s[100010], t[50010];
int binarySearch(int key, int n){
    int left=0;
    int right=n;
    while(right-left>0){
        int mid=(right+left)/2;
        if(s[mid]==key){return 1;}
        else if(s[mid]>key){right=mid;}
        else{left=mid+1;}
    }
    return 0;
}

int main(void){
    int n, q, flag=0, cnt=0;
    scanf("%d", &n);
    for(int i=0; i<n; i++){scanf("%d", &s[i]);}
    scanf("%d", &q);
    for(int i=0; i<q; i++){scanf("%d", &t[i]);}
    for(int i=0; i<q; i++){
        flag=binarySearch(t[i], n);
        if(flag){cnt++;}
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 2316
#include <bits/stdc++.h>
#include <queue>
#define ll long long int
using namespace std;


const int N = 3e5 + 10;
ll n, k, ans = 1e18, arr[N];

int main(int argc, char** argv) {
    cin >> n>>k;
    for (int i = 0; i < n; i++)cin >> arr[i];
    for (int i = 0, j = 0; j < n; j++) {
        if (j - i == k)i++;
        if (j - i == k - 1) {
            if (arr[i] <= 0 && arr[j] <= 0)ans = min(ans, abs(arr[i]));
            else if (arr[i] >= 0 && arr[j] >= 0) ans = min(ans, arr[j]);
            else ans = min(ans, max(abs(arr[i]), abs(arr[j])) + min(abs(arr[i]), abs(arr[j]))*2);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 100 == 0) {
		x /= 100;
		ret++;
	}

	return ret;
}


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

	cin >> a >> b;

	int cnt = 0;
	int val = 0;

	while (cnt < b) {
		val++;
		if (calc(val) == a)cnt++;
	}

	cout << val << endl;
	/*if (a == 0) {
		cout << 1 * b << endl;
	}
	else if (a == 1) {
		cout << 100 * b << endl;
	}
	else if (a == 2) {
		cout << 10000 * b << endl;
	}*/

	
}
	

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

using namespace std;
typedef long long ll;

ll N;
vector<ll> v;

int main(){
    cin >> N;
    if(N==2){
        cout << 1 << endl;
        return 0;
    }
    ll ans = 1;
    for(ll i=2;(i*i)<=(N-1);i++){
        if((N-1) % i != 0) continue;
        ans++;
        if(i*i != N-1) ans++;
    }
    v.push_back(N);
    for(ll i=2;i*i<=N;i++){
        if(N%i != 0) continue;
        v.push_back(i);
        if(i*i != N) v.push_back(N/i);
    }
    for(auto &e : v){
        ll n = N;
        while(n % e == 0) n /= e;
        if(n%e == 1) ans++; 
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n,a[100010];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans = a[0]-1;
    int k = 2;
    for (int i = 1; i < n; ++i) {
        if (a[i]>k) ans += (a[i] - 1) / k;
        if (a[i]==k) k++;
    }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int digit_sum(int n){
  if(n==0){
    return 0;
  }else{
    int res = 0;
    res = n%10;
    res += digit_sum(n/10);
    return res;
  }
}

int main(){
  
  int n,a,b;
  cin>>n>>a>>b;
  int ans = 0;
  int temp;
  REPP(i,n){
    temp = digit_sum(i);
    if(a<=temp && temp<=b){
      ans += i;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 dp(n + 1, 1e9);
  dp[0] = 0;
  rep(i, n) {
    if (dp[i] == 1e9) continue;
    amin(dp[i + 1], dp[i] + 1);
    for (int j = 6; i + j <= n; j *= 6) {
      amin(dp[i + j], dp[i] + 1);
    }
    for (int j = 9; i + j <= n; j *= 9) {
      amin(dp[i + j], dp[i] + 1);
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
int n;
int k;
vec a;
bool f(int m){
    vector<vector<bool>> dp(n+1,vector<bool>(k+1));
    dp[0][0]=true;
    rep2(i,1,n)rep2(j,0,k+1)dp[i][j]=i==m||j<a[i]?dp[i-1][j]:dp[i-1][j]||dp[i-1][j-a[i]];
    rep2(j,max(0,k-a[m]),k-1)if(dp[n][j])return false;
    return true;
}
int main(){
    n=in();
    k=in();
    a=vec(n+1);
    rep(i,n)a[i]=in();
    a[n]=0;
    sort(All(a));
    int l=0,r=n+1;
    while(l+1<r){
        int m=(l+r)/2;
        if(f(m))l=m;
        else r=m;
    }
    cout<<l<<endl;
}

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

const int N = 150005;

int n, m, a[N], cnt;
bool o[N];
using ll = long long;
ll sum, ans = 3e18;
vector<int>v[N], v2[N];

int main () {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]), --a[i];
	for (int i = 1, j = 0; i < n; ++i, ++j) {
		if (a[j] == a[i]) continue ;
		sum += (a[i] - a[j] + m) % m;
		v[(a[j] + 1) % m].push_back(i);
		v2[(a[i] + 1) % m].push_back(i);
		v[0].push_back(i);
	}
	for (int i = 0, x, y; i < m; ++i) {
		for (auto v : ::v2[i]) {
			x = (a[v] - a[v - 1] + m) % m;
			y = (a[v] - i + m) % m + 1;
			if (o[v]) --cnt;
			sum -= o[v] ? (a[v] - i + 1 + m) % m + 1 : x;
			sum += (o[v] = y <= x) ? y : x;
			if (o[v]) ++cnt, ++sum;
		}
		sum -= cnt;
		for (auto v : ::v[i]) {
			x = (a[v] - a[v - 1] + m) % m;
			y = (a[v] - i + m) % m + 1;
			if (o[v]) --cnt;
			sum -= o[v] ? y : x;
			sum += (o[v] = y <= x) ? y : x;
			if (o[v]) ++cnt;
		}
		if (sum < ans) ans = sum;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 12920