akhauriyash/Code-Regression huggingface dataset:
import math


class binarySearch:
    # 添え字「t」によってソート済みリストを二分探索
    def __init__(self, limit, target):
        self.limit = limit
        self.target = target
        self.t = 0

    def condition(self, h, a, b):
        if self.t < 0:
            return False
        count = 0
        for i in range(len(h)):
            if h[i] > b * self.t:
                count += math.ceil((h[i] - b * self.t) / (a - b))
        if count > self.t:
            return False
        else:
            return True

    def search(self, h, a, b):
        low = 0
        high = self.limit
        self.t = int((low + high) / 2)
        while high >= low:
            out = self.condition(h, a, b)
            # print("t:{} _out:{} limit:{}\n".format(t, out, self.limit))
            if not out:
                low = self.t + 1
            else:
                high = self.t - 1
            self.t = int((low + high) / 2)
        # print("low:{} high:{} t:{}".format(low, high, self.t))
        return self.t + 1


def func(a, b, _h):
    _h.sort()
    _h.reverse()
    _sum = 0  # 現在何回以上爆発させることが確定しているか
    aMargin = 0  # _sum回のうちあと何回aを使うことができるか
    for h in _h:
        print("prev cost upper:{}".format(a * aMargin + b * (_sum - aMargin)))
        # まず_sum回で抑える場合にaがいくつ必要か算出
        if h <= a * aMargin + b * (_sum - aMargin):
            # そのうちどれだけaを使わないでいられるか
            h -= b * _sum  # まず必ず減る部分を計算
            if h > 0:
                aMargin -= math.ceil(h / (a - b))  # a が何回必要か
        else:
            # hを0にするのに必要最低限の回数をを算出
            tmpH = h
            tmpH -= a * aMargin + b * (_sum - aMargin)
            extra = math.ceil(tmpH / a)
            _sum += extra
            aMargin += extra
            print("aMargin:{}".format(aMargin))
            # 合計して「_sum」回が最小回数
            # ここで使えるaは「aMargin」回
            # そのうちどれだけaを使わないでいられるか
            h -= b * _sum  # まず必ず減る部分を計算
            aMargin -= math.ceil(h / (a - b))  # a が何回必要か
        print("_sum:{} margin:{}".format(_sum, aMargin))
    return str(_sum)


n, a, b = [int(i) for i in input().split()]
h = [0 for _ in range(n)]
for i in range(n):
    h[i] = int(input())
# print(func(a, b, h))
binary = binarySearch(target=math.ceil(max(h) / a), limit=math.ceil(max(h) / 1))
print(binary.search(h, a, b))
# print("print(func({}, {}, {}))".format(a, b, h))
"""
print("2 vs " + func(5, 3, [8, 7, 4, 2]))
print("4 vs " + func(10, 4, [20, 20]))
print("800000000 vs " + func(2, 1, [900000000, 900000000, 1000000000, 1000000000, 1000000000]))
"""


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

N, T = map(int, input().split())
A = list(map(int, input().split()))
p = -1
dif = h = hc = lc = c = 0
for i in A[-2::-1]:
    a, b = A[p], A[p]-i
    if i > a:
        p = -c-2
    elif b >= dif:
        if a != h : h, hc = a, hc+1
        if b > dif : dif, lc = b, 0
        lc += 1
    c += 1
print(min(hc, lc))

Measured memory_bytes: 15020
import numpy as np
N=int(input())
A=np.array(list(map(int, input().split())))


mod = 10**9+7
ans = 0
#bitの60桁を見ていく
#桁ごとに分割して足していく
for i in range(60):
  #i桁目が1である要素数　N-b1はi桁目が0である要素数
  b1 = np.count_nonzero(A>>i&1)
  #bi * (N-b1) がxorを意味している
  ans += 2**i*b1*(N-b1)
  ans %= mod
print (ans)


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

