akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

/*
イワシの入れ方は2^N- 1通り
ai * aj + bi * bj = 0
ai * aj = - bi * bj
biとajが0でないと仮定すると、
ai / bi = - bj / aj
割り切れるとも限らないから難しいかも

ai * aj + bi * bj = 0 かつ ai * ak + bi * bk = 0のとき、
ai * aj * ak + bi * bj * ak = 0
aj * (- bi * bk) + bi * bj * ak = 0
(bj * ak - aj * bk) * bi = 0
i) bi == 0
	ai * aj = 0, ai * ak = 0となるので、ai = 0 または aj == ak
ii) bj * ak - aj * bk == 0
	aj * bk = bj * ak
	aj : bj = ak : bkとなる

なんか比を保存しておけばよさそう
0は例外パターンで、両方0ならどれもダメ
片方0なら、もう一方が0でなければOK

全体から引いていく
その集合から2個以上選んで、他は任意を足していけばいい
ただ重複が生じてしまいそうなので、包除原理とかでできそうだけど計算量がだめ

普通に計算する
同じ集合からは1個しか出せない
選び方は集合の要素の個数

3
1 2
-1 1
2 -1
だったら...

なんか違う
A * x + B * y = 0
y = - (A / B) * x みたいになるはずで、xとyの比だけ見ればいいはず
A : B = (- Y) : X

一緒に入れちゃいけない集合が違うけど、例外除けば1:1対応になるはず
つまりパターンとしては、集合Aと集合Bが対応しているなら、集合Aのみ使うパターンか集合Bだけ使うパターンかどちらも使わないか

1:1対応にならない
{a, b}, {-b, a}, {b, -a}, {-a, -b}の4パターンが関係する
{a, b} -> {-b, a}と{b, -a}
{-b, a} -> {a, b}と{-a, -b}みたいになる
一緒にしちゃえば問題ないのでは？
aが必ず正と仮定すればいい

3
1 2
-1 1
2 -1
だったら集合は3つ
A = {{1, 2}}
B = {{2, -1}}
C = {{-1, 1}}
AとBが対応しているから、取りうるパターンは3通り
Cを使うか使わないかで2通り
0個を除くので-1
よって3 * 2 - 1 = 5?
なんかあってそう

つまり対応する集合のペアをさがしてあげればいい
ただ、{0, 0}はどれにおいてもダメなので無視して、最後に+sizeする
{0, Y}や{X, 0}については、この組み合わせがペア
*/

int mod = 1000000007;

long long gcd(long long a, long long b)
{
	if (a < 0) a = -a;
	if (b < 0) b = -b;
	if (b == 0) return (a);
	return (gcd(b, a % b));
}

int	main(void)
{
	int n;
	cin >> n;
	multiset<pair<long long, long long>> iwashi;
	long long a, b;
	long long tmp_ans = 0;
	long long a_zero = 0;
	long long b_zero = 0;
	vector<long long> mod_two(n + 1, 1);
	for (int i = 1; i <= n; i++) mod_two[i] = mod_two[i - 1] * 2 % mod;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		long long c = gcd(a, b);
		if (c != 0)
		{
			a /= c;
			b /= c;
		}
		if (a < 0)
		{
			a = -a;
			b = -b;
		}
		if (a == 0 && b == 0) tmp_ans++;
		else if (a == 0 || b == 0)
		{
			if (a == 0) a_zero++;
			if (b == 0) b_zero++;
		}
		else iwashi.insert({a, b});
	}
	long long ans = 1;
	ans *= (mod + mod_two[a_zero] + mod_two[b_zero] - 1) % mod;
	ans %= mod;
	map<pair<long long, long long>, bool> mp;
	auto ptr = iwashi.begin();
	int num, count;
	while (ptr != iwashi.end())
	{
		a = (*ptr).first;
		b = (*ptr).second;
		if (!mp[{a, b}])
		{
			num = iwashi.count({a, b});
			count = 0;
			count += iwashi.count({b, -a});
			count += iwashi.count({-b, a});
			ans *= (mod + mod_two[num] + mod_two[count] - 1) % mod;
			ans %= mod;
			mp[{a, b}] = true;
			mp[{b, -a}] = true;
			mp[{-b, a}] = true;
		}
		ptr++;
	}
	ans += tmp_ans;
	ans %= mod;
	cout << (mod + ans - 1) % mod << endl;
	return (0);
}


