akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}

const ll mod = 1e9 + 7;
const int maxn = 3e5 + 5;

ll f[maxn];

ll mod_exp(ll a, ll b){
	if(b == 0)
		return 1ll;
	if(b % 2 == 0){
		ll t = mod_exp(a, b / 2) % mod;
		return t * t % mod;
	}
	return a * mod_exp(a, b - 1) % mod;
}

ll inv(ll x){
	return mod_exp(x, mod - 2) % mod;
}

ll n_k(int n, int k){
	if(k > n)
		return 0ll;

	ll num = f[n], den = f[k] * f[n - k] % mod;
	return num * inv(den) % mod;
}

ll ways(int n, int m){
	return n_k(n + m, n);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("capastaty_input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	f[0] = 1ll;
	for(int i = 1; i < maxn; i++)
		f[i] = (f[i - 1] * 1ll * i) % mod;

	int n, m, a, b;
	cin >> n >> m >> a >> b;

	ll total = ways(n - 1, m - 1);
	int i = n - a + 1, j = b;
	while(i <= n && j >= 1){

		ll w1 = ways(i - 1, j - 1);
		ll w2 = ways(n - i, m - j);
		total = (total + mod - w1 * w2 % mod) % mod;
		i++;
		j--;
	}

	cout << total << endl;

	return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int N; cin >> N;
    ll ans = 0;
    VL A(N); REP(i,N){cin >> A[i]; ans += A[i];}

    VL n(100000,0); REP(i,N) n[A[i]-1]++;

    int Q; cin >> Q;
    REP(_,Q){
        int b,c; cin >> b >> c;
        ans -= b*n[b-1];
        ans += c*n[b-1];
        n[c-1] += n[b-1];
        n[b-1] = 0;
        cout << ans << en;
    }

    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int dif=1000;
    string S;
    cin >> S;
    for(int i=0; i<S.length()-2; i++){
        if(dif > abs(753-((S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0')))){
            dif = abs(753-((S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0')));
        }
    }
    cout << dif;
}

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

using namespace std;

void print(int a)
{
    if(a==0)return;
    
    print(a/10);
    
    cout<<a%10;
}

int main()
{
    int a,b;
    
    cin>>a>>b;
    
    a--,b--;
    
    int ans=0;
    
    while(a--)
    {
        int x=b;
        while(x--)
            ans++;
    }
        
    if(ans<0)ans=0;
    
    print(ans);
    
    if(ans>0)putchar('\n');
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
        System.out.println(Math.max(0,Math.min(b,d)-Math.max(a,c)));
    }

}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void){
  int P,Q,R,b;
  scanf("%d%d%d",&P,&Q,&R);
  
  if(P>Q)
  {
    b = P;P = Q, Q =b;
  }
   if (Q>R){
    b = Q;Q = R; }
  printf("%d",(P+Q));
  return 0;
}

Measured memory_bytes: 128
unittest
{
	assert( [ "5 2 7" ].parse.expand.solve == "B" );
	assert( [ "1 999 1000" ].parse.expand.solve == "A" );
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto xab = input.front.split.to!( long[] );
	return tuple( xab[ 0 ], xab[ 1 ], xab[ 2 ] );
}

auto solve( long x, long a, long b )
{
	auto xa = ( x - a ).abs;
	auto xb = ( x - b ).abs;
	return ( xa < xb ) ? "A" : "B";
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF /*1000000007*/ 1000000000000000003
#define MOD 1000000007

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;

vector<edge>tree[100010];
vector<P> connect[100005];
long long cost[100005];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N; cin >> N;
	ll K; cin >> K;

	vector<int>A(N);
	vector<int>F(N);
	for (int i = 0; i < N;++i) cin >> A[i];
	for (int i = 0; i < N; ++i) cin >> F[i];

	sort(A.begin(),A.end());
	sort(F.rbegin(), F.rend());

	ll bottom = -1; ll top = 1e12;
	while (bottom + 1 < top) {
		ll middle = (bottom + top) / 2;

		ll sum = 0;
		for (int i = 0; i < N;++i) {
			sum += max(0ll, A[i] - middle / F[i]);
		}
		if (sum <= K) top = middle;
		else bottom = middle;
	}

	cout << top << endl;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
    cout << "Left";
  }
  else if (a + b == c + d) {
    cout << "Balanced";
  }
  else {
    cout << "Right";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll h, w;
    cin >> h >> w;
    string s[h];
    for(ll i = 0; i < h; i++)
        cin >> s[i];
    vector<vector<ll>> dist(h, vector<ll>(w, -1));
    queue<p> que;
    ll count = 0;
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++){
            if(s[i][j]=='.') count++;
        }
    }
    que.push(p(0,0));
    dist[0][0] = 0;
    while(!que.empty()){
        p c = que.front();
        que.pop();
        ll a = c.first, b = c.second;
        for(ll i = 0; i < 4; i++){
            ll x = a+dx[i], y = b+dy[i];
            if(x<0 || x>=h || y<0 || y>=w) continue;
            if(dist[x][y]!=-1 || s[x][y]=='#') continue;
            dist[x][y] = dist[a][b]+1;
            que.push(p(x, y));
        }
    }
    if(dist[h-1][w-1]!=-1)
        cout << count-dist[h-1][w-1]-1 << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

TEST_INPUT = [
    """
    7
    beat
    vet
    beet
    bed
    vet
    bet
    beet
    """,
    """
    8
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    buffalo
    """,
    """
    7
    bass
    bass
    kick
    kick
    bass
    kick
    kick
    """,
    """
    4
    ushi
    tapu
    nichia
    kun
    """
]
ANSWER = [
    "['beet', 'vet']",
    "['buffalo']",
    "['kick']",
    "['kun', 'nichia', 'tapu', 'ushi']"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n, s_list):
    c = Counter(s_list)
    m = max(c.values())
    res_list = [k for k in c.keys() if c[k] == m]
    return list(sorted(res_list))


def input_and_solve(ih):
    n = int(ih.input())
    s_list = [ih.input() for _ in range(n)]
    res = solve(n, s_list)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    for r in res:
        print(r)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        assert str(res) == str(ans)


if __name__ == "__main__":
    test()
    main()


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int64_t N;
int64_t K;
vector<int64_t> A;

int main() {
  std::cout << std::fixed << std::setprecision(20);

  cin >> N >> K;
  A = vector<int64_t>(N,0);

  REP(i,N){
    cin >> A[i];
  }

  int64_t first, last;

  first = A[0];  
  int j = 0;
  for(int i = K+1; i <= N; i++ ){
    first=A[j];
    last = A[i-1];
    if(first < last){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    j++;
    
  }

}

Measured memory_bytes: 4816
#include <iostream> 
#include <queue>
#define rep(i, n) for (int i = 0; i < n; ++i) 
using namespace std;

int main() 
{ 
    int n, m;
    cin >> n >> m;
    priority_queue<int> Q;
    rep(i, n) 
    {
        int a;
        cin >> a;
        Q.push(a);
    }

    rep(i, m) 
    {
        int a = Q.top(); Q.pop();
        Q.push( a/2 );
    }

    long long ans = 0;
    rep(i, n) 
    {
        ans += Q.top(); Q.pop();
    }

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

Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

void gen() {exit(0);}
int main() {
    #ifdef DEBUG
//    freopen("input", "r", stdin);
//    freopen("output", "w", stdout);
//    gen();
    #endif
    int n = 0;
    scanf("%d", &n);
    vector<ll> v = {2, 1};
    ll ans = 0;
    if (n == 1) {
        printf("1\n");
        exit(0);
    }
    for (int i = 2; i <= n; i++) {
        ans = (v[i - 1] + v[i - 2]);
        v.push_back(ans);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		boolean flg = true;
		int n = sc.nextInt();
		for( int i=0; i<n; i++) {
		    int num = sc.nextInt();
		    if (num % 2 == 1) continue;
		    if (num % 3 == 0 || num % 5 == 0) continue;
		    flg = false;
		}
		if (flg) {
		    System.out.println("APPROVED");
		} else {
		    System.out.println("DENIED");
		}
	}
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, m; std::cin >> n >> m;
  vi dp(1 << n, inf);
  dp[0] = 0;
  rep(i, m) {
    int a, b; std::cin >> a >> b;
    int key = 0;
    rep(i, b)  {
      int c; std::cin >> c;
      key += 1 << (c-1);
    }
    rep(i, 1 << n) {
      if (i & key) chmin(dp[i], dp[i-(i&key)]+a);
    }
  }
  if (dp[(1<<n)-1] == inf)
    std::cout << -1 << "\n";
  else
    std::cout << dp[(1<<n)-1] << "\n";
}


Measured memory_bytes: 256
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2
print(ans)

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

namespace diverta_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split(' ');
            var r = long.Parse(a[0]);
            var g = long.Parse(a[1]);
            var b = long.Parse(a[2]);
            var n = long.Parse(a[3]);
            var count = 0;
            for (long i = 0; i <= n; i = i + g)
            {
                for (long j = 0; j <= n-i; j = j + b)
                {
                    if ((n-i-j) % r == 0 )
                    {
                        count++;
                    }
                }
            }
            Console.WriteLine(Convert.ToString(count));
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11348
N = int(input())
X = [int(x) for x in input().split()]
result = -1
for i in range(min(X),max(X)+1):
  total = 0
  for n in range(N):
    total += (X[n]-i)**2
  if result==-1:
    result=total
  if total<result:
    result=total
print(result)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long int dp[1001][1001];
int main()
{
	int n, m, d[1001], c[1001],x=0;
	scanf("%d %d", &n, &m);
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <=m; j++)
		{
			dp[i][j] = 100000000000000000;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &d[i]);
	}
	for (int i = 1; i <= m; i++)
	{
		scanf("%d", &c[i]);
	}
	for (int i = 0; i <=n; i++)
	{
		for (int j = x; j <= m; j++)
		{
			if (i == 0)
				dp[i][j] = 0;
			else
				dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + d[i] * c[j]);
		}
		x++;
	}
	printf("%lld\n", dp[n][m]);
	return 0;
}

Measured memory_bytes: 9488
#include<stdio.h>

char A[810][810];
int B[810][810] = {0};
int H,W,K;
int s_i,s_j;

int abs(int x){
  if(x<0){
    x *= -1;
  }
  return x;
}

void check(int i,int j, int k){
  if((A[i][j]=='.' || A[i][j]=='S') && (abs(i - s_i) + abs(j - s_j)) <= k ){
    B[i][j] = 1;
  } else if(A[i][j]=='#'){
    B[i][j] = -1;
    return;
  }

  if(B[i][j]==1){
    if(B[i+1][j]==0 && i+1<H){
      check(i+1,j,k);
    }
    if(B[i-1][j]==0 && i-1>=0){
      check(i-1,j,k);
    }
    if(B[i][j+1]==0 && j+1<W){
      check(i,j+1,k);
    }
    if(B[i][j-1]==0 && j-1>=0){
      check(i,j-1,k);
    }
  }

  /* printf("%d %d %d\n",i,j,k); */
}

int main(void){
  scanf("%d %d %d",&H,&W,&K);
  int i,j;

  for(i=0;i<H;i++){
    scanf("%s", A[i]);
  }

  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(A[i][j]=='S'){
        s_i = i;
        s_j = j;
      }
    }
    /* printf("%s\n",A[i]); */
  }

  check(s_i,s_j,K);

  /* for(i=0;i<H;i++){ */
  /*   for(j=0;j<W;j++){ */
  /*     printf("%2d",B[i][j]); */
  /*   } */
  /*   printf("\n"); */
  /* } */
  int up = s_i;
  int down = s_i;
  int left = s_j;
  int right = s_j;

  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(B[i][j]==1){
        if(i<up){
          up = i;
        }
        if(i>down){
          down = i;
        }
        if(j<left){
          left = j;
        }
        if(j>right){
          right = j;
        }
      }
    }
  }

  /* printf("left:%d\n",left); */
  /* printf("right:%d\n",right); */
  /* printf("up:%d\n",up); */
  /* printf("down:%d\n",down); */

  int min = 800;
  if(up < min){
    min = up;
    /* printf("up\n"); */
  }
  if(H-1 - down < min){
    min = (H-1) - down;
    /* printf("down\n"); */
  }
  if(left < min){
    min = left;
    /* printf("left\n"); */
  }
  if(W-1 - right < min){
    min = (W-1) - right;
    /* printf("right\n"); */
  }

  /* printf("min:%d\n",min); */

  int ans = 1;
  ans += (min+K-1)/K;

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

  return 0;
}


