akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

template<typename T>
T extgcd(T a,T b,T& x,T& y){
  T d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}

template<typename T>
T mod_inverse(T a,T mod){
  T x,y;
  extgcd(a,mod,x,y);
  return (x%mod+mod)%mod;
}

template<typename T, size_t sz>
struct Combination{
  using ll = long long;
  array<T, sz> fact;

  T mod;
  Combination(T mod):mod(mod){init();}

  void init(){
    fact[0]=1;
    for(int i=1;i<(int)sz;i++)
      fact[i]=(ll)fact[i-1]*i%mod;
  }

  T mod_fact(T n,T& e){
    e=0;
    if(n==0) return 1;
    T res=mod_fact(n/mod,e);
    e+=n/mod;
    if(n/mod%2!=0)return res*(mod-fact[n%mod])%mod;
    return res*fact[n%mod]%mod;
  }

  T mod_comb(T n,T k){
    if(n==k||k==0) return 1;
    T e1,e2,e3;
    T a1=mod_fact(n,e1),a2=mod_fact(k,e2),a3=mod_fact(n-k,e3);
    if(e1>e2+e3) return 0;
    return a1*mod_inverse<ll>((ll)a2*a3%mod,mod)%mod;
  }
};

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  string s;
  cin>>s;

  vector<int> as(n);
  for(int i=0;i<n;i++) as[i]=s[i]-'1';

  const int sz = 1e6+10;
  Combination<int, sz> C(2);

  int is_one=0;
  for(int i=0;i<n;i++)
    if(as[i]&1) is_one^=C.mod_comb(n-1,i);

  if(is_one){
    cout<<1<<newl;
    return 0;
  }

  for(int i=0;i<n;i++){
    if(as[i]==1){
      cout<<0<<newl;
      return 0;
    }
    as[i]/=2;
  }

  int is_two=0;
  for(int i=0;i<n;i++)
    if(as[i]&1) is_two^=C.mod_comb(n-1,i);

  cout<<is_two*2<<newl;
  return 0;
}


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

using namespace std;

int main(void){
	vector<int> prime(100001, 1), num(100001, 0);

	prime[0] = 0;
	prime[1] = 0;

	for (int i = 2; i < 1001; i++){
		if (prime[i] == 1){
			for (int j = i*i; j < 100001; j += i){
				prime[j] = 0;
			}
		}
		else {
			continue;
		}
	}

	num[0] = 0;
	for (int i = 1; i < 100001; i++){
		num[i] += num[i-1];
		if (i % 2 == 1 && prime[i] && prime[(i+1)/2]){
			num[i]++;
		}
	}

	int q;

	cin >> q;

	int l, r;

	for (int i = 0; i < q; i++){
		cin >> l >> r;

		cout << num[r] - num[l-1] << endl;
	}



	return 0;
}

Measured memory_bytes: 1408
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

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

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int Pas[3];
int drink[2];
int main()
{
  for(int i = 0;i < 3;i++){
    cin >>Pas[i];
  }
  for(int i = 0;i < 2;i++){
    cin>>drink[i];
  }
  sort(Pas,Pas+3);
  sort(drink,drink+2);
  cout <<Pas[0]+drink[0]-50<<endl;

  return 0;
}

Measured memory_bytes: 1176
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }
uint32_t nextstr(char *s){
	char c=getchar();
	while(c==' '||c=='\n'||c=='\r'||c=='\t') c=getchar();
	uint32_t len=0;
	while(c!=' '&&c!='\n'&&c!='\r'&&c!='\t'){ *s++=c; len++; c=getchar(); }
	*s='\0';
	return len;
}

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

char s[100001];
int main(void){
	int n=nextstr(s);
	int k=nextpint();
	for(int i=0; i<n; i++){
		int n='{'-s[i];
		if(n!=26 && n<=k){
			k-=n;
			s[i]='a';
		}
	}
	s[n-1]=(s[n-1]-'a'+k)%26+'a';
	puts(s);
}


Measured memory_bytes: 384
#include<stdio.h>
#include<cmath>
int main(){
    int a,b,h,m;
    const double pi=3.1415926535897932384626;
    scanf("%d %d %d %d",&a,&b,&h,&m);
    double d=h*30-5.5*m;
    d=d/180*pi;
    double distance;
    distance=sqrt(a*a+b*b-2*a*b*cos(d));
    printf("%.20f\n",distance);
    return 0;
}

Measured memory_bytes: 2600
x1, x2, x3, x4, x5 = map(int,input().split())

if x1 == 0:
    print("1")

elif x2 == 0:
    print("2")

elif x3 == 0:
    print("3")

elif x4 == 0:
    print("4")

else:
    print("5")

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

using namespace std;