Measured memory_bytes: 54504
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	long long int a[100005], b[100005], c[100005];
	map<long long int, long long int> mp;
	long long int all = n;
	long long int ans = 0LL;
	for(int i=0;i<n;i++){
		cin >> a[i];
		mp[a[i]]++;
		ans += a[i];
	}
	for(int i=0;i<m;i++){
		cin >> b[i] >> c[i];
		mp[c[i]] += b[i];
		ans += b[i]*c[i];
		all += b[i];
	}
	long long int cnt = 0LL;
	for(auto x : mp){
		ans -= (x.first)*(x.second);
		cnt += x.second;
		if(all-cnt==n){
			cout << ans << endl;
			return 0;
		}else if(all-cnt<n){
			ans += (n-all+cnt)*x.first;
			cout << ans << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 15104
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////


function main() {
    var s = readLine();
    s = s.split(",");
    s = s.join(" ");
    
    process.stdout.write(s);
}


Measured memory_bytes: 21064
N, K = map(int, input().split())
p = list(map(int, input().split()))
s = sum(p[:K])
m = s
for i in range(1, N-K+1):
    s = s - p[i-1] + p[i+K-1]
    m = max(m, s)
print((m+K)/2)


Measured memory_bytes: 99192
N, M = map(int,input().split())
D = [list(map(int,input().split())) for i in range(N)]
D.sort()
ans = 0
for i in range(N):
    if M == 0:
        break
    elif M - D[i][1] >= 0:
        ans += D[i][0]*D[i][1]
        M -= D[i][1]
    else:
        ans += D[i][0]*M
        M = 0
print(ans)




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

int main(){

int N, a, cnt = 0;
  cin >> N;
int A[N + 1] = {0};
  for(int i = 0;i < N;i++){
  cin >> a;
  if(a <= N) A[a]++;
  else cnt++;  
  }
  
  for(int i = 1;i <= N;i++){
  if(A[i] > i) cnt += (A[i] - i);
  else if(i > A[i]) cnt += A[i];  
  }

  cout << cnt << endl;
  return 0;
  
}

Measured memory_bytes: 640
/* Problem Description:

*/

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

#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 FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define TRvi(it, c) for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define EPS 1e-10
#define PI acos(-1.0)
#define scan(x) scanf("%d",x)
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) ((x)*(x))
#define LSOne(x) x&(-x)
#define debug(x) cout << #x << " " << x << endl;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;


const int inf = 1e9+10;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
   //  freopen("in" , "r" , stdin);
   //  freopen("out" , "w" , stdout);
    #endif
    int n, k;
    cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; i++){
      cin >> h[i];
    }

    int dp[n];
    for (int i = 0; i < n; i++){
      dp[i] = inf;
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++){
      for (int j = i+1; j <= i+k; j++){
        if (j < n)
          dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
      }
    }
    cout << dp[n-1] << endl;
    return 0;
 }


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

    int a,b;

    scanf("%d", &a);
    scanf("%d", &b);
    if(0<=a && a<=100 && 0<=b && b<=100){
        printf("%d %d\n",a*b, 2*a+2*b );
    }
    else{
        printf("Integer a & b should be not less than 1 and no more than 100\n");
    }

    return 0;
}


Measured memory_bytes: 2040
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    r, g = map(int, open(0).read().split())
    print(r+(g-r)*2)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
using namespace std;
vector<bool> sieve(int N){
        vector<bool> ps(N+1,true);
        ps[0]=ps[1]=false;

        for(int i=2;i<N;++i){
                if(!ps[i])
                        continue;
                for(int j=i+i;j<N;j+=i)
                        ps[j]=false;
        }
        return ps;
}

int main(){
        vector<bool> primes=sieve(2000000);
        int a,d,n;
        long ans;
        while(1){
            scanf("%d %d %d",&a,&d,&n);
            if(a==0 && d==0 && n==0)
                        break;
                for(int x=a;n;x+=d){
                        if(!primes[x])
                                continue;
                        if(--n==0){
                                printf("%d\n",x);
                                break;
                        }
                }
        }
        return 0;
}

Measured memory_bytes: 1260
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    vector<vector<int> >V(n);
    vector<int>cnt(n,0);
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--;b--;
        V[a].push_back(b);
        cnt[b]++;
    }
    bool used[20];fill(used,used+20,false);
    while(true){
        bool update=false;
        for(int i=0;i<n;i++){
            if(cnt[i]==0&&!used[i]){
                update=used[i]=true;
                for(int j=0;j<V[i].size();j++){
                    int to=V[i][j];
                    cnt[to]--;
                }
                printf("%d\n",i+1);
            }
        }
        if(!update)break;
    }
    return 0;
}

Measured memory_bytes: 1052
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);

	int b, f, r, v;
	int room[4][3][10] = { 0 };

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);

		room[b - 1][f - 1][r - 1] += v;
	}

	for (int x = 0; x < 4; x++) {
		for (int y = 0; y < 3; y++) {
			for (int z = 0; z < 9; z++) {
				printf(" %d", room[x][y][z]);
			}
			printf(" %d\n", room[x][y][9]);
		}

		if (x < 3) {
			printf("####################\n");
		}
	}

	return 0;
}

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

int main() {
  int N;
  std::cin >> N;
  int K[N],P[N];
  for(int a = 0; a < N; ++a) {
    std::cin >> K[a] >> P[a];
  }

  int roop;
  int sum;

  for(int b = 0; b < N; ++b) {
    roop = 1;
    while(1) {
      if(K[b] > (P[b] * roop)) {
        ++roop;
        continue;
      }else if(K[b] <= (P[b] * roop)) {
        --roop;
        sum = K[b] - (P[b] * roop);
        if(sum == 0) {
          std::cout << P[b] << std::endl;
          roop = 1;
          break;
        }else if(sum != 0) {
          std::cout << sum << std::endl;
          roop = 1;
          break;
        }
      }
    }
  }
}