Measured memory_bytes: 34304
#include <stdio.h>

int main(void){
    int m,f,r,sum;
    char s;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        sum = m + f;
        if ( r == -1 && m == -1 && f == -1)  break;
        else if (m == -1 || f == -1)  s='F';
        else if (sum >= 80) s ='A';
        else if(sum >= 65 && sum < 80)  s = 'B';
        else if(sum >= 50 && sum < 65)  s = 'C';
        else if(sum >= 30 && sum < 50){
            if(r >= 50)  s = 'C';
            else  s = 'D';
        }
        else if (m == -1 || f == -1)  s='F';
        else  s = 'F';
        printf("%c\n", s);
    }
    return(0);
}

Measured memory_bytes: 600
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solve();
		return;
	}

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		List<Integer> a = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			a.add(sc.nextInt());
		}
		sc.close();

		// 計算
		Collections.sort(a);
		int i;
		for (i = 0; i < N; i++) {
			Integer integer = a.get(i);
			if (x < integer) {
				break;
			}
			if (i == N - 1 && x > integer) {
				break;
			}

			x -= integer;
		}

		// 出力
		System.out.println(i);

		return;
	}
}


Measured memory_bytes: 23508
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> as(n);
    for(int i=0; i<n; ++i){
        cin >> as[i];
        as[i]-=i+1;
    }
    sort(as.begin(), as.end());
    int b=(as[(n-1)/2]+as[n/2])/2;
    long long ans=0;
    for(int i=0; i<n; ++i){
        long long t=as[i];
        t-=b;
        ans+=abs(t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int main(){
  int N; cin>>N;
  ll sumA=0,sumB=0;
  vector<ll> A(N),B(N), C(N);
  rep(i,N){
    cin>>A[i];
    sumA+=A[i];
  }
  rep(i,N){
    cin>>B[i];
    sumB+=B[i];
    C[i]=A[i]-B[i];
  }
  if(sumA<sumB){
    cout<<-1<<endl;
    return 0;
  }
  sort(C.begin(),C.end());
  ll n=0;
  int l=-1;
  rep(i,N) if(C[i]<0) n+=-C[i],l=i;
  if(l==-1){
    cout<<0<<endl;
    return 0;
  }
  int r=N-1;
  while(n>0) n-=C[r--];
  cout<<N-(r-l)<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <tuple>
#include <cstdint>

static int64_t solve(int64_t m, int64_t n, int64_t mod);
static int64_t mod_comb(int64_t n, int64_t k, int64_t mod);
static int64_t mod_inv(int64_t a, int64_t m);

int main()
{
    int64_t m, n;
    std::cin >> n >> m;
    std::cout << solve(m, n, 1000000007) << std::endl;

    return 0;
}

static int64_t solve(int64_t m, int64_t n, int64_t mod)
{
    int64_t i = 2;
    int64_t x = m;
    int64_t r = 1;

    while (i * i <= x) {
        int64_t c = 0;
        while (x % i == 0) {
            c++;
            x /= i;
        }

        if (c != 0) {
            r = r * mod_comb(c + n - 1, c, mod) % mod;
        }

        i++;
    }

    if (x != 1) {
        r = r * n % mod;
    }

    return r;
}

static int64_t mod_comb(int64_t n, int64_t k, int64_t mod)
{
    int64_t r = 1;
    if (n - k < k) {
        k = n - k;
    }

    for (int64_t i = 1; i <= k; i++) {
        r = r * (n - k + i) % mod;
        r = r * mod_inv(i, mod) % mod;
    }

    return r;
}

static int64_t mod_inv(int64_t a, int64_t m)
{
    int64_t p = a, q = m;
    int64_t x = 1, y = 0, u = 0, v = 1;

    while (q != 0) {
        int64_t k = p / q;
        std::tie(p, q) = std::make_tuple(q, p % q);
        std::tie(x, y, u, v) = std::make_tuple(u, v, x - k * u, y - k * v);
    }

    if (x < 0) {
        return x + m;
    } else {
        return x;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  string s; cin >> s;
  set<char> ss; REP(i, s.size()) ss.insert(s[i]);
  ll ans = HIGHINF;
  for (auto cs: ss) {
    ll tmpans = 0;
    string anss = s;
    while (true) {
      string tmps = "";
      set<char> tmpset; REP(i, anss.size()) tmpset.insert(anss[i]);
      if (tmpset.size() == 1) break;
      REP(i, anss.size()-1) {
        if (anss[i] == cs || anss[i+1] == cs) tmps += cs;
        else tmps += anss[i];
      }
      anss = tmps;
      tmpans++;
    }
    chmin(ans, tmpans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    string X; cin>>X;
    int L=SZ(X);
    vec b(4,-1);
    rep(i,L){
        if(X[i]=='N') b[0]=1;
        if(X[i]=='S') b[1]=1;
        if(X[i]=='E') b[2]=1;
        if(X[i]=='W') b[3]=1;
    }
    if((b[0]==b[1]) && (b[2]==b[3])) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <sstream>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int x;
  cin >> x;
  vector<int> vt;
  vt.push_back(1);
  for(int i = 2; i <= x; i++) {
    int tmp = i*i;
    while(tmp <= x){
      vt.push_back(tmp);
      tmp *= i;
    }
  }
  sort(vt.begin(),vt.end());
  cout << vt.back() << endl;
  return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, c, d, ans;

int main() {
	cin >> a >> b >> c >> d;
	
	if(b <= c || d <= a) { ans = 0; }
	else {
		     if(a <= c && c <= b && b <= d) { ans = b - c; }
		else if(c <= a && a <= d && d <= b) { ans = d - a; }
		else { ans = min(b - a, d - c); }
	}
	cout << ans << endl;
	
	return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {     
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int row = int.Parse(input[0]);
            int colums = int.Parse(input[1]);

            //?¨??????????????´??????°
            int rowresult = 0;

            //?????\??§????¨??????§????????????????????????????????????
            List<int> setblist = new List<int>();
            List<int> setalist = new List<int>();


            string text = string.Empty;

            //??\??????????????¨????????¨??????2?¬???????????????????
            int[,] table = new int[row, colums];


            //???????????\?????????????????????????????????

            //??????????????????????¨?????????\??????
            for(int i = 0; i < row; i++)
            {
                string[] columsvalueSt = Console.ReadLine().Split(' ');


                for (int j = 0; j < colums; j++)
                {
                    table[i, j] = int.Parse(columsvalueSt[j]);
                }
            }



            //????????????????¨??????????
            for(int a = 0; a < row; a++)
            {
                setalist.Add(a);
                for(int b = 0; b < colums; b++)
                {
                    rowresult += table[a, b];

                    //?????\??§????¨??????§?????????????????????Add??????
                    setblist.Add(b);

                    text += table[a, b].ToString()+' ';

                }

                //????????????
                Console.WriteLine(text + rowresult.ToString());

                //???????????????
                rowresult = 0;
                text = string.Empty;
            }

            //??\??????????????§?????\????¨????????????????????????????
            ColumsCalc(table, setalist, colums);

        }


        private static void ColumsCalc(int[,] table, List<int> lista, int colums)
        {
            int result = 0;
            int sumresult = 0;

            string text = string.Empty;

            for(int b = 0; b < colums; b++)
            {
                foreach (var seta in lista)
                {
                    result += table[seta, b];

                    //?¨???????????????????
                    sumresult += table[seta, b];

                }

                text += result.ToString() + ' ';
                //???????????????
                result = 0;
            }

            //????????????
            Console.WriteLine(text + sumresult.ToString());

        }
    
    }

}

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

#define int int64_t
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define ll long long
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

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

    int n,a,sum=0,cnt=0,ans=0;
    cin>>n;
    bool bl = false;
    vector<int> x;

    rep(i,n){
        cin>>a;
        x.push_back(a);
        sum += a;
    }

    if(sum % n != 0) bl = true;
    sum /= n;

    rep(i,n){
        cnt += ((x[i] - sum) * (x[i] - sum));
        if(bl) ans += ((x[i] - (sum+1)) * (x[i] - (sum+1)));
    }

    if(bl) cout<<min(cnt,ans)<<'\n';
    else cout<<cnt<<'\n';
}


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

int main() {
	int N, M, Q, L, R, p, q;
	static long long Cum[510][510] = {}, A[510][510] = {};
	cin >> N >> M >> Q;
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		A[L][R]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			Cum[i][j] = Cum[i - 1][j] + Cum[i][j - 1] - Cum[i - 1][j - 1] + A[i][j];
		}
	}
	for (int i = 0; i < Q; i++) {
		cin >> p >> q;
		cout << Cum[q][q] - Cum[p - 1][q] - Cum[q][p - 1] + Cum[p - 1][p - 1] << endl;
	}
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int dp[110][10010]={};

int main(){
	int N,W,v[110]={},w[110]={};
	cin>>N>>W;
	rep(i,1,N+1){
		cin>>v[i]>>w[i];
	}
	rep(i,1,N+1){
		rep(j,0,W+1){
			if(j>=w[i]){
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	o(dp[N][W]);
}

Measured memory_bytes: 5212
#include<stdio.h>
#include<string.h>

#define MAX 1010
#define max(a,b) ((a<b)?b:a)

char s[MAX], t[MAX];
int dp[MAX][MAX],path[MAX][MAX];

int LCS() {
  int n = strlen(s);
  int m = strlen(t);
  memset(dp,0,sizeof dp);
  int i,j,maxi=0;
  for(i=0;i<n;i++) {
    for(j=0;j<m;j++) {
      if( i ) dp[i][j] = max(dp[i][j],dp[i-1][j]);
      if( j ) dp[i][j] = max(dp[i][j],dp[i][j-1]);
      if( s[i] == t[j] ) {
	dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
	maxi = max(maxi,dp[i+1][j+1]);
      }
    }
  }
  return maxi;
}

int main() {
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
  scanf(" %s",&s[0]);
  scanf(" %s",&t[0]);
  printf("%d\n",LCS());
  }
  return 0;
}


Measured memory_bytes: 6700
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    for j in range(n - 1, i, -1):
        if a[j] < a[j - 1]:
            count += 1
            tmp = a[j - 1]
            a[j - 1] = a[j]
            a[j] = tmp

print(" ".join(map(str, a)))
print(count)



Measured memory_bytes: 5600
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;


int days[] = {0,31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string week[] = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
 
int main()
{
	int m, d;
    while(cin >> m >> d && m && d)
    {
        int sum = 0;
        rep(i,m)
        {
            sum += days[i];
        }
        sum += d;
        cout << week[(sum)%7] << endl;
    }

    return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll MAXN = 1e5+200;
set<ll> a;
int main(){
    ll n,m;
    cin>>n>>m;
    double x = 1.0/n;
    ll a = pow(m,x) +1;
    // cout<<a<<endl;
    for(ll i = a; i >= 1; i--){
      if(m % (ll)pow(i,n) == 0){
        cout<<i<<endl;
        break;
      }
    }
}


Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric
import Data.Char
import Data.List
import Data.Ord

main :: IO ()
main = do
  { l1 <- getLine
  ; l2 <- getLine
  ; let l1' = l1 ++ l1
  ; if isInfixOf l2 l1' then putStrLn "Yes" else putStrLn "No"
  }

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 3748
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
using namespace std;

int main(void){
    int n;
    cin >> n;
    int hotel,ans=0,highest=0;
    for(int i=0; i<n; i++){
        cin >> hotel;
        if(highest<=hotel)ans++;
        highest=max(hotel,highest);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    string s,a;
    int i=0;
    cin >> s;
    while(1){
        cin >> a;
        if(a == "END_OF_TEXT") break;
        for(int j = 0;j < a.size();j++)
           if(isupper(a[j])) a[j] = tolower(a[j]);
        if(s == a) i++;
    }
    cout << i << endl;

    return 0;
}


Measured memory_bytes: 3224
n = input().split()
n = [int(i) for i in n]
if not n[1] == 0:
	m = input().split()
	m = [int(i) for i in m]
else:
  	m =[0]

ans_1 = n[0]
ans_2 = n[0]
ans = []
while True:
    if n[1] == 0:
        ans.append(n[0])
    if not n[0] in m:
      ans.append(n[0])
    if len(ans) > 0:
        break    
        
    ans_1 += 1
    ans_2 -= 1
    if not ans_1 in m:
        ans.append(ans_1)
    if not ans_2 in m:
        ans.append(ans_2)
    
    
        
print(min(ans))

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=1000005,M=2000005,inf=1e9;
namespace G{
	struct edge{int v,f,c,p;};
	vector<edge> e[N];
	int d[N],r[N],in[N],n,m,s,t;
	void init(int _n,int _s,int _t){
		n=_n,s=_s,t=_t,m=0;
	}
	void add(int a,int b,int c){
		e[a].pb((edge){b,0,c,(int)e[b].size()});
		e[b].pb((edge){a,0,0,(int)e[a].size()-1});
	}
	int bfs(){
		static int q[N]; int l=0,r=0;
		fill(d+1,d+n+1,0),d[s]=1;
		for(l=r=0,q[r++]=s;l<r;){
			int u=q[l++];
			REP(i,e[u].size()){
				edge &v=e[u][i];
				if(!d[v.v]&&v.f<v.c){
					d[q[r++]=v.v]=d[u]+1;
					if(v.v==t)return 1;
				}
			}
		}
		return 0;
	}
	int dfs(int u,int a){
		if(u==t)return a;
		int res=0; in[u]=1;
		for(int &k=r[u];k<e[u].size();k++){
			edge &v=e[u][k];
			if(v.f<v.c&&d[v.v]==d[u]+1&&!in[v.v]){
				int now=dfs(v.v,min(a,v.c-v.f));
				v.f+=now,e[v.v][v.p].f-=now,res+=now;
				if(!(a-=now))break;
			}
		}
		return in[u]=0,res;
	}
	int flow(){
		int res=0;
		while(bfs()){
			fill(r+1,r+n+1,0);
			res+=dfs(s,inf);
		}
		return res;
	}
}
int cur[N],q[N],an[N],l,r,n,a,b,S,T;
vi e[N];

int main(){
	read(n);
	S=2*n-1,T=S+1;
	G::init(T,S,T);
	rep(i,1,n-1){
		G::add(S,i,1);
		G::add(i+n-1,T,1);
	}
	rep(i,1,n-1){
		read(a);
		rep(j,1,a){
			read(b);
			e[b].pb(i);
			if(b<n)G::add(i,n-1+b,1);
		}
	}
	if(G::flow()!=n-1)return puts("-1"),0;
	rep(i,1,n-1)
		for(auto t:G::e[i])
			if(n<=t.v&&t.v<S&&t.f)
				cur[i]=t.v-(n-1);
	q[r++]=n;
	while(l<r){
		int u=q[l++];
		for(auto v:e[u]){
			if(an[v])continue;
			an[v]=u,q[r++]=cur[v];
		}
	}
	if(r<n)return puts("-1"),0;
	rep(i,1,n-1)
		printf("%d %d\n",cur[i],an[i]);
	return 0;
}

Measured memory_bytes: 89824
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

const ll mod = 1000000007ll;
ll modpow(ll x, ll y, ll m){
    if(y == 0ll)return 1ll;
    ll res = 1ll, tmp = x;
    while(y){
        if(y&1) res = res * tmp % m;
        tmp = tmp * tmp % m;
        y >>= 1;
    }
    return res;
}
ll pom(ll x, ll y){return modpow(x, y, mod);}
ll COM(ll x, ll y){
    if(x < y) return 0;
    if(x < 0 || y < 0) return 0;
    ll res = 1;
    for(int i=0; i<y; i++){
        res = res * (x-i) % mod * pom(y-i, mod-2) % mod;
    }
    return res;
}
int prime[1001001];
bool is_prime[1001001];
int sieve(int n){
    int p = 0;
    for(int i=0; i<=n; i++)is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=n; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j = 2*i; j<=n; j+=i)is_prime[j] = false;
        }
    }
    return p;
}
int N, M;
ll ans = 1;
int main(){
    sieve((int)1e6);
    scanf("%d%d", &N, &M);
    for(int j=2; j*j <= M; j++){
        if(M%j == 0){
            ll cnt = 0;
            while(M%j == 0){
                cnt++;
                M /= j;
            }
            ans *= COM(N + cnt - 1, cnt);
            ans %= mod;
        }
    }
    if(M > 1){
        ans *= N;ans %= mod;
    }
    printf("%lld\n", ans);
}

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

using namespace std;

int main() {
   int N;
   cin >> N;
   int L[N];
   int sum = 0;
   int maxL = 0;
   for (int i = 0; i < N; i++) {
      cin >> L[i];
      sum += L[i];
      maxL = max(maxL, L[i]);
   }
   if (maxL < sum - maxL) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    
    int a,b,c,d,bus,tra;
    
    cin >> a >> b >> c >> d;
    
    if(a > b){
    
    tra = b;
    
    }else{
    
    tra = a;
    
    }
    
    if(c > d){
    
    bus = d;
    
    }else{
    
    bus = c;
    
    }
    
    cout << tra + bus << endl;
    
    
    
    
    
    
    

    
/////////////////////////////////////////////////////
return 0;}

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

int main() {
  int a,b;
  cin >> a>>b;
  
  vector<int> vec(a);
  
  for(int i=0;i<a;i++){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<a;i++){
    b=b-vec.at(i);
  }
  
  cout<<a+b/vec.at(0)<<endl;
}

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

#define fi first
#define se second

const int N = 16;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int a[N][N];
long long d[1 << N];
long long cost[1 << N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                        cin >> a[i][j];
                }
        }
        for(int i = 0; i < (1 << n); i++){
                for(int j = 0; j < n; j++){
                        for(int h = j + 1; h < n; h++){
                                if((i & (1 << j)) && (i & (1 << h))){
                                        cost[i] += a[j][h];
                                }
                        }
                }
        }
        for(int i = 0; i < (1 << n); i++){
                d[i] = cost[i];
                for(int j = i; j > 0; j = (j - 1) & i){
                        d[i] = max(d[i], d[j] + cost[i ^ j]);
                }
        }
        cout << d[(1 << n) - 1] << "\n";
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000
#define vll vector<ll>
using namespace std;
const int N=100005;

void solve()
{
	ll a,b;
	cin>>a>>b;
	if((a+b)&1)
		cout<<"IMPOSSIBLE";
	else
		cout<<(a+b)/2;
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

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

int main() {
    int N, M, i, ans;
    cin >> N;
    cin >> M;

    for (i=M/N; i>0; i--){
        if (M % i == 0) {
            ans = i;
            break;
        }
    }

    cout << ans << '\n';

}

Measured memory_bytes: 256
#include <bits/stdc++.h>                                     
using namespace std;                                 
                                                 
#define ll long long                           
#define MOD 1000000007                      
                                           
int main() {                             
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);     

	int n;
	cin>>n;
	double pi=3.14;
	double ans=2*pi*n;
	cout<<ans<<endl;

	return 0;
}      

Measured memory_bytes: 3792
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<vector<ll>> g(n);
  vector<ll> a(n), b(n);
  REP(i, m) {
    ll p, q;
    cin >> p >> q;
    p--, q--;
    g[p].push_back(q);
    g[q].push_back(p);
    if(s[q] == 'A') a[p]++;
    else b[p]++;
    if(s[p] == 'A') a[q]++;
    else b[q]++;
  }

  // cout << a << endl << b << endl;

  vector<bool> exist(n, true);
  stack<ll> st;
  REP(i, n) {
    if(a[i]==0 || b[i]==0) {
      exist[i] = false;
      st.push(i);
    }
  }

  ll cnt = 0;
  while(st.size()) {
    ll v = st.top(); st.pop();
    // cout << v << endl;
    cnt++;
    for(auto to: g[v]) {
      if(s[v] == 'A') {
        a[to]--;
        if(exist[to] && a[to] == 0) {
          exist[to] = false;
          st.push(to);
        }
      } else {
        b[to]--;
        if(exist[to] && b[to] == 0) {
          exist[to] = false;
          st.push(to);
        }
      }
    }
  }

  if(cnt == n) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<vector<ll>> A(N, vector<ll>(N));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      scanf("%lld", &A[i][j]);
    }
  }

  bool ok = true;
  vector<vector<bool>> need(N, vector<bool>(N, true));
  for (int k = 0; ok and k < N; ++k) {
    for (int i = 0; ok and i < N; ++i) {
      for (int j = 0; ok and j < N; ++j) {
        if (i == k or j == k) { continue; }
        ll val = A[i][k] + A[k][j];
        if (A[i][j] == val) {
          need[i][j] = false;
        }
        else if (A[i][j] > val) {
          printf("-1\n");
          return 0;
        }
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      if (need[i][j]) { ans += A[i][j]; }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
const int HOUSES = 4;
const int STORIES = 3;
const int ROOMS = 10;
int house[HOUSES][STORIES][ROOMS];
int main()
{
	int in;
	std::cin >> in;
	while (in--)
	{
		int a, b, c, d;
		std::cin >> a >> b >> c >> d;
		house[a - 1][b - 1][c - 1] += d;
	}
	for (size_t i = 0; i < HOUSES; i++)
	{
		for (size_t j = 0; j < STORIES; j++)
		{
			for (size_t k = 0; k < ROOMS; k++)
			{
				std::cout << " " << house[i][j][k];
			}
			std::cout << std::endl;
		}
		if (i != HOUSES - 1)
		{
			std::cout << "####################" << std::endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3088