int main(void) {
    long n, k;
    cin >> n >> k;
    vector<long> a(n);
    for(auto &e: a) cin >> e;

    long g = 0, m = 0;
    for(auto &e: a) g = __gcd(g, e), m = max(m, e);

    cout << ((m >= k && (m-k)%g == 0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    cout << !!(N%K) << endl;
    
return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }
    else if(a<b){
        printf("a < b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2684
package main

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

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, H := nextInt(), []int{}
	for i := 0; i < N; i++ {
		H = append(H, nextInt())
	}

	fmt.Printf("%d\n", ABC116C(N, H))
}

// ABC116C ...
func ABC116C(N int, H []int) int {
	res, active := 0, 0

	for i := 0; i < N; i++ {
		if active >= H[i] {
			active = H[i]
		} else {
			res += H[i] - active
			active = H[i]
		}
    }
	return res
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{

int N;
int judge=0;
cin >> N;
vector<int> a(N+1);//配列の宣言
for(int i=0;i<N;i++){
    cin >> a.at(i);
}
for(int i=0;i<N;i++){
    if((a.at(i)%2==0)&&(a.at(i)%3!=0)&&(a.at(i)%5!=0)){
        judge++;
    }
}
if(judge==0){
    cout << "APPROVED" << endl;
}
else{
    cout << "DENIED" << endl;
}
}


Measured memory_bytes: 256
import bisect
import collections
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
cuml=[0]*(N+1)
cuml[0]=A[0]
l=[]
cuml2=[]
l2=[]
buf=[]
ans=0
for i in range(N):
    cuml[i+1]=cuml[i]+A[i+1]
#print(cuml)
for i in range(N+1):
    cuml2.append([(cuml[i]-i)%K,i])
    cuml[i]=(cuml[i]-i)%K
#print(cuml2,cuml)
cuml2.sort(key=lambda x:x[0])
piv=cuml2[0][0]
buf=[]
for i in range(N+1):
    if piv!=cuml2[i][0]:
        l2.append(buf)
        piv=cuml2[i][0]
        buf=[]
    buf.append(cuml2[i][1])
l2.append(buf)
#print(l2)
cnt=0
for i in range(len(l2)):
    for j in range(len(l2[i])):
        num=l2[i][j]
        id=bisect.bisect_left(l2[i], num + K)
        #print(j,id)
        cnt=cnt+(id-j-1)
print(cnt)



Measured memory_bytes: 129272
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


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

	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


int main(void)
{
	int a, b, k;

	while(scanf("%d%d%d", &a, &b, &k)==3)
	{
		int ans=-1;
		int n=0;
		int c=gcd(a, b);
		for(int i=1;i<=c;i++)
		{
			if(c%i==0)
			{
				n++;
				if(n==k)
				{
					ans=c/i;
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    char ch;
    while(true)
    {
        int sum = 0;
        while((ch = getchar()) != '\n')
        {
            sum+= (ch -'0');
        }
        if(sum==0)
        {
            break;
        }
        else
        {
	        printf("%d\n",sum);
        }
    }    
    return 0;
}


Measured memory_bytes: 2716
n, x = map(int, input().split())
xlis = list(map(int, input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
d = 0
for i in range(n):
    d = gcd(d, abs(xlis[i]-x))
print(d)

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    map<ll, ll> M;
    ll ans = 0;
    M[-(A[0] + 1)] = 1;
    FOR(i, N, 1) {
        ll t = A[i] - (i + 1);
        ans += M[t];

        M[-(A[i] + (i + 1))]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27952
#include <iostream>
#include <vector>
#include <cmath>

int main(){
	int n, m, s, c, ans = 0;
	std::cin >> n >> m;
	std::vector<int>a(n, -1);
	for(int i=0; i<m; i++){
		std::cin >> s >> c;
		if(a[s-1] == -1 or a[s-1] == c){
			a[s-1] = c;
		}else{
			ans = -1;
		}
	}
	if(ans == 0){
		for(int i=0; i<n; i++){
			if(a[i]==-1){
				if(i==0 and n>=2){
					a[i] = 1;
				}else{
					a[i] = 0;
				}
			}
			ans += a[i] * (int)std::pow(10, (n-i-1));
		}
	}

	if(a[0]==0 and n>=2){
		ans = -1;
	}


	std::cout << ans << std::endl;
	return 0;
}


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

int main() {

  string s;
  cin >> s;

  vector<int> answer;

  deque<int> S1;
  deque<pair<int, int>> S2;
  int sum = 0;
  
  for (int i = 0; i < s.size(); i++) {  
    if (s[i] == '\\') {
      S1.push_back(i);
    } else if (s[i] == '/' && 0 < S1.size()) {
      int j = S1.back();
      S1.pop_back();
      sum += i - j;
      int a = i - j;
      while (0 < S2.size() && j < S2.back().first) {
        a += S2.back().second;
        S2.pop_back();
      }
      S2.push_back(make_pair(j, a));
    }
  }

  while (0 < S2.size()) {
    answer.push_back(S2.back().second);
    S2.pop_back();
  }

  reverse(answer.begin(), answer.end());
  
  cout << sum << endl;
  cout << answer.size();
  
  for (int i = 0; i < answer.size(); i++) {
    cout << " ";
    cout << answer[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>

int prin(int H,int W,char map[101][101]){
	int i,j;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++)
			printf("%c",map[i][j]);
		puts("");
	}
}

main(){
	char map[101][101];
	int H,W;
	scanf("%d %d",&H,&W);
	getchar();
	int i,j,k,f;
	for(i=0;i<H;i++){
		f=1;
		for(j=0;j<W;j++){
			scanf("%c",&map[i][j]);
			if(map[i][j]=='#')f=0;
		}
		if(f){
			i--;H--;
		}
		getchar();
	}
	for(i=0;i<W;i++){
		f=1;
		for(j=0;j<H;j++){
			if(map[j][i]=='#')f=0;
		}
		if(f){
			for(k=i;k<W-1;k++)
				for(j=0;j<H;j++)
					map[j][k]=map[j][k+1];
			W--;i--;
		}
	}
		prin(H,W,map);
	return 0;
}

Measured memory_bytes: 128
S = gets.chomp

counter = Hash.new(0)

S.each_char do |s|
  counter[s] += 1
end

ks = counter.keys.size
min, max = counter.values.minmax

if S.size == ks
  puts 'YES'
  exit
end

if ks <= 2 || max - min > 1
  puts 'NO'
else
  puts 'YES'
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
struct edge {
    ll from;
    ll to;
    ll cost;
};
int main(void){
    ll n,m;
    ll d[1000];
    vector<edge> edges;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        struct edge add;
        cin>>add.from>>add.to>>add.cost;
        add.from--,add.to--;
        edges.push_back(add);
    }
    fill(d,d+n,-INF);
    d[0]=0;
    for(int i=0;i<n-1;i++){
        for(auto e:edges){
            if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    ll a=d[n-1];
    for(auto e:edges){
        if(d[e.from]!=-INF&&d[e.to]<d[e.from]+e.cost){
            d[e.to]=d[e.from]+e.cost;
        }
    }
    if(a!=d[n-1]) cout<<"inf"<<endl;
    else cout<<d[n-1]<<endl;
}

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

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var K = int.Parse(Console.ReadLine());
            var AB = Console.ReadLine().Split().Select(int.Parse).ToList();

            bool result = false;
            for (int i = AB[0]; i <= AB[1]; i++)
            {
                if (i % K == 0)
                {
                    result = true;
                    break;
                }
            }

            Console.WriteLine(result ? "OK" : "NG");


#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int n,m; cin >> n >> m;
    int sum = 0;
    rep(i,m){
        int a; cin >> a;
        sum += a;
    }
    if(n - sum >= 0) cout << n - sum;
    else cout << -1;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
	int i,j,k,a,b,cnt=0,flag;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b);
		flag=0;
		for(j=2;j*j<=b;j++){
			if(b%j==0){
				flag=1;
				break;
			}
		}
		if(!flag)cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 596
from collections import Counter

N = int(input())
A = list(map(int,input().split()))

Ac = Counter(A).most_common()
#print(Ac)
ans = 0

for i in range(len(Ac)):
    if Ac[i][1] > 1:
        ans += Ac[i][1]-1

print(N-ans if ans%2 == 0 else N-ans-1)


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

using namespace std;

void update(long* c, int* p, int* a, int* head, int* size, int a_size, long* sum, long* max){
        //cout << "add:" <<  *c << endl;
        // push
        if(*size < a_size){
                //cout << "size:" <<  *size<< endl;
                a[*head + *size] = *c;
                *sum += *c;
                *size = *size + 1;
        }
        else{
                //cout << "remove:" <<  a[*head] << endl;
                *sum -= a[*head];
                a[*head] = *c;
                *sum += *c;
                *head = (*head + 1 ) % a_size;
        }
        if(*p){
                if(*max < *sum){
                        //cout << "update: " << *sum << endl;
                        *max = *sum;
                }
        }
        *p = !(*p);
        *c = 1;
}

int main(){
        int n,k;
        int* a;
        cin >> n >> k;
        int a_size = 2 * k + 1;
        a = new int[a_size];
        int head = 0, size =0;
        long sum = 0;
        long max = 0;

        char s;
        long c = 0;int p = 1;
        for(int i=0;i<n;i++){
                cin >> s;
                s -= '0';
                if(s == p){
                        c++;
                }
                else{
                        update(&c, &p, a, &head, &size, a_size, &sum, &max);
                }
        }

        // push
        if(c > 0){
                update(&c, &p, a, &head, &size, a_size, &sum, &max);

                if(p)
                {
                        c = 0;
                        update(&c, &p, a, &head, &size, a_size, &sum, &max);
                }
        }
        else if(p){
                        c = 0;
                        update(&c, &p, a, &head, &size, a_size, &sum, &max);
        }

        //cout << endl;
        cout << max << endl;
}

Measured memory_bytes: 512
from itertools import product

s = input()

ans = 0
for l in product([0, 1], repeat=len(s) - 1):
    num = s[0]
    for i, bit in enumerate(l):
        if bit == 0:
            num = ''.join([num, s[i + 1]])
        elif bit == 1:
            ans += int(num)
            num = s[i + 1]
    ans += int(num)
print(ans)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int A,B;
  cin >> A >> B;
  if(A+B >= 24){
    cout << A+B-24 << endl;
  }
  else{
    cout << A+B << endl;
  }
}

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

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

Measured memory_bytes: 3624
n = gets.chomp.to_i
S = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.to_i
T = gets.chomp.split(" ").map(&:to_i)
#sortS = S.sort{|a, b| a <=> b}

count = 0

T.each do |t|
  left = 0
  # rightはn-1ではなくnにしてる
  right = n
  loop do 
    middle = (right+left) / 2
    break if left == right
    if t == S[middle]
      count += 1
      break
    elsif S[middle] < t
      left = middle + 1
    else t < S[middle]
      #初期値のleft、right間の幅の定義と合わせるために、ここでは-1をしない
      right = middle 
    end
  end
end

puts count



Measured memory_bytes: 17616
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define INF (1LL<<59)
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif 
   /********************* Code starts here ***********************/   
   int n,l,s=0;
   cin>>n>>l;
   vector<int>a(n);
   for(int i=0;i<n;i++)
   {
   	a[i]=l+i;
   	s=s+a[i];
   }
   int ans=inf;
   for(int i=0;i<n;i++)
   {
   	ans=min(ans,abs(s-a[i]-s));
   }
   for(int i=0;i<n;i++)
   {
   	if(abs(s-a[i]-s)==ans)
   	{
   		cout<<s-a[i]<<endl;
   		return 0;
   	}
   }
}	

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(auto& x: A) cin >> x;
    sort(A.begin(), A.end());

    ll left = (ll)-1e18 - 1, right = 1e18;
    while(right - left > 1){
        ll m = (left + right) / 2;
        ll k = 0;
        for(int i=0; i<N; i++){
            if(A[i] > 0){
                ll b = (m >= 0) ? m/A[i] : (m+1)/A[i]-1;
                auto itr = upper_bound(A.begin(), A.end(), b);
                k += distance(A.begin(), itr);
                if(A[i] <= b) k--;
            }
            else if(A[i] < 0){
                ll b = (m >= 0) ? m/A[i] : (m+1)/A[i]+1;
                auto itr = lower_bound(A.begin(), A.end(), b);
                k += distance(itr, A.end());
                if(A[i] >= b) k--;
            }
            else if(m >= 0){
                k += N-1;
            }
        }
        k /= 2;
        // cout << m << " " << k << endl;
        if(k < K) left = m;
        else right = m;
    }

    cout << right << endl;

#ifdef DEBUG
    vector<ll> d(N*(N-1)/2);
    int k = 0;
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            d[k] = A[i]*A[j]; k++;
        }
    }
    sort(d.begin(), d.end());
    if(right == d[K-1]) cout << "AC\n";
    else{
        cout << "WA\n";
        cout << N << " " << K << endl;
        debug(A);
    }
    // debug(d);
#endif
}

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

void Main() {
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i, n) {
        if (ans * 2 < ans + k) {
            ans *= 2;
        } else {
            ans += k;
        }
    }
    cout << ans << endl;
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x,ans=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(i*500+j*100+k*50==x)ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int H, W, N; cin >> H >> W >> N;
    int sr, sc; cin >> sr >> sc;
    string S, T; cin >> S >> T;

    bool isSave = true;

    // 右に押し出す
    int x = sc;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'R') x++;
        if (W < x) isSave = false;
        if (T[i] == 'L' && 1 < x) x--;
    }
    if (W < x) isSave = false;

    // 左に押し出す
    x = sc;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'L') x--;
        if (x < 1) isSave = false;
        if (T[i] == 'R' && x < W) x++;
    }
    if (x < 1) isSave = false;
    
    // 上に押し出す
    int y = sr;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'U') y--;
        if (y < 1) isSave = false;
        if (T[i] == 'D' && y < H) y++;
    }
    if (y < 1) isSave = false;

    // 下に押し出す
    y = sr;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'D') y++;
        if (H < y) isSave = false;
        if (T[i] == 'U' && 1 < y) y--;
    }
    if (H < y) isSave = false;

    cout << (isSave ? "YES" : "NO") << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    int count = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3916
