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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

	ll n, m, k; cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	FOR(i, n) cin >> a[i];
	FOR(i, m) cin >> b[i];

	for(int i = 1; i < n; i++)
		a[i] += a[i-1];
	for(int i = 1; i < m; i++)
		b[i] += b[i-1];


	int cnt = 0;
	FOR(i, n){
		if(a[i] <= k) cnt = max(cnt, i+1);
		else break;
		ll sum = k - a[i];
		int p = distance(b.begin(), lower_bound(all(b), sum));
		if(p == m || b[p] > sum) p--;
		if(p == -1) continue;
		cnt = max(cnt, i+p+2);
	}

	FOR(i, m){
		if(b[i] <= k) cnt = max(cnt, i+1);
		else break;
		ll sum = k - b[i];
		int p = distance(a.begin(), lower_bound(all(a), sum));
		if(p == n || a[p] > sum) p--;
		if(p == -1) continue;
		cnt = max(cnt, i+p+2);
	}

	cout << cnt << '\n';

	return 0;
}


Measured memory_bytes: 6344
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();

    // 読み込んだStringを空白で分解する
    let iter = line.split_whitespace();

    let mut sum = 0;
    for i in iter {
        let num: i32 = i.parse().unwrap();
        sum += num;
    }

    if sum >= 22 {
        println!("bust");
    } else {
        println!("win");
    }
}


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

