akhauriyash/Code-Regression huggingface dataset:
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define limit 1000000000000000000 //1e18
#define mod 1000000007 //1e9+7
#define llu long long unsigned
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<b; i++)
#define repV(i,n)    for(ll i=0; i<v.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;
ll gcd(ll  a, ll b)
{
    if (a%b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a%b));
    }
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    godspeed
    ll  i,j,n,m,k;
    string s,t;
    cin >> n >> m;
    cin >> s >> t;
    bool ans=true;

    for(i=0; i<gcd(n,m); i++)
    {
        if(s.at(n*i/gcd(n,m))!=t.at(m*i/gcd(n,m)))
        {
            ans=false;
            break;
        }

    }
    if(ans)
        cout << lcm(n,m) << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3748
N = int(input())
*B, = map(int, input().split())
MAX = 10**10
A = [MAX] * N
A[0] = B[0]
for i, b in enumerate(B):
    if A[i] > b: A[i] = b
    if A[i+1] > b: A[i+1] = b
print(sum(A))

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

ans = 0
for i in range(1, N+1):
    if i >= K:
        ans += 1/N
    else:
        k = ((K-1)//i) + 1
        count = 0
        while(k/2**count > 1):
            count += 1

        ans += (1/N) * (1/2)**count
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		int n = scan.nextInt();
		while(n != 0){
			int a[][] = new int[n+1][n+1];
			for(int i = 0 ; i < n ; i++){
				for(int j = 0 ; j < n ; j++){
					a[i][j] = scan.nextInt();
					a[i][n] += a[i][j];
				}
			}
			for(int j = 0 ; j < n ; j++){
				for(int i = 0 ; i < n ; i++){
					a[n][j] += a[i][j];
				}
			}
			for(int i = 0; i < n+1 ; i++){
				for(int j = 0 ; j < n+1 ; j++){
					int keta = Integer.toString(a[i][j]).length();
					for(int k = 0 ; k < 5-keta ; k++){
						System.out.print(" ");
					}
					System.out.print(a[i][j]);
				}
				System.out.println();
				a[n][n] += a[i][n];
			}
			n = scan.nextInt();
		}
	}
}

Measured memory_bytes: 30520
x=[i for i in input()]
y=[i for i in range(len(x))]
y=x.copy()
n=int(input())
for i in range(n):
    c=[j for j in input().split()]
    if len(c)==4:
        for j in range(len(c[3])):
            y[j+int(c[1])]=list(c[3])[j]
        x=y.copy()
    elif c[0]=="print":
        for j in range(int(c[1]),int(c[2])+1):
            print(x[j],end="")
        print()
    else:
        for j in range(int(c[2])+1-int(c[1])):
            z=[i for i in range(len(x))]
            z=x.copy()
            y[int(c[2])-j]=z[int(c[1])+j]
        x=y.copy()
            
        