/*
				   _ooOoo_
				  o8888888o
				  88" . "88
				  (| -_- |)
				  O\  =  /O
			   ____/`---'\____
			 .'  \\|     |//  `.
			/  \\|||  :  |||//  \
		   /  _||||| -:- |||||-  \
		   |   | \\\  -  /// |   |
		   | \_|  ''\---/''  |   |
		   \  .-\__  `-`  ___/-. /
		 ___`. .'  /--.--\  `. . __
	  ."" '<  `.___\_<|>_/___.'  >'"".
	 | | :  `- \`.;`\ _ /`;.`/ - ` : | |
	 \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
				   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		fozubaoyou    pass System Test!
		quoted from "https://codeforces.com/contest/472/submission/7996840"
*/
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
#define PI acos(-1)
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void){

	int n;
	cin>>n;
	vi a(n);
	int ud=0;
	rep(i,n)cin>>a[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		int j=0;
		int ud=0;
		int ct=1;
		while(i+j<n){
			// cout<<a[i+j]<<" "<<a[i-1+j]<<endl;
			if(a[i+j]-a[i-1+j]>0){//増加
				if(ud==1||ud==0){
					//増加
					ct++;
					ud=1;
				} else {
					//現象
					break;
				}
			} else if(a[i+j]==a[i-1+j]){
				ct++;
			} else {
				if(ud==2||ud==0){
					ud=2;
					ct++;
				} else {
					break;
				}
			}
			j++;
		}
		i+=max(0,ct-1);
		ans++;
		// cout<<"-----"<<ct<<" "<<i<<endl;
	}
	fin(ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

int main(int argc, char *argv[]){
    std::string S;
    std::cin >> S;
    for(int i=1; i<4; ++i){
        if(S[i-1]==S[i]){
            std::cout << "Bad" << std::endl;
            return 0;
        }
    }
    std::cout << "Good" << std::endl;
    return 0;
}


Measured memory_bytes: 256
x,y=map(int, input().split())
import math
ans=0

def conbi(n,r,mod):
    ue=1
    for i in range(n-r+1,n+1):
        ue*=i
        ue%=mod
 
    sita=1
 
    for i in range(1,r+1):
        sita*=i
        sita%=mod
 
    sita=pow(sita,mod-2,mod)
 
    return (ue*sita)%mod

for a in range(x+1):
    b=(x-a)/2
    if b-int(b)==0:
        b=int(b)
        if y==2*a+b:
            ans+=conbi(a+b,a,10**9+7)

print(ans)

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

    int n;
    cin>>n;
    vector <int> s(n);
    rep(i,n)
    {
        cin>>s[i];
    }

    int q;
    cin>>q;
    vector <int> t(q);
    rep(i,q)
    {
        cin>>t[i];
    }

    for(int i=0;i<q;i++)
    {
        auto iter = lower_bound(s.begin(),s.end(),t[i]);

        if(iter!=s.end() && *iter==t[i])
        {
            count++;
        }
    }

    cout<<count<<endl;

    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

inline ll pow2(ll i) {
  return ((ull)1) << i;
}

signed main() {
  ll N;
  cin >> N;
  multiset<ll> can, born;

  rep(i, pow2(N)) {
    ll x;
    cin >> x;
    can.insert(x);
  }
  {
    auto it = end(can);
    it--;
    born.insert(*it);
    can.erase(it);
  }

  bool ok = true;
  while (!can.empty()) {
    auto next_born = born;
    for (auto it = rbegin(born); it != rend(born); it++) {
      ll x = *it;
      auto jt = can.lower_bound(x);
      if (jt == can.begin()) {
        ok = false;
        goto FIN;
      }
      jt--;
      next_born.insert(*jt);
      can.erase(jt);
    }
    born = next_born;
  }
FIN:
  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 24832
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int N,M,max1=0,all2=0;
	scanf("%d %d",&N,&M);
	int A[M]={0},B[M]={0};
	for(int i=0;i<M;i++){
		scanf("%d %d",&A[i],&B[i]);
		if(A[i]>=N){}
		else if(max1<N-A[i]){//今までの最大でかかるお金より多ければ
			all2+=max1;
			max1=(N-A[i]);
		}
		else{
			all2+=(N-A[i]);
		}
	}
	printf("%d\n",all2);
	return 0;
}
//25:02.130クリア


Measured memory_bytes: 3160
N=int(input())
B=[0 for i in range(N)]
sum_AB=[0 for i in range(N)]
for i in range(N):
    A,B[i]=map(int,input().split())
    sum_AB[i]=A+B[i]
sum_AB.sort(reverse=True)
sum_B=sum(B)
sum_takahashi=-sum_B
i=0
while i<N:
    if i%2==0:
        sum_takahashi+=sum_AB[i]
    i+=1
print(sum_takahashi)


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

#define y1 dmytxdy
#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

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

const int cys=1000000007;
int n,m,k,tot;
int x[100005],y[100005],p[100005];
ll c[100005];
pii a[100005];

ll mod(ll x){return x>=cys?x-cys:x;}
void add(int x,ll g){for(;x<=tot+1;x+=(x&(-x))) c[x]=mod(c[x]+g);}
ll ask(int x){ll ret=0; for(;x;x-=(x&(-x))) ret=mod(ret+c[x]); return ret;}

int main(){
	n=readint(); m=readint();
	for(int i=1;i<=n;i++) x[i]=readint();
	for(int i=1;i<=m;i++) y[i]=readint();
	for(int i=1;i<=n;i++){
		int tmp=lower_bound(y+1,y+m+1,x[i])-y;
		if(tmp>1&&tmp<m+1) a[++k].fi=y[tmp-1]-x[i],a[k].se=y[tmp]-x[i];
	}
	sort(a+1,a+k+1);
	k=unique(a+1,a+k+1)-a-1;
	for(int i=1;i<=k;i++) p[++tot]=a[i].se;
	sort(p+1,p+tot+1);
	tot=unique(p+1,p+tot+1)-p-1;
	for(int i=1;i<=k;i++) a[i].se=lower_bound(p+1,p+tot+1,a[i].se)-p;
	int lst=1;
	add(tot+1,1);
	a[k+1].fi=0;
	for(int i=1;i<=k;i++){
		if(a[i].fi!=a[i+1].fi){
			for(int j=lst;j<=i;j++) add(a[j].se,mod(cys+ask(tot+1)-ask(a[j].se)));
			lst=i+1;
		}
	}
	printf("%lld\n",ask(tot+1));
	return 0;
}

Measured memory_bytes: 6016
#import <stdio.h>
#import <stdlib.h>

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main(int argc, const char * argv[]) {
    int N;
    scanf("%d", &N);
    int *numbers = (int*)malloc(N * sizeof(int));
    
    int n;
    int i = 0;
    while (scanf("%d", &n) != EOF) {
        numbers[i] = n;
        i++;
    }
    
    qsort(numbers, N, sizeof(int), compare_int);
    
    printf("%d", numbers[N-1]-numbers[0]);
    
    free(numbers);
    return 0;
}


Measured memory_bytes: 2164
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b,x,i;
	scanf("%lld %lld",&a,&b);
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	for(i=a;i<=10000000000;i=i+a){
		if(i%b==0)	break;
	}
	printf("%lld",i);
	return 0;
}


Measured memory_bytes: 1720
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
int MAXN = 1e5;
using namespace std;
int main()
{
	int  x , y , z;
	int n=1;
	while(scanf("%d %d %d",&x,&y,&z) != EOF)
	{
		//getchar();
		if ( ( x < 1 ) ||  ( z > MAXN )  ||  ( y + 2*z > x ) )	continue;
		while(   ( x - n*y - ( n + 1 )*z )  >=  0    )
		{
			n = n + 1;
		}
		printf("%d\n", n - 1 );
		n = 1;
	}
}

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

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

    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    for (int i = 1; i <= N; i++) cin >> A[i];
    int total = 0;
    for (int i = 1; i < A.size(); i++) total += abs(A[i] - A[i - 1]);
    for (int i = 1; i < A.size() - 1; i++) {
        int ans = total;
        if (!((A[i - 1] <= A[i] && A[i] <= A[i + 1]) || (A[i - 1] >= A[i] && A[i] >= A[i - 1]))) {
            ans += abs(A[i + 1] - A[i - 1]) - (abs(A[i + 1] - A[i]) + abs(A[i] - A[i - 1]));
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1664
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if (B/A > C) {
			System.out.println(C);
		} else {
			System.out.println(B/A);
		}
	}
}

Measured memory_bytes: 23124
#include <cstdio>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

int main(void) {
  int n, d;
  cin >> n >> d;
  int x = 2*d+1;
  int res = (n+x-1) / x;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1016
var
    n,i:longint;
    ans:int64;
    a:array[0..200010] of longint;
procedure qsort(l,r:longint);
var
    i,j,mid,t:longint;
begin
    i:=l;j:=r;mid:=a[(i+j) div 2];
    repeat
        while a[i]<mid do inc(i);
        while a[j]>mid do dec(j);
        if i<=j then 
            begin
                t:=a[i];a[i]:=a[j];a[j]:=t;
                inc(i);dec(j);
            end;
    until i>j;
    if l<j then qsort(l,j);
    if i<r then qsort(i,r);
end;
begin
    readln(n);
    for i:=1 to n do
        begin
            read(a[i]);
            a[i]:=a[i]-i;
        end;
    qsort(1,n);
    for i:=1 to n do
        ans:=ans+abs(a[i]-a[n div 2+1]);
    writeln(ans);
end. 

Measured memory_bytes: 896
n,k = gets.split.map(&:to_i)
w = []
(n).times do |i|
  w[i] = gets.to_i
end
m = w.max
ans = (m..n*m).bsearch{|i|
  count = 1
  rest = i
  for wi in w do
    if rest >= wi
      rest -= wi
    else
      count += 1
      rest = i-wi
    end
  end
  k >= count
}
printf("%d\n",ans)


Measured memory_bytes: 7796
import bisect
s = input()
children = [0 for i in range(len(s))]
pool = []
for i in range(1, len(s)):
    if s[i-1] == 'R' and s[i] == 'L':
        pool.append(i-1)
for i in range(len(s)):
    idx = bisect.bisect_left(pool, i)
    if s[i] == 'R':
        if (pool[idx] - i) % 2 == 0:
            children[pool[idx]] += 1
        else:
            children[pool[idx]+1] += 1
    else:
        if (pool[idx-1] - i) % 2 == 0:
            children[pool[idx-1]] += 1
        else:
            children[pool[idx-1]+1] += 1
print(*children)

Measured memory_bytes: 8264
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let q: usize = input();
    let lr: Vec<(usize, usize)> = (0..q)
        .map(|_| {
            let l = input();
            let r = input();
            (l, r)
        })
        .collect();

    let mut v = vec![];
    for i in 2..100001 {
        if i % 2 == 0 {
            continue;
        }
        if is_prime(i) && is_prime((i + 1) / 2) {
            v.push(i);
        }
    }

    let mut sum = vec![0i64; 100001];
    for i in 1..100001 {
        sum[i] = sum[i - 1];
        if v.contains(&i) {
            sum[i] += 1;
        }
    }

    for i in 0..q {
        println!("{}", sum[lr[i].1] - sum[lr[i].0 - 1]);
    }
}

fn is_prime(x: usize) -> bool {
    let mut ok = true;
    for i in 2..x {
        if i * i > x {
            break;
        }
        if x % i == 0 {
            ok = false;
            break;
        }
    }
    ok
}


Measured memory_bytes: 6780
n = int(input())
s = input()
cnt = 0
dep = 10**10
for c in s:
    if c == '(':
        cnt += 1
    else:
        cnt -= 1
    dep = min(dep, cnt)
s = '(' * max(0, -dep) + s
cnt = 0
for c in s:
    if c == '(':
        cnt += 1
    else:
        cnt -= 1
s = s + ')' * cnt
print(s)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
	int n; cin >> n;
	int x; cin >> x;
	vector<int> l(n);
	for (int i = 0; i < n; ++i) {
		cin >> l[i];
	}
	int d = 0;
	int ans = 1;
	for (int i = 1; i <= n; ++i) {
		d = d + l[i - 1];	
		if (d <= x) ans++;
	}
	cout << ans << endl;
    return;
}

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



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>ve(1e5+1,0),vo(1e5+1,0);
	for(int i=0;i<n;++i){
		int v; cin>>v;
		if(i&1)++vo.at(v);
		else ++ve.at(v);
	}
	int me=max_element(ve.begin(),ve.end())-ve.begin();
	int mo=max_element(vo.begin(),vo.end())-vo.begin();
	sort(ve.rbegin(),ve.rend()); sort(vo.rbegin(),vo.rend());
	int mx;
	if(me==mo){
		mx=max(ve.front()+*(vo.begin()+1),vo.front()+*(ve.begin()+1));
	}
	else{
		mx=ve.front()+vo.front();
	}
	cout<<n-mx<<"\n"s;
}

