akhauriyash/Code-Regression huggingface dataset:
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int N, K;
string S;

void moveL(int &n){
  while(n != N - 1 && S[n] == '1') n++;
  while(n != N - 1 && S[n] == '0') n++;
}

void moveR(int &n){
  while(n < N && S[n] == '0') n++;
  if(S[n] == '0') n++;
  while(n < N && S[n] == '1') n++;
  if(S[n] == '1') n++;
}

int main(){
  cin >> N >> K;
  cin >> S;
  int ans = 0;
  int l = 0;
  int r = 0;

  if(S[0] == '1') moveR(r);
  rep(i, K) moveR(r);
  while(true){
    //printf("%d %d\n", l, r);
    ans = max(ans, r - l);
    if(r == N) break;
    moveL(l);
    moveR(r);
  }
  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

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

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

	int n, m;
	cin >> n >> m;

	map<pii, int> mp;
	rep(i, n){
		rep(j, n){
			mp[(pii){i, j}] = 0;
			mp[(pii){j, i}] = 0;
		}
	}

	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		mp[(pii){a, b}] = 1;
		mp[(pii){b, a}] = 1;
	}

	vector<int> v;
	rep(i, n) v.push_back(i);

	ll ans = 0;
	do{
		if(v[0] != 0) continue;

		bool ok = true;
		for(int i = 0; i < n-1; i++){
			if(!mp[(pii){v[i], v[i+1]}]){
				ok = false;
				break;
			}
		}
		if(ok) ans++;
	}while(next_permutation(v.begin(), v.end()));

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define lp(i, a, b) for (int i=a;i<=(int)b;++i)
#define lp2(i, a, b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define pr(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define clr(c, x) memset(c,x,sizeof(c));
template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int N = (int) 2e5 + 5;
const ll mod = 998244353;
vii v;
int n, m;
ll tot;
priority_queue<int, vi, greater<int> > pq;

int main() {
    FAST;
    cin >> n >> m;
    lp(i, 1, n) {
        int x;
        cin >> x;
        pq.push(x);
    }
    lp(i, 1, m) {
        int a, b;
        cin >> a >> b;
        v.pb({b, a});
    }
    sort(all(v));
    bool is = false;
    while (!pq.empty() && v.size() && !is) {
        while (!pq.empty() && v.back().S) {
            if (v.back().F < pq.top()) {
                is = true;
                break;
            }
            pq.pop();
            tot += v.back().F;
            v.back().S--;
        }
        if (!v.back().S)
            v.pop_back();
    }
    while (!pq.empty()) {
        tot += pq.top();
        pq.pop();
    }
    cout << tot << "\n";
    return 0;
}

Measured memory_bytes: 1784
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v(3);
int main() {
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < 2; i++) {
		cout << v[i] << " ";
	}
	cout << v[2] << endl;
}


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

int main(){
	int N;
	cin >> N;
	int a=0,un=0;
	int flg = 1;
	for(int i=0;i<N;i++){
		string str;
		cin >> str;
		if(str == "A") a++;
		else un++;
		if(un > a) {
			flg = 0;
		}
	}
	if(flg && a == un) cout << "YES" << endl;
	else 	cout << "NO" << endl;
}

Measured memory_bytes: 3160
class BinaryTree():
    def __init__(self):
        self.root = None

    def insert(self, insert_node):
        p = None
        r = self.root
        while r:
            p = r
            if insert_node.value < r.value:
                r = r.left
            else:
                r = r.right

        if not p:
            self.root = insert_node
        elif insert_node.value < p.value:
            p.left = insert_node
        else:
            p.right = insert_node

    def find(self, find_value):
        p = None
        r = self.root
        while r:
            p = r
            if find_value == r.value:
                return "yes"
            if find_value < r.value:
                r = r.left
            else:
                r = r.right
        return "no"

class Node():
    def __init__(self, value, left, right):
        self.value = value
        self.left  = left
        self.right = right

    def pre_order_search(self):
        l = self.left
        r = self.right
        print("",self.value, end="")
        if l:
            l.pre_order_search()
        if r:
            r.pre_order_search()

    def in_order_search(self):
        l = self.left
        r = self.right
        if l:
            l.in_order_search()
        print("",self.value, end="")
        if r:
            r.in_order_search()