Measured memory_bytes: 7828
#include <bits/stdc++.h>
using namespace std;
 
 
int main(void){
  int N;
  cin >> N;
  int max = 0;
  map<string, int> map;
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    map[s] += 1;
    if(max < map[s]) max = map[s];
  }
  auto begin = map.begin(), end = map.end();
  for (auto iter = begin; iter != end; iter++) {
    // first: key, second: value
    if(iter->second == max){
      cout << iter->first << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 25216
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    string S; cin >> S;
    string ans = "NO";
    if(S =="keyence"){
        ans = "YES";
    } else {
        for(int i = 0; i < 7; i++){
            if(S.substr(0, i) + S.substr(S.size()+i-7, 7-i) == "keyence"){
                ans = "YES";
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long N,A[100005],x;
int main()
{
	int i;
	
	scanf("%lld",&N);
	
	for(i=1;i<=N;i++)scanf("%lld",&A[i]);
	sort(A+1,A+N+1);
	for(i=N-1;i>0;i--)
	{
		if(A[i]==A[i+1])
		{
			if(!x)x=A[i],i--;
			else return printf("%lld",x*A[i]),0;
		}
	}
	puts("0");
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main(){
	int a,b,c; cin>>a>>b>>c;
	int k; cin >> k;
	int t = 0;
	while(b <= a){
		b *= 2;
		t++;
	}
	while(c <= b){
		c *= 2;
		t++;
	}
	cout << (t<=k ? "Yes": "No") << endl;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
)

func main(){
	var s, p string
	var is_end bool
	fmt.Scan(&s)
	fmt.Scan(&p)
	len_s := len([]rune(s))

	for start:=0; start<len_s; start++{
		is_end = true
		i := start
		for _, v := range p{
			if i == len_s {
				i = 0
			}
			if rune(s[i]) != v{
				is_end = false
				break
			}
			i++
		}
		if is_end {
			break
		}
	}
	if is_end {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 1172
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int num=0;
        for(int i=0;i<N;i++) {
            int n = sc.nextInt();
            if(n!=i+1) num++;
        }
        if(num<=2) System.out.println("YES");
        else System.out.println("NO");
    }
}


Measured memory_bytes: 21716
import numpy as np


n, capacity = map(int, input().split())
dp = np.zeros(capacity + 1, dtype=np.int64)
for _ in range(n):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print(dp[-1])

Measured memory_bytes: 14584
# coding: utf-8
# Your code here!

class BIT: #0-indexed
    def __init__(self, n):
        self.tree = [0]*(n+1)
        self.tree[0] = None
#        self.element = [0]*(n+1)
    def sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def range(self,l,r): #a_l + ... + a_r 閉区間
        return sum(r) - sum(l-1) 
    def add(self, i, x):
        i += 1
        while i <= n:
            self.tree[i] += x
            i += i & -i
        # self.element[i] += x
    #def get(self,i): return element[i]        
     
###########################################
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
 
#n = int(input())
n,k = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]
 
sA = sorted(a)
# def zaatu(x): return bisect_left(sA, x) #xの圧縮先
# def modosu(i): return sA[i]  # 逆写像
 
b = BIT(n)
 
from bisect import *
res = [0]*n
for i,ai in enumerate(a):
    j = bisect_left(sA, ai)
    res[i] = i - b.sum(j)
    b.add(j,1)
 
#print(res)

MOD = 10**9 + 7
ans = 0
for i,ai in enumerate(a):
    ans += k*res[i]
    ans %= MOD
    j = bisect_left(sA, ai)
    ans += (k*(k-1)//2%MOD)*(n - b.sum(j))
    ans %= MOD
    

print(ans)













Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int k,t;cin >> k >> t;
	
	int sum = 0;
	int ma = 0;
	
	REP(i,t)
	{
		int tmp;cin >> tmp;sum += tmp;ma = max(ma,tmp);
	}
	
	if(t == 1)
	{
		cout << sum-1 << endl;
		return 0;
	}
	
	ll tmp = sum - ma+1;
	//cout << ma << ' ' << tmp << endl;
	cout << max(0LL,ma-tmp) << endl;
	return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a=-1001,b;
  while(a<-1000 || 1000 < 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: 580
from collections import deque
H, W = map(int, input().split())

gridgraph = [list(input()) for _ in range(H)]
q = deque()
visited = [[False]*W for _ in range(H)]
ans = [[1e+9]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if gridgraph[i][j] == "#":
            q.append((i, j))
            visited[i][j] = True
            ans[i][j] = 0
            
while len(q):
    cy, cx = q.popleft()
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        if not (cy+dy >= 0 and H-1 >= cy+dy and cx+dx >= 0 and W-1 >= cx+dx):
            continue
        if visited[cy+dy][cx+dx]:
            continue
        visited[cy+dy][cx+dx] = True
        ans[cy+dy][cx+dx] = min(ans[cy+dy][cx+dx], ans[cy][cx]+1)
        q.append((cy+dy, cx+dx))

min_value = 0
for a in ans:
    min_value = max(min_value, max(a))
print(min_value)


Measured memory_bytes: 139484
import bisect
N = int(input())
seq = [-int(input()) for i in range(N)] 
LIS = [seq[0]]
for i in range(1,len(seq)):
    if seq[i] >= LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
print(len(LIS))

Measured memory_bytes: 57816
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct{
	int num[6];
}saikoro;



saikoro *s;
int all_num[64][6];

void n(){
	int tmp;
	tmp=s[0].num[4];
	s[0].num[4]=s[0].num[0];
	s[0].num[0]=s[0].num[1];
	s[0].num[1]=s[0].num[5];
	s[0].num[5]=tmp;
}
/*
void s(saikoro *a){
	int tmp;
	tmp=a->num[1];
	a->num[1]=a->num[0];
	a->num[0]=a->num[4];
	a->num[4]=a->num[5];
	a->num[5]=tmp;
}
*/
void e(){
	int tmp;
	tmp=s[0].num[2];
	s[0].num[2]=s[0].num[0];
	s[0].num[0]=s[0].num[3];
	s[0].num[3]=s[0].num[5];
	s[0].num[5]=tmp;
}
/*
void w(saikoro *a){
	int tmp;
	tmp=a->num[3];
	a->num[3]=a->num[0];
	a->num[0]=a->num[2];
	a->num[2]=a->num[5];
	a->num[5]=tmp;
}
*/
void rota(){
	int tmp;
	tmp=s[0].num[1];
	s[0].num[1]=s[0].num[2];
	s[0].num[2]=s[0].num[4];
	s[0].num[4]=s[0].num[3];
	s[0].num[3]=tmp;
	
}

int check(int num,int s_num){
	int i,all=0;
	for(i=0;i<6;i++){
		if(all_num[num][i]==s[s_num].num[i]){
			all++;
		}
	}
	return all;
}

int main(){
	int i,j,k,l,s_num,f_c=0;
	char input[128];
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d",&s_num);
	
	s=malloc(sizeof(saikoro)*s_num);
	
	for(i=0;i<s_num;i++){
		fgets(input,sizeof input,stdin);
		sscanf(input,"%d %d %d %d %d %d",&s[i].num[0],&s[i].num[1]
			,&s[i].num[2],&s[i].num[3],&s[i].num[4],&s[i].num[5]);
		
	}
	
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				for(l=0;l<6;l++){
					all_num[i*16+j*4+k][l]=s[0].num[l];
				}
				rota();
			}
			e();
		}
		n();
	}
	
	for(i=1;i<s_num;i++){
		for(j=0;j<64;j++){
			if(check(j,i)==6){
				f_c=1;
				break;
			}
			
		}
		
	}
	
	
	if(f_c==1){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	
	return 0;
}

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

void solve(long long N, long long K, std::vector<long long> a) {
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll sum = 0;
    ll res = N;

    for (int i = 0; i < N; i++) {
      if (sum + a[i] < K) {
	  sum += a[i];
      } else {
	  res = min(res, N - i - 1);
      }
    }
    cout << res << endl;
}

int main() {

  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, K, std::move(a));
  return 0;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    S = [input() for _ in range(2)]
    d = []
    i = 0
    while i < N:
        if S[0][i] == S[1][i]:
            i += 1
            d.append(0)
        else:
            i += 2
            d.append(1)
    output = 6 if d[0] else 3
    for i in range(len(d)-1):
        if d[i+1] == 0 and d[i] == 0: output *= 2
        elif d[i+1] == 0 and d[i] == 1: continue
        elif d[i+1] == 1 and d[i] == 0: output *= 2
        else: output *= 3
        output %= MOD
    print(output)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B;
  int max=0;
  cin >> A >> B;
  int mul=A*B;
  int plus=A+B;
  int dis=A-B;
  if(mul<plus)
    max=plus;
  else
    max=mul;
  if(max<dis)
    max=dis;
  cout << max << endl;
}

  


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

int main() {
  string S;
  cin >> S;
  string T = "CODEFESTIVAL2016";
  int cnt = 0;
  for (int i=0; i<S.size(); i++) if (S[i] != T[i]) cnt++;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  
  int i, N, H, A, ATK=0;
  
  scanf("%d%d", &H, &N);
  
  for(i = 0; i < N; i++){
    scanf("%d", &A);
    ATK = ATK + A;
  }
    
  if(ATK >= H){
    printf("Yes");
  }
  else
  {
    printf("No");
  }
  
  return(0);
}

Measured memory_bytes: 128
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

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

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int size(int k)
  {
    return(-data[find(k)]);
  }

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

string op(int sign)
{
    return sign == 0 ? "+" : "-";
}

static const string MARCH("MARCH");

bool IsMarch(char c)
{
  for (auto i : MARCH)
  {
    if (i == c) return true;
  }
  return false;
}

char ItoC(int i)
{
  return MARCH[i];
}

int main()
{
    LL N, M;
    cin >> N >> M;
  	if (N == 1 && M == 1) { cout << 1 << endl; return 0; }
    if (N == 1 || M == 1)
    {
      if (M == 1) swap(N, M);
      cout << max((int)(M - 2), 0) << endl;
      return 0;
    }
    cout << (N - 2) * (M - 2) << endl;
    return 0;
}


Measured memory_bytes: 256
#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;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	int counts = 0;
	rep(i,n-2){
		if(p[i+1]>p[i] && p[i+1] < p[i+2]) counts++;
		if(p[i+1]<p[i] && p[i+1] > p[i+2]) counts++;
	}
	cout << counts << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3624
n = int(input())
a = list(map(int, input().split()))

cand = set(a)

exist = set()
dup = set()
for item in a:
    if item in exist:
        dup.add(item)
    else:
        exist.add(item)

dame_set = set()

a.sort()
ret = 0

for val in a:
    if val in dup:
        if val in dame_set:
            continue
        else:
            i = 1
            cnt = 10 ** 6 // val
            while i <= cnt:
                tmp = i * val
                if tmp in cand:
                    dame_set.add(tmp)
                i += 1
    else:
        if val in dame_set:
            continue
        else:
            ret += 1
            i = 1
            cnt = 10 ** 6 // val
            while i <= cnt:
                tmp = i * val
                if tmp in cand:
                    dame_set.add(tmp)
                i += 1

print(ret)


Measured memory_bytes: 144592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

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

    ll q;
    cin >> q;
    vector<ll> m(q);
    rep(i, q) cin >> m[i];

    bool b[4400000];

    rep(bit, 1<<n) {
        ll num = 0;
        rep(i, n) if(bit>>i&1) num += a[i];
        b[num] = true;
    }

    rep(i, q) {
        if(b[m[i]]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}



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

int main() {
  ll a,p,q,sum;
  sum = 0;
  
  cin >> a;
  
  for(ll i=1;i<=a;i++){
    for(ll j=1;j<=a;j++){
      for(ll k=1;k<=a;k++){
		p = __gcd(i,j);
		q = __gcd(p,k);            
		sum += q;
      }
    }
  }
  cout << sum <<endl;
  return 0;  
}




Measured memory_bytes: 3592
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Mon Dec 24 16:07:06 2018
//
package main

import (
	"fmt"
	"sort"
)

type bridge struct {
	from, to int
}

type bridges []bridge

func (b bridges) Len() int {
	return len(b)
}

func (b bridges) Less(i, j int) bool {
	return b[i].to < b[j].to
}

func (b bridges) Swap(i, j int) {
	b[i], b[j] = b[j], b[i]
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	bs := make(bridges, M)
	for i := range bs {
		fmt.Scan(&bs[i].from, &bs[i].to)
	}
	sort.Sort(bs)

	last := 0
	ans := 0
	for _, b := range bs {
		if last < b.from {
			last = b.to - 1
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();

		while(! primeJudg(x)) {
			x++;
		}
		System.out.print(x);
	}

	//素数を判断するメソッド
	public static boolean primeJudg(int a){
		for(int i=2 ; i<a ; i++) {
			if(a%i == 0) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 27112
s = input()
t = input()


idx = -1
count = 0
if set(t) <= set(s):
    for i in t:
        idx = s.find(i,idx + 1)
        if idx == -1:
            idx = s.find(i)
            count += 1
        rep = count * len(s)
    print(idx+1+rep)
else:
    print(-1)

Measured memory_bytes: 3316
n, m = map(int ,input().split())

adj = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a-=1
    b-=1
    adj[a].append(b)
    adj[b].append(a)

from collections import deque
q = deque()

dist = [False] * n
ans = [0] * n

q.append(0)
while len(q) != 0:
    now = q.popleft()
    for to in adj[now]:
        if dist[to] == True:continue
        dist[to] = True
        q.append(to)
        ans[to] = now

print("Yes")
for i in range(1, n):
    print(ans[i] + 1)

Measured memory_bytes: 96088
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	n := scanInt()
	a := scanInts(n)
	mul := big.NewInt(1)
	overflow := false
	limit := big.NewInt(1000000000000000000)
	for i := 0; i < n; i++ {
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
		a := big.NewInt(int64(a[i]))
		mul.Mul(mul, a)
		if limit.Cmp(mul) == -1 {
			overflow = true
			break
		}
	}
	if overflow {
		for i := 0; i < n; i++ {
			if a[i] == 0 {
				fmt.Println(0)
				return
			}
		}
	}
	answer := mul.Int64()
	if overflow {
		answer = -1
	}
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	fmt.Println(a...)
}


Measured memory_bytes: 5936
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);	
	int h, a;
	cin >> h >> a;
	cout << int((h+a-1)/a) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	int cnt=0;
	long long mi=INT_MAX,sum=0;
	while(n--){
		long long x;
		cin>>x;
		sum+=abs(x);
		if(x<0){
			cnt++;
		}
		x=abs(x);
		mi=min(mi,x);
	}
	if(cnt%2==1){
		sum-=(mi*2);
	}
		cout<<sum<<endl;
}

Measured memory_bytes: 384
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	int k = read.to!int;
	
	int ans = n - k + 1;
	
	ans.writeln;
	
	
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

template<int mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x(x%mod) {}
    mint(std::string s) {
        long long z = 0;
        REP(i, s.size()) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& n) {
        return os << n.x;
    }
    bool operator==(const mint a) const {
        return this->x == a.x;
    }
};

vector<vector<int>> tree;
vector<vector<mint<MOD>>> memo;
vector<vector<bool>> f;

// c : 0白 1黒
mint<MOD> dp(int v,int p, int c) {
    if (f[v][c]) return memo[v][c];
    mint<MOD> res = 1;
    if (c == 0) {
        for (auto u : tree[v]) {
            if (u == p) continue;
            res *= dp(u, v, 0) + dp(u, v, 1);
        }
    }
    else {
        for (auto u : tree[v]) {
            if (u == p) continue;
            res *= dp(u, v, 0);
        }
    }
    f[v][c] = true;
    return memo[v][c] = res;
}

int main() {
    int n; cin >> n;
    tree.resize(n);
    memo.resize(n, vector<mint<MOD>>(2));
    f.resize(n, vector<bool>(2, false));
    REP(i, n - 1) {
        int a, b; cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    cout << dp(0,-1,0) + dp(0,-1,1)<< endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;

    ll cnt[9][9] = {};
    REP(i, 9){
    	REP(j, 9){
    		ll x = i+1;
    		ll y = j+1;
    		ll res = 0;

    		ll digit = 10;
    		ll cum = 0;
    		REP(t, 8){
    			ll lb = digit*x + y;
    			ll ub = lb + (t==0 ? 0 : cum);
    			digit *= 10;
    			cum = 10*cum + 90;

    			if(ub<=N){
    				res += (ub/10-lb/10+1);
    			}else if(N<lb){
    				res += 0;
    			}else{
    				res += (N-lb)/10 + 1;
    			}
    		}
    		if(i==j && i+1<=N) res++;
    		cnt[i][j] = res;
    	}
    }
    /*
    REP(i, 9){
    	REP(j, 9){
    		cout << cnt[i][j] << " ";
    	}
    	cout << endl;
    }
    */

    ll ans = 0;
    REP(i, 9){
    	REP(j, 9){
    		if(i==j) ans += (cnt[i][j] * cnt[i][j]);
    		else ans += (cnt[i][j] * cnt[j][i]);
    	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N, M = nm()
P = nl()
assert len(P) == N
pairs = []
for i in range(M):
    x, y = nm()
    x -= 1
    y -= 1
    pairs.append((x, y))


def solve():
    uf = UnionFind(N)
    for (x, y) in pairs:
        uf.union(x, y)
    cnt = 0
    for i in range(N):
        if uf.same(P[i] - 1, i):
            cnt += 1
    return cnt


class UnionFind:
    def __init__(self, n):
        # total number of nodes.
        self.n = n
        # node id -> root node id
        self._root_table = list(range(n))
        # root node id -> group size
        self._size_table = [1] * n

    def find(self, x):
        """Returns x's root node id."""
        r = self._root_table[x]
        if r != x:
            # Update the cache on query.
            r = self._root_table[x] = self.find(r)
        return r

    def union(self, x, y):
        """Merges two groups."""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        # Ensure that x is the larger (or equal) group.
        if self._size_table[x] < self._size_table[y]:
            x, y = y, x

        self._size_table[x] += self._size_table[y]
        self._root_table[y] = x

    def size(self, x):
        return self._size_table[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self._root_table) if x == i]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 25276
N,M,x,y = map(int,input().split())
X = input().split()
Y = input().split()

for i in range(N):
 X[i] = int(X[i])
for i in range(M):
 Y[i] = int(Y[i])
X.sort()
Y.sort()

Z = Y[0]
if( (X[-1]<Z)and(x<Z)and(Z<=y)):
  print('No War')
else:
  print('War')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

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

int main()
{
  int H, W, i, j;
  
  while(1)
    {
      cin >> H >> W;
      if(H==0 && W==0)
	break;

      for(i=0; i<H; i++)
	{
	  for(j=0; j<W; j++)
	    {
	      cout << "#";
	    }
	  cout << endl;
	}
      cout << endl;
    }
  return 0;
}

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

#define int long long
#define w cout
#define e '\n'
#define sz(x) (int)x.size()
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.first >> p.second; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 + 10 , mod = 998244353;

signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for(int i = 0; i <= n - 3  ; i ++ ){
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			ans++;
		}
	}
	w << ans;
}


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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;



void solve() {
	int n;
	cin >> n;
	VI A(n);
	rep(i, n) {
		cin >> A[i];
	}

	sort(all(A));

	int tmp_r = 0;
	rep(i, n) {
		if (A[i] <= A[n - 1] / 2) {
			tmp_r = A[i];
		}
		else {
			if (A[n - 1] - A[i] > tmp_r) {
				tmp_r = A[i];
			}
			break;
		}
	}
	cout << A[n - 1] << " " << tmp_r << endl;
}


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

	solve(); 
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){

	int n,h[100000];
	int i;
	int cur;
	int best;


	scanf("%d",&n);


	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}

	best = 0;
	cur = 0;

	for(i=1;i<n;i++){
		if(h[i-1] >= h[i]){
			cur++;
		}else{
			if(cur > best){
				best = cur;
			}
			cur = 0;
		}
	}

	if(cur > best){
		best = cur;
	}

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






	return 0;
}

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

int main() {
  string s; cin >> s;
  
  bool able = true;
  if (s.size() % 2 == 1) able = false;
  {
    for (int i = 0; i < s.size(); i+=2) {
      if (s[i] != 'h' || s[i+1] != 'i') {
        able = false;
        break;
      }
    }
  }
  
  if (able) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, q;
  string s;
  cin >> n >> q >> s;
  int suml[n+1] = {};
  for(int i=1;i<n;i++){
    suml[i] = suml[i-1];
    if(s[i-1] == 'A' && s[i] == 'C'){
      suml[i]++;
    }
  }
  int l,r;
  for(int i=0;i<q;i++){
    cin >> l >> r;
    cout << suml[--r] - suml[--l] << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
constexpr ll INF = 1LL<<60;

int main() {
    string s;
    cin >> s;
    ll n = s.size();

    ll ans = 0;
    vector<ll> cnt(2019);
    REP(i, n) {
        vector<ll> ncnt(2019);
        REP(j, 2019) {
            ncnt[(j*10+(s[i]-'0'))%2019] += cnt[j];
            if((j*10+(s[i]-'0'))%2019 == 0) ans += cnt[j];
        }
        ncnt[s[i]-'0'] += 1;
        swap(cnt, ncnt);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() { 
    int n, k;
    int result = 0;
    cin >> n >> k;

    if (k == 1) { 
        cout << 0 << endl;
        return 0;
    }
    
    result = n - k;
    if(result > 0) {
        cout << result << endl;
        return 0;
    }

    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int main() {
    int n;
    long long a1, a2, sum = 0;
    cin >> n >> a1 >> a2;
    for (int i = 2; i < n; i++) {
        long long x;
        cin >> x;
        sum ^= x;
    }
    long long w = a1 + a2 - sum, ans = 0;
    if (w < 0 || w & 1 || ((w >>= 1) & sum) || w > a1) {
        cout << -1 << endl;
        return 0;
    }
    ans = w;
    for (int i = 63; i >= 0; i--)
        if (((1LL << i) & sum) && ans + (1LL << i) <= a1)
            ans += (1LL << i);
    if (!ans) {
        cout << -1 << endl;
        return 0;
    }
    cout << a1 - ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007


int main() {
	
	int N;
	string A,B,C;
	cin>>N;
	cin>>A>>B>>C;
	int ans=0;
	fx(N){
		if(A.at(x)==B.at(x)){
			if(A.at(x)==C.at(x)){
				
			}else{
				ans++;
			}
		}else if(A.at(x)==C.at(x)){
			ans++;
		}else if(B.at(x)==C.at(x)){
			ans++;
		}else{
			ans+=2;
		}
	}
	ce(ans)
}

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

bool isKaibun(string str) {
	
	string re = str;
	reverse(re.begin(), re.end());
	return re == str;
}

void Main() {
	string n, n_r, n1, n2;
	cin >> n;
	int N = n.length();

	if (isKaibun(n) && 
		isKaibun(n.substr(0, ((N - 1) / 2))) &&
		isKaibun(n.substr(((N + 3) / 2) - 1, N))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

int main() {
	Main();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i];
        b[i] = a[i];
    }

    sort(all(b));

    rep(i, n) {
        if (a[i] != b[n-1]) cout << b[n-1] << endl;
        else {
            int l = lower_bound(all(b), a[i]) - b.begin();
            int r = upper_bound(all(b), a[i]) - b.begin();
            if (r - l == 1) cout << b[n-2] << endl;
            else cout << a[i] << endl;
        }
    }
}

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

L=[-1 for i in range(N)]
R=[-1 for i in range(N)]

L[0]=min(A[0],B[0])
R[0]=min(A[1],B[0]-L[0])

for i in range(1,N):
    L[i]=min(A[i]-R[i-1],B[i])
    R[i]=min(A[i+1],B[i]-L[i])
    
print(sum(L)+sum(R))

Measured memory_bytes: 19120
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  
  vector<int> A(n);
  int x,num;
  rep(i,n){
    cin>>x;
    if(x==1) num=i;
    A[i]=x;
  }

  cout<<(n+k-3)/(k-1)<<endl;

  return 0;
}

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

int main() {
  int A, B, C, D;
  
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  bool first = true;
  int prob = 1;
  while(n--){
    if (first){
      prob*=k;
      first = false;
    }
    else prob*=(k-1);
  }
  cout << prob << endl;
return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N), B(N-1);

  for (int i = 0; i < N - 1; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    if (i == 0) {
      A.at(i) = A.at(i+1) = B.at(i);
    }
    else {
      if (A.at(i) >= B.at(i)) {
        A.at(i) = B.at(i);
        A.at(i+1) = B.at(i);
      }
      else {
        A.at(i+1) = B.at(i);
      }
    }
  }
  int sum = accumulate(A.begin(), A.end(), 0);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(a: i32, b: i32);
    puts!("{}\n", (b - 1 + a - 2) / (a - 1));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
haiku_list = ['5', '7', '5']

str_input_list = input().rstrip().split(' ')

for a in range(3):
    if haiku_list[a] in str_input_list:
        str_input_list.remove(haiku_list[a])
        haiku_list[a] = '*'

if haiku_list == ['*', '*', '*']:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
fn read_string() -> String {
    use std::io::Read;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    return buf;
}

static mut COMP_COUNT: u32 = 0;

fn main() {
    let input = read_string();
    let input = input.lines().collect::<Vec<_>>();
    let n: usize = input[0].parse().unwrap();
    let mut series = input[1].split_whitespace().map(|s| s.parse().unwrap()).collect::<Vec<u32>>();
    merge_sort(&mut series, 0, n);

    println!("{}", series.into_iter().map(|e| format!("{}", e)).collect::<Vec<String>>().join(" "));
    unsafe {
        println!("{}", COMP_COUNT);
    }
}

fn merge(series: &mut Vec<u32>, left: usize, mid: usize, right: usize) {
    let mut ls = series[left..mid].to_vec();
    ls.push(std::u32::MAX);
    let mut rs = series[mid..right].to_vec();
    rs.push(std::u32::MAX);

    let mut li = 0;
    let mut ri = 0;
    for i in left..right {
        unsafe {
            COMP_COUNT += 1;
        }
        if ls[li] >= rs[ri] {
            series[i] = rs[ri];
            ri += 1;
        } else {
            series[i] = ls[li];
            li += 1;
        }
    }
}

fn merge_sort(series: &mut Vec<u32>, left: usize, right: usize) {
    if left + 1 < right {
        let mid = (left + right) / 2;
        merge_sort(series, left, mid);
        merge_sort(series, mid, right);
        merge(series, left, mid, right);
    }
}


Measured memory_bytes: 37652
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), M = scanner.nextInt(), Q = scanner.nextInt();
        scanner.nextLine();
        int[][] cSum = new int[N + 1][N + 1];
        for (int i = 0; i < M; i++) {
            int[] p = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            cSum[p[0]][p[1]]++;
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                cSum[i][j] += cSum[i][j - 1];
            }
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                cSum[i][j] += cSum[i - 1][j];
            }
        }
        for (int i = 0; i < Q; i++) {
            int[] q = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            int ans = cSum[q[1]][q[1]] - cSum[q[1]][q[0] - 1] - cSum[q[0] - 1][q[1]] + cSum[q[0] - 1][q[0] - 1];
            System.out.println(ans);
        }
    }

}

Measured memory_bytes: 233944
function main()
  
  N = parse(Int, readline())
  A = parse(Int, readline())
  B = parse(Int, readline())
  C = parse(Int, readline())
  D = parse(Int, readline())
  E = parse(Int, readline())
  
  check = min(A, B, C, D, E)
  
  N = ceil(Int, N / check)
  
  println(N + 4)
  
end

main()

Measured memory_bytes: 111372
n = int(input())
a = list(map(int,input().split()))

M = max(a)

a = sorted(a)
a = [a[i] for i in range(n-1)]

b = 0
for i in range(n-1):
    if abs(a[i]-M/2) <= abs(b-M/2):
        b = a[i]

print('{} {}'.format(M,b))

Measured memory_bytes: 63980
import math
import copy
import sys
import bisect
input = sys.stdin.readline

def main():
    n,x = map(int,input().split()) 
    a = list(map(int,input().split()))
    ans=0
    for i in range(n-1):
        while a[i]+a[i+1]>x:
            if a[i+1]>0:
                if a[i]-x>0:
                    ans+=a[i+1]
                    a[i+1]=0
                else:
                    ans+=a[i+1]+a[i]-x
                    a[i+1]=x-a[i]
                    break
            else:
                ans+=a[i]-x
                a[i]=x
    print(ans)

if __name__ == "__main__":
    main()

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

int main() {

  int N;
  cin >> N;
  int r,l;
  int x=0;

  for(int i=0; i<N; i++ ){
    cin >> r >> l;
    x += l-r+1 ;
  }
  cout << x << endl;
}


Measured memory_bytes: 256