akhauriyash/Code-Regression huggingface dataset:
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto b = 20;
  auto c = new int[][](b, n);
  foreach (i; 0..b)
    foreach (j; 0..n)
      c[i][j] = a[j].bitTest(i);

  foreach (i; 0..b)
    foreach (j; 1..n)
      c[i][j] += c[i][j-1];

  auto ans = 0L;
  foreach (l; 0..n) {
    auto r = n;
    foreach (i; 0..b)
      r = min(r, c[i].assumeSorted.lowerBound(c[i][l] + 2 - a[l].bitTest(i)).length);
    ans += r-l;
  }

  writeln(ans);
}

pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
  pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
  pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
  pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }

  pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
  pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }

  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}


Measured memory_bytes: 20188
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int zero = 0, one = 0;
  REP(i,int (s.size())) {
    if(s[i] == '0') zero++;
    if(s[i] == '1') one++;
  }
  int ans = 2 * min(zero,one);
  cout << ans << endl;
}

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

using namespace std;

int cmp_num(string a, string b)
{
    for (int i=0; i<a.length(); i++) {
        if ((char)a[i] > (char)b[i]) {
            return 1;
        } else if ((char)a[i] < (char)b[i]) {
            return -1;
        } else {
            continue;
        }
    }

    return 0;
}

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

    if (a.length() > b.length()) {
        cout << "GREATER" << endl;
    } else if (a.length() < b.length()) {
        cout << "LESS" << endl;
    } else {
        int res = cmp_num(a, b);
        if (res == 1) {
            cout << "GREATER" << endl;
        } else if (res == -1) {
            cout << "LESS" << endl;
        } else {
            cout << "EQUAL" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
s = list(input())
n = len(s)

joinednum = []
sumjoined = 0
sumlist = []
def check(i,j):
    return (i>>j)%2
for i in range(1<<(n-1)):
    prejoined = [s[0]]
    for j in range(n-1):
        
        if check(i,j):
            prejoined.append(s[j+1])
        else:
            if len(prejoined)>0:
      
                joinednum.append(int("".join(prejoined)))
                prejoined = []
                prejoined.append(s[j+1])
            else:
                joinednum.append(int(s[j+1]))
    joinednum.append(int("".join(prejoined)))
    prejoined = []
    sumjoined = sum(joinednum)
    joinednum = []
    sumlist.append(sumjoined)
    sumjoined = 0

 
ans = sum(sumlist)
print(ans)
      
        
    

Measured memory_bytes: 3064
n = int(input())
a = [list() for _ in range(n)]

for i in range(n):
    m = int(input())
    for j in range(m):
        x, y = map(int, input().split())
        a[i].append((x-1, y))
    
ans = 0
for i in range(2 ** n):
    honests = [(i >> j) & 1 for j in range(n)]
    for v in range(n):
        if not honests[v]: continue
        for nv, h in a[v]:
            if h != honests[nv]: break
        else: continue
        break
    else:
        ans = max(ans, sum(honests))

print(ans)


Measured memory_bytes: 3064
from collections import deque 

def bfs(G,dist,s):
    q = deque([])
    dist[s] = 0
    q.append(s)
    
    while len(q) > 0:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv] != -1:
                continue
            
            dist[nv] = dist[v] + 1
            q.append(nv)
  


n,m = 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)

dist = [-1]*n

cnt = 0
for v in range(n):
    if dist[v] != -1:
        continue
    bfs(G,dist,v)
    cnt += 1
    
print(cnt-1)

Measured memory_bytes: 26576
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int bfs( const vector<vector<int>> to, int s, int g ) {
    vector<bool> visited(to.size(), false);
    queue<pair<int,int>> q;
    q.push( make_pair(0,s) );
    while( !q.empty() ) {
        int d = q.front().first;
        int v = q.front().second;
        q.pop();
        if( visited[v] ) continue;
        visited[v] = true;
        if( v == g ) return d;
        for( auto t : to[v] ) q.push( make_pair(d+1, t) );
    }
    return -3;
}

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int V = in, E = in;
    vector<vector<int>> to(V*3);

    rep( i, E ) {
        int u = in-1, v = in-1;
        to[u*3+0].push_back(v*3+1);
        to[u*3+1].push_back(v*3+2);
        to[u*3+2].push_back(v*3+0);
    }

    int S = in-1, G = in-1;
    cout << bfs( to, S*3, G*3 )/3 << "\n";
}


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