m = int(input())
tree = BinaryTree()

for i in range(m):
    inp = input().split()
    if inp[0] == "insert":
        tree.insert(Node(int(inp[1]), None, None))
    elif inp[0] == "find":
        print(tree.find(int(inp[1])))
    else:
        tree.root.in_order_search()
        print()
        tree.root.pre_order_search()
        print()

Measured memory_bytes: 87248
n=int(input())

t = list(map(int,input().split()))

yonba = 0
gusu = 0
kisu = 0

for i in t:
    if i%4==0:
        yonba += 1
    elif i%2==0:
        gusu += 1
    else:
        kisu += 1

if kisu==0:
    print('Yes')
else:
    if kisu <= yonba:
        print('Yes')
    else:
        if kisu-yonba==1 and gusu == 0:
            print('Yes')
        else:
            print('No')

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

def main():
	n, m = map(int, input().strip().split())
	v = [0] * (n+1)
	v[0] = 1
	v[1] = 1
	N = []
	for i in range(m):
		a = int(input().strip())
		N.append(a)
	N.append(-1)
	j = 0
	for i in range(1, n+1):
		if N[j] == i:
			v[i] = 0
			j += 1
		else:
			if i == 1:
				v[i] = 1
			else:
				v[i] = v[i-1] + v[i-2]
	print(v[n] % (10**9+7))

if __name__ == '__main__':
	main()


Measured memory_bytes: 471416
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll n,i,j;
    cin>>n;
    if(n==1) {cout<<0;return 0;}
    ll save = n;
    vector<ll> prime;
    map<ll,ll> mp;
    ll ctr = 0;
    if(n%2==0)
    {
        prime.pb(2);
        while(n%2==0) {n/=2;ctr++;}
        mp[2] = ctr;
    }
    for(i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        {
            ctr = 0;
            prime.pb(i);
            while(n%i==0) {n/=i;ctr++;}
            mp[i] =  ctr;
        }
    }
    if(n>1)
    {
        prime.pb(n);
        mp[n] = 1;
    }
    ll ans = 0;
    for(auto p: prime)
    {
        i=1;
        while((i*(i+1))/2 < mp[p]) i++;
        if((i*(i+1))/2 == mp[p]) ans+=i;
        else ans+=(i-1);
    }
    cout<<ans;
}

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

int main() {
    int N,M,A;
    cin >> N >> M;
    int sum = 0;

    for(int i=0; i<M; i++) {
        cin >> A;
        sum += A;
    }

    cout << max(N - sum, -1) << endl;
    return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;

namespace ITP1_8_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "abcdefghijklmnopqrstuvwxyz";
            int[] memo = new int[26];
            while (true)
            {
                string text = Console.ReadLine();
                if (string.IsNullOrEmpty(text))
                    break;

                foreach (var t in text)
                {
                    char ch = char.ToLower(t);
                    if ('a' <= ch && ch <= 'z')
                        memo[ch - 'a']++;
                }
            }

            for(int i = 0; i < 26; i++)
            {
                Console.WriteLine("{0} : {1}", s[i], memo[i]);
            }
        }
    }
}

Measured memory_bytes: 9124
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    ll c[100001]={};
    ll sum = 0;

    int N;
    cin >> N;

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

    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int B, C;
        cin >> B >> C;
        sum += (C - B) * c[B];
        c[C] += c[B];
        c[B] = 0;

        cout << sum << endl; 
    }
}


Measured memory_bytes: 4424
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;


