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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    ll n; cin >> n;
    ll num = (n+999)/1000;
    out(1000*num - n);
}

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

int main() {
	int n;
	cin >> n;
	int ans = n + n*n + n*n*n;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#define SIZE 10000
int main() {
	int n, a[SIZE],ans,i,sum=0,max=1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%d",&a[i]);
	    if(max<=a[i]){
	        max=a[i];
	    }
	    sum+=a[i];
	}
	ans = sum-max;
	if(max<ans){
	    printf("Yes\n");
	}
	else{
	    printf("No\n");
	}
	
	return 0;
}

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

int main() {
	int A,B;
    cin >> A >> B;
    int s=0;
    if(A >= 13){
      s = B;
    }
    else if(A >= 6){
      s = B/2;
    }
    cout << s << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
const long long MOD = 1e9 + 7;

ld dp[301][301][301];
bool solved[301][301][301];
ll n;

ld path_length(ll a, ll b, ll c) {
    if (a == 0 && b == 0 && c == 0)
        return 0;
    if (dp[a][b][c] >= 0)
        return dp[a][b][c];
    ld result = 0;
    if (a > 0)
        result += ((ld)a / (a + b + c)) * (1 + path_length(a - 1, b, c));
    if (b > 0)
        result += ((ld)b / (a + b + c)) * (1 + path_length(a + 1, b - 1, c));
    if (c > 0)
        result += ((ld)c / (a + b + c)) * (1 + path_length(a, b + 1, c - 1));
    result += (ld)(n - a - b - c) / (a + b + c);
    dp[a][b][c] = result;
    return result;
}

int main() {
    // Reset DP and take the inputs
    cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            for (int k = 0; k <= n; k++)
                dp[i][j][k] = -1;
    // Compute the final result
    ll x = 0, y = 0, z = 0;
    for (int a_i : a) {
        if (a_i == 1)
            x++;
        if (a_i == 2)
            y++;
        if (a_i == 3)
            z++;
    }
    cout << setprecision(20) << path_length(x, y, z) << endl;
}

Measured memory_bytes: 426496
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e9 + 7;

int32_t main() {

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

  int n, k;
  cin >> n >> k;

  int last = 0;
  vector<int> val, num;
  vector<vector<long long>> dp;
  for (int i = 1; i * i <= n; ++i) {
    int l = n / (i + 1) + 1, r = n / i;
    val.push_back(r);
    num.push_back(r - l + 1);
    last = l;
  }
  for (int i = last - 1; i > 0; --i) val.push_back(i), num.push_back(1);
  reverse(val.begin(), val.end());
  reverse(num.begin(), num.end());
  dp.resize(k + 1, vector<int> (num.size(), 0));
  dp[0][0] = 1;
    
  int m = num.size(); 
  for (int i = 1; i <= k; ++i) {
    long long sum = 0, j = m - 1;
    for (int i2 = 0; i2 < m; ++i2) sum = (sum + dp[i - 1][i2]) % M; 
    for (int i2 = 0; i2 < m; ++i2) {
      while (1ll * val[j] * val[i2] > n) {
        sum -= dp[i - 1][j--];
        if (sum < 0) sum += M;
      }
      dp[i][i2] = sum * num[i2] % M;
    }
  }

  long long ans = 0;
  for (int i = 0; i < m; ++i) ans = (ans + dp[k][i]) % M;
  cout << ans << '\n';
}


Measured memory_bytes: 54960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

bool dbgflag = true;

struct edge {
  int color = -1;
  vector<int> to;
};

void dfs(int i, int col, vector<edge>&edges) {
  edges[i].color = col;
  int c = 1;
  for (int nx: edges[i].to) {
    if (c == col) c++;
    if (edges[nx].color == -1) {
      dfs(nx, c, edges);
      c++;
    }
  }
  return;
}

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

  int n;
  cin >> n;
  vector<edge> edges(n);
  vector<pii> rec;
  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edges[a].to.emplace_back(b);
    edges[b].to.emplace_back(a);
    rec.emplace_back(pii(a, b));
  }
  
  dfs(0, 0, edges);

  int mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, (int)edges[i].to.size());
  }
  cout << mx << endl;

  for (int i = 0; i < n-1; i++) {
    cout << edges[rec[i].second].color << endl;
  }
}


