akhauriyash/Code-Regression huggingface dataset:
import java.io.*
import java.util.*

fun solve(D: Int, G: Int, p: IntArray, c: IntArray) {
    // 中途半端に解くのは一種類以下で、完答してない中で一番高い点数のもの
    // 完答リスト
    val combs = (0 until D).toSet().powerSet()
    val candidates = mutableListOf<Int>()
    for (comb in combs) {
        val point = comb.map { p[it] * (it + 1)* 100 + c[it] }.sum()
        val quant = comb.map { p[it] }.sum()
        if (point >= G) candidates.add(quant)
        else {
            val m = (0 until D).toList().filter { it !in comb }.max() ?: continue
            val ret = divCeil(G - point, 100 * (m + 1))
            if (ret < p[m] ) candidates.add(quant + ret)
        }
    }
    println(candidates.min())
    return
}

fun divCeil(a: Int, b: Int) = a / b + if (a % b == 0) 0 else 1

fun <T> Collection<T>.powerSet(): Set<Set<T>> = powerSet(this, setOf(setOf()))

private tailrec fun <T> powerSet(left: Collection<T>, acc: Set<Set<T>>): Set<Set<T>> = when {
    left.isEmpty() -> acc
    else -> powerSet(left.drop(1), acc + acc.map { it + left.first() })
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val D = sc.next().toInt()
    val G = sc.next().toInt()
    val p = IntArray(D)
    val c = IntArray(D)
    for (i in 0 until D) {
        p[i] = sc.next().toInt()
        c[i] = sc.next().toInt()
    }
    solve(D, G, p, c)
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 5050;
const ll inf = 1e18;

int n, p[M];
ll d[M];
ll A, B;
int f[M];

void clear() {
  fill(f, f + M, 0);
}

void add(int at, int val) {
  for (int i = at; i < M; i |= (i + 1)) {
    f[i] += val;
  }
}

int get(int r) {
  int ans = 0;
  for (int i = r - 1; i >= 0; i = (i & (i + 1)) - 1) {
    ans += f[i];
  }
  return ans;
}

void read() {
  cin >> n;
  cin >> A >> B;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
  }
}

void kill() {
  d[0] = 0;
  p[n] = n;
  for (int i = 1; i <= n; ++i) {
    clear();
    d[i] = 1ll * i * A;
    for (int j = i - 1; j >= 0; --j) {
      if (p[j] < p[i]) {
        ll x = get(p[j]);
        ll y = (i - j - x - 1);
        d[i] = min(d[i], x * B + y * A + d[j]);
      }
      add(p[j], 1);
    }
    cerr << i << ": -> " << d[i] << "\n";
  }
  cout << d[n] << "\n";
}

