akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

template<class T>
struct LiChaoTree{
	struct L{
		T a,b;
		L(T a,T b):a(a),b(b){}
		bool operator==(L l){return a==l.a&&b==l.b;};
	};
	T f(L line,T x){
		return line.a*x+line.b;
	}
	int size=1;
	L ini={0,inf};
	vector<L>dat;
	vector<T>X;
	void add(int a,int b,L li,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		if(r<=a||b<=l)return;
		int m=(l+r)/2;
		if(!(a<=l&&r<=b)){
			add(a,b,li,2*k+1,l,m);
			add(a,b,li,2*k+2,m,r);
			return;
		}
		if(dat[k]==ini){
			dat[k]=li;
			return;
		}
		int lx=X[l],mx=X[m],rx=X[r-1];
		bool left=f(li,lx)<f(dat[k],lx);
		bool mid=f(li,mx)<f(dat[k],mx);
		bool right=f(li,rx)<f(dat[k],rx);

		if(left&&right){dat[k]=li;return;}
		if(!left&&!right)return;
		if(mid)swap(li,dat[k]);
		if(left!=mid){
			add(a,b,li,2*k+1,l,m);
		}else {
			add(a,b,li,2*k+2,m,r);
		}
	}
	T query(int a,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		if(r-l==1)return f(dat[k],X[a]);
		if(a<(l+r)/2)return min(query(a,k*2+1,l,(l+r)/2),f(dat[k],X[a]));
		else return min(query(a,k*2+2,(l+r)/2,r),f(dat[k],X[a]));
	}
	LiChaoTree(vector<T>v):X(v){
		int N=len(v);
		while(size<N)size*=2;
		dat.resize(size*2-1,ini);
		X.resize(size*2-1,1e9);
	}
};
int N,C;
int H[200005];
signed main(){
	cin>>N>>C;
	rep(i,N)cin>>H[i];
	vector<int>v(1000001);iota(all(v),0);
	LiChaoTree<int>LCT(v);
	rep(i,N-1){
		if(i){
			int j=LCT.query(H[i]);
			LCT.add(H[i]+1,1000001,{-2*H[i],j+2*H[i]*H[i]+C});
		}else {
			LCT.add(H[i]+1,1000001,{-2*H[i],H[i]*H[i]+C});
		}
	}
	cout<<LCT.query(H[N-1])+H[N-1]*H[N-1]<<endl;
}


Measured memory_bytes: 77460
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;

    ll xj = 0;
    double xb = 0;



    for (int i = 0; i < n; ++i) {
        string xi, ui;
        cin >> xi >> ui;
        if (ui=="BTC") {
            xb += stod(xi);
        }
        else {
            xj += stoll(xi);
        }
    }

    double ans = 0;
    ans = xj + 380000*xb;

    printf("%.16lf\n", (double)(ans));
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int a=n%10;
  if(a==3){
    cout<<"bon"<<endl;
  }
  else if(a==0||a==1||a==6||a==8){
    cout<<"pon"<<endl;
  }
  else{
    cout<<"hon"<<endl;
  }
  
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    double x, y, z, w;
    cin >> x >> y >> z >> w;
    double d = pow(x - z, 2) + pow(y - w, 2);
    d = sqrt(d);
    printf("%lf\n", d);
    return 0;
}


Measured memory_bytes: 3296
### main

loop do
  n, l = gets.split.map(&:to_i)
  break if (n | l) == 0
  
  ants = []
  n.times do
    di, pi = gets.strip.split
    ants << [(di == 'L') ? -1 : 1, pi.to_i]
  end
  #p ants

  t = 0
  rn = n
  last = nil
  
  loop do
    #p ants
    t += 1
    pos = Array.new(n){nil}
    exit_left = nil
    
    for i in (0...n)
      ai = ants[i]
      if ai
        ai[1] += ai[0]
        if ai[1] == 0 || ai[1] == l
          ants[i] = nil
          exit_left = i + 1 if ai[1] == 0
          rn -= 1
          if rn == 0
            last = exit_left || i + 1
            break
          end
          next
        end

        pi = pos[ai[1]]
        if pi
          ants[pi][0] *= -1
          ai[0] *= -1
        else
          pos[ai[1]] = i
        end
        
      end
    end
    break if rn == 0
  end

  puts [t, last].join(' ')
end