Measured memory_bytes: 3092
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		int n;
		while ((n = in.nextInt()) != 0) {
			Set<Point> juels = new HashSet<Point>();
			while (n-- > 0) {
				juels.add(new Point(in.nextInt(), in.nextInt()));
			}
			int m = in.nextInt();
			Point robot = new Point(10, 10);
			while (m-- > 0) {
				juels.remove(robot);
				String next = in.next();
				int d = in.nextInt();
				if (!juels.isEmpty()) {
					int dx = 0, dy = 0;
					switch (next.charAt(0)) {
					case 'N':
						dy = +1;
						break;
					case 'S':
						dy = -1;
						break;
					case 'E':
						dx = +1;
						break;
					case 'W':
						dx = -1;
						break;
					}
					while (d-- > 0) {
						robot.x += dx;
						robot.y += dy;
						juels.remove(robot);
					}
				}
			}
			System.out.println(juels.isEmpty() ? "Yes" : "No");
		}
		in.close();
	}
}

class Point {
	int x, y;

	Point(int x, int y) {
		this.x = x;
		this.y = y;
	}

	@Override
	public int hashCode() {
		return (x << 8) + y;
	}

	@Override
	public boolean equals(Object obj) {
		return this.x == ((Point) obj).x && this.y == ((Point) obj).y;
	}
}

Measured memory_bytes: 36492
#include <bits/stdc++.h>
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const int N = 1e3+50;
const int INF = 2e9;
const double PI = acos(-1);

int arr[2000][2000];

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

    memset(arr,0,sizeof(arr));

    int k=42;
    int n = k*k-k+1;
    // int n=21, k=5;
    int angka = 2;
    for(int i=0;i<k;++i){
        for(int j=0;j<k;++j){
            if(j == 0){
                arr[i][j] = 1;
            }else{
                arr[i][j] = angka;
                angka++;
            }
        }
    }

    angka = 2;
    int cnt = 0;
    for(int i=k;i<n;++i){
        arr[i][0] = angka;
        cnt++;
        if(cnt == k-1){
            cnt = 0;
            angka++;
        }
    }

    angka = arr[1][1];
    cnt = 0;
    int blok;
    for(int j = 1; j < k; ++j){
        for(int t=0;t<k-1;++t){
            blok = 2;
            for(int i = k+t; i <= n ;){
                int realpos;
                if(i == k+t) realpos = i;
                else realpos = i + cnt;
                if(realpos > blok*(k-1)){
                    realpos -= k-1;
                }
                arr[realpos][j] = angka;
                i = realpos + k-1;
                blok++;
            }
            angka++;
        }
        cnt++;
    }
    

    pf("%d %d\n",n,k);
    for(int i=0;i<n;++i){
        for(int j=0;j<k;++j){
            if(j) pf(" ");
            pf("%d",arr[i][j]);
        }
        pf("\n");
    }

    return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  string s;
  cin >> s;
  bool res = false;
  rep(i,sz(s)-1){
    if(s[i]=='A'&&s[i+1]=='C'){
      res = true;
    }
  }
  if(res){
    print("Yes");
  }
  else{
    print("No");
  }
}


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

int N, D;