int main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int mx=100010;
int x,y,a,b,c,tot,tat;
long long e[mx*3],r[mx],g[mx],awa;
int main()
{
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	for (int i=1;i<=a;i++)
	{
		scanf("%d",&r[i]);
	}
	sort(r+1,r+a+1);
	for (int i=a;i>=a-x+1;i--)
	{
	    e[++tat]=r[i];
	}
	for (int i=1;i<=b;i++)
	{
		scanf("%d",&g[i]);
	}
	sort(g+1,g+b+1);
	for (int i=b;i>=b-y+1;i--)
	{
	    e[++tat]=g[i];
	} 
	for (int i=1;i<=c;i++)
	{
		scanf("%d",&tot);
		e[++tat]=tot;
	}
	sort(e+1,e+tat+1);
	for (int i=tat;i>=tat-x-y+1;i--)
	{
		awa+=e[i];
	}
	printf("%lld\n",awa);
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int x;
    cin >> x;
    x -= 200;
    x /= 200;
    cout << 9 - x << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main () {
  long long A, B, N;
  cin >> A >> B >> N;
  long long k = min(N, B - 1);
  long long ku = A * k;
  ku /= B;
  long long ma = k / B;
  ma *= A;
  cout << ku - ma << endl;
}

Measured memory_bytes: 3636
s = input()
n = len(s) - 1

for i in range(2 ** n):
    op = ["-"] * n
    for j in range(n):
        if (i >> j) & 1:
            op[j] = "+"
    f = ""
    for fs, fn in zip(s, op + [""]):
        f += fs + fn
    if eval(f) == 7:
        print(f + "=7")
        exit()


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

int main()
{
    ll n = 0, x = 0, ans = 0;
    cin >> n >> x;
    vector<ll> vec(n);
    rep(i, n) cin >> vec.at(i);
    rep(i, n - 1) {
        if (vec.at(i) + vec.at(i + 1) > x) {
            ans += max((ll)0, abs(x - (vec.at(i) + vec.at(i + 1))));
            vec.at(i + 1) = max((ll)0,vec.at(i + 1) - abs(x - (vec.at(i) + vec.at(i + 1))));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int,int> vii;
typedef vector<ll,ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define stop if(idx==x) return 0
int n;
ll x,idx;
ll layer[60],p[60],ans;

int eat (int z){
    idx++;
    stop;
    if(idx + layer[z-1] > x){
        x = x - idx;
        idx = 0;
        eat(z-1);
        return 0;
    }
    else{
        idx += layer[z-1];
        ans += p[z-1];
    }
    stop;

    idx++;
    ans++;
    stop;

    if(idx + layer[z-1] > x){
        x = x - idx;
        idx = 0;
        eat(z-1);
        return 0;
    }
    else{
        idx += layer[z-1];
        ans += p[z-1];
    }
    stop;

    idx++;
    stop;


}
int main(){
    layer[0] = 1;
    p[0] = 1;
    for(int i=1;i<=52;i++){
        layer[i] = 3 + 2*layer[i-1];
        p[i] = 1 + 2*p[i-1];
    }
    cin>>n>>x;
    eat(n);
    cout<<ans<<endl;

}


Measured memory_bytes: 256
from collections import deque
N, M = map(int, input().split())
R = [[] for i in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    R[a].append(b)
S,T = map(int, input().split())
answer = -1
queue =  deque()
queue.append([S,0])
visited = {}
visited[S] = 1
visited2 = {}
while queue != deque():
    tmp = queue.popleft()
    if tmp[0] == T:
        answer = tmp[1]
        break
    tmp_queue = deque()
    tmp_queue.append(tmp[0])
    for i in range(3):
        tmp2_queue = tmp_queue
        tmp_queue = deque()
        for j in tmp2_queue:
            if (j, i) in visited2:
                continue
            else:
                visited2[j,i] = 1
                tmp_queue += R[j]
    for i in tmp_queue:
        if i in visited:
            continue
        else:
            visited[i] = 1
            queue.append([i,tmp[1]+1])
            
print(answer)

Measured memory_bytes: 96928
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n;
int a[MAX_N + 1];

int main() {
    fastio();

    cin >> n;
    forn1(i, n) cin >> a[i];

    int ans = 0;
    int cur = 1;
    forn(i, n + 10) {
        if (cur == 2) {
            cout << ans << endl;
            return 0;
        }
        ans++;
        cur = a[cur];
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
    kill = min(a[i], b[i])
    b[i] -= kill
    a[i] -= kill
    
    kill2 = min(a[i+1], b[i])
    b[i] -= kill2
    a[i+1] -= kill2

    res += kill + kill2

print(res)



Measured memory_bytes: 19116
#include <stdio.h>
 
int a(int n,int m){
  return (n*n*n*n*n)-(m*m*m*m*m);
}
 
int main() {
  int X=0;
  scanf("%d",&X);
  for(int i=-119;i<=119;i++){
    for(int j=-119;j<=118;j++){
      if(a(i,j)==X){
        printf("%d %d",i,j);
        return 0;
      }
    }
  }
 
  return 0;
}

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

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

    if (A + B + C >= 22){
        cout << "bust" << endl;
    } else cout << "win" << endl;

}

Measured memory_bytes: 256
Sa = list(input())
Sb = list(input())
Sc = list(input())

Sa.reverse()
Sb.reverse()
Sc.reverse()

now = 0
while True:
    if now == 0:
        if not Sa: break
        s = Sa.pop()
    elif now == 1:
        if not Sb: break
        s = Sb.pop()
    else:
        if not Sc: break
        s = Sc.pop()
    
    now = ord(s) - ord("a")

print(chr(ord("A") + now))

Measured memory_bytes: 3064
a, b = map(int, input().split())

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

result = a * b / gcd(a, b)

print(int(result))

Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<ll> x(N),y(N),h(N); rep(i,N) cin>>x[i]>>y[i]>>h[i];
  
  rep(C_x,101){
    rep(C_y,101){
      ll H=1;
      rep(i,N) if(h[i]>0) H=h[i]+abs(x[i]-C_x)+abs(y[i]-C_y);
      int judge=1;
      rep(i,N) {
        if(h[i]==0) {if(H>abs(x[i]-C_x)+abs(y[i]-C_y)) judge=0;}
        else if(H!=h[i]+abs(x[i]-C_x)+abs(y[i]-C_y)) judge=0;
      }
      //cout<<H<<" "<<h[1]<<" "<<abs(x[1]-C_x)<<" "<<abs(y[1]-C_y)<<endl;
      //cout<<judge<<endl;
      if(judge) {cout<<C_x<<" "<<C_y<<" "<<H<<endl; return 0;}
    }
  }
  
  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  bool a01=0,a02=0,a12=0;
  if(a[0]!=a[1]||(a[0]!=a[2]&&a[1]==a[0]))a01=1;
  if(a[0]!=a[2]||(a[0]!=a[1]&&a[2]==a[0]))a02=1;
  if(a[1]!=a[2]||(a[2]!=a[0]&&a[1]==a[2]))a12=1;
  if(a01&&a02&&a12) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n){
        int t;cin>>t;
        a[i]=t-i-1;
    }
    sort(all(a));
    ll tot=0;
    int r=a[n/2];
    rep(i,n)tot+=abs(a[i]-r);
    cout<<tot<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

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

    System.out.print(s.charAt(0));
    System.out.print(s.length()-2);
    System.out.print(s.charAt(s.length()-1));
    }
}

Measured memory_bytes: 35684
//
// Created by 李青坪 on 2018/10/15.
//

#include "cstdio"
#include "algorithm"
using namespace std;
#define MAXN 1000
#define MAXV 10000

int a[MAXN], b[MAXN];
int T[MAXV+1]; //记录排序过后原来的元素应该移动到的位置
int m = MAXV;

int findMinimumCost(int n){
    bool v[n];
    for (int i = 0; i < n; ++i) {
        b[i] = a[i];
        v[i] = false;
    }
    sort(b, b+n);
    for (int j = 0; j < n; ++j) {
        T[b[j]] = j;
    }
    int S = 0;
    for (int k = 0; k < n; ++k) {
        if (v[k]) continue;
        int cur = k;
        int nn = 0; //记录圆中有多少个元素
        int sm = MAXV; //记录圆中的最小元素
        int sum = 0; //记录圆中各元素的和
        while (true){
            v[cur] = true;
            int value = a[cur];
            ++nn;
            sum += value;
            sm = min(sm, value);
            cur = T[value];
            if (cur == k) break;
        }
        S += min(sum + (nn-2)*sm, sum + sm + (nn+1)*m); //是圆内交换代价更小还是借用外来元素的代价更小
    }
    return S;
}
int main(){
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        m = min(m, a[i]);
    }
    int ans = findMinimumCost(n);
    printf("%d\n", ans);
}


Measured memory_bytes: 2840
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

typedef vector< int > VI;
typedef vector< VI > VVI;

int main(){
	while(true){
		int n, m;

		cin >> n >> m;

		if(n == 0 && m == 0){
			break;
		}

		VVI map_cost(m, VI(m, INT_MAX / 4));
		VVI map_time(m, VI(m, INT_MAX / 4));

		for(int i = 0; i < m; i++){
			map_cost[i][i] = 0;
			map_time[i][i] = 0;
		}

		for(int i = 0; i < n; i++){
			int a, b, cost, time;
			cin >> a >> b >> cost >> time;

			a--;
			b--;

			map_cost[a][b] = cost;
			map_time[a][b] = time;
			map_cost[b][a] = cost;
			map_time[b][a] = time;
		}

		for(int k = 0; k < m; k++){
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					map_cost[i][j] = min(map_cost[i][j], map_cost[i][k] + map_cost[k][j]);
					map_time[i][j] = min(map_time[i][j], map_time[i][k] + map_time[k][j]);
				}
			}
		}

		int k;
		cin >> k;

		int p, q, r;

		for(int i = 0; i < k; i++){

			cin >> p >> q >> r;

			p--;
			q--;

			if(r == 0){
				cout << map_cost[p][q] << endl;
			}
			else if(r == 1){
				cout << map_time[p][q] << endl;
			}
		}
	}
}