Measured memory_bytes: 6976
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            long kotae = 1000 - (n % 1000);

            if (kotae == 1000)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(kotae);
            }


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27524
k = [:t,:f,:l,:r,:b,:d]
dc = Hash[*k.zip(gets.split(" ").map(&:to_i)).flatten]
gets.split("").each do |a|
  case a
  when "N"
    dc.merge!({t:dc[:f],f:dc[:d],b:dc[:t],d:dc[:b]})
  when "E"
    dc.merge!({t:dc[:r],l:dc[:t],r:dc[:d],d:dc[:l]})
  when "W"
    dc.merge!({t:dc[:l],l:dc[:d],r:dc[:t],d:dc[:r]})
  when "S"
    dc.merge!({t:dc[:b],f:dc[:t],b:dc[:d],d:dc[:f]})
  end
end
puts dc[:t]

Measured memory_bytes: 8604
N,K = map(int, input().split())
ans = 0

mod0 = N // K
if K % 2 == 0:
    modk2 = mod0
    if N % K >= K // 2:    modk2 += 1 
else:
    modk2 = 0

print(mod0**3 + modk2**3)

Measured memory_bytes: 2940
import java.util.Scanner;

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

	int N = scan.nextInt();
	int A = scan.nextInt();
	int B = scan.nextInt();
	int sum = 0;

	//1~Nまでの数値で条件判定
	for(int i = 1; i <= N; i++){
	    int sub = i;
	    int subsum = 0;
	    while(sub > 0){
		subsum += sub % 10;
		sub /= 10;
	    }
	    if(A <= subsum && subsum <= B){
		sum += i;
	    }else{
	    }
	}

	System.out.println(sum);
    }
}

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

const int INF = 1000000009;
const long LINF = 1123456789012345678;

long gcd(long num1, long num2){
	if(num2 > num1){
		std::swap(num1, num2);
	}
	if(num2 == 0){
		return num1;
	}else{
		return gcd(num2, num1 % num2);
	}
}

long lcm(long num1, long num2){
	return num1 * num2 / gcd(num1, num2);
}

std::string s, t;
long n, m;

int main(){
	scanf("%ld%ld", &n, &m);
	std::cin >> s >> t;
	long g = gcd(n, m);
	for(int i = 0; i < g; i++){
		if(s[i*n/g] != t[i*m/g]){
			printf("-1\n");
			return 0;
		}
	}
	printf("%ld\n", lcm(n, m));
	return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

# define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;


typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vi p(n);
    rep(i, n) cin >> p[i];
    
    int cnt=0;
    for (int i=1;i<n-1;i++){
        if ((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1]))
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	int count;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			int num = sc.nextInt();
			count = 0;
			int res = binarySearch(data, num);
			System.out.println(count);
		}
	}
	
	private int binarySearch(int [] a, int patt){
		int mid, left = 0, right = a.length-1;
		while(left <= right){
			mid = (left + right) / 2;
			count++;
			if(a[mid] == patt){
				return mid;
			}
			if(a[mid] < patt){
				left = mid + 1;
			}
			else{
				right = mid - 1;
			}
		}
		return -1;
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 20316
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V
 
getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]
 
type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)
 
mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac
 
(.<.) f g -- combination
    | f < g = 0 
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)
 
unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)
 
mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a
 
countIf f = length . filter f
 
-- 
--
--

main = do
  [_,_,x,y] <- getIs
  (_x:_) <- reverse . sort <$> getIs
  (_y:_) <- sort <$> getIs
  let wontWar = _x < y && x < _y && _x < _y
  putStrLn $ bool "War" "No War" wontWar