int main(){
  int n;
  cin>>n;
  vector<string> edge(n);
  for (int i=0;i<n;i++){
    cin>>edge.at(i);
    int su=0;
  }
  if(n==2) cout<<2<<endl;
  else{
    int ans=0;
    for(int m=0;m<n;m++){
      vector<string> edges=edge;
      vector<int> v(n,0);
      queue<int> tmp;
      v.at(m)=1;
      tmp.push(m);
      while(!tmp.empty()){
        int x=tmp.front();
        int y=v.at(x);
        tmp.pop();
        for (int i=0;i<n;i++){
          if(edges.at(x).at(i)=='1'){
            if(v.at(i)==0) {v.at(i)=y+1; tmp.push(i);}
            else if(v.at(i)!=y+1){cout<<-1<<endl; return 0;}
          }
          edges.at(x).at(i)='0';
          edges.at(i).at(x)='0';
        }
      }
      int tmpans=0;
      for(int i=0;i<n;i++){
        if(tmpans<v.at(i)) tmpans=v.at(i);
      }
      ans=max(ans,tmpans);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 384
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
//	fastio;
	double a,b,c;
	double l;
	cin>>l;
	a=b=c=l/3.0;
	printf("%.10f",a*b*c);
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func main() {
	const inf = int64(1e16)
	var N int
	var W int64
	fmt.Scan(&N, &W)
	vmax := 1000 * N
	w := make([]int, N)
	v := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		sc.Scan()
		w[i], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		v[i], _ = strconv.Atoi(sc.Text())
	}

	col := vmax + 1
	dp := make([]int64, (N+1)*col)
	for i := 0; i <= vmax; i++ {
		dp[0+i] = inf
	}
	dp[0] = 0

	for i := 0; i < N; i++ {
		for j := 0; j <= vmax; j++ {
			if j < v[i] {
				dp[col*(i+1)+j] = dp[col*i+j]
			} else {
				dp[col*(i+1)+j] = min(dp[col*i+j], dp[col*i+j-v[i]]+int64(w[i]))
			}
		}
	}
	ans := 0
	for j := 0; j <= vmax; j++ {
		if dp[N*col+j] <= W {
			ans = j
		}
	}
	fmt.Println(ans)
}


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

int main()
{
	int LA, LB, LC, LD, RA, RB, RC, RD;
	LA = LB = LC = LD = RA = RB = RC = RD = 0;
	while (1) 
	{
		double a, b;
		cin >> a >> b;
		if (cin.fail())break;
		if (a <0.2)LD++;
		else if (a < 0.6)LC++;
		else if (a < 1.1)LB++;
		else LA++;
		if (b <0.2)RD++;
		else if (b < 0.6)RC++;
		else if (b < 1.1)RB++;
		else RA++;
	}
	cout << LA << " " << RA << endl << LB << " " << RB << endl << LC << " " << RC << endl << LD << " " << RD << endl;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct FenwickTree {
	int n; // [1, n]
	vector<int> bit;
	FenwickTree(int n) : n(n), bit(n+1, 1<<30) {}
	int sum(int i) {
		int s = 1<<30;
		while (i > 0) {
			s = min(s, bit[i]);
			i -= i&-i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= n) {
			bit[i] = min(bit[i], x);
			i += i&-i;
		}
	}
};
int main() {
	ll N, Q;
	cin >> N >> Q;
	FenwickTree a(N-1), b(N-1);
	a.add(1, N-2);
	b.add(1, N-2);
	ll r = 0;
	for (int i = 0; i < Q; ++ i) {
		int t, x;
		cin >> t >> x;
		x -= 2;
		if (t == 1) {
			int y = a.sum(N-1-x);
			r += y;
			b.add(N-1-y, x);
		} else {
			int y = b.sum(N-1-x);
			r += y;
			a.add(N-1-y, x);
		}
	}
	cout << (N-2)*(N-2) - r << endl;
}


Measured memory_bytes: 4772
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    
    pi_table = [0] + [(i * (i + 1) // 2) / i for i in range(1,1001)]
    
    pe = [None] * N
    for i in range(N):
        pe[i] = pi_table[p[i]]
    
    tmp = sum(pe[:K])
    ans = tmp
    for i in range(K, N):
        tmp += (pe[i] - pe[i - K])
        ans = max(ans, tmp)
        
    print(ans)



if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int s;
const int N = 2e3 + 5;
int dp[N][N];
int calc(int ind, int sum){
    if(sum == s){
        return 1;
    }
    if(dp[ind][sum] != -1){
        return dp[ind][sum];
    }
    int res = 0;
    if(s - sum < 3)return 0;
    for(int i = 3; i <= s - sum; i++){
        res += calc(ind + 1, sum + i);
        res %= MOD;
    }
    return dp[ind][sum] = res%MOD;
}
int main(){
    FAST
    cin >> s;
    memset(dp, -1, sizeof(dp));
    cout << calc(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 19376
LI = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print(LI[K - 1])


Measured memory_bytes: 2940
#include<stdio.h>

int main()
{
	//freopen("C:\\Users\\j2402\\Desktop\\nyu.txt","r",stdin);
	//freopen("C:\\Users\\j2402\\Desktop\\syu.txt","w",stdout);
	
	int pasta[3] = {0};
	int ju[2] = {0};

	for(int i=0;i<3;i++)
	{
		scanf("%d",&pasta[i]);

		if(i ==1)
		{
			if(pasta[0] < pasta[1])
			{
				pasta[1] = pasta[0];
			}
		}
		if(i == 2)
		{
			if(pasta[1] > pasta[2])
			{
				pasta[1] = pasta[2];
			}
		}
	}



	for(int i=0;i<2;i++)
	{
		scanf("%d",&ju[i]);
	}

	if(ju[0] < ju[1])
	{
		ju[1] = ju[0];
	}

	printf("%d\n",(pasta[1] + ju[1]) - 50);

	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a, b;
    cin >> a >> b;
    int c = 0;
    vector<int> data = {1, 2, 3};
    for(int i=0; i<data.size(); i++){
        if(a != data.at(i) && b != data.at(i)){
            c = i+1;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main (String[] args)  {


		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		System.out.println(n/(a+b)*a+Math.min(a, n%(a+b)));

	}


}


Measured memory_bytes: 21972
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<unordered_map>
#include<string>
#define LL long long
#define li i<<1
#define ri i<<1|1
using namespace std;
inline LL read()
{
    char c=getchar();LL x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
LL n,a[100],dp[100];
int main()
{
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	dp[1]=1000;
	for(int i=2;i<=n;++i){
		dp[i]=dp[i-1];
		for(int j=1;j<i;++j){
			LL conn=dp[j]/a[j];
			dp[i]=max(dp[i],dp[j]-conn*a[j]+conn*a[i]);
		}
	}
	LL maxx=0;
	for(int i=1;i<=n;++i)
//		printf("%lld\n",dp[i]);
		maxx=max(maxx,dp[i]);
	printf("%lld\n",maxx);
	return 0;
}


Measured memory_bytes: 3720
from itertools import combinations


def main():
    N = int(input())
    L = list(map(int, input().split()))

    c = combinations(L, 3)

    ans = 0
    for cc in c:
        if cc[0] == cc[1] or cc[1] == cc[2] or cc[2] == cc[0]:
            continue
        if cc[0] + cc[1] > cc[2] and cc[0] + cc[2] > cc[1] and cc[1] + cc[2] > cc[0]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int N;
  string S;
  cin >> N >> S;

  for (int i = 0; i < S.size(); i++) {
    S.at(i) = 'A' + (S.at(i) - 'A' + N) % 26;
  }
  cout << S << endl;
}

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a, alice, bob;
    a.resize(n);
    for(int i = 0; i < a.size(); i++){
        cin >> a[i];
    }

    bool flag = true;
    sort(a.begin(), a.end());
    for(int i = a.size() - 1; i > -1; i--){
        if(flag){
            alice.push_back(a[i]);
            flag = false;
        }
        else{
            bob.push_back(a[i]);
            flag = true;
        }
    }

    cout << accumulate(alice.begin(), alice.end(), 0) - accumulate(bob.begin(), bob.end(), 0) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

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

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min({abs(b-a) + abs(c-b),abs(a-b) + abs(c-a),abs(c-a) + abs(b-c)}) << '\n';
    return 0;
}

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

double dist (int x1, int y1, int x2, int y2) {
    return sqrt(pow((x1-x2), 2) + pow((y1-y2), 2));
}

int main()
{
    int n; cin >> n;
    int x[n], y[n];

    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    
    double total = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) 
            total += dist(x[i], y[i], x[j], y[j]);
 
    printf("%.10lf", total/n);
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X = ir()
answer = 0
dir = 0
while True:
    dir += X
    answer += 1
    dir %= 360
    if dir == 0:
        break

print(answer)


Measured memory_bytes: 9164
#include <iostream>
using namespace std;
int main(void){
    int a;
    int b;
    int c;
    cin >> a;
    cin >> b;
    cin >> c;
    if(a<b && b<c){
        cout << "Yes" << endl;
    }else {
        cout << "No" <<endl;
        }
    
}

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <unordered_set>
using namespace std;
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 main() {
	int N;
	cin >> N;
	vector<vector<int>> dp(N + 1, vector<int>(3));
	int a, b, c;
	for (int i = 1; i <= N; i++) {
		cin >> a >> b >> c;
		dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a);
		dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b);
		dp[i][2] = max(dp[i - 1][0] + c, dp[i - 1][1] + c);
	}
	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    ll zero = 0, one = 0;
    REP(i,0,SZ(S)) {
        if(S[i] == '0') ++zero;
        else ++one;
    }
    PR(MIN(zero,one)*2);
    

    return 0;
}

/*



*/

Measured memory_bytes: 3740
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
a_sum = 0
b_sum = 0
for i in range(n):
    c.append(b[i]-a[i])
    if c[i] < 0:
        b_sum += c[i]
    else:
        a_sum += c[i]//2

if a_sum < abs(b_sum):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 10596
import java.util.Scanner;

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




		if((S + T.charAt(T.length()-1)).equals(T)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}



Measured memory_bytes: 39044
#include<iostream>

using namespace std;

int main()
{
	int a,b,k;
	cin >> a >> b >> k;

	int count=0;
	for(int i=100;i>0;i--)
	{
		if(a%i==0 and b%i==0)
			count++;
		if(count==k)
		{
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
N = int(input())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [int(z) for z in input().split()]

total = 0
pre = 999
for i in range(N):
    total += b[a[i]-1]
    if a[i] == pre+1:
        total += c[pre-1]
    pre = a[i]
print(total)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
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; }
const ll INF=(1LL<<61)-1;



int main(){
    ll N,W; cin >> N >> W;
    vector<P> vw(N);
    ll w0 = 0;
    rep(i,N){
        int v,w; cin >> w >> v;
        if(i==0) w0 = w;
        w-= w0;
        vw[i] = make_pair(v,w);
    }

    sort(vw.begin(),vw.end(),greater<P>());
    vector<vector<ll> > sum(5,vector<ll>(110,0));
    int num[5]={0};
    rep(i,N){
        rep(j,4){
            if(vw[i].second==j){
                num[j]++;
                sum[j][num[j]] = sum[j][num[j]-1]+vw[i].first;
            }
        }
    }
    
    ll ans = -1;
    rep(i,num[0]+1){
        rep(j,num[1]+1){
            rep(k,num[2]+1){
                rep(l,num[3]+1){
                    if(w0*(i+j+k+l) + j*1+k*2+l*3 <= W) chmax(ans, sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l]);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
// Created by Tanuj Jain
#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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 int recursion(vector<int>&v, int end, int k)
 {
 	//cout<<end
 	if(end==0)
 		return 0;
 	if(end<0)
 		return 1e6;
 	int ans=1e6;
 	for(int i=1;i<=k;i++)
 	{
 		//find the ans for each child node and take the minimum out of it
 		if(end-i>=0)
 		{
 			int temp=recursion(v,end-i,k);
 			if(temp!=1e6)
 				ans=min(ans,temp+abs(v[end]-v[end-i]));	
 		} 
 		
 	}
 	return ans;
 }
 int recursion_with_memo(vector<int>&v, int end, int &k, unordered_map<int,int>&memo)
 {
 	if(end==0)
 		return 0;
 	//if(end<0)
 	//	return 1e6;
 	int ans=1e9;
 	for(int i=1;i<=k;i++)
 	{
 		if(end-i>=0)
 		{
 			if(memo.find(end-i)==memo.end())
 			{
 				//calu the value
 				int temp=recursion_with_memo(v,end-i,k,memo);
 				//save the value in memo table
 				memo[end-i]=temp;
 				ans=min(ans,temp+abs(v[end]-v[end-i]));
 			}
 			else
 				ans=min(ans,memo[end-i]+abs(v[end]-v[end-i]));

 		}
 	}
 	return ans;

 }
 int bottom_up(vector<int>&v,int k)
 {
 	int n=v.size();
 	vector<int>dp(n,1e9);
 	dp[0]=0;
 	//dp[1]=abs(v[1]-v[0]);
 	for(int i=1;i<n;i++)
 	{
 		for(int j=1;j<=k;j++)
 			if(i-j>=0)
 				dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
 	}
 	//for(int i=0;i<n;i++)
 	//	cout<<dp[i]<<" ";
 	return dp[n-1];
 }
int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	int t,k;
	cin>>t>>k;
	vector<int>v(t);
	for(int i=0;i<t;i++)
		cin>>v[i];
	//cout<<recursion(v,t-1,k);
	//recursion with memoization 
	unordered_map<int,int>memo;
	//int ans=1e6;
	cout<<recursion_with_memo(v,t-1,k,memo);
	//for(auto it:memo)
	//	cout<<it.first<<" "<<it.second<<endl;
	//cout<<bottom_up(v,k);

	
}

Measured memory_bytes: 15652
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, d, a;
    cin >> n >> d >> a;
    pair<int, int> p[n];
    for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
    sort(p, p + n);
    queue<pair<int, int>> q;
    ll res = 0, tmp, extra = 0;
    for (int i = 0; i < n; i++) {
        while (!q.empty()) {
            if(p[i].first > q.front().first){
                extra-=q.front().second;
                q.pop();
            }
            else break;
        }
        p[i].second -= extra;
        if (p[i].second > 0) {
            tmp = p[i].second / a;
            if (p[i].second % a) tmp++;
            res += tmp;
            q.push({p[i].first + 2 * d, a * tmp});
            extra += a * tmp;
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 2688
import math

A, B, H, M = map(int, input().split())

rad_A = math.radians(H * 30 + M / 2)
rad_B = math.radians(M * 6)

A_x = A * math.cos(rad_A)
A_y = A * math.sin(rad_A)
B_x = B * math.cos(rad_B)
B_y = B * math.sin(rad_B)

print(math.sqrt((A_x - B_x) ** 2 + (A_y - B_y) ** 2))


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


bool isPM(int x)
{
    if(x<=1) return false;
    for(int i = 2; i*i <= x; i++)
    {
        if (x%i == 0) return false;
    }
    return true;
}

int main()
{

    int N;
    cin >> N;
    int p=N;
    while(!isPM(p))
    p++;
    cout<<p<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int N; cin >> N;
	vector<int> T(N);
	ll sum = 0;
	for(int i = 0; i < N; i++) {
		cin >> T[i];
		sum += T[i];
	}
	int M; cin >> M;
	vector<int> P(M), X(M);
	for(int i = 0; i < M; i++) cin >> P[i] >> X[i];
	for(int i = 0; i < M; i++) {
		ll ans = sum - T[P[i] - 1] + X[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3560
use std::io::*;

fn read_spc<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    round_up_the_mean();
}

fn round_up_the_mean() {
    let ab: Vec<i64> = read_spc();
    let a_b = ab[0] + ab[1];
    let dab = a_b / 2;
    if a_b % 2 == 0 {
        println!("{}", dab);
    } else {
        println!("{}", dab + 1);
    }
}

Measured memory_bytes: 4352
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = getLine >>= putStrLn . solve 

solve :: String -> String
solve s
    | y >= 2019 && m > 4 = "TBD"
    | otherwise = "Heisei"
    where
        y = read $ take 4 s :: Int
        m = read . take 2 $ drop 5 s :: Int

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 508
#include<stdio.h>
int main()
{
    int A, B;
    scanf("%d%d",&A, &B);
    if(A+B>=A-B&&A+B>=A*B)
    {
        printf("%d",A+B);
    }
    else if(A-B>=A+B&&A-B>=A*B)
    {
        printf("%d",A-B);
    }
    else if(A*B>=A+B&&A*B>=A-B)
    {
        printf("%d",A*B);
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>

using namespace std;

long long int x;

long long int func(long long int n) {
  if(n == -1) {
    return 0;
  }
  else {
    return n / x + 1;
  }
}

int main(void) {
  long long int a, b;
  scanf("%lld %lld %lld", &a, &b, &x);

  printf("%lld\n", func(b) - func(a - 1));
  return 0;
}

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

using namespace std;

const int MX = 200000;

int a[MX];

int main() {
	int n;
	ignore = scanf("%d", &n);
	for (int i = 0; i < n; i++) ignore = scanf("%d", a + i);
	
	sort(a, a + n);
	reverse(a, a + n);
	
	int ans = 0;
	map<int, int> cnt;
	for (int i = 0; i < n; i++) cnt[a[i]]++;
	for (int i = 0, p = (1 << 30); i < n; i++) {
		if (cnt[a[i]] == 0) continue;
		cnt[a[i]]--;
		
		while (p - a[i] > a[i]) p /= 2;
		
		if (cnt[p - a[i]] > 0) {
			cnt[p - a[i]]--;
			ans++;
		}
		else {
			cnt[a[i]]++;
			cnt.erase(p - a[i]);
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 10368
exams = []
exam = [0, 0, 0]
loop do
    exam = gets.split.map(&:to_i)
    break if exam[0] == -1 && exam[1] == -1 && exam[2] == -1
    exams << exam
end
exams.each do |exam|
    score = exam[0] + exam[1]
    case
    when exam[0] == -1 || exam[1] == -1
        puts "F"
    when score >= 80
        puts "A"
    when score >= 65
        puts "B"
    when score >=50
        puts "C"
    when score >= 30
        if exam[2] >= 50
            puts "C"
        else
            puts "D"
        end
    else
        puts "F"
    end
end


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

ll ans[16];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i=0; i<=n; i++)
    {
        ans[i] = 1LL * 1000000000000;
    }

    ll orig_mn[n], mn[n];
    vector<pair<pll, ll>> v;
    for(int i=0; i<n; i++)
    {
        ll x, y, p;
        cin >> x >> y >> p;
        orig_mn[i] = min(abs(x), abs(y));
        v.PB({{x, y}, p});
    }
    for(int i=0; i<(1<<n); i++)
    {
        ll s;
        if(i == 0)
        {
            s = 0;
        }
        else
            s = __builtin_popcount(i);
        vector<int> cities;
        for(int j=0; j<n; j++)
        {
            if(i&(1<<j))
            {
                cities.PB(j);
            }
        }
        vector<ll> pos[2];
        for(int j=0; j<(1<<s); j++)
        {
            pos[0].clear(); pos[1].clear();
            for(int k=0; k<s; k++)
            {
                int xy = (1<<k)&j;
                if(xy)
                {
                    pos[1].PB(v[cities[k]].f.s);
                }
                else
                {
                    pos[0].PB(v[cities[k]].f.f);
                }
            }
            ll tot = 0;
            for(int i=0; i<n; i++)
            {
                mn[i] = orig_mn[i];
                for(int j=0; j<2; j++)
                {
                    for(ll val : pos[j])
                    {
                        if(j)
                        {
                            mn[i] = min(mn[i], abs(v[i].f.s - val));
                        }
                        else
                        {
                            mn[i] = min(mn[i], abs(v[i].f.f - val));
                        }
                    }
                }
                tot += (v[i].s * mn[i]);
            }

            ans[s] = min(ans[s], tot);
        }

    }

    for(int i=0; i<=n; i++)
    {
        cout << ans[i] << "\n";
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a;
    rep(i,n){
        cin >> a;
      	if(a%2==0 && (a%3!=0 && a%5!=0)){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
    
}

Measured memory_bytes: 256
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8[:],i8[:],i8[:],i8[:]), cache=True)
def main(lis_h,lis_w,bomb_h,bomb_w):
  bomb = {}
  for h,w in zip(bomb_h,bomb_w):
    bomb[(h,w)] = 1
  m_h = max(lis_h)
  m_w = max(lis_w)
  m_h_lis = []
  m_w_lis = []
  for i,l in enumerate(lis_h):
    if l==m_h:
      m_h_lis.append(i)
  for i,l in enumerate(lis_w):
    if l==m_w:
      m_w_lis.append(i)
  ans = m_h+m_w
  for h in m_h_lis:
    for w in m_w_lis:
      if (h,w) not in bomb:
        return ans
  return ans-1

H, W, M = map(int, input().split())
bombh = np.zeros(M, np.int64)
bombw = np.zeros(M, np.int64)
lis_h = np.zeros(H, np.int64)
lis_w = np.zeros(W, np.int64)
for i in range(M):
    h,w = map(int, input().split())
    h -= 1
    w -= 1
    bombh[i], bombw[i] = h,w
    lis_h[h] += 1
    lis_w[w] += 1
print(main(lis_h,lis_w,bombh,bombw))


Measured memory_bytes: 136176
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var b = o.l();
  var as = a.reduce((a,b)=>a+b);
  var bs = b.reduce((a,b)=>a+b);
  if(bs > as)return -1;
  var c = [];
  var ans = 0;
  var m = 0;
  for(var i = 0; i < n; i++){
    var t = a[i] - b[i];
    if(t > 0)c.push(t);
    else if(t < 0)m += t, ans++;
  }
  if(ans === 0)return 0;
  c.sort((a,b)=>b-a);
  i = 0;
  while(m < 0){
    ans++, m += c[i++];
  }
  return ans;
}

Measured memory_bytes: 51956
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100,M=100000;
int n,m;
int v[N+1],w[N+1];
int dp[M+1];
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++)for(int j=m;j>=w[i];j--)
		dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	cout<<dp[m];
	return 0;
}
/*1
3 8
3 30
4 50
5 60
*/
/*2
5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
*/
/*3
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/

Measured memory_bytes: 1024
a = [list(map(int, input().split())) for i in range(3)]
output =[[0,0,0],[0,0,0],[0,0,0]]
n = int(input())
check=False
for k in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j]==b:
                output[i][j]=1
for i in range(3):
    if output[i][0]*output[i][1]*output[i][2]==1:
        check=True
    elif output[0][i]*output[1][i]*output[2][i]==1:
        check=True
if output[0][0]*output[1][1]*output[2][2]==1:
    check=True
elif output[2][0]*output[1][1]*output[0][2]==1:
    check=True
if check==True:
    print('Yes')
else:
    print('No')

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

#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define track(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1000000007;
const ll inf=1e15;
const ll N=1e5+10;


int main()
{
	boost;
	ll a,p;
	cin>>a>>p;
	cout<<(3*a+p)/2;
  	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
 
int main (void)
{
  int N;
  scanf("%d",&N);
   if(N % 2 == 0 && N<=100 && N>=0)
   {
     printf("%d",N/2);
   }
     else if(N % 2 == 1 && N<=100 && N>=0)
     {  printf("%d",(N/2)+1);
    
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        long K = sc.nextLong();
        
        long ans = 0L;
        if (K == 0) {	
        	ans = A - B;
        } else if (K == 1) { 
        	ans = B - A;
        } else if (K % 2 == 0) {
        	ans = A - B;
        } else {
        	ans = B - A;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
ll MAX=9223372036854775807;
using namespace std;
int main()
{
    ll n;
    cin >> n;
    vector <vector<ll>> F(n,vector<ll>(10,0));
    vector <vector<ll>> P(n,vector<ll>(11,0));
    for(int i=0;i<n;i++)
    {
         for(int j=0;j<10;j++)
    {

        ll x;
        cin >> x;
        F[i][j]=x;
    }

    }

     for(int i=0;i<n;i++)
    {
         for(int j=0;j<11;j++)
    {

        ll x;
        cin >> x;
        P[i][j]=x;
    }
    }
    ll ans=-1e19;
    ll mask1=0;
    bool B=true;
    for(int mask = 1; mask < (1<<10); mask++)
{
    vector<ll> bin(n+1, 0);
    for(int i=0; i<10; i++)
        if(mask & (1<<i))
    {
        for(int j=0;j<n;j++)
            if(F[j][i]==1)
                bin[j]++;

    }
    ll val=0;
    for(int i=0;i<n;i++)
    {
        val+=P[i][bin[i]];
    }
    ans=max(ans,val);

}

   cout << ans;
    return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;

typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

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

ll n,k;
int main(){
    cin >> n >> k;
    // cout << gcd(n,k) << endl;
    // ll min = gcd(n,k);
    // if(n == 0 or k == min) cout << 0 << endl;
    // else cout << gcd(n,k) << endl;
    // cout << n%k << endl;
    if(n%k > k - n%k)cout << k - n%k << endl;
    else cout << n%k << endl;
}


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

int main(void){
  string S; ll K; cin >> S >> K;
  K--;
  int idx = 0;
  while(1){
    if(idx == K){
      cout << S[idx] << endl;
      return 0;
    }
    if(S[idx] != '1'){
      cout << S[idx] << endl;
      return 0;
    }
    idx++;
  }
  return 0;
}

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

using namespace std;

std::vector<long> get_devisors(const int M) {
    std::vector<long> v;

    for (long i = 1; i * i < M; i++) {
        if (M % i == 0) {
            v.push_back(i);
            if (M != i*i) v.push_back(M/i);
        }
    }

    return v;
}

int main(int argc, char* argv[]) {
    int N, M;

    std::cin >> N >> M;

    auto devisors = get_devisors(M);

    long ans = 1;
    for (auto d : devisors) {
        if (M >= d * N) {
            ans = std::max(ans, d);
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

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

const int N = 1e5 + 10;

char s[N];

int main(){
	int n, flag, now;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if (s[n] == '1'){
		printf("-1\n");
		return 0;
	} 
	if (s[1] == '0' || s[n - 1] == '0'){
		printf("-1\n");
		return 0;
	}
	flag = 1;
	for (int i = 1; i <= (n - 1) / 2; i++){
		if (s[i] != s[n - i]){
			flag = 0;
			break;
		}
	}
	if (!flag){
		printf("-1\n");
		return 0;
	}
	now = 1;
	for (int i = 1; i <= n / 2; i++){
		printf("%d %d\n", now, i + 1);
		if (s[i] == '1') now = i + 1;
	}
	for (int i = n / 2 + 2; i <= n; i++) printf("%d %d\n", now, i);
	return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  if(M==0){
    cout << 0 << ' ' << 0 << endl;
    return 0;
  }
  
  //Memo{(AC(0or1),WA(AC==0の時のみ加算)),(...)}0~n-1
  
  vector<vector<int>> Memo(N,vector<int>(2));
  for(int i=0; i<M; i++){
    int p;
    string s;
    cin >> p >> s;
    if(s=="WA"){
      if(Memo.at(p-1).at(0)==0){
        Memo.at(p-1).at(1)++;
      }
    }
    else if(s=="AC"){
      Memo.at(p-1).at(0)=1;
    }
  }
    
  int AC=0;
  int WA=0;
  for(int i=0; i<N; i++){
    AC += Memo.at(i).at(0);
    if(Memo.at(i).at(0)==1){
      WA += Memo.at(i).at(1);
    }
  }
    
  cout << AC << ' ' << WA << endl;
    
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<vector<int>> c(h, vector<int>(w, 0));

    int v = 0;
    rep(i, h) {
        int j = 0;
        while(j < w) {
            if (a[v] == 0) {
                ++v;
            }
            c[i][j] = v + 1;
            --a[v];
            ++j;
        }
    }

    rep(i, h) {
        rep(j, w) {
            if (i % 2 == 0) {
                cout << c[i][j] << " ";
            }
            else {
                cout << c[i][w - 1 - j] << " ";
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#import <stdio.h>
typedef long long INT;
int main(){
    INT a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    INT A=2*a-b-c;
    INT B=2*b-c-a;
    INT C=2*c-a-b;
    if(a==b&&b==c) {
        if(a%2==0){
            puts("-1");
        }else{
            puts("0");
        }
        return 0;
    }else{
        INT i=0;
        while(A%2==0&&B%2==0&&C%2==0){
            i++;
            A/=2;
            B/=2;
            C/=2;
        }
        printf("%lld",i);
    }
}


Measured memory_bytes: 2164
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll n;
	scanf("%lld", &n);
	ll ans = 0;
	for (int i = sqrt(n); i > 0; --i) {
		if (!(n % i)) {
			ans = i + n / i;
			break;
		}
	}
	printf("%lld\n", ans - 2);

	Please AC;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

int main()
{
    for (ll i = 0; i < 5; i++)
    {
        ll xi;
        cin >> xi;
        if (xi == 0) {
            cout << (i+1) << endl;
        }
    }
    
}


Measured memory_bytes: 3632
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
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;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

template<class T>
T Pow(T a, T b)
{
  // a^b を計算する。
    T res = 1;
    while (b > 0)
    {
        if (b & 1) res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n, ans = 0;
  cin >> n;
  if (n % 2 == 0) REP2(LL, i, 1, 26) ans += n / Pow(5LL, i) / 2;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n;

int main() {

	FAST;

	cin >> n;
	vector <int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> a[i] >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int x, y;
	if (n % 2 == 1) {
		x = a[(n + 1) / 2];
		y = b[(n + 1) / 2];
	}
	else {
		x = a[n / 2] + a[n / 2 + 1];
		y = b[n / 2] + b[n / 2 + 1];
	}
	cout << y - x + 1 << '\n';
	return 0;
}

Measured memory_bytes: 4772
//J-Sushi

#include<iostream>
#include<algorithm>
#include<utility>
#include<map>
#include<string>
#include<vector>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#undef INT_MIN
#undef INT_MAX
#define LL long long
#define INT_MIN -2147483647
#define INT_MAX 1000000009
#define LL_MIN -9223372036854775807
#define LL_MAX 9223372036854775807
#define MOD 1000000007

int N, K, A[109];
int dp[100009][2];
int ans = 0;//1-First, 0-Second

int main(){
	cin >> N >> K;
	for(int i=0; i<N; i++)
		cin >> A[i];
	sort(A, A + N);

	for(int i = 0; i<= K; i++){
		for(int j=0; j < 2; j++){
			if(i < A[0])
				dp[i][j] = j ^ 1;
			else{
				bool tmp = false;
				for(int k = 0; k < N; k++){
					if((i >= A[k]) && (dp[i - A[k]][j ^ 1] == j))
						tmp = true;
				}
				dp[i][j] = (tmp ? j : (j ^ 1));
			}
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}

	string ans = (dp[K][1] ? "First" : "Second");
	cout << ans << endl;

	return 0;
}





Measured memory_bytes: 1024
using System;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ');
			int x = int.Parse(input[0]);
			int a = int.Parse(input[1]);

			if (x < a)
			{
				Console.WriteLine(0);
			}
			else
			{
				Console.WriteLine(10);
			}
		}
	}
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

ll N, A, B, C;
string s[101010];
bool ok = false;
int ans[101010];
int cmds[101010];

void solve(int i, ll A, ll B, ll C) {

    if (ok) return;

    if (i >= N) {
        // 終わった
        ok = true;
        rep(i, N) ans[i] = cmds[i];
        return;
    }

    if (s[i] == "AB") {
        if (B-1 >= 0) {
            cmds[i] = 0;
            solve(i+1, A+1, B-1, C);
            cmds[i] = -1;
        }
        if (A-1 >= 0) {
            cmds[i] = 1;
            solve(i+1, A-1, B+1, C);
            cmds[i] = -1;
        }
    }
    else if (s[i] == "AC") {
        if (C-1 >= 0) {
            cmds[i] = 0;
            solve(i+1, A+1, B, C-1);
            cmds[i] = -1;
        }
        if (A-1 >= 0) {
            cmds[i] = 2;
            solve(i+1, A-1, B, C+1);
            cmds[i] = -1;
        }
    }
    else if (s[i] == "BC") {
        if (C-1 >= 0) {
            cmds[i] = 1;
            solve(i+1, A, B+1, C-1);
            cmds[i] = -1;
        }
        if (B-1 >= 0) {
            cmds[i] = 2;
            solve(i+1, A, B-1, C+1);
            cmds[i] = -1;
        }
    }
}

int main() {
    cin >> N >> A >> B >> C;
    rep(i, N) cin >> s[i];
    solve(0, A, B, C);

    if (ok) {
        cout << "Yes" << endl;
        char tmp[] = { 'A', 'B', 'C' };
        for (int i = 0; i < N; ++i) {
            cout << tmp[ans[i]] << endl;
        }
    }
    else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 13832
//
//  main.cpp
//  ABC159Eteacher
#include <vector>
#include<iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int INF = 1001001001;

int c[10][1005];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = INF;
  rep(div,1<<(h-1)) {
    int g = 0;
    vector<int> id(h);
    rep(i,h) {
      id[i] = g;
      if (div>>i&1) ++g;
    }
    ++g;
    rep(i,g)rep(j,w) c[i][j] = 0;
    rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j]-'0');

    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i,g) now[i] += c[i][j];
      rep(i,g) if (now[i] > k) return false;
      return true;
    };
    rep(j,w) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        if (!add(j)) {
          num = INF;
          break;
        }
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256