int main() {
    cin >> N >> D;
    int cnt = 0;
    for (int i=0; i<N; i++) {
        long long int x, y;
        scanf("%lld %lld", &x, &y);
        if (sqrt(x*x+y*y) <= D) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3716
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=ja

process.stdin.resume();
process.stdin.setEncoding('utf8');

const buf = []
process.stdin.on('data', function (chunk) {
    buf.push(chunk);
});

process.stdin.on('end', function (chunk) {
    const n = buf.map(x => x.toString()).join("") // 文字列化する
        .split("\n") // \nで分割
        // .map(x => Number(x))
        .filter(x => x !== "");

    [, binary, , serch] = n;

    const data1 = binary.split(" ");
    const b1 = data1.map(x => Number(x));

    const data2 = serch.split(" ").map(x => Number(x));
    let count = 0;

    let middle = 0;
    let left = 0;
    let right = b1.length;
    let tr = true;

    for (let i = 0; i < data2.length; i++) {
        while (tr) {
            middle = ~~((left + right) / 2);
            if (b1[middle] === data2[i]) {
                count += 1;
                tr = false;
            } else if (b1[middle] < data2[i]) {
                left = middle + 1;
            } else if (b1[middle] > data2[i]) {
                right = middle - 1;
            }
            if (right < left || left > right) {
                tr = false;
            }
        }
        tr = true;
        right = b1.length;
        left = 0;
        middle = 0;
    }
    console.log(count);

});



Measured memory_bytes: 40288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n,m;
    cin >> n >> m;
    ll h[n];
    rep(i, n) {
        cin >> h[i];
    }
    vector<int> G[n];
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    int ans = 0;
    rep(i, n) {
        for(auto to : G[i]){
            if (h[i] <= h[to]) goto no;
        }
        ans++;
    no:;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9504
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <cmath>
 
int main()
{
	int h, w, k, sx, sy;
 
	std::cin >> h >> w >> k;
 
	std::vector<std::string> v(h);
 
	for (long long i = 0; i < h; i++) {
		std::cin >> v[i];
		auto pos = std::find(v[i].begin(), v[i].end(), 'S');
		if (pos != v[i].end()) {
			sx = i;
			sy = pos - v[i].begin();
		}
	}
 
	std::stack<std::pair<long long, long long> > s;
	s.push({ sx, sy });
 
	int ans = 100000000;
 
	int xx[] = { 1,0,-1,0 }, yy[] = { 0,1,0,-1 };
	while (!s.empty()) {
		int x = s.top().first, y = s.top().second;
		s.pop();
 
		/*ns = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k)));
		*/
		ans = std::min(ans, (std::min({x, h - x - 1, y, w - y - 1})+ k - 1) / k );
		for (int i = 0; i < 4; i++) {
			// 範囲外アクセス
			if (x + xx[i] < 0 || x + xx[i] >= h || y + yy[i] < 0 || y + yy[i] >= w) {
				continue;
			}
			// K回以上の移動
			if (std::abs(x + xx[i] - sx) + std::abs(y + yy[i] - sy) > k) {
				continue;
			}
			if (v[x + xx[i]][y + yy[i]] == '.') {
				s.push({ x + xx[i], y + yy[i] });
				v[x + xx[i]][y + yy[i]] = '#'; // 一度行った場所に行かないようにする
			}
		}
	}
 
	std::cout << ans + 1 << std::endl;
 
	return 0;
}

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

int main () {
  int a[5],k;
  rep(i,5) cin >> a[i];
  cin >> k;

  for(int i = 0; i < 5; i++) {
    for(int j = i + 1; j < 5; j++) {
      if(a[j] - a[i] > k) {
        cout << ":(" << endl;
        return 0;
      }
    }
  }

  cout << "Yay!" << endl;
  return 0;
}


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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...)
#endif

void solve(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int N; std::cin >> N;

  std::vector<std::vector<int>> adjacent(N);
  for(int i = 0; i < N-1; ++i){
    int a, b; std::cin >> a >> b;
    --a, --b;
    adjacent[a].push_back(b);
    adjacent[b].push_back(a);
  }

  int K; std::cin >> K;

  std::vector<int> P(N, -1);

  for(int i = 0; i < K; ++i){
    int v, p; std::cin >> v >> p;
    --v;
    P[v] = p;
  }

  std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> pq;

  for(int i = 0; i < N; ++i){
    if(P[i] != -1){
      pq.emplace(P[i], i);
    }
  }


  while(pq.size()){
    auto [x, i] = pq.top(); pq.pop();

    for(auto j : adjacent[i]){
      if(P[j] == -1){
        P[j] = x + 1;
        pq.emplace(P[j], j);
      }else{
        if(std::abs(P[j] - P[i]) != 1){
          std::cout << "No" << "\n";
          return;
        }
      }
    }
  }

  std::cout << "Yes" << "\n";
  for(auto x : P) std::cout << x << "\n";
}

int main(){
  solve();
  return 0;
}


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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  ll n,m,v,p;cin>>n>>m>>v>>p;
  vector<ll> a(n);
  int i,j;
  rep(i,n)cin>>a[i];
  sort(all(a));
  reverse(all(a));
  int left=0;
  int right=n-1;
  int lasok=0;
  while(left<=right)
  {
    int cent=(left+right)/2;
    ll base=a[cent]+m;
    vector<ll> b(n-1);//sorted
    rep(j,n-1)
    {
      if(j<cent)b[j]=a[j];
      else b[j]=a[j+1];
    }
    rep(j,p-1)b[j]+=m;
    ll jug=m*(v-p);
    if(base<b[p-1])
    {
      right=cent-1;
    }
    else
    {
      int now=n-2;
      while(jug>0&&now>=p-1)
      {
        jug-=min(base-b[now],m);
        b[now]+=min(base-b[now],m);
        now--;
      }
      if(jug>0)
      {
        right=cent-1;
      }
      else
      {
        lasok=cent;
        left=cent+1;
      }
    }
  }
  cout<<lasok+1<<endl;
}


Measured memory_bytes: 1792
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B, K = get_ints

set = SortedSet.new

A.step(B).with_index do |x, i|
  break if i >= K
  set.add(x)
end

B.step(A, -1).with_index do |x, i|
  break if i >= K
  set.add(x)
end

set.to_a.each do |a|
  puts a
end


Measured memory_bytes: 14508
#include <stdio.h>
#include <math.h>
 
 
int main(void) {
    int n, i;
    int s[1001] = {0};
    double mean, dev, tmp, sum;
 
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        sum = 0;
        dev = 0;
        for (i = 0; i < n; ++i) {
            scanf("%d", &s[i]);
            sum += s[i];
        }
        mean = sum / n;
        for (i = 0; i < n; ++i) {
            dev += pow(mean - s[i], 2);
        }
        printf("%lf\n", sqrt(dev/n));
    }
    return 0;
}

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

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

    long long int ans = 0;
    int max = A[0];
    for (int i = 1; i < N; ++i)
    {
        if (max > A[i])
        {
            ans += max - A[i];
        }
        else
        {
            max = A[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
	using namespace std;
	#define sim template < class c
	#define ris return * this
	#define dor > debug & operator <<
	#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
	#ifdef LOCAL
	~debug() { cerr << endl; }
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
	}
	#else
	sim dor(const c&) { ris; }
	#endif
	};
	#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define lel debug()
	#define kek(...) lel << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define ll long long
	#define all(x) (x).begin(), (x).end()
	extern ll mod;
	ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} 
	// 