Measured memory_bytes: 3996
using System;
class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int k = int.Parse(Console.ReadLine());
        int num = 1;
        for (int i = 0; i < n; i++)
        {
            if (num >= k)
                num += k;
            else
                num *= 2;
        }
        Console.WriteLine(num);
    }
}

Measured memory_bytes: 13140
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,ans=00;
  bool can=true;
  cin >> n;
  vector<ll> a(n+1),imo(n+2,0);
  ll x = 1;
  for(int i=0;i<=n;i++){
    cin >> a[i];
    if(i>=1){
      if(a[i]>x){
        can = false;
      }
    }
    if(x<1e9){
      x *= 2;
    }else{
      x = 1e9;
    }
    imo[1] += a[i];
    imo[i+1] -= a[i];
  }
  if(n==0){
    if(a[0]==1){
      cout << 1 << endl;
    }else{
      cout << "-1\n";
    }
    return 0;
  }
  if(a[0]!=0){
    can = false;
  }
  if(!can){
    cout << -1 << endl;
    return 0;
  }
  ans = 1;
  for(int i=1;i<=n;i++){
    imo[i] += imo[i-1];
  }
  x = 1;
  for(int i=1;i<=n;i++){
    ll use = min(x*2,imo[i]);
    ans += use;
    x = use - a[i];
    if(x<0){
      cout  << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4720
N, K, Q = map(int, input().split())
point = [ 0 for i in range(0, N)]

for i in range(0, Q):
    a = int(input())
    point[a-1] = point[a-1] + 1

for j in range(0, N):
    if K + point[j] > Q:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4672
row1 = input().split()
row2 = input().split()
row3 = input().split()

n = int(input())
nums = [input() for i in range(n)]

rows = [row1, row2, row3]

for i in range(0, 3):
    rows += [[row1[i], row2[i], row3[i]]]

rows += [[row1[0], row2[1], row3[2]]]
rows += [[row1[2], row2[1], row3[0]]]

for row in rows:
    j = 0
    for num in nums:
        if num in row:
            j += 1
        if j == 3:
            print('Yes')
            exit()

print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
const double PI = acos(-1);

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

//素因数分解
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
//const auto &pf = prime_factorize(i);
//for (auto p : pf) cout << p.first << " " << p.second;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main()
{
    int a, b; cin >> a >> b;
    cout << a + b/2 << endl;

    return 0;
}


Measured memory_bytes: 3616
def gcd(m, n)
    if m < n 
        gcd(n, m)
    elsif n == 0
        m   
    else
        gcd(n, m % n)
    end 
end

loop do
    ns = gets.split.map(&:to_i)
    break if ns[0] == 0
    ks = ns.each_slice(2).map do |a, m|
        x = a 
        k = 1 
        until x == 1    
            k += 1
            x = x * a % m 
        end 
        k   
    end 
    p ks.inject(1){|lcm, x| x * lcm / gcd(x, lcm)}
end

Measured memory_bytes: 8724
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;

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

struct edge{int to, cost;};

int main(){
    int const INF = 1000000100;
    int n, m;
    cin >> n >> m;
    int l[m], r[m], d[m];
    vector<edge> G[n];
    rep(i, m){
        cin >> l[i] >> r[i] >> d[i];
        l[i]--; r[i]--;
        edge g;
        g.to = r[i];
        g.cost = d[i];
        G[l[i]].push_back(g);
        g.to = l[i];
        g.cost = -d[i];
        G[r[i]].push_back(g);
    }
    int x[n];
    rep(i, n) x[i] = INF;
    rep(i, n){
        if (x[i] != INF){
            continue;
        }
        x[i] = 0;
        queue<P> q;
        q.push(P(i, 0));
        while(q.size() > 0){
            P p = q.front();
            q.pop();
            int dis = p.second;
            int e = p.first;
            rep(j, G[e].size()){
                if (x[G[e][j].to] == INF){
                    x[G[e][j].to] = dis + G[e][j].cost;
                    q.push(P(G[e][j].to, x[G[e][j].to]));
                }
            }
        }
    }
    // rep(i, n) cout << x[i] << " ";
    // cout << endl;
    rep(i, m){
        if (x[r[i]]- x[l[i]] != d[i]){
            cout << "No" << endl;
            return 0;
        }
        
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  int cur = 0;
  rep(i, n) {
    int a;
    cin >> a;
    if(cur+1 == a) cur++;
  }
  if(cur==0) cout << -1 << "\n";
  else cout << n - cur << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 256
M,D = map(int,input().split())
ans = 0
for m in range(4,M+1):
    for i in range(1,D+1):
        d = str(i).zfill(2)
        if int(d[0])<2 or int(d[1])<2:
            continue
        n = int(d[0])*int(d[1])
        if n == m:
            ans += 1
print(ans)


Measured memory_bytes: 40560
# = int(input()
import math
a, b, x = map(int, input().split())
x = x/a

if x <= (a*b) / 2:
    theta = math.atan(b**2 / (2*x))
else:
    theta = math.atan(2*(a*b-x)/(a**2) )
print(math.degrees(theta))


Measured memory_bytes: 3060
h, w = map(int, input().split())
grid = [input() for _ in range(h)]

ans = 0

for i in range(h):
    for j in range(w):
        if grid[i][j] == ".":
            q = [(i, j)]
            dist = [[-1]*w for _ in range(h)]
            dist[i][j] = 0
            while q:
                x, y = q.pop(0)
                for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    nx, ny = x+dx, y+dy
                    if not (nx in range(h) and ny in range(w)):
                        continue
                    if grid[nx][ny] == "#":
                        continue
                    if dist[nx][ny] == -1:
                        dist[nx][ny] = dist[x][y] + 1
                        q.append((nx, ny))
            ans = max(ans, max([max([j for j in i]) for i in dist]))

print(ans)

Measured memory_bytes: 3188