Measured memory_bytes: 1304
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m,i,num;
    float s;
    
    scanf("%d %d",&n,&m);
    
    num = 0;
    s = 0.0;
    
    int a[n];
    
    for(i = 0;i < n;i++)
	{
        scanf("%d",&a[i]);
        
        s += a[i];
    }
    
    s /= 4.0 * (float)m;
    
    for(i = 0;i < n;i++)
	{
        if(a[i] >= s)
            num++;
            
        if(num == m)
            break;
    }
    
    printf("%s\n",num == m?"Yes":"No");
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define EPS 1e-9
#define INF  1e15 +1    /// 10^15 + 1
#define INF2 ((ll)1)<<63 /// 2^63
#define all(a)  a.begin(),a.end()
#define bit(i,j) ((i)&((ll)1<<j))
#define setbit(i,j) ((i)|((ll)1<<j))
#define forn(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define dbg(x) cout << #x"=" << x << '\n';
#define dbg2(x,y) cout << #x"=" << x << " " << #y"=" << y << '\n';
#define dbg3(x,y,z) cout << #x"=" << x << " " << #y"=" << y << " " << #z"=" << z << '\n';
const int MOD = 1000000007;
const int mod = 998244353;
const int nala5 = 1e5 +5;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector < pii > vpii;
typedef vector < pll > vpll;
typedef vector < vpii > vvpii;
typedef vector < vpll > vvpll;
typedef vector < set <int> > vsi;
typedef vector < set <ll> > vsll;

