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

long long N, K, V[1 << 18], ans = -(1LL << 60);

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> V[i];

	for (int i = 0; i < N; i++) {
		for (int j = i - 1; j < N; j++) {
			int t1 = N - (j - i + 1);
			int rem = K - t1; if (rem < 0) continue;

			long long sum = 0; vector<long long> A;
			for (int k = 0; k < i; k++) A.push_back(V[k]);
			for (int k = j + 1; k < N; k++) A.push_back(V[k]);
			sort(A.begin(), A.end());
			for (int k = 0; k < A.size(); k++) sum += A[k];
			for (int k = 0; k < min((int)A.size(), rem); k++) sum -= min(0LL, A[k]);
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int getTypedZone(char c){
  if(c=='q' || c=='w' || c=='e' || c=='r' || c=='t' || c=='a' || c=='s' || c=='d' || c=='f' || c=='g' || c=='z' || c=='x' || c=='c' || c=='v' || c=='b'){
    return 0;
  } else {
    return 1;
  }
}

int getChangeNum(string str){
  int last = getTypedZone(str[0]);
  int now,cnt=0;
  for(int i=1;i<str.size(); i++){
    now = getTypedZone(str[i]);
    if(now != last){
      cnt++;
    }
    last = now;
  }
  return cnt;
}

int main(){

  while(1){
    string str;
    cin >> str;
    if(str.compare("#")==0) break;
    cout << getChangeNum(str) << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<long long> x(n);
	cin >> x;

	long long ans = 0;
	rep(i,n - 1){
		ans += min((x[i + 1] - x[i]) * a, b);
	}
	cout << ans << endl;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int i = N/2;

  if(S == (S.substr(0,i) + S.substr(0,i))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long llong;

int main(int, char**) {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i < 1100; ++i) {
    if ((i * 8 / 100) == a &&
        (i / 10) == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		String[] S = sc.next().split("");
		String T1="",T2="";

		if(N%2==0) {
			for(int i=0;i<N/2;i++) {
				T1+=S[i];
				T2+=S[i+N/2];
			}
			System.out.println(T1.equals(T2)?"Yes":"No");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23764
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a%b
    return b

def divisor(a):
    i = 1
    divset = set()
    while i * i <= a:
        if a % i == 0: divset |= {i, a//i}
        i += 1
    divset.remove(1)
    return divset

def is_prime(a):
    if a <= 3: 
        prime = [False, False, True, True]
        return prime[a]
    i = 2
    while i * i <= a:
        if a % i == 0: return False
        i += 1
    else: return True

N = int(input())
A = [None] * (N+1)
for i in reversed(range(N+1)):
    A[i] = int(input())

primes_bool = [True] * (N + 1)
primes = []
for p in range(2, N+1):
    if primes_bool[p]:
        primes.append(p)
        p_mult = p * 2
        while p_mult <= N:
            primes_bool[p_mult] = False
            p_mult += p

ans = []
used = set()
gcd_of_A = abs(A[N])
for a in A[:N]:
    if a != 0: gcd_of_A = gcd(abs(a), gcd_of_A)

commondiv = divisor(gcd_of_A)
for d in commondiv:
    if d > 1 and is_prime(d): 
        ans.append(d)
        used |= {d}

for p in primes:
    if A[0] % p == 0:
        for i in range(1, p):
            coefficient = 0
            index_a = i
            while index_a <= N:
                coefficient += A[index_a]
                coefficient %= p
                index_a += p-1
            if coefficient > 0: break
        else:
            if p not in used: ans.append(p)

ans.sort()
for a in ans: print(a)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define N 100006
using namespace std;
int n,x,ans,p,f[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&x),f[x]++;
	for(int i=1;i<=100000;i++){
		while(f[i]>=3){
			f[i]=f[i]%3+f[i]/3;
		}
		if(f[i]==2)p++;
		if(f[i])ans++;
	}
	printf("%d",ans-p%2);
}

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

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long L = sc.nextLong();
        long[] a = new long[N];
        for(int n=0; n<N; n++) a[n]=sc.nextLong();

        int root = -1;
        for(int n=1; n<N; n++){
            if(a[n] + a[n-1] >= L) root = n;
        }
        if(root<0){
            System.out.println("Impossible");
            return;
        }
        System.out.println("Possible");
        for(int i=1; i<root; i++) System.out.println(i);
        for(int i=N-1; i>root; i--) System.out.println(i);
        System.out.println(root);

    }
}


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

n, m = map(int, input().split())

box = [1] * n
color = [0] * n
color[0] = 1

for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    box[x] -= 1
    box[y] += 1
    if color[x] == 1:
        color[y] = 1
    if box[x] == 0:
        color[x] = 0

print(sum(color))





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

using ll = long long;
#define mod 1000000007
#define init ios::sync_with_stdio(0), cin.tie(0);
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair

int main()
{
    init;
    int n, k;

    cin >> n >> k;

    int ar[n];

    for (int i = 0; i < n; i++)
        cin >> ar[i];

    sort(ar, ar + n);

    int sum = 0;
    for (int i = 0; i < k; i++)
        sum += ar[i];

    cout << sum;
}

Measured memory_bytes: 3616
from bisect import bisect
n = int(input())
a = [-int(input()) for i in range(n)]
x = [a[0]]
for i in range(1,n):
    if x[-1]<=a[i]: x.append(a[i])
    else: x[bisect(x,a[i])] = a[i]
print(len(x))

Measured memory_bytes: 7832
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處
const int MOD = 1e9 + 7;

LL solve(int K, vector<LL>& pos, vector<LL>& neg) {
    int pp = 0, pn = 0;
    LL ans = 1;
    if (K%2) {
        ans = pos[pp++];
        --K;
    }
    while (K) {
        if (pp >= pos.size() || pp+1 >= pos.size()) {
            ans = (ans * neg[pn++] % MOD + MOD) % MOD;
            ans = (ans * neg[pn++] % MOD + MOD) % MOD;
        } else if (pn >= neg.size() || pn+1 >= neg.size()) {
            ans = (ans * pos[pp++] % MOD + MOD) % MOD;
            ans = (ans * pos[pp++] % MOD + MOD) % MOD;
        } else {
            if (pos[pp] * pos[pp+1] > neg[pn] * neg[pn+1]) {
                ans = (ans * pos[pp++] % MOD + MOD) % MOD;
                ans = (ans * pos[pp++] % MOD + MOD) % MOD;
            } else {
                ans = (ans * neg[pn++] % MOD + MOD) % MOD;
                ans = (ans * neg[pn++] % MOD + MOD) % MOD;
            }
        }
        K -= 2;
    }
    return ans;
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K; cin >> N >> K;
    vector<LL> A(N);
    vector<LL> pos, neg;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i] >= 0)  pos.push_back(A[i]);
        else  neg.push_back(A[i]);
    }
    sort(pos.begin(), pos.end(), greater<LL>());
    sort(neg.begin(), neg.end());
    LL ans = 1;
    if (K == N) {
        for (int i = 0; i < N; ++i) {
            ans = (ans * A[i] % MOD + MOD) % MOD;
        }
    } else if (K%2 == 1) {
        if (pos.size() == 0) {
            for (int i = 0; i < K; ++i) {
                ans = (ans * neg[neg.size()-1-i] % MOD + MOD) % MOD;
            }
        } else if (pos[0] == 0) {
            ans = 0;
        } else {
            ans = solve(K, pos, neg);
        }
    } else {
        ans = solve(K, pos, neg);
    }
    cout << ans << endl;
    return 0;
}


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

int main () {
  int n;
  cin>>n;
  vector<int> a(n);
  for (int i=0;i<n;++i) {
    cin>>a[i];
  }
  int cnt=1;
  int hst=a[0];
  for (int i=1;i<n;++i) {
    if (hst<=a[i]) {
      hst=a[i];
      cnt+=1;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 384
N = int(input())
if N % 4 == 0:
  h, n, w = (3 * N) // 4, (3 * N) // 4, (3 * N) // 4
elif N % 4 == 2:
  h, n, w = N, N, N // 2
elif N % 4 == 3:
  s = N // 4 + 1
  h, n, w = 2 * s, 2 * s, s * N
elif N % 4 == 1:
  s = (N // 4) + 1
  if s % 3 == 0:
    h = s
    n = 2 * (s // 3) * (4 * s - 3)
    w = 2 * (s // 3) * (4 * s - 3)
  elif s % 3 == 2:
    h = N
    n = 4 * (s // 3) + 2
    w = (4 * (s // 3) + 2) * (12 * (s // 3) + 5)
  elif s % 3 == 1:
    l = (N+3)//4
    p = 0
    for i in range(l, 3501):
      m = (N*i)//(4*i-N)+1
      for j in range(m, 3501):
        #print(i, j, (N*i*j)%(4*i*j-N*(i+j)), 4*i*j-N*(i+j))
        if (N*i*j) % (4*i*j-N*(i+j)) == 0 and 4*i*j-N*(i+j) > 0:
          p = 1
          h, n, w = i, j, (N*i*j) // (4*i*j-N*(i+j))
          break
      if p == 1:
        break
print(h, n, w)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int main() {
  vs C(2);
  rep(i,C.size()) cin >> C.at(i);
  
  reverse(all(C.at(0)));
  cout << (C.at(0) == C.at(1) ? "YES" : "NO") << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll x[1111];
vll edge[1111];


pll dfs(ll cur, ll pre) {
  vector<vector<bool>> dp(edge[cur].size() + 2, vector<bool>(5100, false));
  dp[0][0] = true;
  ll y = inf, sum = 0, cnt = 0;

  rep(i, edge[cur].size()) {
    ll to = edge[cur][i];
    if (to == pre) continue;
    pll p = dfs(to, cur);
    sum += p.first;
    sum += p.second;
    rep(j, 5001) {
      if (!dp[cnt][j]) continue;
      if (j + p.first < 5001) dp[cnt + 1][j + p.first] = true;
      if (j + p.second < 5001) dp[cnt + 1][j + p.second] = true;
    }
    cnt++;
  }
  rrep(i, x[cur] + 1) {
    if (dp[cnt][i]) {
      y = i;
      break;
    }
  }
  if (y == inf) {
    cout << "IMPOSSIBLE" << endl;
    exit(0);
  }
  //cout << cur << " " << x[cur] << " " << sum - y << endl;
  return pll(x[cur], sum - y);
}


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



  cin >> n;
  rep(i, n - 1) {
    cin >> tmp;
    edge[i + 2].pb(tmp);
    edge[tmp].pb(i + 2);
  }
  rep(i, n) cin >> x[i + 1];
  dfs(1, 0);
  cout << "POSSIBLE" << endl;


  return 0;
}

Measured memory_bytes: 1664
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int n,m,r;
int dis[205][205];

signed main()
{
    for (int i=0;i<=201;i++){
      for (int j=0;j<=201;j++){
        dis[i][j] = 1e9 ;
      }
    }
    cin >> n >> m >> r ; 
    vi a(r);
    for (int &it: a) cin >> it ; 
    for (int i=1;i<=m;i++){
        int  x, y, c ; 
        cin >> x >> y >> c ; 
        dis[x][y] = dis[y][x] = min(dis[x][y], c) ; 
    }
    for (int k=1;k<=n;k++) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=n;j++) {
                dis[i][j] = min( dis[i][j], dis[i][k]+dis[k][j] ) ; 
            }
        }
    }
    int ans = 1e9 ; 
    sort(all(a));
    do {
        int sum = 0;
        for (int i=1;i<r;i++){
            sum += dis[a[i]][a[i-1]];
        }
        ans = min(ans, sum) ; 
    }
    while (next_permutation(a.begin(),a.end()));
    co ( ans ) ; 
    return 0;
}


Measured memory_bytes: 3964
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int T = sc.nextInt();
		int min = 1001;
		for (int i = 0; i < N; i++) {
			int c = sc.nextInt();
			int t = sc.nextInt();
			if ( c < min && t <= T) {
				min = c;
			}
		}
		if (min == 1001) {
			System.out.println("TLE");
		} else {
			System.out.println(min);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

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

    //全部訪れる場合の金額sum
    int sum = 0;
    sum = abs(a[0]);
    for(int i=0;i<N-1;i++){
        sum += abs(a[i+1]-a[i]);
    }
    sum += abs(a[N-1]);

    //iを訪れない
    int sum2;
    //i=1のとき
    sum2 = sum - abs(a[1]-a[0]) - abs(a[0]) + abs(a[1]);
    cout << sum2 << '\n';
    //i=2,3,4...
    for(int i=1;i<N-1;i++){
        sum2 = sum -abs(a[i+1]-a[i]) - abs(a[i]-a[i-1]) + abs(a[i+1]-a[i-1]);
        cout << sum2 << '\n';
    }
    //i=N
    sum2 = sum - abs(a[N-1]) - abs(a[N-1]-a[N-2]) + abs(a[N-2]);
    cout << sum2 << '\n';
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int n, i, j, sum, ans, tmp, up;
    scanf("%d", &n);
    int arr[n];
    for (i=0; i<n; i++) scanf("%d", &arr[i]);

    sort(arr, arr+n);
    up=arr[n-1];
    up++;
    ans=1000000000;
    for (i=arr[0]; i<up; i++) {
        sum=0;
        for (j=0; j<n; j++) {
            tmp=arr[j]-i;
            sum+=tmp*tmp;
        }
        ans=min(ans, sum);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3820
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;


int main() {
    int N;

    cin >> N;

    vector<LLP> strings;
    long long powers[26];
    powers[0] = 1;
    powers[13] = 1;
    for (int i = 1; i < 13; i++) {
        powers[i] = powers[i - 1] * 10;
    }
    for (int i = 14; i < 26; i++) {
        powers[i] = powers[i - 1] * 10;
    }
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        long long first = 0;
        long long second = 0;
        for (int j = 0; j < s.length(); j++) {
            if (s[j] - 'a' <= 12) first += powers[s[j] - 'a'];
            else second += powers[s[j] - 'a'];
        }
        strings.push_back(make_pair(first, second));
    }
    sort(strings.begin(), strings.end());

    long long  count = 0;
    int k = 1;
    long long temp_count = 0;

    while (k < N) {
        if (strings[k - 1].first == strings[k].first && strings[k - 1].second == strings[k].second) {
            temp_count = (temp_count == 0 ? 2 : temp_count + 1);
        } else {
            if (temp_count > 0) count += temp_count * (temp_count - 1) / 2;
            temp_count = 0;
        }
        k++;
    }
    if (temp_count > 0) count += temp_count * (temp_count - 1) / 2;

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;
typedef long long ll;
const int maxx=1e6+10;
const ll mod=1e9+7;
ll f[maxx],inv[maxx];
ll fpow(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res=res*x%mod;
        x=x*x%mod;
        n >>=1;
    }
    return res;
}
void init(){
    f[0]=inv[0]=1;
    for(int i=1;i<=1000000;i++) f[i]=f[i-1]*i%mod;
    inv[1000000]=fpow(f[1000000],mod-2);
    for(int i=1000000-1;i;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
ll C(int n,int m){
    return f[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
    init();
    int n,m,a,b; cin>>n>>m>>a>>b;
    a=n-a+1;
    ll ans=C(n+m-2,n-1);
    for(int i=n;i>=a;i--){
        ans=(ans-C(b+i-2,b-1)*C((n-i+1)+m-b-2,m-b-1)%mod+mod)%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 15872
import java.util.*;

class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int c[]=new int[26],h=s.nextInt(),w=s.nextInt();
		for(int i=0;i<h;++i)
			s.next().chars().map(o->o-'a').forEach(o->++c[o]);

		int $1=(h%2)*(w%2),$2=(w%2==1?h/2*2:0)+(h%2==1?w/2*2:0),$4=h*w-$1-$2;

		for(int i=0;i<26;++i) {
			while($4>0&&c[i]>=4) {
				$4-=4;
				c[i]-=4;
			}
			while($2>0&&c[i]>=2) {
				$2-=2;
				c[i]-=2;
			}
		}
		for(int i=0;i<26;++i)
			$1-=c[i];
		System.out.println($1==0?"Yes":"No");
	}
}


Measured memory_bytes: 29012
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#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>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

/*全てのライブラリをインクルード*/
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int h,w;
    cin>>h>>w;
    char s[105];
    rep(i,h){
        cin>>s;
        cout<<s<<endl<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
const int N=2e5+10;
int n,a[N],l=1,r=N-10,mid,ans;
map<int,int>p;
inline bool judge(int x){
	p.clear();
	for(register int i=2;i<=n;i++){
		if(a[i]>a[i-1])continue;
		if(x==1)return 0;
		++p[a[i]];
		map<int,int>::iterator it=p.upper_bound(a[i]);
		while(it!=p.end())p.erase(it),it=p.upper_bound(a[i]);
		int pos=a[i];
		while(pos&&p[pos]==x)p[pos]=0,++p[--pos];
		if(!pos)return 0;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)scanf("%d",&a[i]);
	while(l<=r){mid=(l+r+1)>>1;if(judge(mid))ans=mid,r=mid-1;else l=mid+1;}
	printf("%d\n",ans);return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int N, M, A, B, C = ~(1 << 31), D = 65535, lim = 1000001, x[300009], y[300009], z[300009], p[300009];
vector<int> cp[1000009], bit[1000009];
int func() {
	A = 36969 * (A & D) + (A >> 16);
	B = 18000 * (B & D) + (B >> 16);
	return (C & ((A << 16) + B)) % 1000000;
}
void assign(int px, int py, int val) {
	for (int i = px + 1; i <= lim; i += i & (-i)) {
		int ptr = lower_bound(cp[i].begin(), cp[i].end(), py) - cp[i].begin();
		for (int j = ptr + 1; j <= cp[i].size(); j += j & (-j)) {
			bit[i][j - 1] = max(bit[i][j - 1], val);
		}
	}
}
int query(int px, int py) {
	int ret = 0;
	for (int i = px; i >= 1; i -= i & (-i)) {
		int ptr = lower_bound(cp[i].begin(), cp[i].end(), py) - cp[i].begin();
		for (int j = ptr; j >= 1; j -= j & (-j)) {
			ret = max(ret, bit[i][j - 1]);
		}
	}
	return ret;
}
int main() {
	while (scanf("%d%d%d%d", &N, &M, &A, &B), N + M) {
		for (int i = 0; i < N; ++i) scanf("%d%d%d", &x[i], &y[i], &z[i]);
		for (int i = 0; i < M; ++i) x[N] = func(), y[N] = func(), z[N] = func(), ++N;
		for (int i = 0; i < N; ++i) p[i] = i;
		sort(p, p + N, [](int i, int j) { return z[i] != z[j] ? z[i] < z[j] : y[i] > y[j]; });
		for (int i = 0; i <= lim; i++) cp[i].clear();
		for (int i = 0; i < N; i++) {
			for (int j = x[p[i]] + 1; j <= lim; j += j & (-j)) {
				cp[j].push_back(y[p[i]]);
			}
		}
		for (int i = 0; i <= lim; i++) {
			sort(cp[i].begin(), cp[i].end());
			cp[i].erase(unique(cp[i].begin(), cp[i].end()), cp[i].end());
			bit[i] = vector<int>(cp[i].size(), 0);
		}
		int ret = 0;
		for (int i = 0; i < N; i++) {
			int res = query(x[p[i]], y[p[i]]);
			assign(x[p[i]], y[p[i]], res + 1);
			ret = max(ret, res + 1);
		}
		printf("%d\n", ret);
	}
	return 0;
}


Measured memory_bytes: 127284
#include<stdio.h>
#define NTL -1
typedef struct tree{
  int par;
  int lch;
  int rbro;
}tree;
int depth(int,tree *);
int type(int,tree *);
void cpri(int,tree *);
int main(){
  int n,i,j,now,chi,bchi,num;
  /*scan n*/
  scanf("%d",&n);
  tree t[n];
  /*NTL*/
  for(i=0;i<n;i++){
    t[i].par=NTL;
    t[i].lch=NTL;
    t[i].rbro=NTL;
  }
  /*scan tree*/
  for(i=0;i<n;i++){
    scanf("%d%d",&now,&num);
    for(j=0;j<num;j++){
      scanf("%d",&chi);
      if(j==0){
	t[now].lch = chi;
      }
      else t[bchi].rbro = chi;
      bchi = chi;
      t[chi].par = now;
    }
  }
  /* print*/
  for(i=0;i<n;i++){
    chi = i;
    printf("node %d: parent = %d, depth = %d",i,t[i].par,depth(i,t));
    if(type(i,t) == 1){
      printf(", root, [");
      cpri(i,t);
    }
    else if(type(i,t) == 2){
      printf(", internal node, [");
      cpri(i,t);
    }
    else if(type(i,t) == 3)printf(", leaf, []\n");
    
  }
  return 0;
}
int depth(int num,tree *t){
  int d=0;
  while(t[num].par != NTL){
    d++;
    num = t[num].par;
  }
  return d;
}
int type(int num,tree *t){
  if(t[num].par == NTL) return 1;/*root*/
  else if(t[num].lch != NTL) return 2;/*internal*/
  else if(t[num].lch == NTL) return 3;/*leaf*/
  return 3;
}
void cpri(int now,tree *t){
  int i,chi;
  chi = t[now].lch;
  for(i=0;chi!=NTL;i++){
    if(i != 0) printf(", ");
    printf("%d", chi);
    chi = t[chi].rbro;
  }
  printf("]\n");
}


Measured memory_bytes: 3028
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

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


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  int k;
  cin >> k;
  int cnt = 0;
  for(int i = 100; i > 0; i--){
    if(a % i == 0 && b % i == 0){
      cnt++;
      if(cnt == k){
        cout << i << endl;
        return 0;
      }
    }
  }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
  bool flag=true;
  vector <pair<long int,long int> > v;
long int N;
cin>>N;
  for(int i=0;i<N;i++){
    long int a,b;//a=need,b=limit
    cin>>a>>b;
    v.push_back(make_pair(b,a));
  }
  sort(v.begin(),v.end());
  //for(int i=0;i<N;i++)cout<<v[i].first<<" "<<v[i].second<<endl<<endl;
long int clock=0;
  for(int i=0;i<N;i++){
clock+=v[i].second;
//cout<<i+1<<" "<<clock<<endl;
if(clock>v[i].first){
  flag=false;
  break;
  }
}
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N,K,L;
ll a[200005];

bool check(ll x){
    ll sum = 0;
    ll l = 0, r = 0;
    ll cnt = 0;
    while(r < N){
        while(r < N && cnt < K){
            if(a[r++] <= x) cnt++;
        }
        while(cnt >= K){
            sum += (N-r+1);
            if(a[l++] <= x)cnt--;
        }
    }
    return L <= sum;
}

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

    cin >> N >> K >> L;

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

    ll lb = 0, ub = N+1;

    while(ub-lb > 1){
        ll mid = (lb+ub)/2;
        if(check(mid)) ub = mid;
        else lb = mid;
    }

    cout << ub << endl;

    return 0;

}


Measured memory_bytes: 4724
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// 繰り返し自乗法(N^P mod Mを求める)
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}


int main() {
  ll N, a, b;
  cin >> N >> a >> b;
  ll ans = RepeatSquaring(2, N, mod);
  
  mint ANS = ans;
  mint A = a;
  mint B = b;

  // nCa
  mint nCa_bunshi = 1;
  for(int i = 0; i < a; ++i){
    nCa_bunshi *= (mint)(N - i);
  }
  mint nCa_bunbo = 1;
  for(int i = 0; i < a; ++i){
    nCa_bunbo *= (mint)(A - i);
  }
  mint nCa = nCa_bunshi / nCa_bunbo;

  // nCb
  mint nCb_bunshi = 1;
  for(int i = 0; i < b; ++i){
    nCb_bunshi *= (mint)(N - i);
  }
  mint nCb_bunbo = 1;
  for(int i = 0; i < b; ++i){
    nCb_bunbo *= (mint)(B - i);
  }
  mint nCb = nCb_bunshi / nCb_bunbo;

  ANS -= nCa;
  ANS -= nCb;
  ANS -= 1;

  cout << ANS.x << endl;

  return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<queue>
#include<functional>
using namespace std;

const int MAXN = 100100;
int a[MAXN];

int main() {
	string s;
	cin >> s;
	bool r = (s[0] == s[s.length() - 1]) ^ !(s.length() % 2);
	cout << (r ? "Second" : "First") << endl;
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

int main(void){
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> z[i];
    }
    
    ll ans = 0;
    for(int i = 0; i < (1 << 3); ++i){
        vector<int> sign(3);
        for(int j = 0; j < 3; ++j){
            sign[j] = (i & (1 << j)) ? 1 : -1;
        }
        
        vector<pair<ll, int>> temp(N);
        for(int index = 0; index < N; ++index){
            temp[index].first = sign[0] * x[index] + sign[1] * y[index] + sign[2] * z[index];
            temp[index].second = index;
        }
        sort(temp.begin(), temp.end(), greater<pair<ll, int>>());
        
        ll x_sum = 0, y_sum = 0, z_sum = 0;
        for(int index = 0; index < M; ++index){
            int id = temp[index].second;
            x_sum += x[id];
            y_sum += y[id];
            z_sum += z[id];
        }
        
        ans = max(ans, abs(x_sum) + abs(y_sum) + abs(z_sum));
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int S = sc.nextInt();
        int W = sc.nextInt();

        if (W >= S){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 35796
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

a = int( raw_input())

my_list=[]
my_list.append(a)
for i in range (1, 1000000):
    if a % 2 == 1:
        a = a*3 + 1
    else:
        a = a/2

    for j in range( len(my_list) ):
        if a == my_list[j]:
            print i+1
            exit()
    my_list.append( a )


Measured memory_bytes: 34436
a = input().split(" ")
a[0] = int(a[0])
a[1] = int(a[1])
a[2] = int(a[2])
a[3] = int(a[3])
a[4] = int(a[4])
f = (a[0] * 60) + a[1]
g = (a[2] * 60) + a[3]
l = g - f
print(l - a[4])

Measured memory_bytes: 9208
// D - Sum of Divisors
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int N; cin>>N;
	ll s = 0;
	for(int k=N, d=1; d<=N; k=N/++d) s += (ll)d * k * (k+1) / 2;
	cout<< s <<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
//#include <algorithm>
using namespace std;

int main() {
  int n,q;
  cin >> n >> q;

  string c;
  cin >> c;

  //vector<int> v;
  int len = (int)(c.length());
  std::vector<int> num(len,0);
  int tmpValue = 0;

  bool isA = false;
  for(int i = 0; i < len; i++){
    if(c[i] == 'A'){
      isA = true;
    }else if(isA && c[i] == 'C'){
      isA = false;
      //v.push_back(i);
      tmpValue++;
    }else{
      isA = false;
    }
    num[i] = tmpValue;
  }

  for(int i = 0; i < q; i++){
    int l,r;
    cin >> l >> r;
    cout << (num[r - 1] - num[l - 1]) << endl;
  }

  /*int vsize = (int)v.size();
  for(int i = 0; i < q; i++){
    int value = 0;
    int l,r;
    cin >> l >> r;
    for(int j = 0; j < vsize; j++){
      if(v[j] >= l){
        if(v[j] < r){
          value++;
        }else{
          break;
        }
      }
    }
    cout << value << endl;
  }*/

  /*for(int i = 0; i < q; i++){
    int l,r;
    cin >> l >> r;

    int value = 0;
    bool isA = false;
    for(int j = l - 1; j < r; j++){
      if(c[j] == 'A'){
        isA = true;
      }else if(isA && c[j] == 'C'){
        isA = false;
        value++;
      }else{
        isA = false;
      }
      //cout << c[j];
    }

    cout << value << endl;
  }*/
}


Measured memory_bytes: 1408
/*
        HELLO WORLD
        -----------
        SHUBHAM
        -----------
        :) CODING
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ff                                         first
#define ss                                         second
#define pb                                         push_back
#define int                                        long long
#define mp                                         make_pair
#define pii                                        pair<int,int>
#define vi                                         vector<int>
#define mii                                        map<int,int>
#define umii                                       unordered_map<int,int>
#define pqb                                        priority_queue<int>
#define pqs                                        priority_queue<int,vi,greater<int>>
#define setbits(x)                                 __builtin_popcountll(x)
#define zerobits(x)                                 __builtin_ctzll(x)
#define mod                                        1000000007
#define inf                                        1e18
#define ps(x,y)                                    fixed<<setprecision(y)<<x
#define mk(arr,n,type)                             type *arr=new type[n]
#define test(t)                                    int t;cin>>t;while(t--)
#define rep(i,n)                                   for(int i=0;i<n;i++)
#define rep1(i,n)                                  for(int i=1;i<=n;i++)
#define fio                                        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SIZE                                       1000001
#define all(x)                                     (x).begin(),(x).end()
#define sclk()                                     auto start_time = Clock::now()
#define eclk()                                     auto end_time = Clock::now();  cout << "\nTime Taken : " << chrono::duration_cast<chrono::milliseconds>(end_time    - start_time).count() << " ms"
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef std::chrono::high_resolution_clock Clock;

int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}

void f_io()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
vector<vector<int>> input;
int n;
int solve()
{
  int a=0,b=0,c=0;
  int ans=0;
  for(int i=0;i<n;i++)
  {
      int ta=max(b+input[i][0],c+input[i][0]);
      int tb=max(a+input[i][1],c+input[i][1]);
      int tc=max(a+input[i][2],b+input[i][2]);
        a=ta,b=tb,c=tc;
  }
  ans=max({a,b,c});
  return ans;
}
int32_t main()
{
    cin>>n;
    rep(i,n)
    {
        vector<int> temp;
        rep(j,3)
        {
            int u;
            cin>>u;
            temp.pb(u);
        }
        input.pb(temp);
    }
    cout<<solve();
    return 0;
}


Measured memory_bytes: 6708
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <sstream>
using namespace std;

#define LL long long
const int maxn = 100000 + 100;
int n, ans;
LL sub, add;
int A[maxn], B[maxn];
LL C[maxn];

int main() {
    #ifdef Dmaxiya
    freopen("test.txt", "r", stdin);
    #endif // Dmaxiya
    ios::sync_with_stdio(false);

    while(scanf("%d", &n) != EOF) {
        sub = 0;
        add = 0;
        ans = 0;
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &A[i]);
        }
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &B[i]);
            C[i] = A[i] - B[i];
            if(C[i] < 0) {
                sub += -C[i];
                ++ans;
            } else {
                add += C[i];
            }
        }
        if(sub == 0) {
            printf("0\n");
            continue;
        }
        if(sub > add) {
            printf("-1\n");
            continue;
        }
        sort(C + 1, C + n + 1);
        for(int i = n; i >= 1; --i) {
            if(C[i] <= 0) {
                break;
            }
            if(C[i] <= sub) {
                ++ans;
                sub -= C[i];
            } else {
                if(sub != 0) {
                    ++ans;
                }
                break;
            }
        }
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int total=C/A;
		int monooki;
		int[] menu=new int[100];
		for(int i=0;i<N;i++){
			menu[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				if(menu[i]<menu[j]){
					monooki=menu[i];
					menu[i]=menu[j];
					menu[j]=monooki;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(C/A<menu[i]/B){
				A=A+B;
				C=C+menu[i];
			}
		}
		System.out.println(C/A);
	}
}

Measured memory_bytes: 18144
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		if (A + B > C + D) {
			System.out.print("Left");
		}else if(A + B == C + D) {
			System.out.print("Balanced");			
		}else {
			System.out.print("Right");
		}
	}
}


Measured memory_bytes: 22996
function main(input){
 
    const data = input.split(' ')
    const a = parseInt(data[0], 10)
    const b = parseInt(data[1], 10)
 
    if((a * b) % 2 === 0){
        console.log("Even");
    }else{
        console.log("Odd")
    }
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

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

using namespace std;
int e[200005] = {};
int main() {
	int N, M;
	cin >> N >> M;

	bool f = false;
	rep(i, M)
	{
		int a, b;
		cin >> a >> b;
		if (a == 1 || b == N)
		{
			int n = a == 1 ? b : a;
			e[n] ++;
			if (e[n] > 1)
			{
				f = true;
			}
		}
	}

	if (f)
	{
		cout << "POSSIBLE" << endl;
	}
	else
	{
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),M=sc.nextInt();
		double[][] cols = new double[N][3];
		for (int i = 0; i < N; i++)
		{
			double L=sc.nextDouble(),a=sc.nextDouble(),b=sc.nextDouble();
			cols[i][0] = L;
			cols[i][1] = a;
			cols[i][2] = b;
		}
		double maximum = 0;
		if (M > 1)
		{
			double[][] dists = new double[N][N];
			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < N; j++)
				{
					dists[i][j] = dists[j][i] = distance(cols[i], cols[j]);
				}
			}
			maximum = maxDist(dists, new boolean[N], 0, M, N);
		}
		System.out.printf("%.10f\n", maximum);
	}
	
	private static double maxDist(double[][] dists, boolean[] taken, int k, int m, int N)
	{
		if (m == 0)
		{
			double sd = 0;
			for (int i = 0; i < N; i++)
			{
				if (taken[i])
				{
					for (int j = i + 1; j < N; j++)
					{
						if (taken[j])
						{
							sd += dists[i][j];
						}
					}
				}
			}
			return sd;
		}
		else
		{
			if (k >= N)
			{
				return 0;
			}
			else
			{
				taken[k] = false;
				double d1 = maxDist(dists, taken, k + 1, m, N);
				taken[k] = true;
				double d2 = maxDist(dists, taken, k + 1, m - 1, N);
				taken[k] = false;
				return Math.max(d1, d2);
			}
		}
	}
	
	private static double distance(double[] c1, double[] c2)
	{
		double d = 0;
		for (int i = 0; i < 3; i++) d += Math.pow(c1[i] - c2[i], 2);
		return d;
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    cin >> N;
    for(int h=1; h<=3500; h++){
        for(int n=1; n<=3500; n++){
            long long a = N*h*n;
            long long b = 4*h*n-N*(h+n);
            if(b <= 0 || a % b != 0) continue;
            long long w = a / b;
            cout << h << " " << n << " " << w << endl;
            return 0;
        }
    }
    return 0;
}


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

#define mkp make_pair
#define fst first
#define snd second
typedef long long ll;
typedef pair<ll, int> pli;
const int MAXN = 100010;
const ll INF = 1LL<<50;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int n, e, T, d[MAXN], l, r;
ll dp[MAXN], pre;
pli q[MAXN*20];

int main() {
	n = read();
	e = read(), T = read();
	for(int i = 1; i <= n; i++) d[i] = read();
	dp[0] = 0;
	l = r = 0;
	q[++r] = mkp(0, d[1]);
	pre = INF;
	int j = 0;
	for(int i = 1; i <= n; i++) {
		dp[i] = INF;
		pli u = q[l+1];
		while(2*(d[i]-u.snd) > T) {
			l++;
			if(l != r) u = q[l+1];
			else break;
		}
		while(2*(d[i]-d[j+1]) > T) {
			pre = min(pre, dp[j]-(d[j+1]<<1));
			j++;
		}
		if(l != r) dp[i] = min(dp[i], u.fst+T);
		dp[i] = min(dp[i], pre+(d[i]<<1));
		while(l != r && dp[i] < q[r].fst) r--;
		q[++r] = mkp(dp[i], d[i+1]);
		//printf("%lld %lld\n", dp[i], pre);
	}
	printf("%lld\n", dp[n]+e);
	return 0;
}


Measured memory_bytes: 3072