int main(){
	int A,B,C,ans;
	cin>>A>>B>>C;
	if(A+B+1>=C){
		ans=B+C;
	}else{
		ans=A+B+B+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int n;
  double ans = 0.0;
  std::cin >> n;
  for (int i = 0, a; i < n; ++i) {
    std::cin >> a;
    ans += 1.0 / a;
  }
  std::cout << 1.0 / ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10**9+ 7 
def power_(n, p, mod):
    if p == 1:
        return n
    if p % 2 == 0:
        return (power_(n, p//2, mod) ** 2) % mod
    else:
        return n * (power_(n, p//2, mod) ** 2) % mod
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
#a/b = a*(b`)となるb`を求める
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod
fact = [1 for i in range(n*2+1)]
for i in range(1,n*2+1):
    fact[i] = (fact[i-1] * i) % mod
if k + 1 >= n:
    child = fact[n * 2  - 1]
    mother = mod_inv(fact[n], mod) * mod_inv(fact[n-1], mod)
    print((child * mother) % mod)
else:
    #k人までは自由に振り分け、そのあとはnCn-k
    bow = n - k - 1
    """
    child = fact[bow + k]
    mother = (mod_inv(fact[k], mod) * mod_inv(fact[bow], mod)) % mod
    combi = (fact[n] * mod_inv(fact[n - k],mod) * mod_inv(fact[k],mod)) % mod
    aa = power_(n,k,mod)
    aa -= combi
    """
    ans = 0
    #実際に移動する人数を固定
    #ではなく、0人の部屋を固定する
    for i in range(k+1):
        bow = n - i - 1
        child = fact[bow + i]
        mother = (mod_inv(fact[i], mod) * mod_inv(fact[bow], mod)) % mod
        combi = (fact[n] * mod_inv(fact[n - i],mod) * mod_inv(fact[i],mod)) % mod
        ans += (child * mother * combi) % mod
        ans %= mod
    print(ans % mod)

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int64_t sum = accumulate(A.begin(), A.end(), 0LL);
    int mn = *min_element(A.begin(), A.end());
    bool first;
    if(N%2){
        first = sum%2;
    }else{
        first = (sum%2) | (mn%2);
    }
    cout << (first ? "First" : "Second") << endl;
    return 0;
}



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

int main() {
    int n, m;
    cin >> n >> m;
    int hs[n];
    int h[n];
    rep(i,n) {
        cin >> hs[i];
    }
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        if (hs[a] > hs[b]) h[b] = -1;
        else if (hs[b] > hs[a]) h[a] = -1;
        else {
            h[a] = -1;
            h[b] = -1;
        }
    }
    int ans = 0;
    for (int v : h) {
        if (v != -1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4376
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>

using namespace std;

typedef long long ll;

const int MOD = 1000 * 1000 * 1000 + 7;

int main() {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int it = 0;
    int last = -1;
    ll ans = 1;
    while (it < n) {
        if (last == 0) {
            if (a[it] == b[it]) {
                ans *= 2;
                ans %= MOD;
                it++;
                last = 0;
            } else {
                it += 2;
                ans *= 2;
                ans %= MOD;
                last = 1;
            }
        } else if (last == 1) {
            if (a[it] != b[it]) {
                it += 2;
                ans *= 3;
                ans %= MOD;
                last = 1;
            } else {
                it++;
                last = 0;
            }
        } else {
            if (a[it] == b[it]) {
                ans *= 3;
                it++;
                ans %= MOD;
                last = 0;
            } else {
                ans *= 6;
                ans %= MOD;
                it += 2;
                last = 1;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		
		try(BufferedReader br = new BufferedReader(reader)) {
			int n = Integer.parseInt(br.readLine());
			Set<String> input = new HashSet<>();
			for(int i = 0; i < n; i++) {
				input.add(br.readLine());
			}
			System.out.println(input.size());
		} catch (IOException e) {
			e.printStackTrace();
		} 

	}

}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=1000010;
const ll mod=1e9+7;


int main(){
  int r,g,b,n;
  cin >> r >> g >> b >> n;
  ll ans=0;
  for(int i=0; i<=n/r; i++)for(int j=0; j<=n/g; j++){
    if((n-i*r-j*g)%b==0 && (n-i*r-j*g)>=0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)
#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll oo=1e15;
int n;
int a[100005];
bool calculated[100005];
ll value[100005];
ll solve(int idx){
    if(idx>=n) return oo;
    if(idx==n-1) return 0ll;
    if(calculated[idx]) return value[idx];
    ll best=oo;
    f(i,1,3)
        best=min(best,solve(idx+i)+abs(a[idx+i]-a[idx]));
    calculated[idx]=true;
    value[idx]=best;
    return best;
}
int main()
{
    scanf("%d",&n);
    f(i,0,n)
        scanf("%d",&a[i]);
    cout<<solve(0)<<'\n';
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MAX_E = 3000;
const long long MAX_V = 2000;

struct edge { ll from, to, cost; };
ll d[MAX_V];
edge es[MAX_E];
ll V, E;

bool find_negative_loop()
{
    rep(i, MAX_V) {
        d[i] = INF;
    }
    d[0] = 0;
    rep(i, V) {
        rep(j, E) {
            edge e = es[j];
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (i == V - 1 && e.to == V - 1) return true;
            }
        }
    }

    return false;
}
int main()
{
    cin >> V >> E;
    rep(i, E) {
        ll a, b, c;
        cin >> a >> b >> c;
        es[i] = edge{a - 1, b - 1, -c};
    }

    if (find_negative_loop()) {
        cout << "inf" << endl;
    }
    else {
        cout << -d[V - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Problem E - Cell Distance
#include<bits/stdc++.h>
using namespace std;
long long int mod = 1e9+7;

long long int power(long long int x, long long int n)
{
    long long int res = 1;
    while(n > 0)
    {
        if(n&1)
        {
            res = (res * x)%mod;
        }
        x = (x * x)%mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    long long int n, m, k;
    cin >> n >> m >> k;

    vector<long long int> fac(n*m-1, 1);
    vector<long long int> ifac(n*m-1, 1);
    
    for(int i=2; i<n*m-1; i++)
    {
        fac[i] = (i * fac[i-1])%mod;
    }
    for(int i=1; i<n*m-1; i++)
    {
        ifac[i] = power(fac[i], mod-2);
    }

    long long int ans = 0;
    for(int i=1; i<m; i++)
    {
        long long int a = ((long long int)n * n * (m - i))%mod;
        ans += (a * i)%mod;
        ans %= mod;
    }
    for(int i=1; i<n; i++)
    {
        long long int a = ((long long int)m * m * (n - i))%mod;
        ans += (a * i)%mod;
        ans %= mod;
    }

    ans *= (fac[n*m - 2] * ifac[k - 2])%mod;
    ans %= mod;
    ans *= ifac[n*m - k];
    ans %= mod;

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

Measured memory_bytes: 3328
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char (digitToInt)

main :: IO ()
main = do
    n <- readLn :: IO Int
    let d = length (show n)
    let f1 = read [head $ show n] :: Int
    let (px, py) = (9, d - 2)
    let (qx, qy) = (f1 - 1, d - 1)
    let a0 = foldr (\c a -> digitToInt c + a) 0 (show n)
    let a1 = foldr (\c a -> digitToInt c + a) 0 (show px ++ replicate py '9')
    let a2 = foldr (\c a -> digitToInt c + a) 0 (show qx ++ replicate qy '9')
    if n < 10
        then print n
        else print $ maximum [a0, a1, a2]

Measured memory_bytes: 508
def main():
    x, y, z = (int(i) for i in input().split('/'))

    if(x>2019):
        print("TBD")
        return
    elif(y>4):
        print("TBD")
        return
    elif(z>30):
        print("TBD")
        return
    else:
        print("Heisei")
        return

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    rep(i, 10000){
        int ta, tb, tc;
        if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
            cout << i << endl;
            return 0;
        }
        ta = (b + c) / 2;
        tb = (c + a) / 2;
        tc = (a + b) / 2;
        a = ta;
        b = tb;
        c = tc;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAX 128

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int list[MAX];
int n, q;

int main(void) {
    while (1) {
        cin >> n >> q;
        if (n == 0 && q == 0) break;
        for (int i = 0; i < MAX; i++) list[i] = 0;
        for (int i = 0; i < n; i++) {
            int m;
            cin >> m;
            for (int j = 0; j < m; j++) {
                int date;
                cin >> date;
                list[date]++;
            }
        }
        int index = -1, ma = 0;
        for (int i = 0; i < MAX; i++) {
            if (list[i] >= q && (list[i] > ma || index == -1)) {
                index = i;
                ma = list[i];
            }
        }
        if (index != -1) cout << index << endl;
        else cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
N,K,Q = [int(x) for x in input().split()]
A = [int(input()) for _ in range(Q)]
li = [K]*N
btm = Q
for i in A:
    li[i-1] += 1
for i in li:
    if(i>btm):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 10472
n,x,y = map(int, input().split())
x -= 1
y -= 1
ans = [0 for i in range(n+1)]
for i in range(0,n):
    for j in range(i+1,n):
        if (i <= x and j <= x) or (i >= y and j >= y):
            ans[j-i] += 1
        else:
            k = min(abs(x-i) + 1 + abs(y-j), j-i)
            ans[k] += 1
for i in range(1,n):
    print(ans[i])


Measured memory_bytes: 48852
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    string O,E;
    cin >> O >> E;

    string ans = "";
    rep(i, min(len(O),len(E))){
        ans += O[i];
        ans += E[i];
    }
    if(len(O) > len(E)) ans += O.back();

    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
#define MAX 10000
#define NIL -1
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct node{
  int parent,left,right;
};
node T[MAX];
int n,D[MAX],H[MAX];

void setDep(int u ,int d){
  if(u==NIL)return ;
  D[u]=d;
  setDep(T[u].left,d+1);
  setDep(T[u].right,d+1);
}

int setHei(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)h1=setHei(T[u].left)+1;
  if(T[u].right!=NIL)h2=setHei(T[u].right)+1;
  return H[u]=(h1>h2?h1:h2);
}

int setSib(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL){
    return T[T[u].parent].left;
  }
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL){
    return T[T[u].parent].right;
  }
  return NIL;
}
void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",setSib(u));
  int deg=0;
  if(T[u].left!=NIL)deg++;
  if(T[u].right!=NIL)deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ", H[u]);

  if(T[u].parent == NIL)cout<<"root"<<endl;
  else if(T[u].left==NIL&&T[u].right==NIL)cout<<"leaf"<<endl;
  else cout<<"internal node"<<endl;
}

signed main(){
  int v,l,r,root=0;
  cin>>n;
  rep(i,n)T[i].parent=NIL;
  rep(i,n){
    cin>>v>>l>>r;
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }
  rep(i,n)if(T[i].parent==NIL)root=i;
  setDep(root,0);
  setHei(root);
  rep(i,n)print(i);

  return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

vector<ll> AB(1000005,0),ans(3000005,0);

int main(){
    int X,Y,Z,K; cin>>X>>Y>>Z>>K;
    vector<ll> A(X),B(Y),C(Z);
    for (int i = 0; i < X; ++i) {
        cin>>A[i];
    }

    for (int i = 0; i < Y; ++i) {
        cin>>B[i];
    }

    for (int i = 0; i < Z; ++i) {
        cin>>C[i];
    }

    for (int i = 0; i < X; ++i) {
        for (int j = 0; j < Y; ++j) {
            AB[i*Y+j]=A[i]+B[j];

        }
    }

    sort(AB.rbegin(),AB.rend());

    for (int i = 0; i < K; ++i) {
        for (int j = 0; j < Z; ++j) {
            ans[i*Z+j]=AB[i]+C[j];
        }
    }

    sort(ans.rbegin(),ans.rend());
    for (int i = 0; i < K; ++i) {
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 31616
#include<stdio.h>
int main()
{
	int n,x,i,a[105],s=0,min=0;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		s+=a[i];
		if(a[min]>a[i])
		    min=i;
	}
	x-=s;
	printf("%d",n+x/a[min]);
}


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

using namespace std;

int main()
{
	int l, d, r, c=0;
	cin>>l>>r>>d;
	for(int i=l; i<=r; i++)
	{
		if(i%d==0)
		c++;
	}
	cout<<c;
	return 0;
}


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

odd = [i for i in a if i % 2 == 1]
even = [i for i in a if i % 2 == 0]
ecnt = pow(2, len(even))
ocnt = pow(2, max(len(odd)-1,0))
print(0 if (len(odd )== 0 and p == 1) else ecnt * ocnt)


Measured memory_bytes: 38256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>
#include<algorithm>
typedef long long ll;
using namespace std;
typedef pair<int,int> miria;

map<int , int> akagi;

int main(){
  int s,count=1;
  cin >> s;
  for(int i=1;i<=100;i++){
    akagi[i]=0;
  }
  akagi[s]++;
  while(akagi[s]!=2){
    if(s%2==0){
      s /= 2;
    }else{
      s = 3*s+1;
    }
    akagi[s]++;
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())

mod = 10**9+7
count = 0
for i in range(k, n+2):
  maxsum = (i*(n+n-i+1))//2 #組み合わせの最大値
  minsum = (i*(i-1))//2 # 組み合わせの最小値
  count += maxsum - minsum +1
  count %= mod 
print(count)

Measured memory_bytes: 9160
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vector<int> G[100010];
int col[100010];
bool dfs(int v,int c){
	col[v]=c;
	for(auto e:G[v]){
		if(col[e]==c)return false;
		if(col[e]==-1&&!dfs(e,c^1))return false;
	}
	return true;
}
int main(){
	ll n,m;cin>>n>>m;
	fill(col,col+n+1,-1);
	for(int i=0;i<m;i++){
		int a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if(dfs(1,0)){
		ll c1=0,c2=0;
		for(int i=1;i<=n;i++){
			if(col[i])c1++;
			else c2++;
		}
		cout<<c1*c2-m<<endl;
	}else{
		cout<<n*(n-1)/2-m<<endl;
	}
}


Measured memory_bytes: 6528
import java.util.Scanner;
	
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[20000];
		int[] b = new int[20000];
		char[] op = new char[20000];
		
		 for(int i = 0; i <20000; i++) {
			
			 a[i] = sc.nextInt();
			 op[i] = sc.next().charAt(0);
			 if(op[i] == '?') break;
			 b[i] = sc.nextInt();
			
			
		 }
		 
		 for(int i = 0; i <20000; i++) {
			 if(op[i] == '?') break; 
			 
			 else if(op[i] != '?'){ 
				 switch(op[i]) {
				 case '+' : System.out.println( a[i]+b[i]);
				 break;
				 case '-' : System.out.println( a[i]-b[i]);
				 break;
				 case '*' : System.out.println( a[i]*b[i]);
				 break;
				 case '/' : System.out.println( a[i]/b[i]);
				 break;
				 case '?' : break;
				 }
			 }
			 
		 }
		sc.close();
		
   }

}

Measured memory_bytes: 26600
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    // 解説どおり

    let S = rl().chars().vec();
    let T = rl().chars().vec();

    let mut f = BTreeMap::new();
    let mut g = BTreeMap::new();

    let mut ok = true;

    for i in 0..S.len() {
        let (s, t) = (S[i], T[i]);

        if let Some(&s) = f.get(&s) {
            debug!((i, S[i], T[i], s, t));
            ok = ok && s == t;
        } else if let Some(&t) = g.get(&t) {
            debug!((i, S[i], T[i], s, t));
            ok = ok && s == t;
        } else {
            debug!((i, s, t));
            f.insert(s, t);
            g.insert(t, s);
        }
    }

    println!("{}", if ok { "Yes" } else { "No" })
}


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

bool ok = false;

void dfs(int nums[], int len, int opes[], int sum){
  if(ok)  return;
  if(len == 3){
    if(sum == 7){
      string s; s += (char)(nums[0]+'0');
      for(int i=1; i<4; i++){
	string o;
	if(opes[i-1] == 1)  o = "+";
	else  o = "-";
	s = s + o + (char)(nums[i]+'0');
      }
      s += "=7";
      cout << s << endl;
      ok = true;
    }
    return;
  }
  opes[len] = 1;
  dfs(nums, len+1, opes, sum+nums[len+1]);
  opes[len] = -1;
  dfs(nums, len+1, opes, sum-nums[len+1]);
  opes[len] = 0;
}

int main(){
  string s;  cin >> s;
  int nums[4], opes[4] = {0};
  for(int i=0; i<4; i++)
    nums[i] = (int)(s[i]-'0');
  dfs(nums, 0, opes, nums[0]);
    
  return 0;
}


Measured memory_bytes: 3604
a,b,c,x,y = list(map(int, input().split()))
if a + b <= 2*c:
    print(x*a + y*b)
else:
    ans = min(x,y)*2*c
    if x > y:
        ans += (x - y) * min(a, 2*c)
    elif x < y:
        ans += (y - x) * min(b, 2*c)
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    string s;
    cin >> s;
    int n = (int)s.size();
    int ans = 0;
    for (int bit = 0; bit < (1 << s.size()-1); bit++)
    {
        vector<int> v;
        int tmp = -1;
        v.push_back(0);
        for (int i = 0; i < s.size()-1; i++)
        {
            //cerr << tmp << endl;
            if ((1 << i) & bit)
            {
                v.push_back(i+1);
            }
        }
        v.push_back(s.size() );
        //show(v);
        
            for (int i = 0; i < v.size()-1; i++)
            {
                ans += stoll(s.substr(v[i], v[i + 1] - v[i]));
            }
        
        //cerr << ans << endl;
        
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
		String ans="";
		int n=scan.nextInt();
		if(n==-1)break;
		while(true)
		    {
			String sub;
			sub=Integer.toString(n%4);
			ans=sub+ans;
			n=n/4;
			if(n==0)break;
		    }
		System.out.println(ans);
	    }
    }
}

Measured memory_bytes: 21672
N, M = map(int, input().split())
H = list(map(int, input().split()))

g = [[] for _ in range(N)]

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

ans = 0

for i in range(N):
    flag = True
    for j in g[i]:
        if H[i] > H[j]:
            continue
        else:
            flag = False
    if flag:
        ans += 1

print(ans)


Measured memory_bytes: 29432
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int mmi[2000002], fc[2000002];

int fac(){

    mmi[0] = fc[0] = 1;
    for(int i = 1;i<=2000000;i++){
        fc[i] = (fc[i-1]*i)%mod;
        mmi[i] = powm(fc[i],mod-2);
    }
}


void solve(){
   
   int X, Y;
   cin >> X >> Y;

   if((X+Y)%3!=0){
    cout << 0 << endl;
    return;
   }

   int n,m;
   n = (X+Y)/3;
   X-=n;
   Y-=n;
   //cout << X << " " << Y << endl;
   if(X<0 || Y<0){
    cout << 0 << endl;
    return;
   }

   fac();

   n = mmi[X];
   m = mmi[Y];
   int nm = fc[X+Y];

   int ans = ((((nm%mod)*(n%mod))%mod)*(m%mod))%mod;

   cout << ans << endl;

} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,m;
  cin>>n>>m;
  if(m<=n*2){
    cout<<m/2<<endl;
  }else{
    if(m%2==1) m--;
    cout<<(n+(m-2*n)/4)<<endl;
  }
}



Measured memory_bytes: 256
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    A,op,B = input().split()

    A = int(A)
    B = int(B)

    if op == '+':
        res = A + B
    else:
        res = A - B

    print(res)



main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if(a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main(){
    int N;
    cin >> N;
    unsigned A[N];
    unsigned B[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    
    if(N == 2){
        cout << max(A[0], A[1]) << "\n";
        return 0;
    }
    
    unsigned LeftTo[N], RightTo[N], ans = 0;
    
    LeftTo[0] = A[0];
    RightTo[N - 1] = A[N - 1];
    for(int i = 1; i < N; i++){
        LeftTo[i] = euclidean_gcd(A[i], LeftTo[i - 1]);
        RightTo[N - 1 - i] = euclidean_gcd(A[N - 1 - i], RightTo[N - i]);
    }

    ans = RightTo[1];
    for(int i = 1; i < N - 1; i++)
        ans = max(ans, euclidean_gcd(LeftTo[i - 1], RightTo[i + 1]));
    ans = max(ans, LeftTo[N - 1 - 1]);
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1536
a, b = gets.split.map(&:to_i).sort
if 0 < a
  puts "Positive"
elsif a == 0 || b == 0
  puts "Zero"
elsif a < 0 && 0 < b
  puts "Zero"
else # a <= b < 0
  puts (b - a).odd? ? "Positive" : "Negative"
end


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    REP0 (i, N)
    {
        cin >> V[i];
    }

    int ans = 0;

    REP0 (L, min(N, K) + 1)
    {
        int sumL = 0;
        multiset<int> negL;

        REP0 (i, L)
        {
            sumL += V[i];
            if (V[i] < 0)
                negL.insert(V[i]);
        }

        REP0 (R, min(N, K) - L + 1)
        {
            int sum           = sumL;
            multiset<int> neg = negL;
            for (int i = 1; i <= R; i++)
            {
                sum += V[N - i];
                if (V[N - i] < 0)
                    neg.insert(V[N - i]);
            }
            // cout << L << ", " << R << " : " << sum << " -> ";

            int i = 0;
            for (auto n : neg)
            {
                if (i >= K - (L + R))
                    break;
                sum -= n;
                i++;
            }
            // cout << sum << endl;
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
import sys, heapq
def LI(): return list(map(int, sys.stdin.readline().split()))
def LS(): return list(sys.stdin.readline())

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

res = 0
tmp = 1
while tmp < B:
    res += 1
    tmp = tmp - 1 + A

print(res)

Measured memory_bytes: 3060
S = input()
def is_batch(s):
    return True if s==s[::-1] else False

ans = 'No'
n = len(S)
if is_batch(S):
    if is_batch(S[0:(n//2)]):
        if is_batch(S[(n+2)//2:n+1]):
            ans = 'Yes'
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K;
  cin >> N >> K;

  int MAX = 0;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    chmax(MAX, A[i]);
  }

  auto check = [&](int x){
    int cnt = 0;
    REP(i, N){
      cnt += (A[i]+x-1)/x-1;
    }
    return (cnt <= K);
  };

  int ok = MAX;
  int ng = 0;

  while(abs(ok-ng) > 1){
    int mid = (ok+ng)/2;
    (check(mid)? ok: ng) = mid;
  }
  cout << ok << "\n";

  return 0;
}


Measured memory_bytes: 4736
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template #pragma region compress 0.1

int main()
{
    IN(ll, N);
    IN(ll, D);
    IN(ll, A);
    A2IN(ll, X, ll, H, N);
    vii E(N);
    REP(i, N)
    {
        E[i] = {X[i], H[i]};
    }
    SORT(X);
    SORT(E);
    vi r(N + 1);
    ll dmg = 0;
    ll ans = 0;
    REP(i, N)
    {
        dmg -= r[i];
        ll m = max(0LL, (E[i].second - dmg + A - 1) / A);
        ans += m;
        dmg += m * A;
        ll j = upper_bound(ALL(X), X[i] + 2 * D) - X.begin();
        r[j] += m * A;
    }
    OUT(ans);
}

Measured memory_bytes: 8064
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x2 -= x1;
  y2 -= y1;

  int x3, y3, x4, y4;
  x4 = -y2;
  y4 = x2;
  x3 = x4 + x2;
  y3 = y4 + y2;

  x3 += x1;
  y3 += y1;
  x4 += x1;
  y4 += y1;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,inf=0x3f3f3f3f;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int main(){
	int x,n;
	cin>>x>>n;
	int a[105]={};
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		a[x]=1;
	} 
	int ans=1e9,res=0;
	for(int i=-1;i<=101;i++){
		 if(i<0||!a[i]){
		 	if(ans>abs(i-x))
		 		ans=abs(i-x),res=i;
		 }
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endk;
  return 0;
}


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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define mp 					make_pair
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x) 				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 2e9 + 5;
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 1e5+5;
int n, k, x, ar[MAXN], mks  = 0, mn = inf;

bool solve() {
	if (n==1) {
		if (ar[1]!=k) return 0;
		return 1;
	}
	if (mks<k) return 0;
	bool ad = 0;
	for (int i=1; i<=n; i++)
		if ((ar[i]%mn) || ar[i]==k) ad = 1;
	if (ad) return 1;
	for (int i=1; i<=n; i++) 
		if (ar[i]>k && ((ar[i]-k)%mn)==0) return 1;
	return 0;
}

int main() {
	gi(n); gi(k);
	for (int i=1; i<=n; i++) {
		gi(ar[i]);
		mks = max(mks, ar[i]);
		mn = min(mn, ar[i]);
	}
	sort(ar+1, ar+1+n);
	for (int i=2; i<=n; i++) 
		if (ar[i]!=ar[i-1]) mn = min(mn, ar[i]-ar[i-1]);
	if (solve()) printf ("POSSIBLE\n");
	else printf ("IMPOSSIBLE\n");
		
	return 0;
}


Measured memory_bytes: 640