akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
using namespace std;

int main(){
    //n;都市数　m;経路数
    int n, m;
    cin >> n >> m;
    int L[51][51] = {0};

    //経路数だけ回す
    //int r, c;
    for(int i=0; i < m; i++){
        int r = 0;
        int c = 0;
        cin >> r >> c;
        r -= 1;
        c -= 1;
        L[r][c] += 1;
    }


    //行
    int row[n] = {0};
    for(int i=0; i < n; i++){
        for(int j=0; j < n; j++){
            int tmp = L[i][j];
            row[i] += tmp;
        }
    }

    //列
    int column[n] = {0};
    for(int i=0; i < n; i++){
        for(int j=0; j < n; j++){
            int tmp = L[j][i];
            column[i] += tmp;
        }
    }

    //ans
    for(int i=0; i < n; i++){
        cout << row[i] + column[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
class BIT():

    __slots__ = ["n", "data"]

    def __init__(self, length_or_list):
        if isinstance(length_or_list, int):
            self.n = length_or_list + 1
            self.data = [0] * self.n
        else:
            self.n = len(length_or_list) + 1
            self.data = [0] + length_or_list
            for i in range(1, self.n):
                if i + (i & -i) < self.n:
                    self.data[i + (i & -i)] += self.data[i]        

    def point_append(self, index, delta):
        index += 1
        while index < self.n:
            self.data[index] += delta
            index += index & -index
        
    def prefix_folded(self, end):
        res = 0
        while end > 0:
            res += self.data[end]
            end -= end & -end
        return res

    def folded(self, begin, end):
        ret = 0
        while begin < end:
            ret += self.data[end]
            end -= end & -end
        while end < begin:
            ret -= self.data[begin]
            begin -= begin & -begin
        return ret

def main():
    import sys
    input = sys.stdin.buffer.readline

    N, Q = map(int, input().split())
    bit = BIT(list(map(int, input().split())))
    ans = []
    for _ in range(Q):
        a, b, c = map(int, input().split())
        if a:
            ans.append(bit.folded(b, c))
        else:
            bit.point_append(b, c)

    print('\n'.join(map(str, ans)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 169428
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<bool> good(N, true);
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(H[a] >= H[b]) good[b] = false;
        if(H[b] >= H[a]) good[a] = false;
    }
    int ans = 0;
    for(int i = 0; i < N; i++) ans += good[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

typedef vector <vector <int>> matrix;

const int MOD = 1e9 + 7;
 
matrix operator*(const matrix& a, const matrix& b) {
    matrix ans(a.size(), vector <int> (b[0].size()));
    for (int i = 0; i < a.size(); i++)
        for (int j = 0; j < b[0].size(); j++)
            for (int k = 0; k < b.size(); k++)
                ans[i][j] = (ans[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
    return ans;
}
 
matrix power(matrix a, long long m) {
    matrix ans(a.size(), vector <int> (a.size()));
    for (int i = 0; i < (int)a.size(); i++)
        ans[i][i] = 1;
    while (m) {
        if (m % 2) {
            ans = ans * a;
            m--;
        } else {
            a = a * a;
            m /= 2;
        }
    }
    return ans;
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    long long k;
    cin >> n >> k;
    matrix gr(n, vector <int> (n));
    cin >> gr;
    gr = power(gr, k);
    int ans = 0;
    forn (i, 0, n)
        forn (j, 0, n)
            ans = (ans + gr[i][j]) % MOD;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[ans]);
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define GODSPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;
inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
signed main()
{
     GODSPEED;
     int n,k,x,y;
     cin>>n>>k>>x>>y;
     if(n>=k)
     {
         cout<<x*k+(n-k)*y<<endl;
     }
     else
      cout<<x*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
void Yay(bool condition){

    if(condition){
        p("Yay!");
    }else{
        p(":(");
    }
    return;
}

//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[500005],y[500005],z[500005];
long double l[5000];
char s[500005],t[500005];
ll ans;

bool flag,dame;
ll timesize = 0;
ll xmin = INF,xmax = -INF,ymin = INF,ymax = -INF;
ll flag_num = 0;
bool float_flag = false;

int main(){
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	for(i=0;i<=n;i++){
		if(i == 0){
			num = 0;
		}else{
			num = x[i-1] + num;
		}
		if(num <= k)ans++;
	}
	p(ans);
	
	return 0;
}


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

using namespace std;

int n , m = 0;
string  s , t;
int H = 0;
bool a=1;

int main () {
	
	cin >> n >> s >> t;
	
	for (int i = (n-1) ; i >= 0 ; i--){
		for (int j = 0 ; j <= i ; j++){
			if(s[j+m] == t[j]){
				H++;
			}
			else{
				H=0;
				a=0;
				break;
			}
		}
		m++;
		if(a){
			break;
		}
		a=1;
	}
	
	cout<<(2*n)-H<<endl;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[100],j,k;
int main(){
  for(cin>>n;j<n;j++)cin>>a[j];
  sort(a,a+n,greater<int>());
  for(j=0;j<n;j+=2)k+=a[j]-a[j+1];
  cout<<k<<endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  pK K - Multiple Gift
//
//  Created by Hsiu-Fen Chou on 2019/12/20.
//  Copyright © 2019 Hsiu-Fen Chou. All rights reserved.
//

#include <iostream>
using namespace std;

int main() {
    long long X, Y;
    cin >> X >> Y;
    int cnt = 1;
    while (X*2 <= Y){
        X *= 2;
        cnt++;
    }
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int h[100001];
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	bool ok = true;
	for(int i = n - 2; i >= 0; i--){
		if(h[i] <= h[i + 1]) continue;
		else if(h[i] == h[i + 1] + 1) h[i] = h[i + 1];
		else ok = false;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        char[] d = s.toCharArray();
        for(int i = 0; i < d.length; i++) {
            if (d[i] != '1'  && d[i] != '9') {
                continue;
            }
            d[i] = d[i] == '1' ? '9' : '1';
        }
        System.out.println(d);
    }
}


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

int main(){
  int a, b;
  char op;
  cin >> a >> op >> b;
  if(op=='+'){
    cout << a+b;
  }
  else if(op=='-'){
    cout << a-b;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,j,n) for(int i=j; i<n; i++)
#define INF 1000000000000000000 // If you use it, make sure not to put in "int" type variable ;(, use long long int
void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
const ll mod=1000000007;
 
int main()
{
    optimizeIO();
    int nT; nT=1;
	while(nT--)
	{
		ll n; cin>>n;
		ll a[n], b[n], c[n-1], ans=0; 
		rep(i,0,n) { cin>>a[i]; a[i]--; }
		rep(i,0,n) cin>>b[i];
		rep(i,0,n-1) cin>>c[i];
		rep(i,0,n) ans+=b[a[i]];// if(i!=0 && a[i]==a[i-1]+1) ans+=c[i]; }
		for(int i=1; i<n; i++) if(a[i]-a[i-1]==1) ans+=c[a[i]-1];
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
t_score = 0
h_score = 0
for _ in range(n):
    taro, hana = input().split()
    if taro > hana:
        t_score+=3
    elif taro < hana:
        h_score+=3
    else:
        t_score+=1
        h_score+=1
print(t_score, h_score)


Measured memory_bytes: 5592
//Inbornhandsome
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define endl '\n'
#define int long long

int32_t main()
{
    IOS; //FIO;
    string s, t;
    cin >> s >> t;

    int l1 = s.length(), l2 = t.length();
    int cache[l1+5][l2+5], i, j;

    for(i = 0; i < l1+5; i ++)  cache[i][0] = 0;
    for(i = 0; i < l2+5; i ++)  cache[0][i] = 0;

    for(i = 1; i <= l1; i ++) {
        for(j = 1; j <= l2; j ++) {
            if(s[i-1] == t[j-1]) 
                cache[i][j] = 1 + cache[i-1][j-1];
            else 
                cache[i][j] = max(cache[i-1][j], cache[i][j-1]);
        }
    }

    i = l1, j = l2;
    string ans;

    while(i > 0 and j > 0) {
        if(s[i-1] == t[j-1]) {
            ans = s[i-1] + ans;
            i --, j -- ;
        }
        else if(cache[i-1][j] > cache[i][j-1])
            i --;
        else 
            j --;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 70784
S = input()
Acount = 0
count = 0
AKIBA = ["K", "I", "H", "B", "R"]
AKIBAcount = [1, 0, 0, 1, 1]
flag = 1
for i in range(len(S)):
    if count == 5:
        if S[i] == "A":
            Acount += 1
        else:
            flag = 0
        if Acount >= 2:
            flag = 0

    if S[i] == "A":
        Acount += 1
    else:
        if count <= 4:
            if S[i] == AKIBA[count] and Acount <= AKIBAcount[count]:
                count += 1
                Acount = 0
            else:
                flag = 0
                break

if flag == 1 and count == 5:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
from itertools import groupby, accumulate, product, permutations, combinations
from bisect import *
def calc(p,q):
  ind = bisect_right(cum,(cum[q]+cum[p])/2)
  M = cum[ind]-cum[p]
  if ind>0:
    M = min(M,cum[q]-cum[ind-1])
  m = cum[q]-cum[p] - M
  return M, m
ans = float('inf')
N = int(input())
A = list(map(int, input().split()))
cum = [0]+list(accumulate(A))
for i in range(2,N-1):
  lis = [*calc(0,i),*calc(i,N)]
  ans = min(ans,max(lis)-min(lis))
print(ans)

Measured memory_bytes: 110496
N,K = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
p = [1]*41

for i in range(40):
	p[i+1] = p[i]*2

small = False
ans = 0
x = 0
for i in range(41):
	t = p[40-i]
	if x+t>K:
		cnt = 0
		for j in range(N):
			if A[j]&t == t:
				cnt += 1
		ans += cnt*t
	else:
		cnt = 0
		for j in range(N):
			if A[j]&t == t:
				cnt += 1
		if cnt <= N/2:
			x += t
		ans += max(cnt,N-cnt)*t
print(ans)



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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define ll long long
typedef pair<int, int> ii;
const int N = 1e3 + 10;
const int M = 2e4 + 5;
struct book {
    int w, maxn, val;
} t[N];
int n;
ll f[N][M], ans;

bool cmp(const book x, const book y) {
    return (x.w + x.maxn < y.w + y.maxn);
}
signed main()
{
    //freopen("test.inp", "r", stdin);
    scanf("%d", &n);
    FOR(i, 1, n) scanf("%d%d%d", &t[i].w, &t[i].maxn, &t[i].val);
    sort(t + 1, t + n + 1, cmp);

    FOR(i, 1, n) FOR(j, 1, 20000) {
        f[i][j] = f[i - 1][j];
        if(j >= t[i].w && t[i].maxn >= j - t[i].w)
            f[i][j] = max(f[i][j], f[i - 1][j - t[i].w] + 1ll * t[i].val);
        ans = max(ans, f[i][j]);
    }
    printf("%lld", ans);
}


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

int main() {
  string s;
  ll k;
  cin >> s >> k;
  --k;
  int i;
  char c;
  for (i = 0; i < s.size(); ++i) {
    if (s[i] != '1') {
      c = s[i];
      break;
    }
  }
  if (k < i) cout << '1' << endl;
  else cout << c << endl;
  return 0;
}

Measured memory_bytes: 3612
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define loopinc(i, a, b, inc) for(int i = a; i < (b); i += inc)
#define loop(i, a, b) for(int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define rrep(i, n) for (int i = n-1; i >= 0; i--)
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define lloopinc(i, a, b, inc) for(ll i = a; i < (b); i += inc)
#define lloop(i, a, b) for(ll i = a; i < (b); i++)
#define lrep(i, n) lloop(i, 0, n)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> tiii;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector<bitset<5000>> flags(k);
	loop(i, 1, k) rep(j, n) flags[i][j] = true;
	vi arr(n);
	bitset<5000> tmp;
	rep(i, n) {
		int a;
		cin >> a;
		arr[i] = a;
		rrep(j, k-a) if (!flags[j][i]) {
			tmp.reset();
			tmp = flags[j];
			tmp[i] = true;
			flags[j+a] &= tmp;
		}
	}
	int total = n;
	rep(i, n) for (int j = k-1; j >= k-arr[i]; j--) if (!flags[j][i]) {
		total--;
		break;
	}
	cout << total << endl;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


vec a(100005, 0);

void solve() {
    int N; cin >> N;
    int fir; cin >> fir;
    ll md = 998244353;
    if(fir != 0){
        cout << 0 << endl;
        return;
    }
    
    int ma = 0;
    rep(i, N-1){
        int d; cin >> d;
        a[d]++;
        ma = max(ma, d);
    }
    if(a[0] != 0){
        cout << 0 << endl;
        return;
    }

    ll res = 1;
    rep1(i, ma-1){
        res = modint(modint(res) * modint(mod_pow(a[i], a[i+1], mod)));
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

//ll chk[55];
//ll num[55];
//ll num2[55];
//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
priority_queue<long long int> pq;   //�j���\�e��
//stack<int> stk;
//vector<pair<ll,ll>> vint;
//vector<ll> vtime;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//map<ll,ll> mp;



int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3,range;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    a=a1=a2=a3=a4=a5=a6=0;
    //float f,g,h;
    //string s,s1;
    //char now,pre,c;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>a;
        pq.push(a);
    }
    for(i=0;i<m;i++)
    {
        pq.pop();
        if(pq.size()==0)
        {
            cout<<0;
            return 0;
        }
    }
    while(1)
    {
        sum+=pq.top();
        pq.pop();
        if(pq.size()==0) break;
    }
    cout<<sum;
    return 0;
}





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

using namespace std;

#define X first
#define Y second
#define ll long long
#define inf (ll)1e18
const int mod = (int)1e9 + 7;
#define all(x) x.begin(), x.end()

const int N = 1000060;
const int MX = 200020;

int center[2222];
double h[2222];

int main(){
/*
     ___     ___
    (^_^)   (^_^)
   /( | )\ /( | )\
     | |     | |
*/
    cin.tie(0);
    cin.sync_with_stdio(0);

    #ifdef Cyborg101
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

     int a, b;
     cin >> a >> b;
     string s;
     cin >> s;

     bool ok = s[a] == '-';
    for(int i = 0; i < s.size(); ++i){
    	if(i == a) continue;
    	char c = s[i];
    	ok &= (c >= '0' && c <= '9');
    }

   puts(ok ? "Yes" : "No");

   	return 0;
}

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

using namespace std;
//using namespace __gnu_pbds;

#define LL       long long
#define DS       pair<int, int>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && c != a) {
        puts("Yes");
    } else if (a == c && a != b) {
        puts("Yes");
    } else if (b == c && b != a) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <iomanip>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
const int N = 5e6;
const long long LINF = 1e15;
long long road[210][210];
int city[210];
int main() {
	int n, m, r;
	scanf("%d%d%d", &n, &m, &r);
	for (int i = 0; i < r; i++) {
		scanf("%d", &city[i]);
	}
	sort(city, city + r);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			road[i][j] = LINF;
		}
		road[i][i] = 0;
	}
	for (int i = 1; i <= m; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		road[a][b] = c;
		road[b][a] = c;
	}
	long long ans = LINF;
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
			}
		}
	}

	do {
		long long res = 0;
		for (int i = 1; i < r; i++) {
			res += road[city[i - 1]][city[i]];
		}
		ans = min(ans, res);
	} while(next_permutation(city, city + r));
	cout << ans;
  return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K, C; cin >> N >> K >> C;
    string S; cin >> S;
    pair<int, int> left_work[N+1], right_work[N+1];
    left_work[0] = make_pair(0, -mod);
    right_work[N] = make_pair(0, mod);
    for(int i = 0; i < N; i++){
        if(S[i] == 'o'){
            int prev_work = left_work[i].second;
            if(i-prev_work > C) left_work[i+1] = make_pair(left_work[i].first+1, i);
            else left_work[i+1] = left_work[i];
        }
        else left_work[i+1] = left_work[i];
    }
    for(int i = N; i > 0; i--){
        if(S[i-1] == 'o'){
            int next_work = right_work[i].second;
            if(next_work - (i-1) > C) right_work[i-1] = make_pair(right_work[i].first+1, i-1);
            else right_work[i-1] = right_work[i];
        }
        else right_work[i-1] = right_work[i];
    }
    //rep(i, N+1) cout << right_work[i].first; cout << endl;

    vector<int> ans;
    rep(i, N){
        if(S[i] == 'o' && left_work[i].first + right_work[i+1].first < K) ans.push_back(i+1);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}

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

template<int64_t MOD> struct Mint {
    int64_t v;
    Mint() { v = 0; }
    Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

    Mint operator-() { return Mint{-v}; };
    Mint operator+(Mint x) { return Mint(v + x.v); };
    Mint operator-(Mint x) { return Mint(v - x.v); };
    Mint operator*(Mint x) { return Mint(v * x.v); };
    Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

    Mint& operator+=(Mint x) { return *this = (*this + x); };
    Mint& operator-=(Mint x) { return *this = (*this - x); };
    Mint& operator*=(Mint x) { return *this = (*this * x); };
    Mint& operator/=(Mint x) { return *this = (*this / x); };

    static Mint pow(Mint base, int64_t exp) {
        if(exp == 0)  return Mint(1);
        return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
    }

    friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

int main() {
    lint n;
    cin >> n;

    vector<lint> a(n);
    for(lint i=0; i<n; i++)  cin >> a[i];

    mint ans = 0;
    for(lint i=0; i<60; i++) {
        map<lint, mint> mp;
        for(auto e : a) {
            mp[(e>>i)%2] += mint{1};
        }

        ans += mp[0] * mp[1] * mint::pow(2, i);
    }

    cout << ans << endl;
}

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

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for (int i = 0; i < N; i++) std::cin >> a[i];

    int cnt = 0;
    int tgt_num = 1;
    for (int i = 0; i < N; i++)
    {
        if (a[i] == tgt_num) tgt_num++;
        else cnt++;
    }
    
    if (tgt_num == 1) std::cout << -1 << std::endl;
    else std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int m = a[n / 2-1];
	int k = a[n / 2 ];
	cout << k - m << endl;

}

Measured memory_bytes: 640
import sys
import 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

N = INT()
S = [input() for _ in range(N)]

S_head = []
for s in S:
    if s[0] in ['M', 'A', 'R', 'C', 'H']:
        S_head.append(s[0])

S_head_c = Counter(S_head)
ans = 0
for i in list(combinations(['M', 'A', 'R', 'C', 'H'], 3)):
    tmp = 1
    for j in i:
        tmp *= S_head_c[j]
    ans += tmp

print(ans)


Measured memory_bytes: 18268
N = int(input())
a = list()
for i in range(N):
	a.append(int(input()))

temp = 1
count = 0
while temp != 2 and count <= 100001:
	temp = a[temp - 1]
	count += 1

if count > 100000:
	print(-1)
else:
	print(count)


Measured memory_bytes: 49240
program answer
  implicit none
  integer(8) :: i, N, count, han, ss
  character(len=10) :: S
  read(*,*) S
  N=len_trim(S)
  count=0
  do i = 3, N-1
     if(ichar(S(i:i))==67) then
        count=count+1
        han=i
     end if
  end do
 
  if(ichar(S(1:1))==65.and.count==1) then
     ss=1
     do i = 2, N
        if(i/=han) then
           if(ichar(S(i:i))<97.or.122<ichar(S(i:i))) then
              ss=0
           end if
        end if
     end do
  end if

  if(ss==1) then
     write(*,*) 'AC'
  else
     write(*,*) 'WA'
  end if

  stop
 end program answer


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

int main(){
  int n,k; cin >> n >> k;
  int num=1;
  for(int i=0;i<n;i++){
    if(num*2<num+k){
      num*=2;
    }else{
      num+=k;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

int main(){
	ll X;
	cin >> X;
	int ub=10000000, lb=0;
	while(ub-lb > 1){
		ll med = (ub+lb)/2;
		if(med*(med-1)/2 >= X){
			ub = med;
		}
		else{
			lb = med;
		}
	}

	cout << lb << endl;

	return 0;
}


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


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

	long long N, W;
	cin>>N>>W;

	vector<long long> v(N), w(N);
	for(long long i = 0; i < N; i++){
		cin>>w[i]>>v[i];
	}
	vector<vector<long long> > dp(W + 1, vector<long long>(N + 1, 0));
	for(long long i = 1; i <= W; i++){
		for(long long j = 1; j <= N; j++){
			if(w[j - 1] <= i){
				dp[i][j] = max(dp[i][j], v[j - 1] + dp[i - w[j - 1]][j - 1]);
			}
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
		}
	}
	cout<<dp[W][N]<<endl;
}


Measured memory_bytes: 85252
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int cnt=0;
    for(int i=1;i<n;i++)cnt+=(s[i]=='E');
    int ans=cnt;
    for(int i=1;i<n;i++){
	if(s[i-1]=='W')cnt++;
	if(s[i]=='E')cnt--;
	ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const long long MAXN=2e5 + 5;;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}

void solve(){
    string s = "aeiou";
    char c;
    cin >> c;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == c){
            cout << "vowel";
            return;
        }
    }
    cout << "consonant";
}


int main(){
    //freopen("slalom.in","r",stdin);
    //freopen("slalom.out","w",stdout);
    //faster();
    int n = 1;
    //cin >> n;
    while(n--){
        solve();
        cout << endl;
    }
    //fclose(stdout);
}


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

int main() {
  string s; cin >> s;
  vector<int> a(4);
  for (int i = 0; i < 4; i++) a[i] = s[i] - '0';
  
  for (int bit = 0; bit < (1<<3); bit++) {
    int sum = a[0];
    for (int i = 0; i < 3; i++) {
      if (bit & (1<<i)) sum += a[i+1];
      else sum -= a[i+1];
    }
    if (sum == 7) {
      for (int i = 0; i < 3; i++) {
        if (bit & (1<<i)) cout << s[i] << "+";
        else cout << s[i] << "-";
      }
      cout << s[3] << "=7" << endl;
      break;
    }
  }    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <chrono>
using namespace std;
 
typedef long long ll;
typedef pair<int, ll> Pl;

ll dist[100005];
vector<Pl> graph[100005];

struct Timer{
    chrono::high_resolution_clock::time_point st;

    Timer() { reset(); }

    void reset(){
        st = chrono::high_resolution_clock::now();
    }

    chrono::milliseconds::rep elapsed(){
        auto ed = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(ed - st).count();
    }
};

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

    Timer t;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int l, r;
        ll c;
        cin >> l >> r >> c;
        --l, --r;
        graph[l].push_back(Pl(r, c));
    }
    for(int i = 0; i < n-1; ++i){
        graph[i+1].push_back(Pl(i, 0));
    }
    
    fill(dist, dist+n, (ll)1e+17);
    dist[0] = 0;
    priority_queue<Pl, vector<Pl>, greater<Pl>> que;
    que.push(Pl(0, 0));
    while(!que.empty()){
        if(t.elapsed() > 1950)    break;
        Pl p = que.top();
        que.pop();
        ll d = p.first;
        int u = p.second;
        if(dist[u] < d)     continue;
        for(int i = 0; i < (int)graph[u].size(); ++i){
            int v = graph[u][i].first;
            ll cost = graph[u][i].second;
            if(dist[v] > dist[u] + cost){
                dist[v] = dist[u] + cost;
                que.push(Pl(dist[v], v));
            }
        }
    }
    if(dist[n-1] == (ll)1e+17)  dist[n-1] = -1;
    cout << dist[n-1] << "\n";
}

Measured memory_bytes: 12916
#include <iostream>
#include <fstream>
#include <vector>
#include <array>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <random>
#include <limits>
#include <string>
#include <sstream>
#include <bitset>

#include <cassert>
#include <cmath>
#include <ctime>

using namespace std;

void solve (istream &cin = std::cin, ostream &cout = std::cout)
{
    int n;

    cin >> n;

    vector<int> arr (n);

    for (auto &it : arr)
        cin >> it;

    vector<int> nz;
    nz.reserve (arr.size () + 1);

    for (int i = 0; i < arr.size (); i++)
        if (arr[i] != 0)
            nz.push_back (i);
    nz.push_back (arr.size ());

    long long ans = 0;
    int cur = 0;

    for (int i = 0; i < arr.size (); i++)
    {
        while (nz[cur] <= i)
            cur++;

        int s = 0, x = 0;
        int j = i, t = cur;

        while (j < arr.size () && s == x)
        {
            s += arr[j];
            x ^= arr[j];

            while (nz[t] <= j)
                t++;

            if (s == x)
                ans += nz[t] - j;

            j = nz[t];
        }
}

    cout << ans << endl;
}

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

#ifdef LOCAL
    solve ();

    cout << "clock: " << clock () / (double)CLOCKS_PER_SEC << endl;
#else
    solve ();
#endif

    return 0;
}


Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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

def main():
    n, m, x, y = MAP()
    x_max = max(LIST())
    y_min = min(LIST())

    for z in range(x+1, y+1):
        if x_max < z <= y_min:
            print('No War')
            sys.exit()
    print('War')


if  __name__=='__main__':
    main()


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

#define ll          long long
#define pb          push_back
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll b[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    sort(a,a+n);
    sort(b,b+n);
    reverse(a,a+n);
    ll mm,m,h = b[n-1]*a[0];
    ll l = 0;
    mm = l+(h-l)/2;
    while(l<h){
        m = l+(h-l)/2;
        //if(mm==m){m++;l++;}
        //cout<<l<<' '<<m<<' '<<h<<endl;
        ll o = k;
        int flag = 0;
        for(int i=0;i<n;i++){
            if(a[i]*b[i]>m){
                o-=(a[i]-m/b[i]);
                if(o<0){
                    flag = 1;
                    break;
                }
            }
        }
        if(flag==1){
            l = m+1;
        }
        else{
            h = m;
        }
        mm = m;
    }
    mm = l+(h-l)/2;
    cout<<mm<<endl;
}

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

#define slld(longvalue) scanf("%lld", &longvalue)
#define plld(longvalue) printf("%lld\n", longvalue)

#define slf(longvalue) scanf("%lf", &longvalue)
#define plf(longvalue) printf("%lf\n", longvalue)
#define sc(letter) scanf("%c", &letter)
#define pc(letter) printf("%c", letter)

#define ss(name) scanf("%s", name)
#define ps(name) printf("%s", name)

#define pnew printf("\n")

#define ll long long

#define printcase(indexing,ans) printf("Case %lld: %lld\n", indexing, ans)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009


using namespace std;

int main()
{
    ll i, j, k, l, m, n, o;
    ll testcase;
    ll input, flag, tag, ans;

    // freopen("in.txt", "r", stdin);

   cin >> n >> m;

   ans = n + m;

   if(ans % 3 == 0 || n % 3 == 0 || m % 3 == 0) cout << "Possible" << endl;
   else cout << "Impossible" << endl;


}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>

int main() {
	std::vector<char> v;
	v.resize(2);  //reserveがなんか…？
	std::map<char, int> mp;
	mp['A'] = 0;
	mp['B'] = 1;
	mp['C'] = 2;
	mp['D'] = 3;
	mp['E'] = 4;
	mp['F'] = 5;

	for (auto&& x : v) {
		std::cin >> x;
	}

	std::cout << (mp[v[0]] < mp[v[1]] ? "<":mp[v[0]]>mp[v[1]]? ">":"=") << std::endl;

	return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    string S;
    cin >> S;
    if(S[2] == S[3] and S[4]==S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import Foundation

func main() {
    let inputString = readLine()!
    let split: [Int] = inputString.components(separatedBy: " ").map{Int(String($0))!}
    
    let oneNum = split[0]
    let zeroNum = split[1]
    var cardNum = split[3]
    var res = 0
    
    guard (oneNum < cardNum) else {
        print(cardNum)
        return
    }
        res += oneNum
        cardNum -= oneNum
    
    guard (zeroNum < cardNum) else {
        print(res)
        return
    }
        cardNum -= zeroNum
    
    print(res - cardNum)
}

main()


Measured memory_bytes: 14180
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,y=n1()

def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    if x-n>=0 and y-n>=0:
        ans=comb(n,x-n)
        print(ans)
    else:
        print(0)

Measured memory_bytes: 38952
///
// File:  b.cpp
// Author: ymiyamoto
//
// Created on Sun Oct  1 03:11:40 2017
//

#include <cstdint>
#include <iostream>
#include <queue>
#include <string>

using namespace std;
static queue<char> que[3];

int32_t main()
{
  for (uint32_t i = 0; i < 3; i++) {
    string str;
    cin >> str;
    for (uint32_t j = 0; j < str.size(); j++) {
      que[i].push(str[j]);
    }
  }

  uint32_t parent = 0;
  while (true) {
    if (que[parent].empty()) {
      cout << (char)(parent + 'A') << endl;
      return 0;
    }
    uint32_t tmp = que[parent].front() - 'a';
    que[parent].pop();
    parent = tmp;
  }

  return 0;
}

Measured memory_bytes: 256
//20:38
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+10;
int D[N];
map<int,vector<int>>M;
bool has[N];
int main()
{
	//freopen("/home/zz7/CFInput","r",stdin);
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&D[i]),M[D[i]].push_back(i);
	if(D[0]!=0)cout<<-1<<'\n';
	else{
		for(int i=0;i<n-1;i++)
			if(D[i+1]-D[i]>1)return cout<<-1<<'\n',0;
		ll sum=0;
		for(auto k:M){
			for(auto idx:k.second){
				if(k.first>0){
					if(!has[idx-1])sum+=k.first;
					else sum+=1;
				}
			}
			for(auto idx:k.second)has[idx]=true;
		}cout<<sum<<'\n';
	}
}


Measured memory_bytes: 23040