akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const double g = 1.0;
const double eps = 1e-8;

double V,X;
vector<double> OX,OY;

double calc(double vy,double t){
  return vy*t-g*t*t/2;
}

int cmp(double lb,double ub,double a){
  return a < lb + eps ? -1 : a > ub - eps ? 1 : 0;
}

bool check(double qx,double qy){
  // vx^2 + vy^2 = V^2 , vx * t = qx, vy * t - 0.5*g*t*t = qy
  double a=g*g/4,b=g*qy-V*V,c=qx*qx+qy*qy;
  double D=b*b-4.0*a*c;
  if(D<0&&D>-eps)D=0;
  if(D<0)return false;
  for(int d=-1;d<=1;d+=2){
    double t2=(-b+d*sqrt(D))/(2*a);
    if(t2<=0)continue;
    double t=sqrt(t2);
    double vx=qx/t,vy=(qy+g*t*t/2.0)/t;
    

    double yt=calc(vy,X/vx);
    if(yt<-eps||eps<yt)continue;
    
    bool flg=true;
    for(int i=0;i<(int)OX.size();i++){
      double ox=OX[i],oy=OY[i];
      double yt=calc(vy,ox/vx);
      if(yt<oy+eps)flg=false;
    }
    if(flg)return true;
  }
  return false;
}


int d,n,b;
double p[10],h[10];
double nd;

bool judge(double m){
  V=m;


  bool flg=check(nd,0);


  for(int i=0;i<n;i++){
    flg|=check(OX[i],OY[i]);
  }
  return flg;
}

void make_table(int B){
  OX.clear();
  OY.clear();
  nd=(double)d/(double)B;

  for(int i=0;i<n;i++){
    double np=p[i];
    while(np>nd)np-=nd;
    OX.push_back(np);
    OY.push_back(h[i]);
  }
}

double solve(){
  double res=1e9;
  for(int I=1;I<=b+1;I++){
    make_table(I);
    double l=0,r=1e9,m;
    for(int i=0;i<100;i++){
      m=(l+r)*0.5;

      //      printf("%.3f %d\n",m,judge(m));
      if(judge(m))r=m;
      else l=m;
    }
    //printf("%d %.8f\n",I,l);
    res=min(res,l);
  }
  return res;
}

int main(){
  cin>>d>>n>>b;
  for(int i=0;i<n;i++)cin>>p[i]>>h[i];
  printf("%.8f\n",solve());
  return 0;
}

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

public class AtCoder_161_C
{
    public static void Main()
    {
        long[] line1 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        long n = line1[0];
        long k = line1[1];

        var dic = new Dictionary<long, bool>();
        if (n > k)
        {
            dic.Add(k, true);
        }
        else
        {
            dic.Add(n, true);
        }

        while (true)
        {
            long next = 0;
            if (n > k)
            {
                next = n % k;
            }
            else
            {
                next = k - n;
            }

            if (dic.ContainsKey(next))
            {
                break;
            }

            dic.Add(next, true);
            n = next;
        }

        Console.WriteLine(dic.Keys.Min());
    }
}


Measured memory_bytes: 13280
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 100010
int n, m, ans, a[MAXN];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    std::sort(a + 1, a + n + 1);
    m = a[n] >> 1;
    ans = -1;
    int pos = std::lower_bound(a + 1, a + n, m) - a;
    if (pos < n && std::abs(a[pos] - m) < std::abs(ans - m)) ans = a[pos];
    pos--;
    if (pos > 0 && std::abs(a[pos] - m) < std::abs(ans - m)) ans = a[pos];
    printf("%d %d\n", a[n], ans);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 998244353;
constexpr long long inf = 3e18;

template<int MOD>
struct mint{
	int n;
	mint():n(0){}
	mint(int x):n(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD){}