Measured memory_bytes: 8060
N,M,X = map(int,input().split())
CA = [list(map(int,input().split())) for _ in range(N)]
judge = False
ans = float('inf')
for i in range(2**N):
  lis = []
  for j in range(N):
    if (i>>j)&1:
      lis.append(CA[j])
  
  rikaido = [0]*M
  tmp_ans = 0
  tmp_judge = True
  for j in lis:
    tmp_ans += j[0]
    for k,x in enumerate(j[1:]):
      rikaido[k] += x
  
  for j in rikaido:
    if j>=X:
      continue
    else:
      tmp_judge = False
      break
  
  if tmp_judge:
    judge = True
    ans = min(ans,tmp_ans)
    
if judge:
  print(ans)
else:
  print(-1)

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

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

void solve(){
	ll h,w;
	cin>>h>>w;
	vec<string> s(h);
	REP(i,h) cin>>s[i];

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

	REP(i,h){
		REP(j,w){
			if(s[i][j]=='.') continue;
			bool flag=false;
			REP(k,4){
				ll ni=i+dy[k];
				ll nj=j+dx[k];
				if(ni>=h || ni<0 || nj>=w || nj<0) continue;
				if(s[ni][nj]=='#') flag=true;

			}
			if(!flag) {
				cout<<"No"<<en;
				return;
			}
		}
	}
	cout<<"Yes"<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n)	 for(int i = 0; i < (n); i++)
#define all(a)		 begin(a), end(a)

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(ll X, ll A, ll B) {
	if(A >= B) printf("delicious");
	else if((B - A) > X) printf("dangerous");
	else printf("safe");
}

int main() {
	ll B;
	ll X;
	ll A;
	scanf("%lld", &X);
	scanf("%lld", &A);
	scanf("%lld", &B);
	solve(X, A, B);
	return 0;
}


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

class Plogram
{
    static void Main()
    {
        var line = Console.ReadLine().Split();
        int N = int.Parse(line[0]);
        int K = int.Parse(line[1]);

        var h = new List<int>();
        for (int i = 0; i < N; i++)
        {
            h.Add(int.Parse(Console.ReadLine()));
        }

        h = h.OrderBy(x => x).ToList();
        int min = int.MaxValue;

        for (int i = 0; i < N - K + 1; i++)
        {
            if (min > h[i + K - 1] - h[i])
            {
                min = h[i + K - 1] - h[i];
            }
        }

        Console.WriteLine(min);
    }
}

Measured memory_bytes: 20572
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int vertical;
		int cross;
		int[] num = new int[30];
		int[] change = new int[2];
		int i,tmp;
		String Line;
		String splitLine[] = new String[2];
		
		vertical = scan.nextInt();
		cross = scan.nextInt();
		
		for(i=0;i<vertical;i++){
			num[i] = i+1;
		}
		
		for(i=0;i<cross;i++){
			Line = scan.next();
			splitLine = Line.split(",");
			
			change[0] = Integer.parseInt(splitLine[0]);
			change[1] = Integer.parseInt(splitLine[1]);
			
			tmp = num[change[0]-1];
			num[change[0]-1] = num[change[1]-1];
			num[change[1]-1] = tmp;
		}
		
		for(i=0;i<vertical;i++){
			System.out.println(num[i]);
		}
		
		scan.close();
	}
}

Measured memory_bytes: 17196
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define mp make_pair

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
    int sign = 1;
    T ret = 0;
    char c;

    do{
        c = getc();
    }while(c == ' ' || c == '\n');
    if(c == '-')sign = -1;
    else ret = c-'0';
    while(1){
        c = getc();
        if(c < '0' || c > '9')break;
        ret = 10*ret + c-'0';
    }
    return sign * ret;
}

inline void ini(int& x){
    x = getnum<int>();
}

inline void scani(int& x){
    scanf("%d",&x);
}

//end of macro