int main(){
  int n;
  for(;;){
    cin >> n;
    if(!n) { break; }
    int a, b;
    int asum = 0, bsum = 0;
    for(int i = 0; i < n; i++) {
      cin >> a >> b;
      if(a > b){
	asum+=a+b;
      } else if(a < b) {
	bsum+=a+b;
      } else {
	asum+=a;
	bsum+=b;
      }
    }
    cout << asum << " " << bsum << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>


using namespace std;


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

  cin >> a >> b >> c;

  int flag=1, comp=a;
  while (comp <= a*b){
    if (comp%b == c){
      cout << "YES" << endl;
      flag = 0;
      break;
    }
    comp += a;
  }

  if (flag) cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int A,B,C,X,Y,minn;
    int total=0;
    while(cin>>A>>B>>C>>X>>Y)
    {
       int sum1=0,sum2=0;
       total=X*A+Y*B;
       if(X>Y)
         {
             sum1=Y*C*2+A*(X-Y);
             sum2=X*C*2;
         }
        else
        {
            sum1=X*C*2+B*(Y-X);
            sum2=Y*C*2;
        }
        minn=min(sum1,sum2);
        cout<<min(minn,total)<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
def Main(N, A):
    d = {}
    for i in range(1, N+1):
        d[i] = 0
    for e in A:
        d[e] += 1
    return d.values()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    out = Main(N, A)
    for e in out:
        print(e)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38932
#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;cin>>n;
    int i=n/111;

    if(n%111 != 0)
        ++i;
    cout<<(i*111)<<endl;

 return 0;
 }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    while(h!=0)
    {
        int i,j;
        for(i=0; i<h; i++)
        {
            for(j=0; j<w; j++)
                if(i%2==0&&j%2==0||i%2==1&&j%2==1)
                    cout<<"#";
                else
                    cout<<".";
            cout<<endl;
        }
        cout<<endl;
        cin>>h>>w;
    }
    return 0;
}




Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
ll dp[400+5][400+5];
ll arr[400+5];
ll pre[400+5];
ll min(ll a, ll b){if(a<b) return a;return b;}

void preC(){
	pre[0] = arr[0];
	for(ll i = 1;i<N;i++)
		pre[i] = arr[i]+pre[i-1];
}

ll sum(ll i, ll j){
	/*if (i == 0)return pre[j-1];
	return pre[j-1]-pre[i-1];*/
	
	ll s = 0;
	for(ll k = i;k<j;k++)s+=arr[k];
	return s;
}

ll solve(ll i, ll j){
	if (i>j) return 0;
	
	if(dp[i][j] != -1) return dp[i][j];
	
	if (i+1 == j) return dp[i][j] = 0;
	ll ans = 1e18;
	for(ll k = i+1;k<j;k++){
		ans = min(ans, sum(i,j) + solve(i,k) + solve(k,j));
	}
	dp[i][j] = ans;
	return dp[i][j];
}
int main(){
	cin>>N;
	for(ll i = 0;i<N;i++)cin>>arr[i];
	memset(dp, -1, sizeof dp);
	//preC();
	cout<<solve(0, N)<<endl;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    if (s.find("R") < 10) ans = 1;
    if (s.find("RR") < 10) ans = 2;
    if (s.find("RRR") < 10) ans = 3;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
N, A, B = map(int, input().split())

sm = 0

for i in range(1, N+1):
    digit = str(i)
    sm_t = 0
    for d in digit:
        sm_t += int(d)
    
    if sm_t >= A and sm_t <= B:
        sm += i

print(sm)

Measured memory_bytes: 3060
#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))

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() {
  vi32 ans = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
  int k;
  cin >> k;
  cout << ans[k - 1] << endl;
}


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

int main() {
    int A,B,C;
    int K;

    cin >> A >> B >> C;
    cin >> K;

    int cnt = 0;

    bool con1 = false;  //BがAより大きい B > A
    bool con2 = false;  //CがBより大きい C > B

    while (con1 == false){
        if (B <= A){
            cnt++;
            B *= 2;
        }
        if (B > A){
            con1 = true;
        }
    }

    while (con2 == false){
        if (C <= B){
            cnt++;
            C *= 2;
        }    
        if (C > B){
            con2 = true;         
        }
    }

    if (cnt <= K){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }


}


Measured memory_bytes: 3632
import numpy as np
N = int(input())
ary = np.array([list(map(int, input().split())) for i in range(N)])

zoro = (ary[:, 0] == ary[:, 1]).astype(int)

f = "No"
for i in range(len(zoro) - 2):
  if zoro[i] + zoro[i+1] + zoro[i+2] == 3:
    f = "Yes"
    break

print(f)


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

int main () {
  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;
  
  int water = 0,sugar=0;
  int ans_water = min (A,B),ans_sugar=0;
  
  for(int a=0;100*A*a<=F;a++){
    for(int b=0;100*B*b<=F;b++){
      
  
  for(int c=0;c*C<=F;c++){
    for(int d=0;d*D<=F;d++){
      water = a*A+b*B;
      sugar=c*C+d*D;
      if(water>0 && sugar<=E*water && 100*water+sugar<=F){
        if(100*ans_water*sugar>ans_sugar*100*water){
          ans_water = water;
          ans_sugar = sugar;
        }
           }
           }
           }
           }
           }
           cout << 100*ans_water+ans_sugar << " "  << ans_sugar << endl;
           }

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        int C[]=new int[12];
        int temp[]=new int[12];
        int A[][]=new int [12][12];

        int N,M,X,min,tmp,flag;
        min=Integer.MAX_VALUE;

        Scanner sc=new Scanner(System.in);

        N=sc.nextInt();
        M=sc.nextInt();
        X=sc.nextInt();

        for(int i=0;i<N;i++){
            C[i]=sc.nextInt();
            for(int j=0;j<M;j++){
                A[i][j]=sc.nextInt();
            }
        }

        for(int i=0;i<Math.pow(2,N);i++){
                 tmp=0;flag=0;
            for(int m=0;m<M;m++)
                temp[m]=0;
            for(int j=0;j<N;j++){
                if((1&i>>j)==1){   
                    for(int t=0;t<M;t++)
                    temp[t]+=A[j][t];
                    tmp+=C[j];
                }
                
            }
            for(int t=0;t<M;t++)
            if(temp[t]<X){
            flag++;
            }
           // System.out.println(tmp+"  "+flag);
            if(flag==0){
            min=Math.min(min,tmp);
            }
        }
    if(min==Integer.MAX_VALUE){
    System.out.println(-1);
    System.exit(0);
    }

        System.out.println(min);
    }
}

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