int main(){
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
    string s,t;
    int n,m;
    cin>>s>>t;
    n = s.size(); m = t.size();
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    vvpii cor(n+1);
    for(int i=0;i<=n;i++){
        cor[i].resize(m+1);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1] == t[j-1] && dp[i-1][j-1] + 1 > dp[i][j]){ dp[i][j] = dp[i-1][j-1] + 1; cor[i][j] = mp(i-1,j-1); }
            if(dp[i-1][j] > dp[i][j]){ dp[i][j] = dp[i-1][j]; cor[i][j] = mp(i-1,j); }
            if(dp[i][j-1] > dp[i][j]){ dp[i][j] = dp[i][j-1]; cor[i][j] = mp(i,j-1); }
        }
    }
    string res="";
    int x=n, y=m;
    while(x > 0 && y > 0){
        if(s[x-1] == t[y-1]){
            res+=s[x-1];
        }
        int a = cor[x][y].fi, b=cor[x][y].se;
        x = a; y = b;
    }
    reverse(all(res));
    cout<<res<<'\n';
}	


Measured memory_bytes: 109204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
 os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os << "(" << P.first << "," << P.second << ")";}

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


#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector< pii >


const int mod=1e9+7;
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}
inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;} 

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int ans =0 ;	
	int n;cin>>n;
	string s, t;
	cin>>s>>t;
	vi same(n, 1);
	for(int i=0;i<n;i++){
		if(s[i]!=t[i])same[i]=0;
	}
	int i,j;
	for(i=0;i<n;i++){
		// trace(i);
		if(i==0){
			if(same[i])ans = 3;
			else ans = 6, i++;
			continue;
		}
		if(same[i]){
			if(same[i-1])ans = mul(ans, 2);
		}
		else{
			if(same[i-1])ans = mul(ans, 2);
			else ans = mul(ans, 3);
			i++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n; string s;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
cin >> s;
for (int i=0; i<s.size(); i++){
	cout << (char)((s[i]-'A'+n)%26+'A');
}
return 0;
}


Measured memory_bytes: 256
///BISMILLAHIR RAHMANIR RAHMIM
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000002
int pri[MAX+2];
int cnt[MAX+2];
void sieve(int n)
{
    pri[1]=1;
    for (int i=2;i<=n;i++)
    {
        if(pri[i]==0)
        {
            for (int j=i+i;j<=n;j+=i)
            {
                pri[j]=1;
            }
        }
    }
    int tot = 0;
    for(int i = 1;i<=n;i++)
    {
        if(pri[i]==0)
            tot++;
        cnt[i] = tot;
    }
}
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    sieve(MAX);
    int n;
    while(cin>>n)
    {
        cout << cnt[n] << "\n";
    }
    return 0;
}

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

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

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