int main(){
    int n;
    cin >> n;
    int a[n+1], b[n];
    rep(i, 0, n+1) cin >> a[i];
    rep(i, 0, n) cin >> b[i];

    ll ans = 0;
    rep(i, 0, n){
        int left = min(a[i], b[i]);
        ans += left;        
        a[i] -= left;
        b[i] -= left;

        int right = min(a[i+1], b[i]);
        ans += right;
        a[i+1] -= right;
        b[i] -= right;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {

  int N, A, B;
  cin >> N >> A >> B;
  vector <char> a(N);
  int x = 0; //現在の国内の学生予選通過人数
  int b = 0; //現在の海外の学生予選通過人数(海外だけの順位)
  for (int i = 0; i < N; i++) {
     cin >> a.at(i);
     if (a.at(i)=='a'&& x+b<A+B) {
        cout << "Yes" << endl;
        x++;
     }
     else if(a.at(i)=='b'&& x+b<A+B && b+1<=B) {
        cout << "Yes" << endl;
        b++;
     }
     else {
        cout << "No" << endl;
     }
  }

}

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

int main()
{
	string a,b;
	cin >> a >> b;
	
	if(a[0] == b[2]){
		if(a[1] == b[1]){
			if(a[2] == b[0]){
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128
const int maxn = 2e5;

int s[maxn], t[maxn];
std::vector<pii> c[50];

signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, cnt;
  cin >> n >> cnt;
  for(int i = 0; i < n; ++i) {
  	int x, y, z;
  	cin >> x >> y >> z;
  	c[z].eb(pii(x, y));
  } 
  for(int i = 1; i <= cnt; ++i) {
  	sort(all(c[i]));
  	int m = (int)c[i].size();
  	if(m == 0) continue;
  	auto x = c[i][0];
  	for(int j = 1; j < m; ++j) {
  		if(c[i][j].fi == x.se) {
  			x.se = c[i][j].se;
  		} else {
  			s[x.fi - 1]++;
  			t[x.se]++;
  			x = c[i][j];
  		}
  	}
  	s[x.fi - 1]++;
  	t[x.se]++;
  }
  int res = 0, cur = 0; 
 	for(int i = 0; i < maxn; ++i) {
 		cur += s[i];
 		cur -= t[i];
 		res = max(res, cur);
 	}
 	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2304
#!/usr/local/bin/python3

N, A, B = map(int, input().split())
S = input()
cur_rank = 1
world_cur_rank = 1

for s in S:
    pass_cond = cur_rank <= A+B
    if s == 'a' and pass_cond:
        print('Yes')
        cur_rank += 1
    elif s == 'b' and pass_cond and world_cur_rank <= B:
        print('Yes')
        cur_rank += 1
        world_cur_rank += 1
    else:
        print('No')


Measured memory_bytes: 9188
// Submissions: WA, WA, AC

#include <bits/stdc++.h>

using namespace std;

#define INF int(1e9)
#define EPS 1e-9
#define MOD int(1e9 + 7)

int n, m, k;
const int NUM_OF_DIRECTIONS = 4;

inline bool isValidNode(int x, int y) {
	return x >= 0 && x < n && y >= 0 && y < m;
}

inline bool isWithinK(int x, int y, int ox, int oy, int k) {
	return (x == ox && abs(y - oy) <= k) || (y == oy && abs(x - ox) <= k);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n >> m >> k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1;
	--y1;
	--x2;
	--y2;

	bool vis[NUM_OF_DIRECTIONS][n * m];
	bool empty[n * m];

	for (int i = 0; i < n; i++) {
		char c;
		for (int j = 0; j < m; j++) {
			cin >> c;
			empty[i * m + j] = c != '@';
			for (int k = 0; k < 4; k++)
				vis[k][i * m + j] = false;
		}
	}

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

	int dist[NUM_OF_DIRECTIONS][n * m];
	for (int i = 0; i < NUM_OF_DIRECTIONS; i++)
		for (int j = 0; j < n * m; j++)
			dist[i][j] = INF;

	int s = x1 * m + y1;

	priority_queue<tuple<int, int, int, int>> pq;
	for (int i = 0; i < NUM_OF_DIRECTIONS; i++) {
		dist[i][s] = 1;
		pq.push(make_tuple(-1, s, s, i));
	}

	while (!pq.empty()) {
		auto node = pq.top();
		pq.pop();
		int pos = get<1>(node), origin = get<2>(node), dir = get<3>(node);

		if (vis[dir][pos])
			continue;
		vis[dir][pos] = true;

		for (int i = 0; i < NUM_OF_DIRECTIONS; i++) {
			int x = pos / m + dx[i], y = pos % m + dy[i];
			int newPos = x * m + y;
			int newDir = i;
			if (!isValidNode(x, y) || !empty[newPos] || vis[newDir][newPos])
				continue;
			int newCost = 0;
			int newOrigin = origin;
			if (!isWithinK(x, y, origin / m, origin % m, k)) {
				++newCost;
				newOrigin = pos;
			}
			if (dist[dir][pos] + newCost < dist[newDir][newPos]) {
				dist[newDir][newPos] = dist[dir][pos] + newCost;
				pq.push(
						make_tuple(-dist[newDir][newPos], newPos, newOrigin,
								newDir));
			}
		}
	}
	int e = x2 * m + y2;
	int ans = INF;
	for (int i = 0; i < NUM_OF_DIRECTIONS; i++)
		ans = min(ans, dist[i][e]);
	cout << (ans == INF ? -1 : ans) << '\n';
	return 0;
}


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

#define ll long long
#define N (1<<19)
#define mod 924844033
#define gen 5
ll K(ll x,int y=mod-2){
  ll t=1;
  for (;y;y>>=1,x=x*x%mod) if (y&1) t=t*x%mod;
  return t;
}
namespace FFT{
  void fft(int *a,int n){
    for (int i=0,j;i<1<<n;++i){
      for (int o=j=0;o<n;++o) j=j<<1|i>>o&1;
      if (i<j) swap(a[i],a[j]);
    }
    for (int o=0,len,w0;o<n;++o){
      len=1<<o; w0=K(gen,(mod-1)/(len*2));
      for (int i=0;i<1<<n;i+=len*2){
        int *l=a+i,*r=a+i+len,w=1,x,y;
        for (int j=0;j<len;++j){
          x=l[j], y=1ll*r[j]*w%mod;
          l[j]= x+y>=mod? x+y-mod: x+y;
          r[j]= x-y<0? x-y+mod: x-y;
          w=(ll)w*w0%mod;
        }
      }
    }
  }
  void realmain(int *a,int *b,int n){
    fft(a,n); fft(b,n);
    for (int i=0;i<1<<n;++i) a[i]=1ll*a[i]*b[i]%mod;
    reverse(a+1,a+(1<<n));
    fft(a,n); ll inv=K(1<<n);
    for (int i=0;i<1<<n;++i) a[i]=a[i]*inv%mod;
  }
}

int n,a[N],b[N],x,y; ll jc[N],inv[N];
vector<int>G[N/2];

int dfs(int x,int fff){
  int sz=1;
  for (auto y:G[x]) if (y-fff) sz+=dfs(y,x);
  if (fff) ++a[sz],++a[n-sz];
  return sz;
}

int main(){
  cin.tie(0); cin>>n;
  for (int i=n;--i;) cin>>x>>y, G[x].push_back(y), G[y].push_back(x);
  dfs(1,0);
  jc[0]=inv[0]=b[0]=1;
  for (int i=1;i<=n;++i) b[i]=inv[i]=K(jc[i]=jc[i-1]*i%mod);
  for (int i=0;i<=n;++i) a[i]=a[i]*jc[i]%mod;
  reverse(a,a+n+1);
  FFT::realmain(a,b,19);
  reverse(a,a+n+1);
  for (int i=1;i<=n;++i)
    printf("%lld\n",(jc[n]*inv[i]%mod*inv[n-i]%mod*n%mod\
                     -a[i]*inv[i]%mod+mod)%mod);
}

Measured memory_bytes: 30720
#include <cstdio>

int main()
{
    long long X, A, B;
    scanf("%lld %lld %lld", &X, &A, &B);
    if (B - A <= 0)
    {
        printf("delicious\n");
        return 0;
    }
    else
    {
        if (X >= B - A)
        {
            printf("safe\n");
            return 0;
        }
        else
        {
            printf("dangerous\n");
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 128
from itertools import product
n, m, x = map(int, input().split())

c = []
a = []
for i in range(n):
    tmp = list(map(int, input().split()))
    c.append(tmp[0])
    a.append(tmp[1:])


INF = 10**9
ans = INF

for i in product([0,1], repeat=n):
    skill = [0] * m
    cost = 0
    for j in range(n):
        if i[j] == 1:
            for k in range(m):
                skill[k] += a[j][k]
            cost += c[j]
    if min(skill) >= x:
        ans = min(ans, cost)

if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9024
(setq n(read))
(setq a(loop for i from 1 to n collect(read-line)))
(setq m(read))
(setq b(loop for i from 1 to m collect(read-line)))
(setq s 0)
(dolist(i a)
  (setq u 0)
  (dolist(j a)(if(string= i j)(incf u)))
  (dolist(j b)(if(string= i j)(decf u)))
  (setq s(max s u)))
(princ s)

Measured memory_bytes: 15588
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (w, h, n) = get!(i32, i32, i32);
    let mut x_min = 0;
    let mut x_max = w;
    let mut y_min = 0;
    let mut y_max = h;

    for _ in 0..n {
        let (x, y, z) = get!(i32, i32, i32);
        match z {
            1 => {
                x_min = cmp::max(x_min, x);
            },
            2 => {
                x_max = cmp::min(x_max, x);
            },
            3 => {
                y_min = cmp::max(y_min, y);
            },
            4 => {
                y_max = cmp::min(y_max, y);
            },
            _ => {}
        }
    }
    println!("{}", if x_max - x_min < 0 || y_max - y_min < 0 { 0 } else { (x_max - x_min) * (y_max - y_min) });
}

Measured memory_bytes: 4352
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Odds of Oddness
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  int on = (n + 1) / 2;
  printf("%.10lf\n", (double)on / n);
  return 0;
}


Measured memory_bytes: 256
//File Name: B.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年11月13日 星期日 23时39分55秒
                                   
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 20000 + 10;
int f[MAXN],a[MAXN],b[MAXN];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1,p;i<=n;i++){
		scanf("%d",&p);
		f[p] = i;
	}
	for(int i=1;i<=n;i++){
		a[i] = 30000 * i + f[i];
		b[i] = 30000 * (n - i) + 1;
	}
	for(int i=1;i<=n;i++){
		printf("%d",a[i]);
		if(i == n) puts("");
		else printf(" ");
	}
	for(int i=1;i<=n;i++){
		printf("%d",b[i]);
		if(i == n) puts("");
		else printf(" ");
	}
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int n;
int h[100001];
int dp[100001];

int main() {
    int k;
    cin >> n >> k;
    rep(i, n) cin >> h[i];
    rep(i, 100001) dp[i] = inf;
    dp[0] = 0;
    rep(i, n - 1) {
        rrep(j, 1, k + 1) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


MOD = 10**9 + 7

X, Y = read_ints()
if (X + Y) % 3 != 0:  # !=0
    print(0)
    exit()

pascal_depth = int((X + Y) / 3)  # パスカルの三角形に当たるn
x, y = int((X + Y) * 2 / 3), (X + Y) / 3
pascal_k = x - X  # 端からいくつずれているか

if pascal_k > pascal_depth / 2:
    pascal_k = pascal_depth - pascal_k


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inverse = [0, 1]  # 逆元テーブル計算用テーブル

    for i in range(2, n + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)
    return g1[n] * g2[r] * g2[n - r] % mod


a = cmb(pascal_depth, pascal_k, MOD)
print(a)


Measured memory_bytes: 82452
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/4/ITP1_4_A


def main():
    a, b = (int(e) for e in input().split())
    d = int(a / b)
    r = a % b
    f = a / b
    print(f"{d} {r} {f:.5f}")


if __name__ == "__main__":
    main()



Measured memory_bytes: 5632
C = [list(map(int, input().split())) for _ in range(3)]
flag = True
for i in range(2):
    if C[i+1][0]-C[i][0] == C[i+1][1]-C[i][1] and C[i+1][0]-C[i][0] ==  C[i+1][2]-C[i][2]:
        pass
    else:
        flag = False

for i in range(2):
    if C[0][i+1]-C[0][i] == C[1][i+1]-C[1][i] and C[0][i+1]-C[0][i] ==  C[2][i+1]-C[2][i]:
        pass
    else:
        flag = False

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        for (int i = 0; i < n; i++) {
            sc.nextInt();
        }
        int i = 1;
        int tmp = m - 1;
        while (m < n) {
            i++;
            m += tmp;
        }
        System.out.println(i);
    }
}


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

#define F first
#define S second
#define nl '\n'
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using ll  = long long;
using ull = unsigned long long;
using vi  = vector<int>;
using vl  = vector<ll>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvl = vector<vl>;
using ii  = pair<int, int>;
using vii = vector<ii>;
using vs  = vector<string>;
using msi = map<string, int>;
using iss = istringstream;

int main()
{
    FASTIO;
    int n; cin >> n;
    string tmp;

    vs verdicts = {"AC", "WA", "TLE", "RE"};

    msi cnts;
    for(string v : verdicts) cnts[v] = 0;

    rep(i, 0, n-1) {
        cin >> tmp;
        cnts[tmp]++;
    }

    for(string v : verdicts)
        cout << v << " x " << cnts[v] << nl;

    return 0;
}


Measured memory_bytes: 3660
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int A[3][3];
bool s[3][3] ={};
int N;
signed main(){
	rep(i, 3)
		rep(j, 3)
		cin >> A[i][j];
	cin >> N;
	rep(i, N){
		int b;
		cin >> b;
		rep(j, 3)
			rep(k, 3)
			if(A[j][k] == b) s[j][k] = true;
	}
	bool flg;

	rep(i, 3){
		flg = true;
		rep(j, 3) flg &= s[i][j];
		if(flg){
			cout << "Yes" << endl;
			return 0;
		}

		flg = true;
		rep(j, 3) flg &= s[j][i];
		if(flg){
			cout << "Yes" << endl;
			return 0;
		}
	}
	flg = true;
	rep(i, 3) flg &= s[i][i];
	if(flg){
		cout << "Yes" << endl;
		return 0;
	}
	flg = true;
	rep(i, 3) flg &= s[2-i][i];
	if(flg){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
int W,n;
int dno=0;
int v[1000],w[1000];
int dp[1001][1001];
int r(int i,int j){
  int rv;
  if(dp[i][j]>=0) return dp[i][j];
  if(i==n) rv=0;
  else if(j<w[i]) rv=r(i+1,j);
  else  rv=max(r(i+1,j),r(i+1,j-w[i])+v[i]);
  dp[i][j]=rv;
  return rv;
}
int main(){
  while(1){
    dno++;
    cin>>W;
    if(W==0) break;
    cin>>n;
    for(int i=0;i<n;i++) scanf("%d,%d",&v[i],&w[i]);
    memset(dp,-1,sizeof(dp));
    cout<<"Case "<<dno<<":"<<endl;
    int aw=0;
    for(int i=W;i>0;W--){
      if(aw>r(0,W)) break;
      aw=r(0,W);
    }
    cout<<aw<<endl;
    cout<<W+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 5216
import numpy as np
import sys

input = sys.stdin.readline

A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if  (a*500 + b*100 + c*50) == X:
                ans+=1

print(ans)

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

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p){
  ll n=solveLinear(a,p,1);
  n=n%p;
  if(n<0)return n+p;
  return n;
}
 
int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int p[3]={0};
  int q[n]={0};
  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      if(p[j]==a[i]){
        q[i]++;
      }
    }
    for(j=0;j<3;j++){
      if(p[j]==a[i]){
        p[j]++;
        break;
      }
    }
  }
  ll prod=1;
  for(i=0;i<n;i++){
    prod=(prod*q[i])%MOD;
  }
  cout<<prod<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#define EPS (1e-7)
using namespace std;





int main() {

	int N, K;
	int ans = 0;
	cin >> N >> K;

	vector<int> A(200001,0);
	vector<int> B;
	B.reserve(200001);
	int temp;
	for (auto i = 0; i < N; i++)
	{
		cin >> temp;
		A[temp] += 1;
	}
	sort(A.begin(), A.end(), greater<int>());
	int kind = 0;
	for (auto i = 0; i < 200001; i++)
	{
		if (A[i] > 0) { 
			kind += 1; 
			B.push_back(A[i]);
		}
		else break;
	}
	sort(B.begin(), B.end());

	int i = 0;
	while (K < kind) {

		ans += B[i];

		kind -= 1;
		i += 1;
	}



	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N, K, Q;
	cin >> N >> K >> Q;

	vector<int> A(N), ans(N, K - Q);
	for (int i = 0; i < Q; i++) {
		int a;
		cin >> a;
		a--;
		ans[a]++;
	}

	for (int i = 0; i < N; i++) {
		if (ans[i] > 0) cout << "Yes" << "\n";
		else cout << "No" << "\n";
	}

	return 0;
}

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

int main() {
	string st,mid,last;
	cin>>st>>mid>>last;
	int a,b;
	a=st.length();
	b=mid.length();
	if(st.at(a-1)==mid.at(0) && mid.at(b-1)==last.at(0)){cout<<"YES";}
	else {cout<<"NO";}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int x, y;

	while(1){
		scanf("%d %d", &x, &y);
			if(x==0 && y==0)break;
				if(x<y){
			printf("%d %d\n", x, y);
			}

		else{
			printf("%d %d\n", y, x);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <ctype.h>

int main(void)
{
    char ch;
    
    while((ch=getchar())!=EOF){
        if(isupper(ch)){
            putchar(tolower(ch));
        }
        else{
            putchar(toupper(ch));
        }
    }
    
    return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;

public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
   int     N = scan.nextInt();
   long a=1;
        long b=1;
       long c=1;
        for(int i=0;i<N;i++){
            a=(a*10)%1000000007;
            b=(b*9)%1000000007;
            c=(c*8)%1000000007;

        }
   a=a-2*b+c;
        while(a<0){a=a+1000000007;}
        System.out.println(a);
    }
}


Measured memory_bytes: 27212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

int main(void){
  int n,a,b;
  cin>>n>>a>>b;

  a*=n;

  if(a>b){
    cout<<b<<endl;
  }
  else{
    cout<<a<<endl;
  }

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

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

const int INF = 1e9;
vector<ll> h;
ll N,A,B;

bool check(ll X){
    auto h2 = h;
    //まとめて爆風を処理
    rep(i,N){
        h2[i] = max(0LL, h[i]-X*B);
    }
    //個々にA-Bずつ減らしていく
    ll cnt = 0;
    rep(i,N){
        cnt += h2[i]/(A-B);
        if(h2[i]%(A-B)!=0){
            cnt++;
        }
    }
    return cnt<=X;
}

int main() {
    cin>>N>>A>>B;
    h.resize(N);
    rep(i,N)cin>>h[i];
    ll ng = 0, ok = INF;
    while(ok - ng > 1){
        ll mid = (ok+ng)/2;
        if(check(mid)){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    cout<<ok<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
char s[maxn];
int n;
ll ans;
int cnt[30];
vector<int> pos[30];
int bit[maxn];
inline void add(int x,int v)
{
	x++;
	while(x<maxn)
	{
		bit[x]+=v;
		x+=x&-x;
	}
}
inline int sum(int x)
{
	x++;
	int ret=0;
	while(x>0)
	{
		ret+=bit[x];
		x-=x&-x;
	}
	return ret;
}
void move(int fr,int to)
{
	cout<<"move "<<fr<<" "<<to<<endl;
	fr=fr-sum(fr);
	cout<<"rmove "<<fr<<" "<<to<<endl;
	assert(fr<=to);
	ans+=to-fr;
	if(fr==to)return;
	cout<<"addinterval "<<fr+1<<" "<<to<<endl;
	add(fr+1,1);
	add(to+1,-1);
}
int res[maxn];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
		cnt[s[i]-'a']^=1;
	int one=0,onepos;
	for(int i=0;i<26;i++)
		if(cnt[i])one++,onepos=i;
	if(one>1)
	{
		printf("-1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
		pos[s[i]-'a'].push_back(i);
	for(int i=0,j=0;i<(n)/2;i++,j++)
	{
		int ch=s[j]-'a';
		int po=lower_bound(pos[ch].begin(),pos[ch].end(),j)-pos[ch].begin();
		int no=pos[ch].size()-1-po;
	//	cout<<i<<" "<<j<<" "<<ch<<" "<<po<<" "<<no<<endl;
		if(po==no)
		{
		//	cout<<"place "<<j<<" "<<n/2<<endl;
			res[n/2]=j;
			i--;
		//	move(i,n/2+1);
		}
		else if(po<no)
		{
		//	cout<<"place "<<i<<" "<<j<<" "<<n-1-i<<" "<<pos[ch][no]<<endl;
			res[i]=j;
			res[n-1-i]=pos[ch][no];
		//	move(pos[ch][no],n-1-i);
		}
		else
		{
			i--;
			continue;
		}
	}
	if(!res[n/2])
	{
		res[n/2]=pos[onepos][pos[onepos].size()/2];
	}
	for(int i=0;i<n;i++)
	{
	//	cout<<i<<" "<<res[i]<<endl;
		ans+=i-sum(res[i]);
		add(res[i],1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#define intt long long

int main() {
	std::string S; std::cin >> S;
	int N = S.size();
	std::vector<int> COUNT(N);
	for (int i = 0; i < N; ++i) {
		int count1 = 0;
		if (S[i] == 'R') {
			int j;
			for (j = i; j < N; ++j) {
				++count1;
				if (S[j] == 'L') {
					i = j;
					--count1;
					break;
				}
			}
			if (count1 % 2 == 1) {
				COUNT[j] += count1 / 2;
				COUNT[j - 1] += (count1 / 2) + 1;
			}
			else {
				COUNT[j] += count1 / 2;
				COUNT[j - 1] += count1 / 2;
			}
		}
	}
	std::reverse(S.begin(), S.end());
	std::reverse(COUNT.begin(), COUNT.end());
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'L') {
			int j;
			int count2 = 1;
			for (j = i; j < N; ++j) {
				if (S[j] == 'R') {
					--count2;
					i = j;
					break;
				}
				else
					++count2;
			}
			if (count2 % 2 == 1) {
				COUNT[j] += count2 / 2;
				COUNT[j - 1] += (count2 / 2) + 1;
			}
			else {
				COUNT[j] += count2 / 2;
				COUNT[j - 1] += count2 / 2;
			}
		}
	}
	std::reverse(S.begin(), S.end());
	std::reverse(COUNT.begin(), COUNT.end());

	for (int i = 0; i < N; ++i) {
		if (i > 0)
			std::cout << " ";
		std::cout << COUNT[i];
	}
	std::cout << std::endl;

	return 0;
}

Measured memory_bytes: 3840
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int dist[201][201];
int N, M, R;

int main() {
    cin >> N >> M >> R;
    vector<int> r(R);
    for (int i = 0; i < R; ++i) {
        cin >> r[i];
    }
    sort(r.begin(), r.end());
    fill((int *)dist, (int *)(dist + 201), inf);
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        dist[a][b] = dist[b][a] = c;
    }
    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int ans = inf;
    do {
        int d = 0;
        for (int i = 1; i < R; ++i) {
            d += dist[r[i - 1]][r[i]];
        }
        ans = min(d, ans);
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp1[333][333*333];
ll dp2[333][333*333];

void modadd(ll &a, ll b){
    a += b;
    a %= MOD;
}

void cal_dp1(vector<int> v){
    dp1[0][0] = 1;
    int n = v.size();
    REP(i, n){
        REP(j, (i+1)*333)if(dp1[i][j]){
            modadd(dp1[i+1][j], dp1[i][j] * 2);
            modadd(dp1[i+1][j + v[i]], dp1[i][j]);
        }
    }
}

void cal_dp2(vector<int> v){
    dp2[0][0] = 1;
    int n = v.size();
    REP(i, n){
        REP(j, (i+1)*333)if(dp2[i][j]){
            modadd(dp2[i+1][j], dp2[i][j]);
            modadd(dp2[i+1][j + v[i]], dp2[i][j]);
        }
    }
}
int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

    int n;cin >> n;
    ll sum = 0;
    vector<int> v(n);
    REP(i, n)cin >> v[i], sum += v[i];
    cal_dp1(v);
    cal_dp2(v);

    ll A = 1;
    ll B = 0;
    ll C = 0;
    REP(i, n)A = (A * 3) % MOD;
    REP(i, 333*333)if(i >= (sum+1) / 2)modadd(B, dp1[n][i]);
    if(sum % 2 == 0)C = dp2[n][sum / 2];

    ll ans = (10LL * MOD + A - 3 * B + 3 * C) % MOD;
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 524544
//Template
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

int main() {
	string s; cin >> s;
	ll a = 0;
	ll ans = 0;

	rep(i, 0, s.size()) {
		if (s[i] == 'A') {
			if (i != 0 && s[i - 1] != 'A') {
				a = 1;
			}
			else {
				a++;
			}
		}
		else if (s[i] == 'C') {
			if (i >= 2 && (s[i - 1] == 'B' && s[i - 2] == 'A')) {
				ans += a;
				s[i] = 'A';
			}
			else {
				a = 0;
			}
		}
		else if (s[i] == 'B') {
			if (i != 0 && s[i - 1] != 'A') {
				a = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  vector<string> s;
  string buf;
  while(cin>>buf, buf!="0"){
    s.push_back(buf);
  }

  for(int i=0; i<(int)s.size(); i++){
    int re=0;
    for(int j=0; j<s[i].length(); j++){
      re += s[i][j]-'0';
    }
    cout << re << endl;
  }

  return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,n) cin>>a[i];
  sort(a,a+n);
  rep(i,n){
    //cout<<a[i]<<" ";
  }
  //cout<<endl;
  int l=1,r=1000000000;
  int mid=(l+r)/2;
  while(l!=r){
    int cnt=0;
    rep(i,n){
      //cout<<(a[i]+mid-1)/mid<<" ";
      cnt+=(a[i]+mid-1)/mid;
      cnt--;
    }
    //cout<<endl;
    //cout<<mid<<" "<<cnt<<endl;
    if(cnt>k) l=mid+1;
    else r=mid;
    mid=(r+l)/2;
  }
  cout<<min(mid,a[n-1])<<endl;
  return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug_x(x) cout<< #x <<"---> : "<<x<<endl;
#define debug_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll mod=1e7;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll _;
/***********************/

int main(){
    //ssd;
    int a, b,h,w;
    cin>>a>>b>>h>>w;
    double pi = 2*asin(1.0);
    printf("%4.10f",sqrt(a*a+b*b -2*a*b*cos((h*30-w*5.5)*pi/180)));
    return 0;
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define revv(V) reverse(allv(V))
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 205;

int A[MAXN];

vector<int> Ans;

int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];
	
	for(int t = 0; t <= N; t++) {
		vector<int> V;
		for(int i = 2; i <= N; i++) {
			if(A[i-1] > A[i]) {
				swap(A[i-1], A[i]);
				V.eb(i-1);
			}
		}
		if(V.empty()) break;

		for(int t = 0; t < V[0]; t++) Ans.eb(1);
		Ans.eb(N-1);
		for(int i = 1; i < sz(V); i++) {
			for(int t = 0; t < V[i]-V[i-1]; t++) Ans.eb(1);
			Ans.eb(N-1);
		}
		for(int t = 0; t < N-V.back(); t++) Ans.eb(1);
	}

	printf("%d\n", sz(Ans));
	for(int v : Ans) printf("%d\n", v);
	return 0;
}

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

int main(){
    string n;
    cin>>n;
    for(int i=0;i<3;i++){
        if(n[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
  int n,k;
  cin>>n>>k;
  vi p(n);
  rep(i,n) cin>>p[i];
  sort(all(p));
  int ans=0;
  rep(i,k) ans+=p[i];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3624
// "for if God is with them who can be against them."
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
void solve() {
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll>a(n);
	vector<ll>b(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	ll ans = 0, res = 0;
	vector<ll>prea(n);
	vector<ll>preb(m);
	ll ind = -1;
	prea[0] = a[0];
	if (prea[0] <= k) {
		ans++;
		ind = 0;
	}
	preb[0] = b[0];
	for (int i = 1; i < n; i++) {
		prea[i] = a[i] + prea[i - 1];
		if (prea[i] <= k) {
			//cout << prea[i] << endl;
			ans++;
			ind = i;
		}
	}
	REP(i, 1, m - 1) {
		preb[i] = b[i] + preb[i - 1];
	}
	if (ind == -1) {
		auto it = upper_bound(all(preb), k);
		if (it != preb.end()) {
			cout << (it - preb.begin());
		}
		else
			cout << m;
		return;
	}
	//cout << ans << endl;
	res = max(res, ans);
	for (int i = ind; i >= 0; i--) {
		auto it = upper_bound(all(preb), k - prea[i]);
		if (it != preb.end()) {
			res = max(res, ll(ans + int(it - preb.begin())));
		}
		else
			res = max(res, ll(ans + m));
		ans--;
	}
	auto it = upper_bound(all(preb), k);
	if (it != preb.end()) {
		res = max(res, ll(it - preb.begin()));
	}
	else
		res = max(res, m);
	cout << res;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}


#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

Measured memory_bytes: 9508
#!/usr/bin/env pypy3

import sys
sys.dont_write_bytecode = True
stdin = sys.stdin
input = stdin.readline
#sys.setrecursionlimit(100000)

#import numpy as np
#import scipy as sp

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5.  Import from math after it.
from fractions import gcd
from fractions import Fraction as Frac

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(func = input, sep = None, conv = int):
    return list(map(conv, func().split(sep = sep)))

################################################################################

N, = list(map(int, input().split()))
W = list(map(int, input().split()))
i1 = 0
i2 = N - 1
S1 = S2 = 0
T = None
while i1 <= i2:
    if S1 < S2:
        S1 += W[i1]
        i1 += 1
    else:
        S2 += W[i2]
        i2 -= 1
print(abs(S1 - S2))


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,b,c,d,e,f,g,h;
    while(cin>>a>>b>>c>>d>>e>>f){
            h=0;g=0;
    h=(d*c-a*f)/(b*d-a*e);
    g=(c-b*h)/a;
    printf("%.3lf %.3lf\n",g,h);
    }
    return 0;

}

Measured memory_bytes: 3092
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int ceil(int a){
	return a % 2 ? a / 2 + 1 : a / 2;
}
int main() {
	int n, k, a, b;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < k; i++){
		scanf("%d%d", &a, &b);
		if (a > ceil(n))a = n - a + 1;
		if (b > ceil(n))b = n - b + 1;
		printf("%d\n", min(a, b) % 3 ? min(a, b) % 3 : 3);
	}
}

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

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint a,b;
char op;

void solve(){
  while(1){
    cin >> a >> op >> b;
    if(op=='?')break;
    if(op=='+')cout << a+b;
    if(op=='-')cout << a-b;
    if(op=='*')cout << a*b;
    if(op=='/')cout << a/b;
    cout << endl;
  }
}

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



Measured memory_bytes: 3096
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

m = 0
ba = -1
for ai in a:
    m = m + b[ai-1]
    if ba + 1 == ai:
        m = m + c[ba-1]
    ba = ai
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256