typedef long long int ll;
int main(){

ll result, a, b, c, k, s1, s2, s3;

cin >> a >> b >> c;

cin >> k;

k = pow(2,k);

s1 = a + b + c*k;

s2 = a + c + b*k;

s3 = c + b + a*k;

result = max(s1, s2);
result = max(result, s3);

cout << result << endl;



    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String str = scan.nextLine();
			String ansStr = "";
			char[] chArray = str.toCharArray();
			for(int i = 0;i < chArray.length;i++){
				if(chArray[i] == '@'){
					int a = Integer.parseInt(chArray[i+1]+"");
					String nStr = chArray[i+2] + "";
					while(a > 0){
						ansStr += nStr;
						a--;
					}
					i += 2;
				}else{
					ansStr += chArray[i] + "";
				}
			}
			System.out.println(ansStr);
		}
	}
}

Measured memory_bytes: 17168
n = int(input())
s = list(input())


ans = 10**6
r = [0]
w = [0]

for i in range(n):
    r.append(r[i] + (s[i] == "R"))
    w.append(w[i] + (s[i] == "W"))

# print(r)
# print(w)

for i in range(n + 1):
    mi = min(w[i], r[-1] - r[i])
    ma = max(w[i], r[-1] - r[i])
    # print(i, mi, ma)
    # mi = min(r[i], w[-1])
    # ma = max(w[i], r)
    # ans = min(ans, i - w[i] + (r[-1] - r[i]))
    ans = min(ans, mi + (ma-mi))

print(ans)

Measured memory_bytes: 104748
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 1000000000000000001;