	mint &operator+=(const mint &p){
		if((n+=p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator-=(const mint &p){
		if((n+=MOD-p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator*=(const mint &p){
		n=n*p.n%MOD;
		return *this;
	}
	mint &operator/=(const mint &p){
		*this*=p.inverse();
		return *this;
	}
	mint operator-()const{return mint(-n);}
	mint operator+(const mint &p)const{return mint(*this)+=p;}
	mint operator-(const mint &p)const{return mint(*this)-=p;}
	mint operator*(const mint &p)const{return mint(*this)*=p;}
	mint operator/(const mint &p)const{return mint(*this)/=p;}
	mint operator==(const mint &p)const{return n==p.n;}
	mint operator!=(const mint &p)const{return n!=p.n;}

	friend ostream &operator<<(ostream &os,const mint &p){
		return os<<p.n;
	}
	friend istream &operator>>(istream &is,mint &p){
		int x;is>>x;
		p=mint(x);
		return is;
	}
	mint pow(int x)const{
		mint res(1),mul(n);
		while(x>0){
			if(x&1)res*=mul;
			mul*=mul;
			x>>=1;
		}
		return res;
	}
	mint inverse()const{
		return pow(MOD-2);
	}
};
using modint=mint<mod>;

template<class T>
class BIT{
	int N;
	vector<T>bit;
	void add_(int x,T y){
		while(x<=N){
			bit[x]+=y;x+=x&-x;
		}
	}
	T sum_(int x){
		T res=0;
		while(x>0){
			res+=bit[x];x-=x&-x;
		}
		return res;
	}
public:
	int lower_bound(T w){
		if(w<=0)return -1;
		int x=0;
		int k=1;while(k*2<=N)k*=2;
		for(;k>0;k/=2){
			if(x+k<=N&&bit[x+k]<w){
				w-=bit[x+k];
				x+=k;
			}
		}
		return x;
	}
	void add(int x,T y){add_(x+1,y);}
	T sum(int l,int r){return sum_(r)-sum_(l);}
	BIT(int x):N(x),bit(x+1){}
};

int N,K,A[200005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>K;
	rep(i,N){cin>>A[i];A[i]--;}

	BIT<modint>bit(N),bit2(N);
	modint ans;
	rep(i,N){
		int j=max(0ll,i+1-K);
		modint k=(modint(K-1)/modint(K)).pow(j);
		ans+=bit.sum(A[i],N)*k/modint(2);
		ans+=bit2.sum(A[i],N)-bit.sum(A[i],N)*k;
		ans+=bit.sum(0,A[i])*k/modint(2);
		bit.add(A[i],modint(1)/k);
		bit2.add(A[i],1);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 7952
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  int sum = 0;
  for(int i=0; i<N; i++){
    cin >> vec[i];
    sum ^= vec[i];
  }
  for(int i=0; i<N; i++){
    cout << (sum ^ vec[i]) << endl;
  }
}
  

Measured memory_bytes: 4044
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
ll LINF = numeric_limits<ll>::max() / 2;

int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(3 * n);
    for(int i = 0; i < 3 * n; i++) cin >> a[i];
    vector<ll> frontmax(n+1);
    ll frontmaxtemp = 0;
    priority_queue<int, vector<int>, greater<int> > fq;
    for(int i = 0; i < n; i++){
        frontmaxtemp += a[i];
        fq.push(a[i]);
    }
    frontmax[0] = frontmaxtemp;
    for(int i = 0; i < n; i++){
        if(a[n+i] > fq.top()){
            int old = fq.top();
            fq.pop();
            fq.push(a[n+i]);
            frontmaxtemp += a[n+i] - old;
        }
        frontmax[i+1] = frontmaxtemp;
    }

    reverse(a.begin(), a.end());
    vector<ll> backmin(n+1);
    ll backmintemp = 0;
    priority_queue<int> bq;
    for(int i = 0; i < n; i++){
        backmintemp += a[i];
        bq.push(a[i]);
    }
    backmin[0] = backmintemp;
    for(int i = 0; i < n; i++){
        if(a[n+i] < bq.top()){
            int old = bq.top();
            bq.pop();
            bq.push(a[n+i]);
            backmintemp += a[n+i] - old;
        }
        backmin[i+1] = backmintemp;
    }

/*
    for(int i = 0; i < n+1; i++){
        cout << frontmax[i] << " " << backmin[i] << endl;
    }
*/
    ll ans = -LINF;
    for(int i = 0; i < n+1; i++){
        ll dif = frontmax[i] - backmin[n-i];
        if(dif > ans) ans = dif;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4216
import Control.Applicative
import Control.Monad
import Data.List
main = getLine >>= main' . map read . words >>= putStrLn
    where
        main' [n, m] = solve (n - m + 1) <$> replicateM n getLine <*> replicateM m getLine

solve :: Int -> [String] -> [String] -> String
solve c as bs
    | res = "Yes"
    | otherwise = "No"
    where
        res = recf c as
        recf 0 _ = False
        recf n xs
            | r = True
            | otherwise = recf (n - 1) $ tail xs
            where
                r = reccolf c xs

        reccolf 0 _ = False
        reccolf n xs
            | r = True
            | otherwise = reccolf (n - 1) $ map tail xs
            where
                r = all ff $ zip bs xs
                ff (b, x) = b `isPrefixOf` x


Measured memory_bytes: 892
<?php


[$A, $V] = fscanf(STDIN, "%d%d");
[$B, $W] = fscanf(STDIN, "%d%d");
[$T] = fscanf(STDIN, "%d");
if($A === $B){
    echo "YES";
    exit;
}
if($V <= $W){
    echo "NO";
    exit;
}

$saD = abs($B - $A);
$saV = $V- $W;

if($saV * $T >= $saD){
    echo "YES";
}else{
    echo "NO";
}


Measured memory_bytes: 16120
#include <iostream>
#include <cstdlib>
using namespace std;

char s[12],t[12];
int n,ans;

void solve(int idx,int cost){
	if(idx == n) ans = min(ans,cost);

	if(s[idx] == t[idx]){
		solve(idx+1,cost);
	}
	else{
		int rotate = t[idx] - s[idx];
		int x = abs(rotate);
		if(t[idx] < s[idx] && x > 10-x)
			rotate = 10-x;
		else if(t[idx] > s[idx] && x > 10-x)
			rotate = -(10-x);

		for(int i=idx;i<n;i++){
			for(int j=idx;j<=i;j++) s[j] = (s[j] + 10 + rotate) % 10;
			solve(idx+1,cost+1);
			for(int j=idx;j<=i;j++) s[j] = (s[j] + 10 - rotate) % 10;
		}
	}
}

int main(void){
	while(cin>>n,n){
		cin>>s>>t;
		for(int i=0;i<n;i++){
			s[i] -= '0';
			t[i] -= '0';
		}

		ans = 999999999;
		solve(0,0);
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 872
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  string p[10];
  p[0] = "0111111";
  p[1] = "0000110";
  p[2] = "1011011";
  p[3] = "1001111";
  p[4] = "1100110";
  p[5] = "1101101";
  p[6] = "1111101";
  p[7] = "0100111";
  p[8] = "1111111";
  p[9] = "1101111";
  int N;
  while(cin >>N && N != -1){
    string s = "0000000";
    REP(nn, N){
      int n; cin >>n;
      REP(i, s.length()){
        if(s[i] == p[n][i]) cout <<"0";
        else{
          cout <<"1";
          s[i] = (s[i] == '1' ? '0' : '1');
        }
      }
      cout <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1200
N,Y = map(int,input().split())

for i in range(2001):
    for j in range(2001):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            if N-i-j >= 0:
                print(i,j,N-i-j)
                exit()
else:
    print(-1,-1,-1)

Measured memory_bytes: 3060
/* ????????????????????????????????¢????????°??§?§£??? */
#include<bits/stdc++.h>
#define dump(a) cout << #a << " " << a << endl
#define N_MAX 100
#define W_MAX 10000
using namespace std;

int N,W;
vector<int> weights;
vector<int> values;
int dp[N_MAX+1][W_MAX+1];

int dfs(int i, int w)
{
	if (dp[i][w] != -1) { return dp[i][w]; }

	int res=0;
	if (i == N) { res = 0; }
	else if (w < weights[i]) {
		//??????w????´??????????????????¨???
		res = dfs(i+1, w); //?????????????????????????????\?????????
	}
	else {
		//?????????????????????????????????????????¨?????¨??\????????¨??????value?????????????????????????????????return
		res = max(dfs(i+1,w), dfs(i+1,w-weights[i])+values[i] );
	}
	dp[i][w]=res;
	return res;
}

int main() {
	memset(dp,-1,sizeof(dp));

	cin >> N >> W;
	int v,w;
	for(int i=0; i<N; i++) {
		cin >> v >> w;
		values.push_back(v);
		weights.push_back(w);
	}
	cout << dfs(0,W) << endl; //0?????????????¨????,W??\???

	return EXIT_SUCCESS;
}

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

using namespace std;

#define INF 1e4
#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N;
ll h,n,w;


int solve(){
    rep(i,3500){
        h = i+1;
        rep(j,3500){
            n = j+1;
            if(4*h*n-(h+n)*N > 0 && (N*h*n)%(4*h*n-(h+n)*N)==0){
                w = (N*h*n)/(4*h*n-(h+n)*N);
                printf("%lld %lld %lld\n",h,n,w);
                return 0;
            }
        }
    }
}

int main(){
    cin >> N;

    solve();
}


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

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

	long double d = c - a - b;
	if(d > 0 && d * d > 4 * a * b){
		cout << "Yes" << endl;
	} else {
			cout << "No" << endl;
	}
  	return 0;
}


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

int main() {
	int N,K,X,Y,s=0;
	cin >> N >> K >> X >> Y;
	if(N > K)
	{
		s = (X * K) + Y * (N - K);
	}
	else
	{
		s = X * N;
	}
    cout << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<cstdlib>
using namespace std;

int main() {
  int a, ans = 0;
  bool flag = false;
  string b, c;
  cin >> a >> b >> c;
  if(b.length() < c.length()) swap(b, c);
  for(int i = 0; i < b.length(); i++) {
    if(b[i] == c[0]) {
      ans++;
      for(int j = i + 1; j < b.length(); j++) {
        if(c.length() - 1 < j - i) {
          break;
        }
        if(b[j] != c[j - i]) {
          ans = 0;
          break;
        }
        ans++;
        if(j == b.length() - 1) {
          flag = true;
        }
      }
    }
    if(flag) break;
  }
  int aa = b.length() + c.length();
  cout << (aa - ans < a ? a : aa - ans) << endl;
}


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



int main() {
	long long int n, m, d = 0, q, s[200006] = {}, taka=0, b[200006] = {}, leng = 0, goal, two = 0, three = 0, temp = 0,mi=100000000000000;

	cin >> n;
	for (int i = 0; i <n; i++) {
		cin >> s[i];
		leng += s[i];
		
	}
	for (int i = 0; i < n-1; i++) {
		taka += s[i];
		if (abs(2*taka - leng) < mi) { mi = abs(2*taka - leng); }
	}
	cout << mi;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int mod=1000000007,INF=1099999999999999999;



long long int res=0,n,m,a[200005],b[200005],sum=0,tmp=1;
string str;
char ch;
typedef pair<long long int,long long int>pa;
priority_queue<pa>pq;
pa PAIR;



int main() {
	cout << fixed << setprecision(10);
	cin>>n;
	for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        if(b[i]>a[i]){pq.push({b[i],i});}
    }
    while(!pq.empty()){
        PAIR=pq.top();
        pq.pop();
        long long int i=PAIR.second;
        if(b[i]-b[(n+i-1)%n]-b[(i+1)%n]>=a[i]){
                if(b[i]%(b[(n+i-1)%n]+b[(i+1)%n])>=a[i]){
                    res+=b[i]/(b[(n+i-1)%n]+b[(i+1)%n]);
                    b[i]%=(b[(n+i-1)%n]+b[(i+1)%n]);
                }else{
                    res+=(b[i]-a[i])/(b[(n+i-1)%n]+b[(i+1)%n]);
                    b[i]=b[i]-(b[i]-a[i])/(b[(n+i-1)%n]+b[(i+1)%n])*(b[(n+i-1)%n]+b[(i+1)%n]);
                }
                if(b[i]>a[i]){
                    pq.push({b[i],i});
            }
            
        }
        
    }

    for(int j=0;j<n;j++){
        if(a[j]!=b[j]){cout<<-1;return 0;}
    }
    cout<<res;

} 


Measured memory_bytes: 8816
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

template <ll mod> class ModInt {
    ll a;
public:
    constexpr ModInt(const ll a = 0) noexcept : a((a % mod + mod) % mod) {}
    constexpr ll &value() noexcept { return a; }
    constexpr ModInt operator + (const ModInt &rhs) const noexcept { return ModInt(*this) += rhs; }
    constexpr ModInt operator - (const ModInt &rhs) const noexcept { return ModInt(*this) -= rhs; }
    constexpr ModInt operator * (const ModInt &rhs) const noexcept { return ModInt(*this) *= rhs; }
    constexpr ModInt operator / (const ModInt &rhs) const noexcept { return ModInt(*this) /= rhs; }
    constexpr ModInt &operator += (const ModInt &rhs) noexcept {
        a += rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator -= (const ModInt &rhs) noexcept {
        a += mod - rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator *= (const ModInt &rhs) noexcept {
        a = a * rhs.a % mod;
        return *this;
    }
    constexpr ModInt pow(ll t) const noexcept {
        if (t == 0) return 1;
        auto ret = pow(t >> 1);
        ret *= ret;
        if (t & 1) ret *= *this;
        return ret;
    }
    constexpr ModInt inv() const noexcept { return pow(mod - 2); }
    constexpr ModInt operator /=(const ModInt &rhs) { return (*this) *= rhs.inv(); }
    constexpr bool operator == (const ModInt &rhs) const noexcept { return this->a == rhs.a; }
    constexpr bool operator != (const ModInt &rhs) const noexcept { return this->a != rhs.a; }
    friend constexpr ostream &operator << (ostream &os, const ModInt &rhs) noexcept { return os << rhs.a; }
    friend constexpr istream &operator >> (istream &is, ModInt &rhs) {
        is >> rhs.a;
        return is;
    }
};
using mint = ModInt<MOD>;

class Combination {
public:
    vector <mint> fac, inv, fiv;
    Combination(int N) : fac(N + 1), inv(N + 1), fiv(N + 1) {
        fac[0] = inv[0] = fiv[0] = fac[1] = inv[1] = fiv[1] = 1;
        for (ll i = 2; i <= N; i++) {
            fac[i] = fac[i - 1] * i; // n!
            inv[i] = inv[MOD % i] * (MOD - MOD / i); // n^-1
            fiv[i] = fiv[i - 1] * inv[i]; // (n!)^-1
        }
    }
    mint C(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[k] * fiv[n - k];
    }
    mint P(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[n - k];
    }
    mint H(ll n, ll k) {
        if (n == 0 && k == 0) return 1;
        return C(n + k - 1, k - 1);
    }
};

int main() {
    int s;
    cin >> s;

    Combination com(2000);

    mint ans = 0;
    for (int i = 1; i <= s / 3; i++) {
        ans += com.H(s - 3 * i, i);
    }

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

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

#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	int N; cin >> N;
	vector<int> p(N);
	rep(i, 0, N) { cin >> p[i]; p[i]--; }
	vector<int> a(N), b(N);
	rep(i, 0, N) {
		a[i] = i*N + 1;
	}
	b = a;
	reverse(all(b));
	dumpc(a);
	dumpc(b);
	rep(i, 1, N) {
		int add = i;
		int diffa = p[i] == N - 1 ? INF : a[p[i] + 1] - a[p[i]];
		int diffb = p[i] == 0 ? INF : b[p[i] - 1] - b[p[i]];
		a[p[i]] += min(add, diffa);
		add -= min(add, diffa);
		b[p[i]] += min(add, diffb);
	}
	cout << a[0];
	rep(i, 1, N)cout << " " << a[i];
	cout << endl;
	cout << b[0];
	rep(i, 1, N)cout << " " << b[i];
	cout << endl;
	return 0;
}

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

int main() {
  //freopen("EARRAYS.INP", "r", stdin);
  //freopen("EARRAYS.OUT", "w", stdout);
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);

  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];

  ll cnt = 0ll;
  rep(i, N) {
    if (A[i] < B[i]) cnt += (B[i] - A[i]) / 2ll;
    else cnt -= (A[i] - B[i]);
  }

  cout << (0 <= cnt ? "Yes" : "No") << endl;

  return 0;
}


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

string S;

int main(){
  cin >> S;
  int m = stoi(S.substr(5, 2));
  int d = stoi(S.substr(8, 2));
  if (m <= 4 && d <= 30) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


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

int main(){
    int N,p;
    cin >> N;
    p=N%10;
    if(p==3){
        cout << "bon";
    }else if(p==0 || p==1 || p==6 || p==8){
        cout << "pon";
    }else{
        cout << "hon";
    }
    return 0;
}


Measured memory_bytes: 3620
n = gets.to_i
result = Array.new(n) { Array.new }
alphabet = 'abcdefghij'
max_index = 0
tmp_str = ''
n.times do |i|
  if i == 0
    tmp_str = "#{alphabet[max_index]}"
    result[i] << alphabet[max_index]
  else
    result[i-1].each do |prev_str|
      max_char = prev_str.chars.sort[-1]
      ("a".."#{max_char.succ}").each do |ch|
        result[i] << prev_str + ch
      end
    end
  end
  max_index += 1
end
puts result[n-1].join("\n")

Measured memory_bytes: 16252
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
ll lcm(ll i,ll j){ return i/__gcd(i,j)*j; }
int main(){
  int n;
  cin >> n;
  
  ll t[n];
  rep(i,n) cin >> t[i];
  
  ll L = t[0];
  rep(i,n) L = lcm(L,t[i]);
  
  cout << L << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{long long int n,u;
 cin>>n;
 u=n%10;
 if((u==2)||(u==4)||(u==5)||(u==7)||(u==9))
     cout<<"hon";
 else if((u==0)||(u==1)||(u==6)||(u==8))
    cout<<"pon";
 else if(u==3)
    cout<<"bon";
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = sc.nextLong();
		sc.close();

		long x = n / b + 1;
		long z = x * b - 1;
		while (z > n) {
			z -= b;
		}
		long ans1 = a * z / b - a * (z / b);
		long ans2 = a * n / b - a * (n / b);
		System.out.println(Math.max(ans1, ans2));
	}
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> hps(N);
    
    for(int i = 0; i < N; i++)
    {
        int A;
        cin >> A;
        hps.at(i) = A;
    }
    sort(hps.begin(), hps.end(), greater<ll>());
    ll total = 0;
    for(int i = K; i < N; i++){
        total += hps.at(i);
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,X,M;
int main(){
    cin>>N>>X>>M;
    map<ll,ll> mp;
    for(ll i=0;i<M;i++)mp[i]=-1;
    vector<ll> v;
    while(v.size()<N){
        if(mp[X]!=-1){
            ll ans=0;
            for(ll i=0;i<mp[X];i++){
                ans+=v[i];
            }
            ll sum=0;
            for(ll i=mp[X];i<v.size();i++){
                sum+=v[i];
            }
            ans+=(N-mp[X])/(v.size()-mp[X])*sum;
            for(ll i=mp[X];i<mp[X]+(N-mp[X])%(v.size()-mp[X]);i++){
                ans+=v[i];
            }
            cout<<ans<<endl;
            return 0;
        }
        mp[X]=v.size();
        v.push_back(X);
        X=(X*X)%M;
    }

    ll ans=0;
    for(auto x:v) ans+=x;
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

int main(void){

  vector<char> c(3);

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

  sort(c.begin(),c.end());

  if(c[0]=='a' and c[1]=='b' and c[2]=='c') cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    double d, t, s;
    cin >> d >> t >> s;
    if(d/s <= t) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 3656
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    vector<int> d(n,0);
    for (int i = 0; i < n; i++){
        cin>>d[i];
    }
    
    sort(d.begin(), d.end());
    
    if(d[n/2-1]==d[n/2] )cout<<0<<'\n';
    else cout<<d[n/2]-d[n/2-1]<<'\n';
    
    
    
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //aからb - 1まで
#define print(x) cout<<x<<endl  //xを改行付きで出力
#define scan(x) cin>>x //xを入力
const int INF = 1000000007;  //最大値兼MOD
//  cin.tie(0);
//  ios::sync_with_stdio(false);
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
 int a,b,c;
 int count = 0;
 cin>>a>>b>>c;
 REP(i,a,b + 1){
   if(c % i == 0)count++;
 }
 cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 3108
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

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

    if (n - a < b - 1 || n - a > (b - 1) * a) {
        cout << -1 << endl;
        exit(0);
    }
    vector<int> seq;
    for (int i = n - a + 1; i <= n; i++)
        seq.push_back(i);
    for (int seg = b - 1; seg > 0; seg--) {
        long long st = (n - a) * (seg - 1) / (b - 1);
        long long ed = (n - a) * seg / (b - 1);
        for (int i = st + 1; i <= ed; i++)
            seq.push_back(i);
    }
    string sep = "";
    for (auto i : seq) {
        cout << sep;
        cout << i;
        sep = " ";
    }
    cout << endl;
}


Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int mx = 0;
	for (int i = 0; i < n - 1; ++i) {
		mx = max(mx, abs(a[i + 1] - a[i]));
	}
	mx = max(mx, k - a[n - 1] + a[0]);
	cout << k - mx << '\n';
 	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
int main() {
	int a, b, c, d, e, f, g, h, i, j;
	cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
	cout << (a + e + i == b + f + g && a + e + i == c + d + h ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
//Name: Sum of Integers II
//Level: 2
//Category: 数学,数え上げ,分割数,メモ化再帰
//Note:

/**
 * いわゆる分割数。
 *
 * f(k,m,s) = m以上の数をk個使ってsを作るパターン数
 * として、メモ化再帰を書く。
 *
 * オーダーは O(NMS)。
 * ただし、Mは使える数の種類数で、M=101。
 */
#include <iostream>
#include <algorithm>

using namespace std;

long long memo[10][102][1001];
bool visited[10][102][1001];

long long calc(int k, int m, int s) {
    if(k == 0) return s == 0;
    if(s < 0) return 0;
    if(visited[k][m][s]) return memo[k][m][s];

    visited[k][m][s] = true;
    for(int i = m; i <= min(s, 100); ++i) {
        memo[k][m][s] += calc(k-1, i+1, s-i);
    }
    return memo[k][m][s];
}

bool solve() {
    int N, S;
    if(!(cin >> N >> S)) return false;
    if(!N && !S) return false;
    cout << calc(N, 0, S) << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    while(solve()) ;
    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int X, Y, Z, K;
ll A[1005], B[1005], C[1005];
vector <ll> AB, ans;

int main(){
  cin >> X >> Y >> Z >> K;
  for (int i = 0; i < X; i++) cin >> A[i];
  for (int j = 0; j < Y; j++) cin >> B[j];
  for (int k = 0; k < Z; k++) cin >> C[k];

  for (int i = 0; i < X; i++){
    for (int j = 0; j < Y; j++){
      AB.push_back(A[i] + B[j]);
    }
  }
  sort(AB.begin(), AB.end(), greater<ll>());

  for (int i = 0; i < min(int(AB.size()), K); i++){
    for (int j = 0; j < Z; j++){
      ans.push_back(AB[i] + C[j]);
    }
  }
  sort(ans.begin(), ans.end(), greater<ll>());
  for (int i = 0; i < K; i++) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 44036
#include<bits/stdc++.h>
using namespace std;
const int N =1e6+5;
const long long M = (long long)1e9+7;
#define     ll      long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%I64d",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>t abs(t a) {
    if(a>=0)return a;
    return -a;
}
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     vi          vector<int>
#define     vl          vector<ll>
#define     pb          push_back
#define     all(x)      x.begin(),x.end()
#define     LB          lower_bound
#define     UB          upper_bound
#define     Mx(a,b)     (a>b)?a:b
#define     Mn(a,b)     (a<b)?a:b

int a[N];

int main() {
    int n=Int,k=Int,m=Int;
    int x=abs(n-k);
    int y=abs(n-m);
    (x>y)?puts("B"):puts("A");
    return 0;
}



Measured memory_bytes: 256
X, K, D = map(int, input().split())
X = abs(X)

if X >= D * K:
  print(X - D * K)
else:
  K -= int(X / D)
  # for i in range(0, int(X/D)):
  #   X -= D
  X %= D
  if K % 2:
    print(D - X)
  else:
    print(X)

Measured memory_bytes: 9180
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author lstd
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using namespace std;

class CRemainderMinimization2019 {
public:
	void solve(std::istream& in, std::ostream& out) {
		ll l, r;
		in >> l >> r;
		ll ans = INFINITY;
		r = min(l+2019, r);
		for (ll i = l; i <= r; i++){
			for (ll j = i+1; j <= r; j++){
				ans = min(ans, (i*j)%2019);
			}
		}
		out << ans;

	}
};

int main() {
	CRemainderMinimization2019 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

typedef long long int ll;
void solved(){
	ll n,k;cin>>n>>k;
	if(n % k == 0 && n >= k){
		cout<<"0"<<endl;
		return ;
	} 
	if(n < k){
		cout<<min(n,abs(k - n))<<endl;
	}else{
		cout<<min(n % k,k % (n % k))<<endl;
	}
} 
int main(){
	solved();
	return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a,b;
    vector < vector <int> > v(100010);
    queue<int> que;
    vector<int> dis(100010,-1);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    que.push(1);
    dis[1] = 0;
    while(!que.empty()){
        int x = que.front();
        que.pop();
        for(auto y:v[x]){
           if(dis[y] == -1){
            dis[y] = x;
            que.push(y);
           }
        }
       
    }
    bool flag = 1;
    for(int i = 1; i <= n; i++){
        if(dis[i] == -1) 
            flag = 0;
    }
    if(flag){
        puts("Yes");
        for(int i = 2; i <= n; i++){
            cout << dis[i] << endl;
        }
    }
    else
    puts("No");
    
    return 0;
}
 

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

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == b[i] && b[i] == c[i]) ans += 0;
        else if(a[i] == b[i] or b[i] == c[i] or a[i] == c[i]) ans += 1;
        else ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import Data.Bool
import Data.Char
import qualified Data.ByteString.Char8 as C
import Data.List

main = sol <$> geti <*> gets >>= put

geti = unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine

gets = fmap (C.filter isPunctuation) . C.lines <$> C.getContents

put = putStrLn . bool "No" "Yes"

sol [n,m] ss = f (n-m) (take n ss) (drop n ss)

f k as bs = or [and $ zipWith C.isPrefixOf bs (C.drop j <$> drop i as) | i <- [0..k], j <- [0..k]]


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<ll> pq;
    rep(i,n){
        ll a;
        cin>>a;
        pq.push(a);
    }
    rep(i,m){
        ll x=pq.top();
        pq.pop();
        x/=2;
        pq.push(x);
    }

    ll ans=0;
    while(!pq.empty()){
        ll x=pq.top();
        pq.pop();
        ans+=x;
    }

    cout<<ans<<endl;
}


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

nums = list(map(int, list(input().rstrip('\r\n'))))
ans_op = [''] * 3
for bit in range(2**3):
    total = 0
    tmp = [''] * 3
    for i in range(3):
        if i == 0:
            total += nums[i]
        if (bit >> i) & 1:
            total += nums[i+1]
            tmp[i] = '+'
        else:
            total -= nums[i+1]
            tmp[i] = '-'
    if total == 7:
       ans_op = tmp
       break
ans = ''
for i in range(3):
    if i == 0:
        ans += (str(nums[i]))
    ans += (ans_op[i] + str(nums[i+1]))
ans += '=7'
print(ans)

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

using namespace std;

#define INF 1e9
#define MAXN 105
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

string ans = "";
int N,L;
vector<string> S;

void solve(){
    sort(S.begin(), S.end());

    rep(i, N) ans += S[i];

    cout << ans << endl;
}

int main(){
    cin >> N >> L;

    S.resize(N);

    rep(i, N) cin >> S[i];

    solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void){
	string a,b;
	cin>>a>>b;
	a+=b;
	int num=atoi(a.c_str());
	for(int i=1;num>=i*i;i++){
		if(num==i*i){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
    return 0;
}

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


int calc(const std::vector<int>& as, const std::vector<int>& bs, int n) {
  std::vector<int> diff(n);
  int64_t sum = 0;
  for (int i = 0; i < n; i++) {
    diff[i] = as[i] - bs[i];
    sum += diff[i];
  }

  if (sum < 0)
    return -1;

  std::sort(diff.begin(), diff.end());

  auto head = diff.begin();
  auto tail = diff.end() - 1;
  int ans = 0;
  int64_t remain = 0;
  while (*head < 0) {
    int minus = *head;
    head++;
    ans++;
    while (minus + remain < 0) {
      remain += *tail;
      tail--;
      ans++;
    }
    remain += minus;
  }

  return ans;
}

int main() {
  int n;
  std::vector<int> as, bs;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    std::cin >> x;
    as.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    std::cin >> x;
    bs.push_back(x);
  }

  std::cout << calc(as, bs, n) << std::endl;
  return 0;
}


Measured memory_bytes: 1528
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull =  unsigned long long;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define pii pair<int,int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<"# "<<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))

int n;
ll dp[3007][3007][3];
int a[3007];

ll solve(int i,int j,int player)
{
	if(i>j)return 0;
	if(dp[i][j][player]!=-1)return dp[i][j][player];
	ll ans;
	if(player==1){
		if(i==j){
			ans = a[i]+solve(i+1,j,2);
		}
		else{
			ll samne = a[i]+solve(i+1,j,2);
			ll pisone = a[j]+solve(i,j-1,2);
			ans = max(samne,pisone);
			dp[i][j][player]=ans;
		}
	}
	else {
		if(i==j){
			ans = -a[i]+solve(i+1,j,2);
		}
		else{
			ll samne = -a[i]+solve(i+1,j,1);
			ll pisone = -a[j]+solve(i,j-1,1);
			ans = min(samne,pisone);
			dp[i][j][player]=ans;
		}
	}
	return dp[i][j][player]=ans;
}
int main()
{
	fast_io
	mem(dp,-1);
	cin >>n;
	for(int i=0;i<n;i++)cin >>a[i];
		cout <<solve(0,n-1,1)<<endl;
	return 0;
}


Measured memory_bytes: 212480
import sys

readline = sys.stdin.readline

N = int(readline())

XY = [list(map(int, readline().split())) for i in range(N)]

diff_list = {}

for x1, y1 in XY:
    for x2, y2 in XY:
        if x1 == x2 and y1 == y2:
            continue
        diffx = x2 - x1
        diffy = y2 - y1
        diff = (diffx, diffy)
        if not (diff in diff_list): diff_list[diff] = 0
        diff_list[diff] += 1

values = diff_list.values()
if len(values) > 0:
    m = max(values)
    ans = N - m
else:
    ans = 1

print(ans)

Measured memory_bytes: 39536
require 'pp'
# Yes No Yes

s = gets.chomp.chars
t = gets.chomp.chars
ss = s.group_by{|x|x}.map{|k,v|[v.size]}.sort_by{|a|a[0]}
tt = t.group_by{|x|x}.map{|k,v|[v.size]}.sort_by{|a|a[0]}
puts ss == tt ? 'Yes' : 'No'


Measured memory_bytes: 27516
#include "bits/stdc++.h"

#define all_of(x) std::begin(x), std::end(x)
#ifdef _GLIBCXX_DEBUG
    #define debug(x) cerr << #x << ": " << x << endl
#else
    #define debug(x) 
#endif

using namespace std;

using LL = long long;

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

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
        
    int N;
    cin >> N;
    vector<bool> A(N);
    for(int n = 0; n < N; ++n) {
        int x, y;
        cin >> x >> y;
        A[n] = (x == y);
    }
    for(int n = 0; n < N - 2; ++n) {
        if(A[n] and A[n + 1] and A[n + 2]) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    
    
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

int gcd(int a, int b){
    int tmp; 
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    tmp = a%b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a%b;
    }

    return b;
}

int main(){
    int n;
    int x;
    int ans;
    cin >> n >> x;
    vector<int> a(n);
    int tmp_a;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        tmp_a-=x;
        tmp_a=abs(tmp_a);
        a[i]=tmp_a;
    }
    sort(a.begin(),a.end());
    ans = a[0];
    if(n>=2){
        for(int i=1; i<n; i++){
            ans = gcd(ans, a[i]);
        }
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N+1), B(N);
  for(int i=0; i<=N; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  
  ll ans = 0;
  
  for(int i=0; i<N; i++){
    if(A[i]>=B[i]){
      A[i] -= B[i];
      ans += B[i];
    }else{
      B[i] -= A[i];
      ans += A[i];
      A[i] = 0;
      
      if(A[i+1]>=B[i]){
        A[i+1] -= B[i];
        ans += B[i];
      }else{
        B[i] -= A[i+1];
        ans += A[i+1];
        A[i+1] = 0;
      }
    }
  }
  
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
int cnt[101];

ll dp[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=2;i<=N;i++) {
		x=i;
		for(j=2;x>1;j++) {
			while(x%j==0) {
				cnt[j]++;
				x/=j;
			}
		}
	}
	dp[1]=1;
	for(i=1;i<=100;i++) if(cnt[i]) {
		for(j=75;j>=1;j--) {
			for(x=1;x<=cnt[i];x++) {
				if(j*(x+1)<=75) dp[j*(x+1)]+=dp[j];
			}
		}
	}
	cout<<dp[75]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
//ITP1-9-D: Transformation
//2019.05.20

#include <stdio.h>
#include <string.h>

int main(void){
  char str[1001];
  char tmp[1001];
  char cmd[8];
  int i, j, q, a, b;

  scanf("%s\n", str);
  scanf("%d\n", &q);

  for (i = 0; i < q; i++) {
    scanf("%s %d %d", cmd, &a, &b);
    if (strcmp(cmd, "print") == 0) {
      for (j = a; j < b+1; j++) printf("%c", str[j]);
      printf("\n");
    }else if (strcmp(cmd, "reverse") == 0) {
      strcpy(tmp, str);
      for (j = a; j < b+1; j++){
        str[j] = tmp[b-j+a];
      }
    }else if (strcmp(cmd, "replace") == 0) {
      char p[b-a+1+1];
      scanf("%s\n", p);
      for (j = a; j < b+1; j++) str[j] = p[j-a];
    }
  }

  return 0;
}



Measured memory_bytes: 2040
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	string s;
	cin>>s;	
	int n=atoi(&s[0]),co=0;
	rep(i,s.size())if(s[s.size()-1-i]!='0'){
		int t=pow(10,i+1);
		int a=n/t,b=n%t;
		int x=a+b,y=b-a;
		if(x>=0&&y>=0&&x%2==0&&y%2==0)co++;
	}
	cout<<co<<endl;
}
 
 

Measured memory_bytes: 1236