Measured memory_bytes: 1020
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(void){
	int A, B, T;	cin >> A >> B >> T;

  int time = A;
  int ans = 0;

  while(time <= T+0.5)  {
    ans += B;
    time += A;
  }

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = (int) 2e5 + 5;

int x[MAXN + 1];
ll sp1[MAXN + 1], sp2[MAXN + 1];


int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n, i, l;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> l >> n;
    int a = 0, b = 0;
    for(i = 1; i <= n; i++) {
        cin >> x[i];
        sp1[i] = sp1[i - 1] + x[i];
    }
    for(i = n; i >= 1; i--) {
        sp2[i] = sp2[i + 1] + l - x[i];
    }
    ll ans = 0;
    for(i = 1; i <= n; i++) {
        int mid = (i + n + 1) / 2;
        ll cur = 2LL * (sp1[mid - 1] - sp1[i - 1]) + 2LL * sp2[mid + 1];
        if((n - i + 1) % 2 == 0) {
            cur += (l - x[mid]);
        }
        else {
            cur += x[mid];
        }
        ans = max(ans, cur);
    }
    for(i = n; i >= 1; i--) {
        int mid = (i + 1) / 2;
        ll cur = 2LL * sp1[mid - 1] + 2LL * (sp2[mid + 1] - sp2[i + 1]);
        if(i % 2) {
            cur += (l - x[mid]);
        }
        else {
            cur += x[mid];
        }
        ans = max(ans, cur);
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}



Measured memory_bytes: 4224
from collections import deque

N = int(input())
edges = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

que = deque([])
que.append((0, 0))

minDist = [float('inf') for _ in range(N)]

while que:
    now, dist = que.popleft()

    if minDist[now] <= dist:
        continue
    minDist[now] = dist

    for to in edges[now]:
        if dist + 1 < minDist[to]:
            que.append((to, dist + 1))

now = N - 1
minPath = [now]
dist = minDist[N - 1]
while dist > 0:
    for back in edges[now]:
        if minDist[back] == dist - 1:
            minPath.append(back)
            dist -= 1
            now = back
            break


edges[minPath[len(minPath) // 2]].remove(minPath[len(minPath) // 2 - 1])
edges[minPath[len(minPath) // 2 - 1]].remove(minPath[len(minPath) // 2])

confilm = [0 for _ in range(N)]
que.clear()
que.append(0)

while que:
    now = que.popleft()

    confilm[now] = 1

    for to in edges[now]:
        if confilm[to] == 0:
            que.append(to)

blackCount = sum(confilm)
witeCount = N - blackCount

if blackCount > witeCount:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 29464
#include<bits/stdc++.h>
#define LL long long
#define L(x) x<<1    //左儿子 x*2
#define R(x) x<<1|1 //右儿子  x*2+1
using namespace std;
int a[105];
int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

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

    if (c < b/a)
    {
        cout << c;
    }
    else 
    {
        cout << static_cast<int>(b/a);
    }

        
    return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
as = Array.new(M,Array.new(2,0))
ans = Array.new(M,0)
M.times do |i|
  as[i] = gets.split.map(&:to_i)
end

#$par[i]=iならば根
$par = (0..(N-1)).to_a
#ユニオンのサイズを保持する。初期値は1
$size = Array.new(N,1)
#ここからUnion-find#
#根を求める
def get_root(x)
  if $par[x] == x then
    return x
  else
    #経路圧縮, できるだけ根につなぐ
    get_root($par[x])
    #return $par[x]
  end
end

#xとyが同じ集合に属するか否か
def is_same?(x, y)
  get_root(x)==get_root(y)
end

#xとyの属する集合を併合
def unite(x,y)
  delta = 0
  x = get_root(x)
  y = get_root(y)

  if !(x==y) then
    delta = $size[y]*$size[x]
    x,y = y,x if $size[x]>$size[y]
    #yが新たな親になる
    $par[x]=y
    #サイズを更新
    $size[y] += $size[x]
    $size[x] = 0
  end
  return delta
end
#ここまでUnion-find#

#エントリーポイント#
#入力の後ろから繋ぎたいので、入力を逆順にする
as = as.reverse
#ansの初期値はN*(N-1)/2
ans[M-1] = N*(N-1)/2
#一つずつ繋ぎつつ答えをansに格納
(M-1).times do |i|
  #つなぐ
  ans[M-2-i] = ans[M-1-i] - unite(as[i][0]-1,as[i][1]-1)
end

puts ans

Measured memory_bytes: 13944
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


int main(void){

	int w, n;
	int left[30] = {}, right[30] = {};
	int ans[30] = {};
	scanf("%d%d", &w, &n );
	for( int i = 0; i < n; i++ ) {
		scanf("%d,%d", left + i, right + i);
		left[i] --;
		right[i] --;
	}
	for( int i = 0; i < w; i++ ) {
		int tmp = i;
		for( int j = 0; j < n; j++ ) {
			if( tmp == left[j] )
				tmp = right[j];
			else if( tmp == right[j] )
				tmp = left[j];
		}
		ans[tmp] = i + 1;
	}
	for( int i = 0; i < w; i++ )
		cout << ans[i] << endl;


    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

ld r;

void solve(){
    cin >> r;
    cout << (ld)2*pi*r << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3808
import sys
N = int(input())
S = list(input())
xList = []
yList = []
zList = []
sum = 0
a = 0
while a < N-2:
    if xList.count(S[a]) == 0:
        xList.append(S[a])
        b = a+1
        a += 1
        while b < N-1:
            if yList.count(S[b]) == 0:
                yList.append(S[b])
                c = b+1
                b += 1
                while c < N:
                    if zList.count(S[c]) == 0:
                        zList.append(S[c])
                        c += 1
                        sum += 1
                    else:
                        c += 1
                print(zList,file=sys.stderr)
                zList = []
            else:
                b += 1
        yList = []
    else:
        a += 1
print(sum)

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



int main(){
  string S;
  string R0={};
  string R1={};
  int i;
  int count0=0;
  int count1=0;
  
  int S_length;
  cin >> S;
  S_length=(int)(S.length());
  
  for(i=0;i<S_length;i++){
    R0+='1';
    R0+='0';
  }
  
  for(i=0;i<S_length;i++){
    R1+='0';
    R1+='1';
  }
  
  for(i=0;i<S_length;i++){
    if(R0[i]!=S[i]){
      count0++;
    }
  }
  
  for(i=0;i<S_length;i++){
    if(R1[i]!=S[i]){
      count1++;
    }
  }
  
  if(count1>count0){
    cout << count0 << endl;
  }else{
    cout << count1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	ans := 0
	if a <= b {
		ans += a
	} else {
		ans += b
	}

	if c <= d {
		ans += c
	} else {
		ans += d
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1768
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  string s; cin>>s;
  FOR(i,0,s.length()) {
    int a = s[i] - 'A';
    a += 26 - 3;
    a %= 26;
    cout << char('A' + a);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=int(a); i<int(b); ++i)

using namespace std;

int main(){
    int n, q;
    int A[2010], m[2010], res[2010];
    cin >> n;
    rep(i, 0, n) cin >> A[i];
    cin >> q;
    rep(i, 0, q){
        cin >> m[i];
        res[i] = false;
    }

    rep(bit, 0, 1<<n){
        int s = 0;
        rep(i, 0, n){
            if (1 & bit>>i) s += A[i];
        }

        rep(i, 0, q){
            if (m[i] == s) res[i] += 1;
        }
    }

    rep(i, 0, q){
        cout << (res[i] ? "yes" : "no") << endl;
    }
}


Measured memory_bytes: 3100
#include<stdio.h>

int main(void){
  long a[200000];
  int i,k,n,m=0,c=0;

  for(i=0;i<=100000;i++)
    a[i]=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&k);
    if(k>100000){ c++; continue;}
    if(k>m) m=k;
    a[k]++;
  }
  for(i=0;i<=m;i++)
   if(a[i]!=i && a[i]!=0){
     if(a[i]>i) c= c+a[i]-i;
     else c+=a[i];
   }

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

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
  string s;
  cin>>s;
  int n=s.length();
  if(n>k)
  {
    int i=0;
    while(i<k)
    {
      cout<<s[i];
      i++;
    }
    cout<<"...";
  }
  else
    cout<<s<<"\n";
}


Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    cout.precision(5); cout << fixed;
    cout << a/b << " " << a%b << " " << (double)a/b << "\n";

    return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int a,b;
  cin >> a >> b;
  int c = min(a,b);
  int d = max(a,b);
  string ans = string(d,(c + '0'));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 5005;

int i,j,n,k,p[N],c[N];

void solve()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>p[i];
    }
    for(i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    int ans=-INF;
    for(i=1;i<=n;i++)
    {
        vi score,vis(n+1);
        int start=p[i];
        while(!vis[start])
        {
            score.pb(c[start]);
            vis[start]=1;
            start=p[start];
        }
        int sum=0;
        for(j=0;j<sz(score);j++)
            sum+=score[j];
        if(sum>0)
        {
            int times=k/sz(score),rem=k%sz(score);
            int best1=times*sum,pref=0,mx=0;
            for(j=0;j<rem;j++)
            {
                pref+=score[j];
                mx=max(mx,pref);
            }
            best1+=mx;
            ans=max(ans,best1);
            if(times)
            {
                int best2=(times-1)*sum,pref=0,mx=0;
                for(j=0;j<sz(score);j++)
                {
                    pref+=score[j];
                    mx=max(mx,pref);
                }
                best2+=mx;
                ans=max(ans,best2);
            }
        }
        else
        {
            int pref=0,mx=-INF;
            for(j=0;j<min(sz(score),k);j++)
            {
                pref+=score[j];
                mx=max(mx,pref);
            }
            ans=max(ans,mx);
        }
    }
    cout<<ans;
}

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

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

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

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

    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define N 200010
typedef long long ll;
using namespace std;
int n,a[N];
ll ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    if(a[1]){
        cout<<"-1"<<'\n';
        return 0;
    }
    for(int i=2;i<=n;i++){
        if(a[i]>a[i-1]){
            if(a[i]==(a[i-1]+1)) ans++;
            else {
                cout<<"-1"<<'\n';
                return 0;
            }
        }
        else ans += a[i];
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector dp(n + 1, 0LL);
  dp[0] = 1000;
  REP(i, n) {
    chmax(dp[i + 1], dp[i]);
    REP(j, i) chmax(dp[i + 1], dp[j] + (a[i] - a[j]) * (dp[j] / a[j]));
  }
  cout << dp[n] << '\n';
  return 0;
}


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

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans += min(a,k);
    k -= min(a,k);
    k -= min(b,k);
    ans -= k;
    cout << ans << endl;
    return 0;
}


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

int main() {
    size_t N;
    int M;
    scanf("%zu %d", &N, &M);

    std::vector<int> B(N, 1), R(N);
    R[0] = 1;

    for (int i=0; i<M; ++i) {
        size_t x, y;
        scanf("%zu %zu", &x, &y);
        --x, --y;

        ++B[y];
        if (R[x])
            R[y] = 1;

        if (!--B[x])
            R[x] = 0;
    }

    int res=0;
    for (size_t i=0; i<N; ++i)
        if (R[i])
            ++res;

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> a(n);

	int sum = 0;

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

		sum += a[i];
	}

	sort(a.begin(), a.end(), greater<int>());

	sum -= (a[0] / 2);

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef set<int> si;
typedef map<string, int> msi;
int main()
{
    int ans = 0;
    int np = 0;
    int ng = 0;

    string s; cin >> s;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'g'){
            if(np < ng) {ans++; np++;}
            else{ng++;}
        }else{
            if(np < ng) {np++;}
            else {ng++; ans--;}
        }
//        cout << np << " " << ng << " " << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int N, K; cin >> N >> K;
  int result = (K==1) ? 0 : N-K;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long long s;
    cin >> s;
    if(s == 1e18){
        cout << "0 0 0 1000000000 1000000000 0";
        return 0;
    }
    cout << 0 << " " << 0 << " " << static_cast<long long>(1e9) << " " << 1 << " " << static_cast<long long>(1e9 - s % static_cast<long long>(1e9)) << " " << s / static_cast<long long>(1e9) + 1 << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=4000;
typedef pair<int,int> p;

int main(){
  int h, w;
  cin >> h >> w;
  char maz[h][w];
  for(int i=0; i<h; ++i){
    for(int j=0; j<w; ++j){
      cin >> maz[i][j];
    }
  }
  int ans=0;
  for(int i=0; i<h; ++i){
    for(int j=0; j<w; ++j){
      if(maz[i][j] == '#') continue;
      vector<vector<int>> dif(h, vector<int>(w,INF));
      dif.at(i).at(j)=0;
      queue<p> que;
      que.push(make_pair(i,j));
      while(!que.empty()){
        int x, y;
        x= que.front().first;
        y= que.front().second;
        if(x-1>=0 && maz[x-1][y] == '.' && dif[x-1][y] == INF){
          que.push(make_pair(x-1,y));
          dif[x-1][y] = dif[x][y] +1;
        }
        if(y-1>=0 && maz[x][y-1] == '.' && dif[x][y-1] == INF){
          que.push(make_pair(x,y-1));
          dif[x][y-1] = dif[x][y] +1;
        }
        if(x+1<h && maz[x+1][y] == '.' && dif[x+1][y] == INF){
          que.push(make_pair(x+1,y));
          dif[x+1][y] = dif[x][y] +1;
        }
        if(y+1<w && maz[x][y+1] == '.' && dif[x][y+1] == INF){
          que.push(make_pair(x,y+1));
          dif[x][y+1] = dif[x][y] +1;
        }
        ans = max(ans, dif[x][y]);
        que.pop();
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define chmax(a, b) a = max((a), (b))
using namespace std;
using ll = long long;

ll dp[60][2];


int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

    memset(dp, -1, sizeof(dp));

    dp[50][0] = 0;
    rrep(i, 50, 0)
    {
        ll mask = 1LL << i;
        ll cnt = 0;
        rep(j, 0, n) if(mask & a[j]) ++cnt;

        ll cost0 = cnt * mask;
        ll cost1 = (n - cnt) * mask;

        // smaller -> smaller
        if (dp[i + 1][1] != -1)
            chmax(dp[i][1], dp[i + 1][1] + max(cost0, cost1));

        // same -> smaller
        if (k&mask)
            chmax(dp[i][1], dp[i + 1][0] + cost0);

        // same -> same
        if (k&mask)
            chmax(dp[i][0], dp[i + 1][0] + cost1);
        else
            chmax(dp[i][0], dp[i + 1][0] + cost0);

        // cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << ' ' << cost0 << ' ' << cost1 << ' ' << mask <<endl;
    }

    ll ans = max(dp[0][1], dp[0][0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
/*
w2sc
2019/12/19
19:14:17
*/
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
struct Point{
    double x,y;
    Point(){}
    Point(double xx,double yy){x=xx,y=yy;}
    Point operator +(Point A){return Point(x+A.x,y+A.y);}
    Point operator -(Point A){return Point(x-A.x,y-A.y);}
    Point operator *(double k){return Point(k*x,k*y);}
    double operator *(Point A){return x*A.x+y*A.y;}
    double operator ^(Point A){return x*A.y-y*A.x;}
    double len(){return sqrt(x*x+y*y);}
};
typedef Point Vec;
struct Line{
    Point A,B;
    Line(){}
    Line(Point AA,Point BB){A=AA,B=BB;}
};
int main()
{
    Line l;
    Point p;
    scanf("%lf%lf%lf%lf",&l.A.x,&l.A.y,&l.B.x,&l.B.y);
    int q;
    scanf("%d",&q);
    while(q--)
    {
        scanf("%lf%lf",&p.x,&p.y);
        Vec v=p-l.A,u=(l.B-l.A);
        u=u*(u*v/u.len()/u.len());
        Point re=p+(u-v)*2;
        printf("%.10f %.10f\n",re.x,re.y);
    }
    return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;

int keta(ll x){
  int ret = 0;
  while (x) {
    x /= 10;
    ret++;
  }
  return ret;
}

vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}

//素因数分解
map<ll, ll> prime_factor(ll n){
  map<ll, ll> res;
  for (int i = 2; i * i <= n; i++){
    while (n % i == 0){
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main(){
  ll n, a, b, keta_a, keta_b, tmp;
  cin >> n;
  vector<ll> x = divisor(n);
  int ans = INF;

  rep(i, x.size()){
    a = x[i];
    b = n / x[i];
    keta_a = keta(a);
    keta_b = keta(b);
    tmp = (keta_a > keta_b) ? keta_a : keta_b;
    ans = (ans < tmp) ? ans : tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long gcd(long long c, long long d)
{
    if(c < d){
        long long k = c;
        c = d;
        d = k;
    }
    if(d == 0) return c;
    return gcd(d, c%d);
}
int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ac = (a-1)/c, ad = (a-1)/d, acd = (a-1)/(c*d/gcd(c,d));
    long long bc = b/c, bd = b/d, bcd = b/(c*d/gcd(c,d));
    cout << (b - a + 1) + (ac + ad - acd) - (bc + bd - bcd) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    long long num_count[100001] = {0};

    long long  N, K;
    cin >> N >> K;

    int a, b;
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        num_count[a] += b;
    }

    long long sum = 0;
    for(int i = 0; i <= 100000; i++){
        sum += num_count[i];
      //  cout << sum << endl;

        if(sum >= K){
            cout << i << endl;
            return 0;
        }
    }


}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;cin>>a>>b;
  if(b==100)b++;
  cout<<(int)pow(100,a)*b<<endl;

  return 0;

}


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

int main()
{
  int N,M;
  
  scanf("%d %d",&N,&M);
  
  long a[100000]={0};
  
  for(int i=0;i<N;i++)
    scanf("%lu",&a[i]);
  
  int flag[100000]={0};
  
  for(int i=0;i<M;i++)
  {
    int A,B;
    
    scanf("%d %d",&A,&B);
    
    if(a[A-1]==a[B-1])
    {
      flag[A-1]++;
      flag[B-1]++;
    }
    else if(a[A-1]<a[B-1])
      flag[A-1]++;
    else
      flag[B-1]++;
  }
  
  int ans=0;
  for(int i=0;i<N;i++)
  {
    if(flag[i]==0)
      ans++;
  }
  
  printf("%d",ans);
}

Measured memory_bytes: 2856
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;//1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

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

template<class T1, class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class Rng>
void in(vector<Rng>& v, LL st = -1, LL en = -1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N, T;
	cin >> N >> T;
	LL ans = 1e15;
	for (LL n = 0; n < N; n++) {
		LL c, t;
		cin >> c >> t;
		if (t <= T) {
			ans = min(ans, c);
		}
	}
	if (ans == 1e15)cout << "TLE\n";
	else cout << ans << "\n";
	return 0;
}

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

using namespace std;

struct Katana
{
    int64_t basic;
    int64_t extra;

    bool operator<(const Katana &other) const
    {
        return extra > other.extra;
    }
};

int main()
{
    int64_t n, health;
    cin >> n >> health;

    vector<Katana> katanas(n);
    int64_t max_basic = 0;

    for (auto &k : katanas) {
        cin >> k.basic >> k.extra;
        max_basic = max(max_basic, k.basic);
    }
    sort(katanas.begin(), katanas.end());

    int64_t res = (health + max_basic - 1) / max_basic;
    int64_t extra = 0;

    for (int64_t i = 0; i < n; i += 1) {
        extra += katanas[i].extra;
        auto left = health - extra;

        if (left <= 0) {
            res = min(res, i + 1);
        } else {
            res = min(res, i + 1 + (left + max_basic - 1) / max_basic);
        }
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define DETA 1000
int main(void)
{
  int x[1000] = {0}; 
  int y[1000] = {0};
  int z[1000] = {0};
  int i,j;

  scanf("%d", &i);

  for(j=0; j<i; j++){
  scanf("%d %d %d", &x[j], &y[j], &z[j]);
  }

  for(j=0; j<i; j++){
    if(x[j]*x[j] == y[j]*y[j] + z[j]*z[j] || y[j]*y[j] == x[j]*x[j] + z[j]*z[j] || z[j]*z[j] == x[j]*x[j] + y[j]*y[j]){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }

  return 0;
}

Measured memory_bytes: 588
n, m = [int(x) for x in input().split()]
xlist = [int(x) for x in input().split()]
if len(xlist) == 1:
    print(0)
else:
    xlist.sort()
    difflist = []
    for i in range(len(xlist)-1):
        difflist.append(abs(xlist[i] - xlist[i + 1]))
    difflist.sort(reverse=True)
    if difflist[n - 1:] != []:
        print(sum(difflist[n - 1:]))
    else:
        print(0)

Measured memory_bytes: 13832
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define out(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n, a, b;
    cin >> n >> a >> b;

    out(min(a*n,b))

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N=2005,inf=1e9+99;
int flag[N],sz[N],sum[N];
int n,a,b,ans=inf;
char s[N];
vi e[N];

void dfs1(int u,int fa){
	sum[u]=sz[u]=0;
	for(auto v:e[u])
		if(v!=fa){
			dfs1(v,u);
			sz[u]+=sz[v];
			sum[u]+=sum[v]+sz[v];
		}
	sz[u]+=flag[u];
}

int dfs2(int u,int fa){
	if(sum[u]<=1)return sum[u];
	int k=0,mx=0;
	for(auto v:e[u])
		if(v!=fa&&sum[v]+sz[v]>mx)
			k=v,mx=sum[v]+sz[v];
	if(mx*2>sum[u]){
		int rem=sum[u]-mx;
		int ret=dfs2(k,u)+sz[k];
		if(ret<=rem)return sum[u]&1;
		return ret-rem;
	}
	return sum[u]&1;
}

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	rep(i,1,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		e[a].pb(b),e[b].pb(a);
	}
	rep(i,1,n)flag[i]=s[i]-'0';
	rep(i,1,n){
		dfs1(i,0);
		if(!dfs2(i,0))
			ans=min(ans,sum[i]/2);
	}
	if(ans>=inf)puts("-1");
	else cout<<ans<<endl;
	return 0;
}

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

using namespace std;

// 2変数の最大公約数を求める関数
int gcd_func(int a, int b)
{
	// 2変数の剰余が0になったら、『割られる数』＝『最大公約数』
	if (b == 0)
	{
		return a;
	}
	
	return gcd_func(b, a % b);
}


int main()
{
	// Nは10の5乗なので、int型
	int N;
	cin >> N;
	// Aは10の9乗なので、long型
	vector<long> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	
	long answer = A[0];
	// モンスターの体力の低い方から高い方に攻撃し続けると
	// 最終的な体力の結果は元の体力における最大公約数と同じになるため、
	// 全ての体力における最大公約数を求めてみる
	for (int i = 0; i < N; i++)
	{
		answer = gcd_func(A[i], answer);
	}
	
	cout << answer << endl;
	
	return 0;
}

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

int main(){
	int nums[101]={0};
	int a;
	
	while( scanf(" %d", &a) != EOF ){
		++nums[a];
	}
	
	int max=0;
	for(int i=1; i<=100; ++i)
		if(max < nums[i]) max=nums[i];
		
	for(int i=1; i<=100; ++i)
		if(max==nums[i])
			printf("%d\n", i);
			
	return 0;
}

Measured memory_bytes: 1184
#include<iostream>

using namespace std;

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

int x[1000],y[1000];
int main() {
    while(true) {
        int n;
        cin >> n;
        if(n == 0)break;
        int w,h;
        cin >> w >> h;

        rep(i,n)cin >> x[i] >> y[i];
        int s,t;
        cin >> s >> t;

        int ans = 0;
        for(int i = 1;i <= w - s + 1;i++) {
            for(int j = 1;j <= h - t + 1;j++) {
                int sum = 0;
                rep(k,n) {
                    if(i <= x[k] && x[k] < i + s && j <= y[k] && y[k] < j + t) {
                        sum++;
                    }
                }
                ans = max(sum,ans);
            }
        }
        cout << ans << endl;
    }
    return 0;

}


Measured memory_bytes: 3060
import sys

def selection_sort(n, A):
    for i in range(n-1):
        minj = i
        for j in range(i+1,n):
            if A[minj][1:] > A[j][1:]:
                minj = j

        A[i], A[minj] = A[minj], A[i]
    return A

def bubble_sort(n, A):

    for i in range(n):
        for j in range(n-1, i, -1):
            if A[j-1][1:] > A[j][1:]:
                A[j], A[j-1] = A[j-1], A[j]
    return A

def is_stable(in_data, out_data):
    len_data = len(in_data)

    for i in range(len_data):
        for j in range(i+1, len_data):
            for a in range(len_data):
                for b in range(a+1, len_data):
                    if in_data[i][1] == in_data[j][1] and\
                       in_data[i] == out_data[b] and\
                       in_data[j] == out_data[a]:
                        return False

    return True

n = int(sys.stdin.readline().strip())
card = sys.stdin.readline().strip().split(' ')

raw = card[:]
bs = bubble_sort(n, raw)
raw = card[:]
ss = selection_sort(n, raw)

print(' '.join(bs))

if is_stable(card, bs):
    print('Stable')
else:
    print('Not stable')

print(' '.join(ss))

if is_stable(card, ss):
    print('Stable')
else:
    print('Not stable')



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

long long A, B;

long long xor_sum(long long n) {
    if (n < 1 || n == 3) return 0;
    if (n == 2) return 3;
    int i = 0;
    while (n >> (i + 1)) i++;
    long long m = (1LL << i);
    if ((n - m) & 1) {
        return xor_sum(n - m);
    } else {
        return xor_sum(n - m) + m;
    }
}

int main() {
    cin >> A >> B;
    cout << (xor_sum(B) ^ xor_sum(A - 1)) << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define FOR(i,l,r) for(int i = l ; i <= r ;++i )
#define inf 1<<30
#define EPS (1e-9)
#define ALL(T)  T.begin(),T.end()
#define lson(i)     i<<1
#define rson(i)     (i<<1|1)
using namespace std;
typedef pair<int,int> pii;

int check(int k){
	int t = k;
	int res = 0;
	while(t){
		res++;
		t/=10;
	}
	return res%2;
}
int main(){
	int n;
	int cnt =0;
	cin >>n;
	FOR(i,1,n){
		if(check(i)){cnt++;}
	}
	 cout <<cnt<<endl;
}

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

using namespace std;

int N, M;
vector< vector<bool> > ts;
vector< vector<int> > done;
void init() {
    cin >> N >> M;
    ts.resize(N);
    done.resize(N);
    for (int i = 0; i < N; i++) {
        ts[i].resize(i+1, false);
        done[i].resize(i+1, -1);
    }
}

void enclose(int a, int b, int x) {
    if (done[a][b] < x) {
    //if (!ts[a][b]) {
        ts[a][b] = true; if (x == 0) return;
        enclose(a+1, b, x-1);
        enclose(a+1, b+1, x-1);
        done[a][b] = x;
    }
}

int main() {
    init();
    for (int i = 0; i < M; i++) {
        int A, B, X;
        cin >> A >> B >> X;
        A--, B--;
        enclose(A, B, X);
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < ts[i].size(); j++) {
//            cout << ts[i][j] << ' ';
            if (ts[i][j]) cnt++;
        }
//        cout << endl;
    }
    cout << cnt << endl;

    return 0;
}

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

L=[0 for i in range(N+1)]
E=[1 for i in range(N+1)]
E[0]=0
E[1]=0
for i in range(2,N+1):
    if E[i]==1:
        for j in range(2,N+1):
            if i*j>=N+1:
                break
            E[i*j]=0
#print(E)
L[1]=N
#print(L)
for i in range(2,N+1):
    L[i]=N//i
#print(L)
l=[0 for i in range(N+1)]
mod=10**9+7
ans=0
for i in range(N):
    cnt=pow(L[N-i],K,mod)
    for j in range(2,N+1):
        if (N-i)*j>=N+1:
            break
        cnt-=l[(N-i)*j]
    l[N-i]=(cnt%mod)
    ans+=(cnt%mod)
#print(l)
#print(ans)
ANS=0
for i in range(len(l)):
    ANS+=i*l[i]
    ANS%=mod
print(ANS)
#print(l)

Measured memory_bytes: 83428