int n;
int sum[2][105];
int main(void){
    cin >> n;
    for (int i = 0; i < 2; i++){
        for (int j = 1; j <= n; j++){
            int s;
            cin >> s;
            sum[i][j] = sum[i][j - 1] + s;
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++){
        ans = max(ans, sum[0][i] + sum[1][n] - sum[1][i - 1]);
    }

    cout << ans << endl;
        
}

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

#define INF 10000000

int main(){
	double a,b,p,q,r;	cin>>a>>b>>p>>q>>r;

	double NG=0,OK=INF;;

	while(abs(OK-NG)>0.001){
		double mid=(OK+NG)/2;
		double s=max(mid-a,0.0)*q, E;

		if(b<mid){
			E=p*b - (mid-b)*r;
		}else{
			E=p*mid;
		}

		if(s<E)NG=mid;
		else OK=mid;

	}
	printf("%.6lf\n",OK);

	return 0;
}



Measured memory_bytes: 3212
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    A = list(mi())
    s = sum(A)
    t = 0
    m = math.inf
    for i in range(N):
        t += A[i]
        m = min(m, abs(s-2*t))

    print(m)

if __name__ == '__main__':
    main()

Measured memory_bytes: 32252
#include <stdio.h>
#define REP(i, n) for(i = 0; i < n; ++i)
#define FOR(i, a, b) for(i = a; i < b; ++i)

void yes_or_no(char boolean){
    if(boolean){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

void traverse(int now,int N, char chk[N], char matrix[N][N]){
     chk[now] = 1;
     int next;

     REP(next, N){
         if(matrix[now][next] == 1 && chk[next] != 1){
             traverse(next, N, chk,  matrix);
         }
     }
}

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    char matrix[N][N];
    int list_p[M], list_q[M];
    char chk[N];
    int x, y;
    int i;
    int ans = 0;

    REP(x, N){
        chk[x] = 0;
        REP(y, N){
            matrix[x][y] = (x == y)? 1 : 0;
        }
    }

    REP(i, M){
        scanf("%d %d", &list_p[i], &list_q[i]);
        x = list_p[i] - 1, y = list_q[i] - 1;
        matrix[x][y] = 1;
        matrix[y][x] = 1;
    }

    REP(i, M){
        x = list_p[i] - 1, y = list_q[i] - 1;
        matrix[x][y] = 0;
        matrix[y][x] = 0;


        traverse(0, N, chk, matrix);

        int k;
        char bridge = 0;

        REP(k, N){
            if(chk[k] == 0){
                bridge = 1;
            }else{
                chk[k] = 0;
            }
        }


        if(bridge) ans++;

        matrix[x][y] = 1;
        matrix[y][x] = 1;         
    }

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

    return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	map < int, int > cnt;
	ll ans = 0;
	cin >> n;
	For (i, 1, n) {
		int x;
		cin >> x;

		if (cnt.count(i-x)) ans += cnt[i-x];
		cnt[x+i]++;

	}
	cout << ans << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 27120
import math

K = int(input())
ans = 0

A = {}
for a in range(1, K+1):
    A[a] = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        num = math.gcd(a, b)
        A[num] += 1

for c in range(1, K+1):
    for k in A.keys():
        num = math.gcd(c, k) * A[k]
        ans += num

print(ans)

Measured memory_bytes: 9176
x, k, d = map(int, input().split())
x_abs = abs(x)
if x_abs - k * d >= 0:
  print(x_abs - k * d)
else:
  kk = k - x_abs // d
  x_now = x_abs - (k - kk) * d
  if kk % 2 == 0:
    print(x_now)
  else:
    print(abs(x_now - d))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF = (1LL<<60);
const int MOD = 1000000007;

int N;
vector<ll> a(500);
bool seen[500][500];
ll memo[500][500];
ll sum[500];

// [l, r) のコストの最小値
ll rec(int l, int r){
    if(seen[l][r]) return memo[l][r];
    seen[l][r] = true;
    if(l==r) return 0;

    ll mi = INF;
    for(int i=l;i<r;i++){
        mi = min(mi, rec(l,i) + rec(i+1,r));
    }

    return memo[l][r] = mi+sum[r]-sum[l-1];
}

int main(){
    cin >> N;
    rep(i,N){
        cin >> a[i+1];
        sum[i+1] = sum[i] + a[i+1];
    }
    cout << rec(1,N) << endl;
}

Measured memory_bytes: 5324
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef unsigned long long ull;

const int MOD = 1000000007 ; //  , 1000000009 , 1000000023 ,998244353
const ll INF = ll(1e18);
const ld PI = 4*atan((ld)1);

ll power(ll x,ll n) {
  ll result=1;
  while(n>0){
    if(n&1)result = ((result) * (x));
    
    x=((x)*(x));
    
    n >>= 1;
  }
  return result;
}
ll gcd(ll a,ll b){
  if(a==0)return b;
  return gcd(b%a,a);
}

int main() {
  #ifdef AVI  
    freopen("input.txt" , "r" , stdin);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  vector<string>ar = {"SUN", "MON", "TUE", "WED", "THU", "FRI" , "SAT"};
  string s;
  cin >> s;
  ll i;
  for(i=0 ; i<7 ; i++){
    if(s==ar[i])break;
  }
  cout << 7-i;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[100010];
    rep(i, N) cin >> a[i];
    sort(a, a + N);
    int ans = 0;
    int sum = 0;
    rep(i, N - 1) {
        sum += a[i];
        if(sum * 2 >= a[i + 1]) ans++;
        else ans = 0;
    }
    cout << ans + 1 << endl;


    return 0;
}
// 1 2 7 20 30 40

Measured memory_bytes: 4400
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	private Scanner sc;

	private int p;
	private String line;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		int lines = Integer.parseInt(sc.nextLine());

		for (int i = 0; i < lines; i++) {
			line = sc.nextLine();
			
			p = 0;
			System.out.println(expression());
		}
	}

	private int expression() {
		double value = term();
		
		return (int)sub_expression(value);
	}
	
	private int sub_expression(double value) {
		if (line.charAt(p) == '+') {
			p++;
			
			value = value + term();
			value = sub_expression(value);
		} else if (line.charAt(p) == '-') {
			p++;
			
			value = value - term();
			value = sub_expression(value);
		}
		
		return (int)value;
	}
	
	private int term() {
		double value = factor();
		
		return (int)sub_term(value);
	}
		
	private int sub_term(double value) {
		if (line.charAt(p) == '*') {
			p++;
			
			value = value * factor();
			value = sub_term(value);
		} else if (line.charAt(p) == '/') {
			p++;
			
			value = value / factor();
			value = sub_term(value);
		}
		
		return (int)value;
	}
	
	private int factor() {
		double value = 0;
		
		switch (line.charAt(p)) {
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			String number = "";
			while (Character.isDigit(line.charAt(p)) == true) {
				number = number + line.charAt(p);
				p++;
			}
			value = Integer.parseInt(number);
			break;
		case '(':
			p++;
			
			value = expression();
			p++;
			break;
		}
		return (int)value;
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++){
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  int species = 0;
  for (int i = 0; i < N - 2; i++){
    int a = L[i];
    for (int j = i + 1; j < N - 1; j++){
      int b = L[j];
      for (int k = j + 1; k < N; k++){
        if (L[k] < a + b){
          species++;
        }
        else {
          break;
        }
      }
    }
  }
  cout << species << endl;
}


Measured memory_bytes: 256
use proconio::*;

fn run() {
    input! {
        n: usize,
        p: [(u64, u64); n],
    }
    let mut x = p.iter().map(|p| p.0).collect::<Vec<_>>();
    let mut y = p.iter().map(|p| p.1).collect::<Vec<_>>();
    x.sort();
    y.sort();
    let ans = if n % 2 == 1 {
        let m = n / 2;
        y[m] - x[m] + 1
    } else {
        let m = n / 2;
        (y[m] + y[m - 1]) - (x[m] + x[m - 1]) + 1
    };
    println!("{}", ans);
}

fn main() {
    run();
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 998244353;
const double EPS = 1e-9;

int DP[3010];

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

	int N, S;
	cin >> N >> S;
	vector<int> A(N);
	rep(i, 0, N)cin >> A[i];

	int ans = 0;
	rep(i, 0, N)
	{
		if (A[i] > S)continue;
		ans += DP[S-A[i]] * (N - i);
		if (A[i] == S)ans += (i + 1)*(N - i);
		ans %= MOD;
		rrep(j, 0, S)
		{
			if (j + A[i] <= S)
			{
				DP[j + A[i]] += DP[j];
				DP[j + A[i]] %= MOD;
			}
		}
		DP[A[i]] += i + 1;
		DP[A[i]] %= MOD;
	}

	cout << ans << endl;

	return 0;
}

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

public class Main {
    public static double cross(double x1, double y1, double x2, double y2) {
        return x1 * y2 - x2 * y1;
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayList<String[]> points = new ArrayList<String[]>();
        for (int i = 0; i < n; i++){
            String[] s = br.readLine().split(" ");
            points.add(s);
        }
        ArrayList<double[]> edges = new ArrayList<double[]>();
        for (int i = 0; i < n - 1; i++){
            double xi = Double.parseDouble(points.get(i)[0]);
            double yi = Double.parseDouble(points.get(i)[1]);
            double xi1 = Double.parseDouble(points.get(i+1)[0]);
            double yi1 = Double.parseDouble(points.get(i+1)[1]);
            double[] vector = new double[2];
            vector[0] = xi1 - xi;
            vector[1] = yi1 - yi;
            edges.add(vector);
        }
        // i == n -1
        double xn = Double.parseDouble(points.get(n-1)[0]);
        double yn = Double.parseDouble(points.get(n-1)[1]);
        double xn1 = Double.parseDouble(points.get(0)[0]);
        double yn1 = Double.parseDouble(points.get(0)[1]);
        double[] vector = new double[2];
        vector[0] = xn1 - xn;
        vector[1] = yn1 - yn;
        edges.add(vector);
        
        boolean flag = true;
        for (int i = 0; i < n - 1; i++){
            if (cross(edges.get(i)[0], edges.get(i)[1], edges.get(i+1)[0],edges.get(i+1)[1])< 0){
                System.out.println(0);
                flag = false;
                break;
            }
        }
        if (flag){
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 17136
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

bool check(vector<int> &line,int val,int k){
  vector<int> needs;
  foreach(i,line){
    needs.emplace_back(i%val);
  }
  sort(all(needs));
  ll l_sum = 0;
  ll r_sum = 0;
  foreach(i,needs)r_sum+=val-i;
  foreach(i,needs){
    l_sum += i;
    r_sum -= val-i;
    if(l_sum>=r_sum){
      return l_sum <= k;
    }
  }
}

int main(){
  int n = in();
  int k = in();
  vector<int> line(n);
  foreach(i,line)i=in();

  int sum = 0;
  foreach(i,line)sum+=i;
  int ans = 0;
  for(int i=1;i*i<=sum;++i){
    if(sum%i)continue;
    if(check(line,sum/i,k)){
      ans = sum/i;
      break;
    }
    if(check(line,i,k))ans=i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
int main(int argc, const char * argv[]) {
    long n;
    std::cin >> n;
    int digit = static_cast<int>(log10(static_cast<double>(n))) + 1;
    long count=0;
    while(digit != 1)
    {
        long k = n - static_cast<long>(pow(10.0, static_cast<double>(digit-1))) + 1;
        n -= k;
        if(digit%2 == 1) count += k;
        digit--;
    }
    count += n;
    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))
 
ll ketasu(ll x){
	ll ans = 0;
	while(x){
		x/=10;
		ans++;
	}
	return ans;
}


int main(){ 
	ll N,ans=0;
	cin >> N;
	FOR(i,1,N+1){
		if(ketasu(i)%2){
			ans++;
		}
	}
	cout << ans << endl;
}


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

int main()
{
	int n;
	cin >> n;
	for (double i = 1; i <= 50000; i += 1)
	{
		if((int)(i * 1.08) == n)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;

	return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var A = input[1];
            var B = input[2];

            Console.WriteLine((B - A) % 2 == 0 ? "Alice" : "Borys");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
n, m = gets.split.map(&:to_i)
input = Array.new(m)
m.times do |i|
  x, y = gets.split.map(&:to_i)
  input[i] = [x, y, i]
end
sorted = input.sort_by { |x| x[1] }
nums = Array.new(n + 1, 1)
ans = Array.new(m)
sorted.each do |x, y, i|
  ans[i] = "#{x}".rjust(6, "0") + "#{nums[x]}".rjust(6, "0")
  nums[x] += 1
end
ans.each { |x| puts x }

Measured memory_bytes: 18900
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}



int main(){
	int a,b;
	cin>>a>>b;
	if(a<=b){
		cout<<a<<endl;
	}else{
		cout<<a-1<<endl;
	}
}


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

int main(){
	int n;
	cin >> n;
	
	double sy = 0, sb = 0;
	
	for(int i=0; i<n; i++){
		double x;
		string u;
		cin >> x >> u;
		
		if(u[0] == 'J') sy += x;
		else sb += x;
	}
	
	cout << (sy + sb * 380000) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#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 REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

std::string s;
int N;
int main() {
    cin >> N;
    int a = N / 1000;
    int b = N % 1000;
    if (a) {
        cout << "ABD" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++){
		if (i % 3 == 0){
			cout << " " << i;
		}
		else if (i % 10 == 3){
			if (i % 3 == 0 ){
				cout << "";
			}
			else{
				cout << " " << i;
			}
		}
		else if (i % 100 == (i % 10) + 30 | i % 1000 == (i % 100) + 300 | i % 10000 == (i % 1000) + 3000 ){
			if (i % 3 == 0 )
			{
				cout << "";
			}
			else if (i % 10 == 3 )
			{
				cout << "";
			}
			else{
				cout << " " << i;
			}
		}
	}
	cout << endl; return 0;
}






Measured memory_bytes: 3100
import math


def sieve_of_eratosthenes(n):
    max_prime = int(math.sqrt(n))
    targets = [i for i in range(2, n + 1)]
    primes = []
    if n == 1:
        return primes
    while targets[0] <= max_prime:
        p = targets[0]
        primes.append(p)
        targets = [i for i in targets if i % p != 0]
    primes.extend(targets)
    return primes


n = int(input())
p = sieve_of_eratosthenes(n)
ans = 1
for i in p:
    cnt = 0
    for j in range(2, n + 1):
        while j % i == 0:
            j //= i
            cnt += 1
    ans *= cnt + 1
    ans %= 10 ** 9 + 7
print(ans)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
int main(void){

	while(1){
		int n,m;
		int maxi=0;

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

		vector<int> s(m+1),k(m+1);
		int c;
		vector<P> total(n);
		vector<P> mini(n);

		FOR(i,0,n-1){
			total[i].second=i+1;
			mini[i].second=i+1;
			total[i].first=0;
			mini[i].first=0;
		}

		FOR(i,1,m){
			cin>>s[i]>>k[i];
			FOR(j,1,k[i]){
				cin>>c;
				total[c-1].first+=s[i];
				if(k[i]==1){
					mini[c-1].first+=s[i];
				}
			}
		}
		
		sort(total.begin(),total.end());
		sort(mini.begin(),mini.end());

		if(total[n-1].second==mini[0].second){
			cout<<total[n-1].first-mini[1].first+1<<endl;
		}else{
			cout<<total[n-1].first-mini[0].first+1<<endl;
		}
		
		
	}

}


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

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

    return gcd(b, a % b);
}

void Main()
{
    int64_t K;
    cin >> K;
    
    int64_t result = 0;
    for(int64_t i = 1; i <= K; ++i)
    {
        for(int64_t j = 1; j <= K; ++j)
        {
            for(int64_t k = 1; k <= K; ++k)
            {
                result += gcd(gcd(i, j), k);
            }
        }
    }

    cout << result << endl;
}

int main()
{
    Main();
}


Measured memory_bytes: 3636
n = gets.to_i
a = gets.split.map(&:to_i).sort
b = Hash.new(0)
n.times do |i|
    b[a[i]] += 1
end
if a[-1]-a[0] > 1
    puts "No"
    exit
end
if b.keys.size == 1
    if a[0] == n-1 || a[0] <= n/2
        puts "Yes"
    else
        puts "No"
    end
else
    if b[a[0]] < a[-1] && a[-1] <= b[a[0]]+b[a[-1]]/2
        puts "Yes"
    else
        puts "No"
    end
end

Measured memory_bytes: 15360
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a[] = {1,
               1,
               1,
               2,
               1,
               2,
               1,
               5,
               2,
               2,
               1,
               5,
               1,
               2,
               1,
               14,
               1,
               5,
               1,
               5,
               2,
               2,
               1,
               15,
               2,
               2,
               5,
               4,
               1,
               4,
               1,
               51};
    int k;
    cin >> k;
    cout << a[k - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));

int N;

void dfs(string s, char mx) {
	if (s.size() == N) { //終了条件
		cout << s << endl;
		return;
	}
	for (char c = 'a'; c <= mx + 1; c++) { //文字列に追加できるのは、mxの次の文字まで
		string t = s;
		t += c;
		dfs(t, max(mx, c));
	}
}

signed main() {
	cin >> N;
	dfs("", 'a' - 1);
}

Measured memory_bytes: 1536
package main

import (
	"fmt"
)

func main() {
	S, T := readString()
	Sc, Tc, D := readInt(), readInt(), readLine()

	if S == D {
		Sc--
	} else if T == D {
		Tc--
	}

	fmt.Println(Sc, Tc)

}

func readInt() int {
	var v int
	fmt.Scan(&v)
	return v
}

func readString() (string, string) {
	var v, w string
	fmt.Scanf("%s %s", &v, &w)
	return v, w
}

func readLine() string {
	var v string
	fmt.Scanln(&v)
	return v
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 10000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;

	return 0;
}


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

typedef long long lint;
int A[200001];
int I[200001];
int N;

lint sum(int l,int r,int d){
    if(l==r) return A[l];
    int mi,mid;
    lint min,mind=200001;
    for(int i=d,j=l;i<=N;i++,j++){
        if(j>r){ mi=mid; min=mind; break; }
        if(A[j]<mind){ mind=A[j]; mid=j; }
        if(I[i]>=l && I[i]<=r){
            mi=I[i];
            min=i;
            break;
        }
    }
    return min*(mi-l+1)*(r-mi+1)+(mi>l?sum(l,mi-1,d+1):0)+(r>mi?sum(mi+1,r,d+1):0);
}
int main(){
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i];
        I[A[i]]=i;
    }
    cout << sum(1,N,1) << endl;
    return 0;
}//

Measured memory_bytes: 17408
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;


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

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

int gcd3(int a, int b, int c){
  int res;
  res = gcd(a,b);
  return (gcd(res,c));
}


int main(){
  int k;
  cin >> k;
  ll res = 0;
  vector<int> a(3);
  for (int i = 1; i <= k; i++){
    for(int j = i; j <= k; j++){
      for (int m = j; m <= k; m++){
        if (i == j && j == m){
          res += gcd3(i,j,m);
        }
        else if (i == j && j != m){
          res += gcd3(i,j,m)*3;
        }
        else if (i != j && j == m){
          res += gcd3(i,j,m)*3;
        }
        else{
          res += gcd3(i,j,m)*6;
        }
      }
    }
  }

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

Measured memory_bytes: 3632
//InHisName
#include<bits/stdc++.h>
using namespace std;
bool mark[200100];
vector<int>adj[200100];
int n,m;
int main(){
	ios_base::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=0,x,y;i<m;i++){
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for(int i=0;i<adj[1].size();i++)
		for(int j=0;j<adj[adj[1][i]].size();j++)
			mark[adj[adj[1][i]][j]]=true;
	if(!mark[n])
		cout<<"IM";
	cout<<"POSSIBLE";
	return -0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = 3.141592654;
ll arr[100];

int main()
{
#ifndef oj
    //freopen("input", "r", stdin);
    //freopen("output.txt","w",stdout);
#endif
    // system("cls");
    //getchar();
    // cout<<adj[1][0];

    int t,sum=0;
    // cin>>t;
    t=1;
    while(t--)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll cnt=0;
        for(int i=0;i<s.size()-2;i++)
        {
            if(s[i]=='A')
            {
                if(s[i+1]=='B')
                {
                    if(s[i+2]=='C')
                    {
                        cnt++;
                        i+=2;
                    }
                }
            }

        }
        cout<<cnt<<endl;

    }

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct Edge {
  ll src, src_m;
  ll dst, dst_m;
  ll weight;
};
bool operator>(const Edge& a, const Edge& b){
  return a.weight > b.weight;
}

static const ll INF = (ll)(1e18);

int N, M, S;
vector<vector<ll>> G[55];
pair<ll,ll> V[55];
ll cost[55][2505];

ll solve(int goal){
  rep(i,55) rep(j,2505) cost[i][j] = INF;
  
  int start = 0, start_m = S;
  priority_queue<Edge,vector<Edge>,greater<Edge> > que;
  que.push((Edge){-1,-1,start,start_m,0}); 
  while(!que.empty()){
    Edge e = que.top(); que.pop();
    if(e.dst == goal){
      return e.weight;
    }
    if(cost[e.dst][e.dst_m] != INF) continue;
    cost[e.dst][e.dst_m] = e.weight;

    //頂点間移動
    rep(i,G[e.dst].size()){
      ll nxt_i = G[e.dst][i][0];
      ll nxt_A = G[e.dst][i][1];
      ll nxt_B = G[e.dst][i][2];
      if(e.dst_m < nxt_A) continue;
      que.push((Edge){e.dst,e.dst_m,nxt_i,e.dst_m-nxt_A,e.weight+nxt_B}); 
    }
    //頂点内移動
    if(e.dst_m < 2500){
      ll nxt_C = V[e.dst].first;
      ll nxt_D = V[e.dst].second;
      que.push((Edge){e.dst,e.dst_m,e.dst,min(2500LL, e.dst_m+nxt_C),e.weight+nxt_D}); 
    }
  }
}


int main(){
  cin >> N >> M >> S;
  rep(i,M){
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].push_back({v,a,b});
    G[v].push_back({u,a,b});
  }
  rep(i,N){
    ll c, d;
    cin >> c >> d;
    V[i] = make_pair(c, d);
  }

  if(S >= 2500) S = 2500;

  REP(i,1,N){
    cout << solve(i) << endl;
  }
  
  return 0;
}



Measured memory_bytes: 24912