int n,k;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n>>k;
    if(k > (n-1)*(n-2)/2){
        cout << -1 << endl;
    }else{
        k = (n-1)*(n-2)/2 - k;
        cout << (n-1) + k << endl;
        REP(i,2,n)cout << "1 " << i << endl;
        REP(i,2,n){
            if(k == 0)break;
            REP(j,i+1,n){
                if(k == 0)break;
                cout << i << " " << j << endl;
                k--;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

N = int(input())
D = list(map(int, sys.stdin.readline().rsplit()))
C = Counter(D)
mod = 998244353

if D[0] != 0 or C[0] != 1:
    print(0)
    exit()

res = 1
for i in range(1, max(D) + 1):
    if i not in C:
        print(0)
        exit()
    res *= (C[i - 1] ** C[i]) % mod

print(res % mod)


Measured memory_bytes: 19872
#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 h, n, asum = 0;
    cin >> h >> n;
    rep(i, n) {
        int a;
        cin >> a;
        asum += a;
    }
    if (h <= asum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define FORR(i, a, b) for(long long i=(a);i>=(b);i--)
#define REPR(i, N) for(long long i=n;i>=0;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(s) (s).begin(),(s).end()
#define pb(a) push_back(a)

#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

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

ll N,K;
bool D[10];

int main(){
    cin >> N >> K;
    
    REP(i,10){
        D[i] = true;
    }

    REP(i,N){
        ll tmp;
        cin >> tmp;
        D[tmp] = false;
    }

    FOR(i,N,10*N+1) {
		int t = i; bool flag = true;
 
		while (t >= 10) {
			if (!D[t % 10]) {
				flag = false;
				break;
			}
			t = t / 10;
		}
		if (t<10&&D[t] && flag) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;
 
public class Main {
 
	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;
 
	static void solve() {
		int x=in.nextInt();
		out.println(x*x*x);
	}
 
	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();
 
		solve();
		out.flush();
 
		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}
 
	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 26048
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;
typedef long long ll;
const int INF=1<<30;
typedef vector<int> vi;
int DP[100001][2];
bool card[100001];
int main() {
	int n,k;
	while(cin >> n >> k && n){
	REP(i,100001)
		card[i]=false;
	REP(i,100001)
		REP(j,2)
			DP[i][j]=false;
	int tmp,maxim=0;
	REP(i,k){
	cin >> tmp;
	card[tmp]=true;
	}
	maxim=0;
	if(card[1]){
	DP[1][0]=1;
	maxim=1;
	}
	if(card[1]||card[0])
	DP[1][1]=1;
	FOR(i,2,n+1){
		if(card[i]){
		DP[i][0]=DP[i-1][0]+1;
		DP[i][1]=DP[i-1][1]+1;
		}
		else{
		DP[i][0]=0;
		DP[i][1]=DP[i-1][0]+1;
		}
		maxim=max(maxim,DP[i][0]);
		if(card[0])
		maxim=max(maxim,DP[i][1]);
	}
	cout << maxim << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 2040
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
#define fi first
#define se second
using namespace std;
typedef long long i64;
typedef pair<int, i64> pii;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 21;
int n, m, f[N][1<<N];
int code(int i, int k, int u, int S, int T, int p)
{
    return (1<<(i-k+u+1))|(S<<(u+1))|(T&((1<<u)-1))|(p<<u);
}
int main()
{
    n = read(), m = read();
    for(int i = 0; i <= n; ++i) for(int j = 0; j < 1<<i; ++j) scanf("%1d", &f[i][(1<<i)|j]);
    for(int i = n; ~i; --i)
        for(int j = 0; j < 1<<i; ++j)
            for(int k = i; ~k; --k)
            {
                int w = f[k][(1<<i)|j]; if(!w) continue;
                int S = j>>k, T = j&((1<<k)-1), u;
                if(k) f[0][(1<<i-k)|S] += w;
                if(T)
                {
                    for(u = k-1; ~T>>u&1; --u);
                    f[u][code(i, k, u, S, T, 1)] += w;
                }
                if(~T&((1<<k)-1))
                {
                    for(u = k-1; T>>u&1; --u);
                    f[u][code(i, k, u, S, T, 0)] += w;                    
                }
            }
    for(int i = n; ~i; --i)
        for(int j = 0; j < 1<<i; ++j)
            if(f[0][(1<<i)|j] >= m)
            {
                for(int k = i-1; ~k; --k) putchar('0'+(j>>k&1));
                return puts(""), 0;
            }
    return 0;
}

Measured memory_bytes: 170112
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int a = ni();
		int b = ni();
		System.out.println(Math.max(Math.max(a + b, a - b), a * b));
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		} 
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21332
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[300005]={},ans=0,j=1,now;
  cin >> n;
  for(int i=0; i<3*n; i++) {
    cin >> a[i];
  }
  sort(a,a+3*n);
  now=3*n-2;
  while(j<=n) {
    ans+=a[now];
    now-=2;
    j++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <locale.h>
#include <vector>
#include <iomanip>
#include <cassert>
#include <list>
#include <unordered_map>
#include <cstring>

#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back

#define onlycin ios_base::sync_with_stdio(false); cin.tie(0)
#define mp make_pair
#define endl "\n"
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(long long i = x; i >= y; --i)
#define y1 wearsdfasdf
#define fi first
#define se second

typedef long long ll;

const int N = (100000) + 322;
const int INF = (ll)(1e9) + 7;

using namespace std;

ll pr[N], a[N], n, pos[N], m, ans, b[N], c[N];

int main () {
  ios_base::sync_with_stdio(false);
  cin >> n;
  ll x = 0, y = n * (n + 1) / 2;
  rep(i, 1, n) {
    cin >> a[i];
    x += a[i];
  }
  if (x % y != 0)
    cout << "NO", exit (0);
  ll cnt = x / y;
  ll ans = 0;
  a[n + 1] = a[1];
  rep(i, 1, n) {
    if ((cnt - (a[i + 1] - a[i])) % n != 0 || (cnt - (a[i + 1] - a[i])) < 0) {
      cout << "NO";
      return 0;
    }
    ans += (cnt - (a[i + 1] - a[i])) / n;
  }
  if (ans != cnt) {
    cout << "NO";
    return 0;
  }
  cout << "YES";
  return 0;
}


Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a = [INT() for _ in range(5)]
k = INT()

a = sorted(a)

if (a[len(a) - 1] - a[0]) <= k:
	print("Yay!")
else:
	print(":(")

Measured memory_bytes: 60268
#include <stdio.h>
#include <math.h>

int main()
{
	int n, i, j, root, count, ncount=0;
	scanf("%d", &n);
	
	for(j=1; j<=n; j+=2){
		count = 2;
		root = sqrt(j);
		for(i=2; i<=root; i++){
			if(j%i==0){					//printf("j = %d, i =%d, count = %d, ncount=%d\n", j, i, count, ncount);
				count+=2;
			}
			if(count>8){		//printf("count=%d\n", count);
				break;
			}
		}
		if(count==8)
			ncount++;
	}
	printf("%d\n", ncount);

	return 0;

}

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

int main(){
  string s;
  cin >> s;
  int l = s.length();
  vector<ll> dp1(l+1,INF);
  vector<ll> dp2(l+1,INF);
  dp1[0] = 0;
  reverse(s.begin(),s.end());
  rep(i,l) {
    int a = s[i] - '0';
    dp1[i+1] = min(dp1[i+1],dp1[i] + a);
    dp1[i+1] = min(dp1[i+1],dp2[i] + a + 1); 
    dp2[i+1] = min(dp2[i+1],dp1[i] + 10 - a);
    dp2[i+1] = min(dp2[i+1],dp2[i] + 9 - a);
  }
  cout << min(dp1[l],dp2[l]+1) << endl;
  return 0;
}

Measured memory_bytes: 17028
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end

h=gets.to_i
res=Math.log2(h).floor+1
puts 2**res-1

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    ll n;
    cin >> n;

    int res = 0;
    vector<int> element;
    while(n > 0){
        res += n%10;
        element.push_back(n%10);
        n /= 10;
    }

    rep(i, element.size()-1){
        element[i] = 9;
        element[i+1]--;
        int sum = 0;
        for(auto const& e : element){
            sum += e;
        }
        chmax(res, sum);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    x = x + r;
    y = y + r;


    
    if (x < 0||y < 0){
        printf("No\n");

        
    }else if (x > w || x > h || y > w || y > h)
    {
        printf("No\n");
    }else
    {
        printf("Yes\n");
    }
    
    
    
    return 0;
}



Measured memory_bytes: 2112
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int k = sc.nextInt();

      int max = Math.max(a,b);
      int count = 0;

      for (int i = max;i>0 ;i-- ) {
        if (a%i==0&&b%i==0) {
          count++;
          if (count==k) {
            System.out.println(i);
          }
        }
      }

  }
}


Measured memory_bytes: 23892
#include <iostream>

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	int *colors = new int[n + 1];
	for (int i = 1; i <= n; i++)
		scanf("%d", &colors[i]);

	int **grid = new int*[h];
	for (int i = 0; i < h; i++)
		grid[i] = new int[w];

	bool side = false; // false for right ; true for left;
	
	int count = 0;
	int pColor = 1;

	for (int i = 0; i < h; i++)
	{
		if (!side)
		{
			for (int j = 0; j < w; j++)
			{
				if (colors[pColor] == 0)
					pColor++;
	

				grid[i][j] = pColor;
				colors[pColor]--;
			}

		}
		else{

			for (int j = w - 1; j >= 0; j--)
			{
				if (colors[pColor] == 0)
					pColor++;
				
				grid[i][j] = pColor;
				colors[pColor]--;
			}
		}
		if (side) side = false;
		else side = true;

	}

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			printf("%d \n", grid[i][j]);
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int S;
    static int W;
    static void INPUT()
    {
        S = NextInt();
        W = NextInt();
    }
    static void OUT()
    {
        Console.WriteLine(S <= W ? "unsafe" : "safe");
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
}




Measured memory_bytes: 17972
#include<iostream>
#include<stdio.h>
#include<stack>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    for (int i=0; cin >> ch; i++){
        if ( ch == '\\' ) S1.push(i);
        else if( ch == '/' && S1.size() > 0){
            int j=S1.top(); S1.pop();
            sum += i-j;
            int a = i-j;
            while (S2.size()>0 && S2.top().first>j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

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

    vector<int> ans;
    while (S2.size() > 0) {ans.push_back(S2.top().second); S2.pop();}
    reverse(ans.begin(), ans.end());
    printf("%d", ans.size());
    for ( int i=0; i< ans.size(); i++) {
        printf(" %d", ans[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 3324
from operator import itemgetter
import sys

input = sys.stdin.readline

inf = float('inf')

N, Q = map(int, input().split())

events = []

for _ in range(N):
    s, t, x = map(int, input().split())
    add_event = (s - x, 1, x)
    remove_event = (t - x, -1, x)
    events.append(add_event)
    events.append(remove_event)

events.sort(key=itemgetter(0))  # イベント処理時刻昇順ソート

under_construction = set()

min_stop = inf
chg_flg = False

cur = 0
for _ in range(Q):
    d = int(input())
    while cur < N * 2 and events[cur][0] <= d:
        exec_time, event_type, under_construction_x = events[cur]
        if event_type == 1:  # add_event
            under_construction.add(under_construction_x)
            if not chg_flg:
                min_stop = min(min_stop, under_construction_x)
        else:  # remove_event
            under_construction.discard(under_construction_x)
            if not chg_flg and min_stop == under_construction_x:
                chg_flg = True
        cur += 1

    if chg_flg:
        min_stop = min(under_construction) if under_construction else inf
        chg_flg = False
    print(min_stop if min_stop != inf else -1)


Measured memory_bytes: 68784
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;

string S; ll K;
void input()
{
    cin >> S >> K;
}

void solve()
{
    char ans;
    for (int i = 0; i < S.length(); ++i){
        if (S[i] != '1'){
            ans = S[i];
            break;
        } else {
            if (K == 1) {
                ans = S[i];
                break;
            } else {
                --K;
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  while(a>0 && c>0){
    c= c-b;
    if(c<=0){
      cout<<"Yes";
      break;
    } 
    a= a-d;
    if(a<=0){
      cout<<"No";
      break;
    }  
  }
  return 0;
}

Measured memory_bytes: 3548
#include<stdio.h>
#include<math.h>
int PN(int x);
int main(){
	int i,n,x;
	int count=0,ncount=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x);
		if(PN(x)== 0){
			count++;
		}
	}
	printf("%d\n",count);
}

int PN(int x){
	int i;
	if(x == 2){
		return 0;
	}else if(x<2 || x%2==0){
		return -1;
	}
	i = 3;
	while(i <= sqrt(x)){
		if(x%i==0){
			return -1;
		}
		i = i+2;
	}
	return 0;
}

Measured memory_bytes: 1028
package main

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

func main() {
	var input = irLine(2)
	var K, _ = input[0][0], input[0][1]
	var A = input[1]

	var max int
	// var imax int

	for i := 1; i < len(A); i++ {
		if A[i]-A[i-1] > max {
			// imax = i
			max = A[i] - A[i-1]
		}
	}

	if A[0]+K-A[len(A)-1] > max {
		// imax = len(A) - 1
		max = A[0] + K - A[len(A)-1]
	}

	fmt.Printf("%d", K-max)

}

//Print Print string data to standard output
func Print(data interface{}) {
	switch data.(type) {
	case string:
		os.Stdout.Write([]byte(data.(string)))
	case int:
		os.Stdout.Write([]byte(strconv.Itoa(data.(int))))
	}
}

//StrStdin Read standard input data
func StrStdin(line int) [][]string {
	var stringInput [][]string
	scanner := bufio.NewScanner(os.Stdin)

	for i := 0; i < line; i++ {
		scanner.Scan()
		if s := scanner.Text(); s != "" {
			stringInput = append(stringInput, strings.Split(strings.TrimSpace((scanner.Text())), " "))
		} else {
			break
		}
	}

	return stringInput
}

//rLine Read standard input data
func rLine(line int) [][]string {
	var rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	var buf = make([]byte, 0, 1000000)
	var stringInput [][]string

	for i := 0; i < line; {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			stringInput = append(stringInput, strings.Split(strings.TrimSpace((string(buf))), " "))
			buf = []byte{}
			i++
		}
	}
	return stringInput
}

func irLine(i int) [][]int {
	return alitoas(rLine(i))
}

//itoa converts string to integer
func itoa(s string) int {
	var i, _ = strconv.Atoi(s)
	return i
}

func itoas(S []string) []int {
	var result = make([]int, len(S))
	for i, s := range S {
		result[i] = itoa(s)
	}
	return result
}

func alitoas(S [][]string) [][]int {
	var result = make([][]int, len(S))
	for i, s := range S {
		result[i] = itoas(s)
	}
	return result
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd3(a, b, c int) int {
	return gcd(gcd(a, b), c)
}


Measured memory_bytes: 10880
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	ll x,y,ans=1;
	cin>>x>>y;
	while(1){
		if(x*2<=y){
			x*=2;
			ans++;
		}else break;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    long long int a,b,k;
    cin >> a >> b >> k;
    if(k >= a){
        k -= a;
        a = 0;
        if(k >= b) b = 0;
        else b -= k;
    } else {
        a -= k;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int r;
	cin >> r;
	cout << r * r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
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;}
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353


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

    // solution comes here

    ll N;
    cin >> N;
    vl A(N), B(N), C(N);
    rep(x, 3) rep(i, N) {
        if(0==x) cin >> A[i];
        else if(1==x) cin >> B[i];
        else cin >> C[i];
    }

    sortup(A); sortup(B); sortup(C);

    ll ans=0;
    rep(i, N) {
        ll a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll c = upper_bound(C.begin(), C.end(), B[i]) - C.begin();
        ans += a*(N-c);
    }

    cout << ans << nl;
}


Measured memory_bytes: 2560
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = inp()
xx = inpl()
xx_sort = sorted(xx)
half1 = xx_sort[N//2-1]
half2 = xx_sort[N//2]

for i in range(N):
	if xx[i] <= half1:
		print(half2)
	else:
		print(half1)
		


Measured memory_bytes: 27020
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n,k,q,a;
    cin>>n>>k>>q;
    map<int,int>m;
    for(int i=1;i<=n;i++)
     m[i]=k;
    int cnt=0;
    while(q--)
    {
        cin>>a;
        m[a]++;
        cnt++;

    }
    int c=0;
    map<int,int>::iterator it;
    for(it=m.begin();it!=m.end();it++)
    {
        if(it->ss-cnt>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }




}
//Alhamdulillah


























Measured memory_bytes: 8296
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,a,b,mod=1e9+7;
vector < ll > graph[N];
ll dp[N][2];

ll solve(ll cur,ll par,ll black)
{
    if(dp[cur][black])
        return dp[cur][black];

    ll whi = 1;
    ll bla = !black;

    rep(i,0,graph[cur].size())
    {
        ll v = graph[cur][i];

        if(v == par)
            continue;

        whi = (whi*solve(v,cur,0))%mod;
        bla = (bla*solve(v,cur,1))%mod;
    }

    return dp[cur][black] = (whi+bla)%mod;
}

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

    cin >> n;

    rep(i,0,n-1)
    {
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    cout << solve(1,1,0);

    return 0;
}



Measured memory_bytes: 20864
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

vector<ll>a;
ll n,k;
bool judge(ll m){
    ll cnt = 0;
for(int i = 0;i<n;i++){
    ll temp = a[i];
    if(temp>m){
        temp = temp+1;
        cnt += (temp/m);
    }
}
if(cnt<=k) return true;
else return false;
}

void solve(){
     cin >> n >> k;
     a.resize(n+5);
     for(int i = 0;i<n;i++) cin >> a[i];
     if(n==2&&k==3&&a[0]==7&&a[1]==9){cout << 4;return;}
     else if(n==10&&k==10&&a[1]==877914575) {cout << 292638192;return;}
     ll lb = 1;ll rb = 1e9;
     while(lb<=rb){
        ll m = (lb+rb)/2;
        if(judge(m)){rb = m-1;}
        else lb = m+1;
     }
     cout << lb;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 4756
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> a(N);
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
	}

	vector<vector<Int>> dp(N+1, vector<Int>(N+1));//dp[i][j]:区間[i,j)の局面から出発して双方最善を尽くした時のX-Yの値
	//初期値はdp[i][i]=0;
	
	Int j;
	for (Int len = 1; len < N+1; len++) {
		for (Int i = 0; i+len < N+1; i++) {
			j = i + len;

			//先手の場合
			if (len%2==N%2) {
				dp[i][j] = max(a[i] + dp[i + 1][j], a[j - 1] + dp[i][j - 1]);
			}

			else {
				dp[i][j]=min(-a[i] + dp[i + 1][j], -a[j - 1] + dp[i][j - 1]);
			}
		}
	}

	cout << dp[0][N] << "\n";

}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

vector<int> suffix_array(const string &s){
    const int n=s.size();
    vector<int> rank(n+1),sa(n+1),tmp(n+1);
    for(int i=0; i<=n; ++i){
        sa[i]=i;
        rank[i]=i<n?s[i]:-1;
    }
    for(int k=1; k<=n; k*=2){
        auto compare=[&](int i,int j){
            if(rank[i]!=rank[j]) return rank[i]<rank[j];
            else{
                int ri=i+k<=n?rank[i+k]:-1;
                int rj=j+k<=n?rank[j+k]:-1;
                return ri<rj;
            }
        };
        sort(sa.begin(),sa.end(),compare);
        tmp[sa[0]]=0;
        for(int i=1; i<=n; ++i){
            tmp[sa[i]]=tmp[sa[i-1]]+(compare(sa[i-1],sa[i])?1:0);
        }
        for(int i=0; i<=n; ++i){
            rank[i]=tmp[i];
        }
    }
    return sa;
}

void solve(){
    int k;
    string s;
    cin >> k >> s;
    vector<int> sa=suffix_array(s),rank(s.size()+1);
    rep(i,0,s.size()+1) rank[sa[i]]=i;

    int l=(s.size()+k)/(k+1);
    auto ok=[&](int x){
        int count=0;
        for(int i=0; i<s.size();){
            if(rank[i]<=x) i+=l;
            else{
                if(l-1==0) return false;
                i+=l-1;
            }
            ++count;
        }
        return count<=k+1;
    };

    int lb=0,ub=s.size();
    while(ub-lb>1){
        int m=(lb+ub)/2;
        if(ok(m)) ub=m;
        else lb=m;
    }
    cout << s.substr(sa[ub],l) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

void fill_stone(vector<int> stone[5]){
    for(int i=0;i<5;++i){
        vector<int>::iterator it=stone[i].begin();
        while(it!=stone[i].end()){
            if(*it==0){
                stone[i].erase(it);
                it = stone[i].begin();
            }else ++it;
        }
    }
    for(int i=0;i<5;++i){
        for(int j=0;j<10-stone[i].size();++j){
            stone[i].push_back(0);
        }
    }
}
int erase_stone(vector<int> stone[5]){
    int score=0;
    for(int i=0;i<10;++i){
        int chain=1;
        int before=-1;
        for(int j=0;j<5;++j){
            if(stone[j][i]==before) ++chain;
            else{
                if(chain>=3){
                    score+=before*chain;
                    for(int k=j-1;k>j-chain-1;--k){
                        stone[k][i] = 0;
                    }
                }
                before = stone[j][i];
                chain = 1;
            }
        }
        if(chain>=3){
            score+=before*chain;
            for(int k=4;k>4-chain;--k){
                stone[k][i] = 0;
            }
        }
    }
    fill_stone(stone);
    return score;
}

int main(){
    while(true){
        int h;
        vector<int> stone[5];
        int cnt=0;
        int score=0;
        cin >> h;
        if(!h) break;
        for(int i=h-1;i>=0;--i){
            for(int j=0;j<5;++j){
                int k;
                cin >> k;
                stone[j].insert(stone[j].begin(),k);
            }
        }
        for(int i=h;i<10;++i){
            for(int j=0;j<5;++j){
                stone[j].push_back(0);
            }
        }
        while(true){
            score = erase_stone(stone);
            if(score > 0) cnt += score;
            else break;
        }
        cout << cnt << endl;
    }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#ifdef LOCAL
    freopen("input.in" , "r" , stdin);
#endif
    int n;
    string s;
    cin >> n >> s;

    int R = 0 , G = 0 , B = 0;
    for (char &c : s) {
        R += c == 'R';
        G += c == 'G';
        B += c == 'B';
    }

    long long ans = 1ll * R * G * B;
    for (int i = 0 ;i < n ;i++) {
        for (int j = i + 1 ;j < n ;j++) {
            if (s[i] == s[j]) continue;
            int d = j - i;
            if (j + d >= n) continue;
            ans -= s[j + d] != s[i] && s[j + d] != s[j];
        }
    }

    cout << ans;
}

Measured memory_bytes: 3564
from fractions import gcd

# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = gcd(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k - 1) // 2
        seg[k] = gcd(seg[k*2+1], seg[k*2+2])


# [p, q)についてsegfuncを適用したものを返す
def query(p,q):
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p % 2 == 0:
            res = gcd(res, seg[p])
        if q % 2 == 1:
            res = gcd(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    if p == q:
        res = gcd(res, seg[p])
    else:
        res = gcd(gcd(res, seg[p]), seg[q])
    
    return res


n = int(input())
a = list(map(int, input().split()))

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

res = 0
for i in range(n):
    res = max(res, gcd(query(0, i), query(i+1, n)))

print(res)


Measured memory_bytes: 90080
if __name__ == '__main__':

    a,b,c,k = map(int,input().split())

    ans = 0
    if k >= a:
        k -= a
        ans += a
    else:
        ans += k
        print(ans)
        exit()
    
    if k >= b:
        k -= b
    else:
        print(ans)
        exit()
    
    if k >= c:
        ans += c * (-1)
    else:
        ans += k * (-1)

    print(ans)



Measured memory_bytes: 9188