using namespace std;
const int N = 400005;
ll mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	ll pre = 0, ans = 1e18 + 10;
	if (n > k) n %= k;
	while (1) {
		ans = min(ans, n);
		pre = n;
		n = abs(n - k);
		if (pre <= n) {
			break;
		}
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
priority_queue<pair<int, int>>pq;
vector<pair<int, int>>v;
int n, m, a, b, p = 0, ans = 0;
signed main() {
	cin >> n >> m;
	for1(i, n) {
		cin >> a >> b;
		v.push_back(make_pair(a, b));
	}
	sort(v.begin(), v.end());
	for1(i, m) {
		while (p < v.size()) {
			if (v[p].first <= i) { pq.push(make_pair(v[p].second, v[p].first)); p++; if (p == n)break; }
			else break;
		}
		if (pq.size()) { ans += pq.top().first; pq.pop(); }
	}
	cout << ans << endl;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define Rep(i, N) for(int i = 0; i < N; i++)
#define pb push_back
#define LLINF 1LL << 60
#define INF 1 << 28
#define F first
#define S second
typedef pair<int, int> Pi;
typedef vector<int> vint;

inline void chmax(int &a, int b) { a = max(a, b); }
inline void chmin(int &a, int b) { a = min(a, b); }

int N, M;
int val[100005];
int A, B;
vint bs, D;

int dfs(int v, int X) {
  if(v < N) {
    if(val[v] == LLINF) {
      return 1;
    } else {
      if(val[v] >= X) return 0;
      else return LLINF;
    }
  }
  
  vint s;
  for(int i = (v - N) * 3; i < (v - N) * 3 + 3; i++) s.pb(dfs(i, X));
  sort(s.begin(), s.end());
  return min(s[0] + s[1], LLINF);
}
  

signed main()
{
  
  cin >> N >> M;
  fill_n(val, 100005, LLINF);
  
  Rep(i, M) {
    cin >> A >> B; B--;
    val[B] = A;
    bs.pb(A);
  }

  Rep(i, N - M) {
    cin >> A;
    bs.pb(A); D.pb(A);
  }
  
  sort(bs.begin(), bs.end());

  int l = 0, r = N;
  while(l + 1 < r) {
    int m = (l + r) / 2;
    int cnt = 0, X = bs[m];
    Rep(i, D.size()) if(D[i] >= X) cnt++;
    if(dfs(N + N / 2 - 1, X) <= cnt) l = m;
    else r = m;
  }

  cout << bs[l] << endl;
  return 0;
}

Measured memory_bytes: 5596
#include <iostream>

int main(){
    int W, H, x, y, r = 0;
    std::cin >> W >> H >> x >> y >> r;
    bool isCircleIn = 1;
    isCircleIn = isCircleIn && ((x+r>W || x-r<0) ? 0 : 1);
    isCircleIn = isCircleIn && ((y+r>H || y-r<0) ? 0 : 1);
    std::cout << (isCircleIn ? "Yes" : "No") << std::endl;
    
    return 0;
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;

long long GCD(long long A, long long B) {
	return (B == 0 ? A : GCD(B, A % B));
}

int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int main() {
	int N;
	cin >> N;
	int L = ((N + 1) / 2) * 2;
	vector<int> Primes;
	for (int i = 100; ; i++) {
		bool check = true;
		for (int j = 2; j * j <= i; j++) {
			if (i % j == 0) {
				check = false;
				break;
			}
		}
		if (check) Primes.push_back(i);
		if (Primes.size() == L) break;
	}
	vector<long long> X(N), Y(N);
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			X[i] = Primes[i / 2];
			Y[i] = Primes[i / 2 + L / 2];
		}
		else {
			X[i] = X[i - 1] * 2;
			Y[i] = Y[i - 1] * 2;
		}
	}
	vector<vector<long long> > ANS(N, vector<long long>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if ((i & 1) == (j & 1)) ANS[i][j] = X[i] * Y[j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if ((i & 1) != (j & 1)) {
				ANS[i][j] = 1;
				for (int k = 0; k < 4; k++) {
					int ni = i + dx[k], nj = j + dy[k];
					if (0 <= ni && ni < N && 0 <= nj && nj < N) {
						ANS[i][j] *= ANS[ni][nj] / GCD(ANS[i][j], ANS[ni][nj]);
					}
				}
				if (i % 2 == 0) ANS[i][j] *= 2;
				ANS[i][j]++;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cout << ANS[i][j] << (j == N - 1 ? '\n' : ' ');
		}
	}
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int n;

void countingSort(int *A, int *B, int k){
  int C[10010] = {};

  for(int i = 1;i <= n;i++) C[A[i]]++;
  for(int i = 1;i <= k;i++) C[i] += C[i - 1];
  for(int i = n;i >= 1;i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
}

int main(){

  int k = 0;
  int *a, *b;

  cin >> n;
  a = (int *)malloc(sizeof(int) * n + 1);
  b = (int *)malloc(sizeof(int) * n + 1);
  for(int i = 1;i <= n;i++){
    cin >> a[i];
    k = max(k, a[i]);
  }

  countingSort(a, b, k);

  for(int i = 0;i < n;i++){
    cout << (i?" ":"");
    cout << b[i + 1];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 18724
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

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

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


Measured memory_bytes: 256
def main():
    import sys
    from collections import Counter
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    S = int(input())
    MOD = 10 ** 9 + 7
    if S < 3:
        print(0)
        return
    a, b, c, ans = 0, 0, 0, 0
    for i in range(3, S):
        d = (a + 1) % MOD
        a = (a + b) % MOD
        b, c = c, d
    print((a + 1) % MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9448
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		int N=S.length();
		int max=0;
		for(int i=1;i<=N;i++){
			for(int j=0;j+i<=N;j++){
				String a=S.substring(j,j+i);
				boolean key=true;
				for(int k=0;k<a.length();k++){
					char b=a.charAt(k);
					if((b=='A'||b=='C'||b=='G'||b=='T')==false)
						key=false;
				}
				if(key&&i>max)
					max=i;
			}
		}
		System.out.println(max);
	}
}


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

using namespace std;

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


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

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

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


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

	ll n;
	cin >> n;
	Array s(n, 0);

	ll min = INF;
	ll sum = 0;
	REP(i, n) {
		cin >> s[i];
		sum += s[i];
		if (s[i] % 10 != 0 && min > s[i]) min = s[i];
	}

	if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else {
		if (min != INF) {
			cout << sum - min << endl;
		}
		else {
			cout << 0 << endl;
		}
	}

	return 0;
}

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

int main(void){
    int K, S;
    cin >> K >> S;
    int score = 0;
    for (int i = 0; i <= K; ++i)
    {
        for (int j = 0; j <= K; ++j)
        {
            int z = S - i - j;
            if (i + j + z == S && z >= 0 && z <= K)
            {
                score++;
            }

        }
    }
    cout << score << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout<<"debuglandınız\n";
ll int N,i,j,K;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> N >> K;
	vector<long long int> v(N),dp(N, 999999999);
	for(i=0;i<N;i++)cin>>v[i];
	dp[0]=0;
	for(i=0;i<N;i++){
		for(j=1;j<=K;j++){
			if(i+j>=N)break;
			dp[i+j]=min(dp[i+j], dp[i]+abs(v[i]-v[i+j]));
		}
	}
	cout<<dp[N-1];
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int a, b, c; std::cin >> a >> b >> c;
	if (b + c > a) std::cout << b + c - a << std::endl;
	else std::cout << 0 << std::endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=1<<s.nextInt(),k=s.nextInt();
		StringJoiner sb = new StringJoiner(" ");

		if(n==2) {
			if(k==0)
				System.out.println("0 0 1 1");
			else
				System.out.println(-1);
			return;
		}

		if(k>=n) {
			System.out.println(-1);
			return;
		}

		for(int i=0;i<n;++i) {
			if(i!=k)
				sb.add(String.valueOf(i));
		}
		sb.add(String.valueOf(k));
		for(int i=n-1;i>=0;--i) {
			if(i!=k)
				sb.add(String.valueOf(i));
		}
		sb.add(String.valueOf(k));

		System.out.println(sb);
	}
}

Measured memory_bytes: 44748
a = list(map(int,input().split()))
t1 = a[0]#hp
t2 = a[1]#atc
a1 = a[2]
a2 = a[3]

if a1%t2 == 0:
  if a1/t2 < t1/a2+1:
    print("Yes")
  else:
    print("No")
else:
  if a1/t2 < t1/a2:
    print("Yes")
  elif (a1//t2 == t1//a2) and (t1%a2 != 0):
    print("Yes")
  elif (a1//t2 == t1//a2) and (t1%a2 == 0):
    print("No")
  else:
    print("No")

Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

map<string, int> dist;

void bfs(){
  pair<string, int> u;
  queue<pair<string, int> > Q;
  Q.push(make_pair("01234567", 0));
  dist["01234567"] = 0;
  while(!Q.empty()){
    u = Q.front(); Q.pop();
    int pos;
    for(int i=0;i<u.first.size();i++){
      if(u.first[i] == '0'){
	pos = i;
	break;
      }
    }
    string tmp;
    if(pos!=0 && pos!=4){
      tmp = u.first;
      swap(tmp[pos], tmp[pos-1]);
      if(dist.find(tmp) == dist.end()){
	dist[tmp] = u.second+1;
	Q.push(make_pair(tmp, u.second+1));
      }
    }
    if(pos!=7 && pos!=3){
      tmp = u.first;
      swap(tmp[pos], tmp[pos+1]);
      if(dist.find(tmp) == dist.end()){
	dist[tmp] = u.second+1;
	Q.push(make_pair(tmp, u.second+1));
      }
    }
    tmp = u.first;
    if(pos<4){
      swap(tmp[pos], tmp[pos+4]);
      if(dist.find(tmp) == dist.end()){
	dist[tmp] = u.second+1;
	Q.push(make_pair(tmp, u.second+1));
      }
    }else{
      swap(tmp[pos], tmp[pos-4]);
      if(dist.find(tmp) == dist.end()){
	dist[tmp] = u.second+1;
	Q.push(make_pair(tmp, u.second+1));
      }
    }
  }
}

main(){
  bfs();
  string str;
  while(cin >> str){
    char c;
    for(int i=0;i<7;i++){
      cin >> c;
      str += c;
    }
    cout << dist[str] << endl;
  }
  return 0;
}

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

const int MAXN = 3010;

string s,t;
int dp[MAXN][MAXN],N,M;
stack<char> resposta;

int solve(int a,int b){

	if(a < 0 || b < 0) return 0;

	if(dp[a][b] != -1) return dp[a][b];

	if(s[a] == t[b]) return dp[a][b] = 1 + solve(a-1,b-1);

	return dp[a][b] = max(solve(a-1,b),solve(a,b-1));

}

void build(int a,int b){

	if(a < 0 || b < 0) return;

	if(s[a] == t[b]){
		resposta.push(s[a]);
		build(a-1,b-1);
		return;
	}

	if(solve(a-1,b) > solve(a,b-1)) build(a-1,b);
	else build(a,b-1);

}

int main(){

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

	cin >> s;
	cin >> t;

	N = (int)s.size();
	M = (int)t.size();

	build(N-1,M-1);

	while(!resposta.empty()){
		cout << resposta.top();
		resposta.pop();
	}
	cout << endl;

	return 0;

}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
 
using namespace std;
  
int main() {
  long long n;
  cin >> n;
  
  vector<long long> a;
  
  for(long long i; i < n; i++){
    long long b;
    cin >> b;
    a.push_back(b);
  }
  
  long long t = 0;
  for(long long l; l < n; l++){
    for(long long m = l+1; m < n; m++) {
      t = t + a.at(l) * a.at(m);
    }
  }
  cout << t;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) ((a) < (b) ? (b) : (a))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;



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

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



int main() {

	int i, j, k;
	//ll N, M, K;
	int N, M, K;


	cin >> i >> j >> k;
	cout << k << " " << i << " " << j;

	return 0;
	
}

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

#define MOD 1000000007

class UnionFind {
private:
	vector<ll> parents;
	vector<ll> ranks;

public:
	vector<ll> sizes;

	UnionFind(ll s): parents(s), ranks(s), sizes(s, 1) {
		for(ll i = 0; i < s; i++) parents[i] = i;
	}

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

	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(ranks[x] < ranks[y]) {
			parents[x] = y;
			sizes[y] += sizes[x];
		} else {
			parents[y] = x;
			sizes[x] += sizes[y];
			if(ranks[x] == ranks[y]) ranks[x]++;
		}
	}

	bool same(ll x, ll y) {
		return find(x) == find(y);
	}
};

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

    int N, M;
    cin >> N >> M;

    UnionFind uf(N);

    for(int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }

    vector<bool> c(N);

    int ans = 0;

    for(int i = 0; i < N; i++) {
        int x = uf.find(i);
        if(c[x]) continue;
        ans++;
        c[x] = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    ll H;
    ll n=1;
    cin >> H;
    while (true) {
        ans += n;
        if (H == 1) {
            break;
        } else {
            H /= 2;
            n *= 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)

int N;
int H;
vector<int> thrower;

int a[101010];
int b[101010];
// int dp[1000000001];

int main(void){
    // Your code here!
    cin >> N >> H;
    // int ans = 0;
    REP(i,0,N) {
       cin >> a[i] >> b[i];
       
    }
    int ma = 0;
    REP(i,0,N) {
       ma = max(ma,a[i]);
    }
    
    REP(i,0,N) {
       if (b[i] > ma)  thrower.push_back(b[i]);
    }
    
   
    sort(thrower.begin(),thrower.end(),greater<int>());
    
    int ans = 0;

    for (int x: thrower) {
        // cout << x << endl;
        ans++;
        H -= x;
        if (H <= 0) {cout << ans << endl; return 0;}
    }
 
    ans += (H + ma -1) / ma;
    // return ans;
    
    cout << ans << endl;
    // long long test = H;
    // int count = 0;
    // REP(i,1,N+1) {
    //     test -= b[i];
    //     count += 1;
    //     if (test <= 0) {cout << i << endl; return 0;}
    //     if (i == N) cout << test << endl;
    // }
    
    // REP(i,1,N+1) {
        
    // }
    
    
    // cout << count << endl;
}


Measured memory_bytes: 1660
fun main(args: Array<String>) {
  val sc = if (args.size > 1) java.util.Scanner(java.io.File(args[1])) else java.util.Scanner(System.`in`)
  solve(sc)
}

fun solve(sc: java.util.Scanner) {
  val N = sc.nextInt()
  val A1 = Array(N) { sc.nextInt() }
  val A2 = Array(N) { sc.nextInt() }
  val result = (0..(N-1)).map { i ->
                               (A1.slice(0..i) + A2.slice(i..(N-1))).sum()
                              }.max()
  println(result)
}


Measured memory_bytes: 36016
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] reader = ReadLine().Split(' ');
        int x1 = int.Parse(reader[0]);
        int y1 = int.Parse(reader[1]);
        int x2 = int.Parse(reader[2]);
        int y2 = int.Parse(reader[3]);
        int sax = x2-x1;
        int say = y2-y1;
        for(int i=0;i<say;i++){
            Write("U");
        }
        for(int i=0;i<sax;i++){
            Write("R");
        }
        for(int i=0;i<say;i++){
            Write("D");
        }
        for(int i=0;i<sax;i++){
            Write("L");
        }
        
        Write("LU");
        for(int i=0;i<say;i++){
            Write("U");
        }
        for(int i=0;i<sax;i++){
            Write("R");
        }
        Write("RDRD");
        for(int i=0;i<say;i++){
            Write("D");
        }
        for(int i=0;i<sax;i++){
            Write("L");
        }
        WriteLine("LU");
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<numeric>
#include<climits>
#include<map>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

int main(void) {
	int a,p;
	cin >> a >> p;
	cout << (a * 3 + p) / 2 << endl;
}

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

vector<ll> calc_primes(ll n) {
  vector<ll> primes;
  vector<bool> filtered(n + 1);

  for (ll i = 2; i <= n; i++) {
    filtered[i] = false;
  }

  for (ll i = 2; i <= n; i++) {
    if (!filtered[i]) {
      primes.push_back(i);
      for (ll j = i; j <= n; j += i) {
        filtered[j] = true;
      }
    }
  }
  return primes;
}

ll pow_mod(ll n, ll m, ll mod) {
  if (m == 0) return 1;
  if (m % 2 == 0) {
    ll tmp = pow_mod(n, m / 2, mod);
    return (tmp * tmp) % mod;
  } else {
    return (n * pow_mod(n, m - 1, mod)) % mod;
  }
}

unordered_map<ll, ll> prime_factors(ll n, vector<ll> &primes) {
  unordered_map<ll, ll> ans;
  for (ll p : primes) {
    while (n % p == 0) {
      if (ans.count(p) == 0) {
        ans[p] = 0;
      }
      ans[p]++;
      n /= p;
    }
  }
  if (n > 1) {
    if (ans.count(n) == 0) {
      ans[n] = 0;
    }
    ans[n]++;
  }
  return ans;
}

int main() {
  const ll mod = 1000000007;
  vector<ll> primes = calc_primes(1000);

  ll n;
  cin >> n;

  vector<ll> a(n);
  vector<unordered_map<ll, ll>> f(n);
  unordered_map<ll, ll> lcm;

  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    f[i] = prime_factors(a[i], primes);
    for (auto factor : f[i]) {
      lcm[factor.first] = max(factor.second, lcm[factor.first]);
    }
  }

  // for (auto factor : lcm) {
  //   cout << factor.first << " " << factor.second << endl;
  // }

  ll lcm_all = 1;
  for (auto factor : lcm) {
    lcm_all *= pow_mod(factor.first, factor.second, mod);
    lcm_all %= mod;
  }
  
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += (lcm_all * pow_mod(a[i], mod - 2, mod)) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

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

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	cin >> n;
	
	int counter = 0;
	for (int i = 1; i <= n; i++)
	{
		int number = i;
		int digit = 0;
		while (true)
		{
			digit++;
			number /= 10;
			if (number == 0)
			{
				break;
			}
		}
		
		if ((digit % 2) != 0)
		{
			counter++;
		}
	}
	
	cout << counter << endl;

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    double d;
    cin >> d;
    double ans=2*pi*d;
    printf("%.12lf",ans);
    return 0;
}


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

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

    string s, t;
    cin >> s >> t;
    int s_length = s.length();
    bool same = false;
    for (int i = 0; i < s_length; ++i) {
        s = s.back() + s.substr(0, s_length - 1);
        if (s == t) {
            same =true;
            break;
        }
    }
    if (same) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map (fun x -> int x)
let char2String(value) = List.ofSeq value |> List.toArray |> System.String


let c1 = readString()
let c2 = readString()

if c1 = char2String(Seq.rev c2) then "YES" else "NO"
|> printfn "%s"

Measured memory_bytes: 14044
#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main(){

    int N;
    cin >> N;
    string S;
    cin >> S;

    vector <int> black(N + 1);
    vector <int> white(N + 1);

    black[0] = 0;
    white[0] = 0;

    for(int i = 1; i < N + 1 ; i++){
        if (S[i - 1] == '.') {
            black[i] = black[i - 1] + 1;
            white[i] = white[i - 1];
        }else
        {
            black[i] = black[i - 1];
            white[i] = white[i - 1] + 1;
        }
    }
/*
    for(int i = 0; i < N + 1; i++){
        cout << black[i] << " " << white[i] << endl;
    }
*/  

    int min = N;
    int count;

    if (white[N] == N) {
        min = 0;
    }else{
        for(int i = 0; i < N + 1; i++){
            count = white[i] + (black[N] - black[i]);
            if (min > count) {
                min = count;
            }
        }
    }
    cout << min << endl;

    return 0;
}

Measured memory_bytes: 2180