void solve(int n){
    vector<int> p(n+1), t(n+1);
    for (int i = 0; i < n; ++i) {
        cin >> p[i+1] >> t[i+1];
    }
    vector<vector<int>> dp(n+1, vector<int>(4, INF<int>));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        int ok = 0;
        for (int j = 0; j < 4; ++j) {
            if(dp[i][j] != INF<int>){
                if(j != 3){
                    if(t[i+1]-t[i] >= (j+1)*abs(p[i+1]-p[i])){
                        dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+abs(p[i+1]-p[i]));
                        ok = 1;
                    }
                }
                if(t[i+1]-t[i] >= (j+1)*p[i]+p[i+1]){
                    dp[i+1][1] = min(dp[i+1][1], dp[i][j]+p[i]+p[i+1]);
                    ok = 1;
                }
            }
        }
        if(!ok){
            printf("NG %d\n", i+1);
            return;
        }
    }
    int ans = INF<int>;
    for (int j = 0; j < 4; ++j) {
        ans = min(ans, dp.back()[j]);
    }
    printf("OK %d\n", ans+p.back());
}


int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


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

int main(){
    long long N,K,sum=0;
    cin >> N >> K;
    vector<int> HP(N);

    for(int i=0; i<N; i++){
        cin >> HP[i];
    }

    sort(HP.begin(),HP.end());

    for(int i=0; i<N-K; i++){
        sum+=HP[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int opt[3001][3001];
char s[3010], t[3010];

vector<char> ans;

void constructAns(int n, int m) {
	if (n == 0 || m == 0) return;
	else if (s[n-1] == t[m-1]) ans.push_back(s[n-1]), constructAns(n-1, m-1);
	else if (opt[n][m] == opt[n-1][m]) constructAns(n-1, m);
	else constructAns(n, m-1);
}

int main() {
	scanf("%s", s);
	scanf("%s", t);
	int n = strlen(s), m = strlen(t);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (s[i-1] == t[j-1]) opt[i][j] = opt[i-1][j-1] + 1;
			else opt[i][j] = max(opt[i-1][j], opt[i][j-1]);
		}
	}
	constructAns(n, m);
	reverse(ans.begin(), ans.end());
	for (char c : ans) printf("%c", c);
	printf("\n");
	return 0;
}



Measured memory_bytes: 35456
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int find(int x, auto &pa) {
    return pa[x] < 0 ? x : pa[x] = find(pa[x], pa);
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    vector<pair<pii, int>> arr(n);
    for (int i = 0 ; i < n ; i++) {
        auto &p = arr[i].F;
        cin >> p.F >> p.S;
        arr[i].S = i;
    }
    sort(arr.begin(), arr.end());
    vector<int> ans(n, 0);
    map<int, int> mp;
    vector<int> pa(n, -1);
    vector<pii> stk;
    for (auto &p : arr) {
        int minV = p.F.S;
        while (stk.size() && p.F.S > stk.back().F) {
            minV = min(minV, stk.back().F);
            int x = find(p.S, pa);
            int y = find(stk.back().S, pa);
            if (x != y) {
                if (pa[x] > pa[y])
                    swap(x, y);
                pa[x] += pa[y];
                pa[y] = x;
            }
            stk.pop_back();
        }
        stk.push_back({minV, p.S});
    }
    for (int i = 0 ; i < n ; i++) {
        cout << -pa[find(i, pa)] << '\n';
    }
}

Measured memory_bytes: 7452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	ll k;
	cin>>s>>k;
	ll ocnt = 0;
	while(s[ocnt] == '1')
		ocnt++;
	char a = ocnt>=k?'1':s[ocnt];
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
r = [input().split() + [i] for i in range(n)]
for i in range(n):
  r[i][1] = int(r[i][1])
r.sort(reverse=True, key=lambda x:x[1])
r.sort(key=lambda x:x[0])
for i in r:
  print(i[2]+1)

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

int main()
{
    int n, i;
    cin>>n;
    for(i=1; i<=9; i++)
        if(n%i==0)
            if(n/i>=1 && n/i<=9)
            {
                cout<<"Yes";
                return 0;
            }
    cout<<"No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){

int h,a,i;
cin >> h >> a;

for(i=0;h>0;i++){
  h=h-a;
}

cout << i << endl;

}


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

int main() {
  ll X;
  cin >> X;
  for (ll b = -500; b <= 500; b++) {
    ll a = X + pow(b, 5);
    double A = pow((double) a, 0.2);
    ll AA = (ll) A;
    double AAA = (double) AA;
    if (abs(A - AAA) < 0.0000000000001) {
      cout << A << " " << b << endl;
      break;
    }
  }
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

signed main(void){
  int a,b,c;cin >> a >> b >> c;
  int ans = max(b+c-a,0);
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

#define MAXN 100000

int n,a[MAXN];
long long sum[MAXN + 1];

long long psum(int a, int b){
    return sum[b + 1] - sum[a];
}

int main(){
    ios::sync_with_stdio(0);

    int L;

    cin >> n >> L;

    for(int i = 0;i < n;++i){
        cin >> a[i];
    }

    bool ok = false;
    vector<int> ans;

    for(int i = 0;i + 1 < n && !ok;++i){
        if(a[i] + a[i + 1] >= L){
            ok = true;
            for(int j = 0;j < i;++j)
                ans.push_back(j + 1);
            for(int j = n - 1;j > i + 1;--j)
                ans.push_back(j);
            ans.push_back(i + 1);
        }
    }

    if(!ok) cout << "Impossible\n";
    else{
        cout << "Possible\n";
        for(int x : ans){
            cout << x << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);

const int N = 105;
char s[N];

void init() {
    scanf("%s",s);
}

void solve() {
    int n = strlen(s);
    int ans = 0;
    rep (i,n/2) if (s[i] != s[n-i-1]) ans++;
    printf(IN,ans);
}


#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}


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

int main() {
    int n, t, result = 0;
    cin >> n >> t;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int best = 0, worst = a[0];
    for (int i = 0; i < n; ++i) {
        best = max(best, a[i] - worst);
        worst = min(worst, a[i]);
    }
    worst = a[0];
    for (int i = 0; i < n; ++i) {
        if (a[i] - worst == best) {
            ++result;
        }
        worst = min(worst, a[i]);
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int a[100005]={0};


int main()
{
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
   scanf("%d",&a[i]);
  }
  sort(a,a+n);
  int t=n/2;
  int k=t-1;
  int ans=a[t]-a[k];
  printf("%d\n",ans);
}


Measured memory_bytes: 768
import math
A, B, H, M = map(int, input().split())

a = 30 * (H%12) + 0.5 * M
b = 6 * M

degree = min(abs(a-b), 360 - abs(a-b))
ans = A**2 + B ** 2 - 2*A*B*math.cos(math.radians(degree))


print(ans**0.5)


Measured memory_bytes: 9524
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;

const int maxn=1e5+5;

int n;
int fa[maxn];
queue<pii> q;
set<int>s[maxn];
map<pii,int>cnt;
set<int>::iterator it;

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

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

int main() {
	n=read();
	for(int i=1;i<2*n-1;i++) {
		int x=read(),y=read();
		s[x].insert(y),s[y].insert(x);
		if(x>y)swap(x,y);
		pii tmp=make_pair(x,y);
		cnt[tmp]++;
		if(cnt[tmp]==2)q.push(tmp);
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<n;i++) {
		if(q.empty()) {puts("NO");return 0;}
		int x=0,y=0;
		for(;x==y;x=find(q.front().first),y=find(q.front().second),q.pop());
		if(s[x].size()>s[y].size())swap(x,y);fa[x]=y;
		for(it=s[x].begin();it!=s[x].end();it++) {
			int v=*s[x].find(*it);
			s[v].erase(s[v].find(x));
			if(v==y)continue;
			s[v].insert(y),s[y].insert(v);
			pii tmp;
			if(v>y)tmp=make_pair(y,v);
			else tmp=make_pair(v,y);
			cnt[tmp]++;
			if(cnt[tmp]==2)q.push(tmp);
		}
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 43520
#include <iostream>
#include <cstdio>
#include <algorithm>
#define PII pair<ll, ll>
#define F first
#define S second

using namespace std;

typedef long long ll;

ll n;
ll x;
PII a[200005];

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a[i].S, &a[i].F);
    }
    sort(a, a + n);
    for(ll i = 0; i < n; i++)
    {
        x += a[i].S;
        if(x > a[i].F)
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int maxN = 30;

vector<ll> factorize(ll x) {
    vector<ll> ans;

    for(ll i = 1; i * i <= x; i++) {
        if(x % i == 0) {
            ll j = x / i;
            if(i != 1) {
                ans.push_back(i);
            }

            if(i != j) {
                ans.push_back(j);
            }
        }
    }

    return ans;
}

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

    ll n;   cin >> n;

    vector<ll> a = factorize(n);
    vector<ll> b = factorize(n - 1);

    int ans = 0;

    map<int, int> vis;

    for(auto &x : a) {
        ll cur = n;
        while(cur % x == 0) {
            cur /= x;
        }

        if(cur % x == 1) {
            ans++;
            vis[x] = true;
        }
    }

    for(auto &x : b) {
        if(vis[x]) {
            continue;
        }

        ans++;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define db double
#define lli long long int
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define pi pair<lli,lli>
void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
}
//double dist()
void solve()
{
	lli n,ctr=0;
	db d,x,y,z;
	cin>>n;
	cin>>d;
	rep(i,0,n)
	{
		cin>>x>>y;
		z=(x*x+y*y);
		z=sqrt(z);
		if(z<=d)ctr+=1;
	}
	cout<<ctr;
}
int main()
{
  fast();
 	solve();
 return 0; 
}

Measured memory_bytes: 3860
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        sc.nextLine();

        char[][] s = new char[h][w];
        for(int i=0; i<h; i++) {
            s[i] = sc.nextLine().toCharArray();
        }
        sc.close();

        int[] x = {1, 1, 0, -1, -1, -1, 0, 1};
        int[] y = {0, 1, 1, 1, 0, -1, -1, -1};

        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                if(s[i][j] == '.') {
                    int cnt = 0;
                    for(int k=0; k<8; k++) {
                        int nx = i + x[k];
                        int ny = j + y[k];
                        if(nx < h && ny < w && nx >= 0 && ny >= 0 && s[nx][ny] == '#') {
                            cnt++;
                        }
                        s[i][j] = (char)(cnt + '0');
                    }
                }
            }
        }
        for(int i=0; i<h; i++) {
            String ans = new String(s[i]);
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
const int MOD = 1e9 + 7;

using namespace std;

int main(){
    vector<pair<int,int>> prime;
    int n,a=2;
    long long ans=1;
    scanf("%d",&n);

    while(a<=n){
        int k=a;
        for(int i=0;k!=1&&i<prime.size();){
            if(k%prime[i].first){
                ++i;
                continue;
            }else{
                k/=prime[i].first;
                ++prime[i].second;
            }
        }
        if(k!=1) prime.push_back(make_pair(k,1));
        ++a;
    }

    REP(i,prime.size()) ans = ans*(prime[i].second+1)%MOD;

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
n = int(input())
prt = [-1 for i in range(n)]
chd = [[] for i in range(n)]
root = -1

def preOrder(num):
    if num == -1:
        return
    print(f' {num}', end = '')
    preOrder(chd[num][0])
    preOrder(chd[num][1])

def inOrder(num):
    if num == -1:
        return
    inOrder(chd[num][0])
    print(f' {num}', end = '')
    inOrder(chd[num][1])

def postOrder(num):
    if num == -1:
        return
    postOrder(chd[num][0])
    postOrder(chd[num][1])
    print(f' {num}', end = '')
    
for i in range(n):
    idx, left, right = map(int, input().split())
    chd[idx].append(left)
    chd[idx].append(right)
    if left >= 0:
        prt[left] = idx
    if right >= 0:
        prt[right] = idx

for i in range(n):
    if prt[i] == -1:
        root = i
        break

print('Preorder')
preOrder(root)
print('\nInorder')
inOrder(root)
print('\nPostorder')
postOrder(root)
print('')


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


def solve(N: int):
    ns = [0]*N
    for i in range(1,N+1):
        for k in range(1,N//i+1):
            ns[i*k-1] += i*k
    print(sum(ns)) 
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 151400
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

string str[10010], T;
int judge(string s){
	if(s == T)return 2;
	if(s > T)return 0;
	else return 1;
}

int solve(int p){
	string s = str[p];
	int size = str[p].size(), ret[2] = {};
	rep(i,size)if(str[p][i] == '?')s[i] = 'z';
	ret[0] = judge(s);
	rep(i,size)if(str[p][i] == '?')s[i] = 'a';
	ret[1] = judge(s);
	if(ret[0] == 2 or ret[1] == 2)return -1;
	if(ret[0]+ret[1] == 1)return -1;
	if(ret[0]+ret[1] == 0)return 0;
	return 1;
}

signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n)cin >> str[i];
	cin >> T;
	int cnt = 0, r = 0;
	rep(i,n){
		int tmp = solve(i);
		if(tmp == -1)r++;
		else cnt += tmp;
	}
	//printf("%lld %lld\n", r, cnt);
	rrep(i,r+1){
		printf("%lld%c", cnt+i, i == r+1 ? '\n' : ' ');
	}
	return 0;
}




Measured memory_bytes: 1024
import java.util.Scanner;

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

    long A = scanner.nextLong();
    long B = scanner.nextLong();

    long res = 0;
    for (int i = 0; i < 40; i++) if ((count(B, i) - count(A - 1, i)) % 2 == 1) res += 1L << i;
    System.out.println(res);
  }

  private static long count(long a, int i) {
    a++;
    long n = 1L << i;
    long m = 1L << (i + 1);
    return (a / m) * n + Math.max((a % m) - n, 0);
  }
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int N, H;
vec<int> a, b;

signed main() {
   cin >> N >> H;
   a.resize(N), b.resize(N);
   int aMax = 0;
   rep (i, N) {
      cin >> a[i] >> b[i];
      chmax(aMax, a[i]);
   }

   vec<int> bCand;
   rep (i, N) {
      if (b[i] > aMax) {
         bCand.push_back(b[i]);
      }
   }

   int cnt = 0;
   sort(all(bCand));
   reverse(all(bCand));
   rep (i, bCand.size()) {
      H -= bCand[i];
      cnt++;
      if (H <= 0) {
         cout << cnt << endl;
         return 0;
      }
   }

   // dbg2(H, cnt)
   // cnt += H / aMax + (H % aMax != 0);
   // cnt += H / aMax;
   cnt += (H + (aMax - 1)) / aMax;

   cout << cnt << endl;

   return 0;
}

Measured memory_bytes: 2936
import fractions

# スペース区切りの整数の入力
A,B,K = map(int, input().split())

divisor = fractions.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)

Measured memory_bytes: 5048
#include<iostream>
#include<cstdlib>
#include<string>

using namespace std;

int main(void){
	string number;
	int num, i;
	while(1){
		num = 0;
		cin >> number;
		for(i = 0;i < number.size();i++){
			num = num + number[i] - '0';
		}
		if(num == 0){
			break;
		}
		cout << num << endl;
	}

	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
ll A, B, N;
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   cin >> A >> B >> N;
   ll x = min(N, B - 1);
   cout << floor(A * x / B) - A * floor(x / B) << endl;

   return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using lli = long long int;
ll MM = 1000000000;
ll mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)

int main(){
    int n; cin >> n;
    ll t[n];
    ll all_time = 0;
    for(int i = 0; i < n; i++){
        cin >> t[i];
        all_time += t[i];
    }
    ll ans = all_time;
    int m; cin >> m;
    int p[m], x[m];
    for(int i = 0; i < m; i++){
        cin >> p[i] >> x[i];
    }
    for(int i = 0; i < m; i++){
        ans -= t[p[i] - 1];
        ans += x[i];
        cout << ans << endl;
        ans = all_time;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=100005;
//i_am_noob
int n,a,b;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	if(n==1){
		print1("Hello World");
		return 0;
	}
	cin >> a >> b;
	print1(a+b);
	return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int count = 1;
  for (int i = 1; i<n; i++) {
    if (s[i] != s[i-1]) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	
	int a, b;
	cin >> a >> b;

	int kotae = (a + b) / 2 + (a + b) % 2;

	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main(int argc, char const *argv[])
{
    int N,K,X,Y;
    std::cin >> N >> K >> X >> Y;
    int fee = -1;
    if(N >= K){
        fee = K * X + (N - K) * Y;
    } else{
        fee = N * X;
    }
    std::cout << fee << '\n';    
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
using namespace std;
string str;
int len;
int main()
{
	cin>>str;
	for(int i=0;i<=str.length();i++)
	{
		if(str[i]=='?')	str[i]='D';
	}
	cout<<str;
	return 0;
}

Measured memory_bytes: 3724
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
const int maxn=500+7;
int n,m,H,W;
int main(){
	std::cin>>n>>m>>H>>W;
	bool h=(n%H>0),w=(m%W>0);
	if(!h && !w)return puts("No"),0;
	puts("Yes");
	if(h){
		int k=(n+H-1)/H,x=n*maxn+1,y=k*maxn;
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)
				printf("%d%c",i%H==1 ? x-y : -y," \n"[j==m]);
	}else {
		int k=(m+W-1)/W,x=m*maxn+1,y=k*maxn;
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)
				printf("%d%c",j%W==1 ? x-y : -y," \n"[j==m]);
	}return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

    int res = 100000;
    for (int start = 0; start <= 1; start++) {
        int num = start;
        int count = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] - '0' != num) count++;
            num = 1 - num;
        }
        res = min(res, count);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512