akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#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 INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    LL N;
    cin >> N;
    int i = sqrt(N);
    while (N % i != 0){
        i--;
    }
    cout << max(floor(log10(i))+1, floor(log10(N/i))+1) << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //WOOOOOOO AtCoder is HELPING!!!!!!!!!!
		//Arraylist cheese for the win
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		long ans = 0;
		ArrayList<Long> deductions = new ArrayList<Long>();
		for (int i = 0; i < N; i++) {
			long x = input.nextLong();
			ans+=x;
			while (x>0) {
				long sub = x-x/2;
				deductions.add(sub);
				x/=2;
			}
		}
		Collections.sort(deductions);
		int index = deductions.size()-1;
		int cnt = 0;
		while (cnt < M) {
			ans-=deductions.get(index);
			cnt++;
			index--;
			if (index==-1) break;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 167304
#include <iostream>

using namespace std;

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 300000;
    int b = -1;
    int cnt_b[200001];
    int cnt_w[200001];
    cnt_b[0] = 0;
    for(int i = 0; i < N; i++){
        if(i == 0){
            if(S[i]  == '#') cnt_b[i+1] = 1;
            else cnt_b[i+1] = 0;
        }
        else{
            if(S[i]  == '#') cnt_b[i+1] = cnt_b[i]+1;
            else cnt_b[i+1] = cnt_b[i];
        }
    }
    cnt_w[N] = 0;
    for(int i = N-1; i >= 0; i--){
        if(i == N-1){
            if(S[i]  == '.') cnt_w[i] = 1;
            else cnt_w[i] = 0;
        }
        else{
            if(S[i]  == '.') cnt_w[i] = cnt_w[i+1]+1;
            else cnt_w[i] = cnt_w[i+1];
        }
    }
    for(int i = 0; i <= N; i++){
        ans = min(ans, cnt_b[i]+cnt_w[i]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 2180
N = int(input())
cards = list(map(int, input().split()))

subtotals = [cards[0]]
for i in range(1, N):
    subtotals.append(subtotals[i - 1] + cards[i])

ans = 0
for i in range(N - 1):
    diff = abs(subtotals[-1] - 2*subtotals[i])
    ans = diff if i == 0 else min(ans, diff)

print(ans)

Measured memory_bytes: 23800
import sys

input = sys.stdin.readline
N = int(input())
peoples = list(input().strip())

E = 0
W = 0
for p in peoples:
    if p == "E":
        E += 1
    else:
        W += 1

ans = float("inf")
tmp = E
for i in range(N):
    if peoples[i] == "E":
        tmp -= 1
    if 0 < i and peoples[i-1] == "W":
        tmp += 1
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 11552
N, M = map(int, input().split())
C = []
for _ in range(N):
    A, B = map(int, input().split())
    C.append((A,B))
C.sort()
cnt = 0
res = 0
for i in range(N):
    if cnt+C[i][1]<=M:
        res += C[i][1]*C[i][0]
        cnt += C[i][1]
    else:
        break
print((M-cnt)*C[i][0] + res)

Measured memory_bytes: 78996
#include <iostream>

#define MAX 100
#define MIN 1

int bubble_sort(int A[MAX], int N) {
  int swap_count = 0;

  bool flag = true;
  while(flag) {
    flag = false;
    for (int j = N - 1; j > 0; j--) {
      if (A[j] < A[j - 1]) {
        int tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
        flag = true;
        swap_count++;
      }
    }
  }

  return swap_count;
}

int main() {
  int N;
  std::cin >> N;
  int A[MAX];
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }

  int swap_count = bubble_sort(A, N);

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

  std::cout << swap_count << std::endl;
  return 0;
}


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

int main()
{
    double a, b, c;
    cin >> a >> b >> c;
    double l = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2.0 * a * b * cos(c * (M_PI / 180.0)));
    double h = b * sin((180.0 - c) * (M_PI / 180.0));
    cout << fixed << setprecision(8) << a * h / 2 << endl;
    cout << fixed << setprecision(8) << a + b + l << endl;
    cout << fixed << setprecision(8) << h << endl;
}


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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=2e5 +10, M=(ll)1e9+1 ;
const int mod =(ll)998244353 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";


void work(){
	ll n,x,y;
	cin >> n >> x >> y;
	ll dist[n+1][n+1];
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			dist[i][j]=INF;
		}
	}

	for(ll k=0;k<n;k++){
		for(ll i=1;i<=n;i++){
			if(i+k<=n){
				dist[i][i+k]=k;
				dist[i+k][i]=k;
			}
			if(i-k>0){
				dist[i][i-k]=k;
				dist[i-k][i]=k;
			}
		}
	}


	dist[x][y]=1;
	dist[y][x]=1;


	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			if(dist[i][j]> dist[i][x]+dist[x][j]){
				dist[i][j]=dist[i][x]+dist[x][j];
				dist[j][i]=dist[i][j];
			}

			if(dist[i][j]> dist[i][y]+dist[y][j]){
				dist[i][j]=dist[i][y]+dist[y][j];
				dist[j][i]=dist[i][j];
			}

		}
	}
	vl ans(n+1,0);

	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			if(dist[i][j]!=INF)
				ans[dist[i][j]]++;
		}
	}

	for(ll i=1;i<n;i++)
		cout << ans[i]/2 << "\n";

}

int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	}
return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int a[100000+10];
int main(){
	int n;
	cin>>n;
	if(n&1==1){
		cout<<0<<endl;
		return 0;
	}
	rb(i,1,n){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	if(a[n/2+1]==a[n/2]){
		cout<<0<<endl;
		return 0;
	}
	cout<<a[n/2+1]-a[n/2]; 
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll mod = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int n,x; cin>>n>>x;
    vector<int> l(n);
    rep(i,0,n) cin>>l[i];
    vector<int> box(10010);
    int place=0;
    rep(i,0,n){
        box[place]++;
        place+=l[i];
    }
    box[place]++;
    int sum=0;
    rep(i,0,x+1){
        sum+=box[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
# 約20分
# 簡単な問題なのだがパッと正確にイメージできていない

n = int(input())
l = []
for j in range(1,n+1):
    if j%2 != 0:
        l.append(j)
b = 0
for i in l:
    a = 0
    for k in range(1,i+1):
        if i%k == 0:
            a += 1
    if a == 8:
        b += 1
print(b)


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

int main() {
    int n;
    cin >> n;
    vector<ll> l(n);
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    sort(l.begin(), l.end());

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            for (int k = j+1; k < n; ++k) {
                if(l[i] == l[j] || l[j] == l[k] || l[i] == l[k]) continue;
                if(l[i] + l[j] > l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=100000;
struct node
{
	int num,id;
}a[N+5];
inline bool operator < (node a,node b)
{
	return a.num<b.num;
}
int n;
int ran[N+5];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].num);
		a[i].id=i;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		ran[a[i].id]=i;
	
	int ans=0;
	for(int i=1;i<=n;i+=2)
		ans += !(ran[i]&1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int32_t main()
{
   IOS;
  /* #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/	
   int n;
   cin>>n;
   int s=inf;
   for(int i=1;i<n;i++)
   {
   	int a=i,b=n-i;
   	int S=0;
   	while(a)
   	{
   		S=S+a%10;
   		a=a/10;
   	}
   	while(b)
   	{
   		S=S+b%10;
   		b=b/10;
   	}
   	s=min(s,S);
   }
   cout<<s<<endl;
} 

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

#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define per(i, b, a) for(int i = b; i >= (a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (1000*1000*1000+7)
#define inf (2*1000*1000*1000+9)
#define infl ((ll)2*1000*1000*1000*1000*1000*1000+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc; 
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

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


void solve(){
	string s; cin>>s; 
	ll ans=0; 
	ll agg=0; 
	per(i,sz(s)-1,0){
		if(s[i]=='W') agg++; 
		else ans+=agg; 
	}
	cout<<ans; 
}


int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


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

// ---- ----

LL n, k;

LL q(LL v) { return v * v * v; }

int main() {
	cin >> n >> k;
	
	LL ans = q(n / k);
	if(k % 2 == 0) { ans += q((n + k / 2) / k); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		String StrN = sc.next();
		String StrA = sc.next();
		String StrB = sc.next();
		long n = Long.parseLong(StrN);
		long a = Long.parseLong(StrA);
		long b = Long.parseLong(StrB);

		long block = n / (a+b);
		long surplus = n%(a+b);
		
		long result = (block * a) + (surplus<a?surplus:a);
		System.out.println(result);
	}
}

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

int A[200001];
int ANS[200001];

int main(){
  int N;
  cin >> N;
  rep(i, N-1) cin >> A[i];
  rep(i, N-1) ANS[A[i]]++;
  rep(i, N) cout << ANS[i+1] << endl;
}


Measured memory_bytes: 5160
package main

import "fmt"

func main() {
	var h1, m1, h2, m2, k int
	fmt.Scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k)
	var out int
	out = 60*(h2-h1) + (m2 - m1) - k

	fmt.Println(out)
}


Measured memory_bytes: 1820
#include<stdio.h>

int main(void)
{
  int card[4][13];
  int x,i,j;
  int num,y;
  int false,true;
  char a;
  false = 0 ;
  true = 1;

  for( i = 0; i < 4; i++){
    for( j = 0; j < 13; j++){
      card[i][j] = false;
	}
  }


     scanf(" %d",&x);

  for( y = 0; y < x; y++){
    scanf(" %c %d", &a, &num);

    switch(a){
    case 'S':
      card[0][num-1] = true;
      break;
    case 'H':
      card[1][num-1] = true;
      break;
    case 'C':
      card[2][num-1] = true;
      break;
    case 'D':
      card[3][num-1] = true;
      break;
    }
  }

  for(i = 0;i < 4;i++){
    for(j = 0;j < 13;j++){
      if (card[i][j] == false){	
	if(i == 0){
	  printf("S %d\n", j+1);
	}
	else if(i == 1){
	  printf("H %d\n", j+1);
	}
	else if(i == 2){
	  printf("C %d\n", j+1);
	}
	else if(i == 3){
	  printf("D %d\n", j+1);
	}
	else{}
      }
    }
  }


  return 0;
}

Measured memory_bytes: 596
#include <utility>
#include <cstring>
#include <cstdio>
#include <queue>
#define MOD 1000000007
typedef long long ll; 
int lst[100005], to[400005], pre[400005], w[400005], tot;
std::priority_queue<std::pair<ll, int> > que; 
inline void add_edge(int u, int v, int _w)
{
	to[tot] = v;
	pre[tot] = lst[u]; 
	w[tot] = _w; 
	lst[u] = tot++; 
}
void bfs(int n, int s, ll *dis, int *dp)
{
	memset(dis, 0x3f, n << 3); 
	dis[s] = 0; 
	dp[s] = 1; 
	que.push({0, s}); 
	while (!que.empty())
	{
		ll d = -que.top().first;
		int u = que.top().second; 
		que.pop(); 
		if (dis[u] != d)
			continue; 
		for (int i = lst[u]; ~i; i = pre[i])
		{
			int v = to[i]; 
			if (dis[v] > dis[u] + w[i])
			{
				dis[v] = dis[u] + w[i]; 
				dp[v] = 0; 
				que.push({-dis[v], v}); 
			}
			if (dis[v] == dis[u] + w[i])
				(dp[v] += dp[u]) %= MOD; 
		}
	}
}
ll dis_s[100005], dis_t[100005]; 
int dp_s[100005], dp_t[100005]; 
int main()
{
	// freopen("ARC090-E.in", "r", stdin); 
	memset(lst, -1, sizeof(lst)); 
	int n, m, s, t; 
	scanf("%d%d%d%d", &n, &m, &s, &t); 
	for (int i = 0; i < m; i++)
	{
		int u, v, _w;
		scanf("%d%d%d", &u, &v, &_w); 
		add_edge(--u, --v, _w); 
		add_edge(v, u, _w); 
	}
	bfs(n, --s, dis_s, dp_s); 
	bfs(n, --t, dis_t, dp_t); 
	ll ans = (ll)dp_s[t] * dp_s[t] % MOD; 
	for (int u = 0; u < n; u++)
	{
		if (dis_s[u] + dis_t[u] == dis_s[t] && dis_s[u] == dis_t[u])
			(ans -= (ll)dp_s[u] * dp_s[u] % MOD * dp_t[u] % MOD * dp_t[u]) %= MOD; 
		for (int i = lst[u]; ~i; i = pre[i])
		{
			int v = to[i]; 
			if (dis_s[u] + dis_t[v] + w[i] == dis_s[t] && dis_s[u] << 1 < dis_s[t] && dis_t[v] << 1 < dis_s[t])
				(ans -= (ll)dp_s[u] * dp_s[u] % MOD * dp_t[v] % MOD * dp_t[v]) %= MOD; 
		}
	}
	printf("%lld\n", (ans + MOD) % MOD);
	return 0; 
}


Measured memory_bytes: 9328
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n;
        n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int q;
        int ans=0;
        q=sc.nextInt();
        int c;
        int l,r,mid;
        while(q>0){
            q--;
            c=sc.nextInt();
            l=-1;r=n-1;
            while(r-l>1){
                mid=(l+r)/2;
                if(a[mid]>=c)r=mid;
                else l=mid;
            }
            if(a[r]==c)ans++;
        }
        System.out.println(ans);
}
}


Measured memory_bytes: 68708
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;
const ll INF = 1LL << 60;

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int ans=0;
  if(k-a>=0){
    ans += a;
  }else{
    cout << k << endl;
    return 0;
  }

  k = k-(a+b);
  if(k<=0){
    cout << a << endl;
    return 0;
  }else{
    ans += k*(-1);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;int prime[30];int main(){int count=1;prime[0]=2;for(int i=3;i<100;i+=2){bool t=true;for(int j=1;j<count;j++){if(i%prime[j]==0)t=false;}if(t==true){prime[count]=i;count++;}}int n;while(cin>>n){n++;int ans=0;for(int cut=2;cut<n-1;cut++){bool t=true,f=true;for(int i=0;i<count;i++){if(cut%prime[i]==0&&cut!=prime[i])t=false;}for(int i=0;i<count;i++){if((n-cut)%prime[i]==0&&n-cut!=prime[i])f=false;}if(t==true&&f==true)ans++;}cout<<ans<<endl;}return 0;}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int minNum = N_MAX;
    string S;
    cin >> S;
    
    for (int i = 0; i < S.size() - 2; i++) {
        string string3Num = S.substr(i,3); 
        int num = atoi(string3Num.c_str());
        int diff = abs(753 - num);
        if (minNum > diff) {
            minNum = diff;
        } 
    }
    cout << minNum << endl;
	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 n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<LinkedList<Tuple>> list = new ArrayList<>();
        for(int i = 0; i <= n; i++) list.add(new LinkedList<>());
        int[] memo = new int[3];
        for (int i = 0; i < m; i++) {
            memo[0] = sc.nextInt();
            memo[1] = sc.nextInt();
            memo[2] = sc.nextInt();
            list.get(memo[0]).add(new Tuple(memo[1], memo[2]));
            list.get(memo[1]).add(new Tuple(memo[0], -memo[2]));
        }
        // DFS
        Queue<Integer> queue = new LinkedList<>();
        boolean[] visit = new boolean[n + 1];
        int[] distance = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            if (!visit[i]) {
                distance[i] = 0;
                visit[i] = true;
                queue.add(i);
                while (!queue.isEmpty()) {
                    int curr = queue.poll();
                    Iterator<Tuple> it = list.get(curr).iterator();
                    while(it.hasNext()) {
                        Tuple next = it.next();
                        if (!visit[next.x]) {
                            visit[next.x] = true;
                            distance[next.x] = distance[curr] - next.y;
                            queue.add(next.x);
                        } else {
                            if (distance[next.x] != distance[curr] - next.y) {
                                System.out.println("No");
                                return;
                            }
                        }
                    }
                }
            }
        }
        System.out.println("Yes");
    }

    static class Tuple {
        final int x;
        final int y;
        Tuple(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}

Measured memory_bytes: 175316
import java.util.Scanner;

class Main{



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int A= sc.nextInt();
		int B = sc.nextInt();
		System.out.println((A-1)*(B-1));
	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 23764
import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n,m=MI()
to=[[] for _ in range(n)]
for _ in range(m):
    u,v=MI1()
    to[u].append(v)
    to[v].append(u)

cnt=0
fin=[False]*n
for u in range(n):
    if fin[u]:continue
    fin[u]=True
    cnt+=1
    stack=[u]
    while stack:
        u=stack.pop()
        for v in to[u]:
            if fin[v]:continue
            fin[v]=True
            stack.append(v)

print(cnt-1)


Measured memory_bytes: 26372
mod = 998244353

# 貰うDP
# Pythonで普通に通った．
def main(N, S):
    dp = [0 if n != 0 else 1 for n in range(N)]     # dp[i]はマスiに行く通り数． (答えはdp[-1]), dp[0] = 1 (最初にいる場所だから1通り)
    A = [0 if n != 0 else 1 for n in range(N)]      # dp[i] = A[i] - A[i-1] (i >= 1), A[0] = dp[0] = 1 (i = 0) が成り立つような配列を考える．

    for i in range(1, N):   # 今いる点 (注目点)
        for l, r in S:  # 選択行動範囲 (l: 始点, r: 終点)
            if i - l < 0:   # 注目点が選択行動範囲の始点より手前の場合 → 注目点に来るために使用することはできない．
                break
            else:           # 注目点に来るために使用することができる場合
                if i - r <= 0:  # lからrの間で，注目点に行くために使用できる点を逆算． そこに行くことができる = 選択行動範囲の値を選択することで注目点に達することができる通り数．
                    dp[i] += A[i-l]
                else:
                    dp[i] += A[i-l] - A[i-r-1]
        dp[i] %= mod
        A[i] = (A[i-1] + dp[i]) % mod
    print(dp[-1])

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    S = {tuple(map(int, input().split())) for k in range(K)}
    S = sorted(list(S), key = lambda x:x[0])    # 始点でsort (範囲の重複がないため)
    main(N, S)

Measured memory_bytes: 24768
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a, b, c, d, n, k, x,l;
    string s, t;
    ll ans = INF;
    double dans = 0;
    string sans = "Good";

    cin  >> n >> l;
    ll sum = (l-1) * n + (n*(n+1)/2);
    
    ll tmp=0;
    rep1(i, n){
        if(abs(ans) > abs(l + i -1)){
            ans = abs(l + i -1);
            tmp = l+i-1;
        }
    }



    std::cout << sum - tmp << endl; 
    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] a = new int[3][3];
        boolean[][] c = new boolean[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int n = sc.nextInt();
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (b[i] == a[j][k]) {
                        c[j][k] = true;
                        break;
                    }
                }
            }
        }
        if (c[0][0] && c[0][1] && c[0][2] || c[1][0] && c[1][1] && c[1][2] || c[2][0] && c[2][1] && c[2][2]
                || c[0][0] && c[1][0] && c[2][0] || c[0][1] && c[1][1] && c[2][1] || c[0][2] && c[1][2] && c[2][2]
                || c[0][0] && c[1][1] && c[2][2] || c[0][2] && c[1][1] && c[2][0]) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <set> 
#include <iterator> 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)


int main()
{
    
    fastio();

        ll n,w;
        cin>>n>>w;
        vector <pair<ll, ll> > v;
        ll a,b,mx=0,ans=0;
        for(ll i=0;i<n;i++)
        {
            cin>>a>>b;
            v.pb(mp(a,b));
            mx+=b;
        }
        ll dp[mx+1]={0};
        for(int i=1;i<=mx;i++)
            dp[i]= 100000000000000;
        for(int i=0;i<n;i++)
        {
            for(int j=mx;j>=v[i].ss;j--)
            {
                dp[j] = min(dp[j],dp[j-v[i].ss]+v[i].ff);
            }
        }
        for(int i=mx;i>=0;i--)
        {
            if(dp[i]<=w)
            {
                ans=i;
                break;
            }
        }
        cout<<ans<<endl;
        
}


Measured memory_bytes: 1024
import collections
N, M = map(int, input().split())
S = [list(map(int, input().split())) for i in range(M)]
smax = max([s[0] for s in S])
smin = min([s[1] for s in S])
if smin - smax + 1 >= 0 :
    print(smin - smax + 1)
else :
    print(0)


#S2 = [set(range(s[0], s[1] + 1)) for s in S]
#S3 = set.intersection(*S2)
#print(len(S3))

#ans = set(range(S[0][0], S[0][1] + 1))
#for s in S[1:] :
#    a = set(range(s[0], s[1] + 1))
#    ans = ans & a
#    if len(ans) == 0 :
#        break
#print(len(ans))

Measured memory_bytes: 28560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) (X).begin(), (x).end()
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  string s, t; cin >> s;
  if (N%2 == 0) {
    rep (i, N/2) {
      if (s.at(i) != s.at(i + N/2)) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
  }
  else
    cout << "No" << endl;

  return 0;
}


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

int main() {
  int payment;
  while (1) {
    cin >> payment;
    if (payment == 0) break;

    int change = 1000 - payment;
    int ans = 0;
    ans += change / 500; change %= 500;
    ans += change / 100; change %= 100;
    ans += change / 50; change %= 50;
    ans += change / 10; change %= 10;
    ans += change / 5; change %= 5;
    ans += change;

    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    string S;
    cin >> S;

    int cnt = 1;
    for(int i=1; i<N; i++)
        if(S[i-1] != S[i]) cnt++;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
import math

a, b, x = map(int, input().split())
s = x / a

if s >= a * b / 2:
    h = ((a * b - s) * 2) / a
    radian = math.atan2(h, a)
    angle = math.degrees(radian)
    print(angle)
else:
    h = 2 * s / b
    radian = math.atan2(b, h)
    angle = math.degrees(radian)
    print(angle)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
	int h,w;
	cin >> h >> w;
	char temp;
	for(int i=0; i<=h+1; i++){
		for(int j=0; j<=w+1; j++){
			if(i==0 || j==0 || i==h+1 || j==w+1){
				cout << "#";
				continue;
			}
			cin >> temp;
			cout << temp;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) (a).begin(),(a).end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define ub(s,x) upper_bound(all(s),x)-s.begin()
#define uniq(a) a.erase(unique(all(a)),a.end())
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
typedef long long ll;
const int INF = 1e9;


template<typename T>
class BIT {
    public:
    int n;
    vector<T> bit; // i: [1,n]
    BIT(int size) {
        n = size + 1;
        bit = vector<T>(n+1,0);
    }

    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }

    T sum(int i) {
        T ret = 0;
        while (i > 0) {
            ret += bit[i];
            i -= i & -i;
        }
        return ret;
    }

    T range(int l, int r) {
        return sum(r) - sum(l-1);
    }
};

ll n;
vector<int> a;

bool check(int x) {
    vector<int> b(n);
    rep(i,n){
        b[i] = (a[i] >= x ? +1 : -1);
    }
    vector<ll> s(n+1);
    rep(i,n){
        s[i+1] = s[i] + b[i];
    }
    vector<pair<ll, int>> vp(n+1);
    rep(i,n+1) {
        vp[i] = {s[i],i};
    }
    sort(all(vp));
    vector<ll> c(n+1);
    rep(i,n+1){
        c[vp[i].second] = i;
    }

    ll result = 0;
    BIT<int> bit(n+1);
    rep(i,n+1){
        result += bit.sum(c[i]+1);
        bit.add(c[i]+1, 1);
    }

    return (n*(n+1)/2 + 1)/2 <= result;
}

int main(void) {
    cin >> n;
    a.resize(n);
    vector<int> meds(n);

    rep(i,n){
        cin >> a[i];
        meds[i] = a[i];
    }
    sort(all(meds));
    int l = 0, r = n;
    while (l + 1 < r) {
        int mid = (l+r)/2;
        // debug(mid);
        if (check(meds[mid])) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << meds[l] << endl;
    return 0;
}

/*
int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }

    vector<ll> med;
    // [l,r)
    rep(r,n+1)rep(l,r){
        printf("[l,r) = [%d,%d)\n", l,r);
        vector<ll> v;
        for(int i = l; i < r; i++){
            cout<<a[i]<<" ";
            v.push_back(a[i]);
        }
        cout<<endl;

        sort(all(v));
        med.push_back(v[v.size()/2]);
        cout<<"med: "<<med.back()<<endl;
        cout<<"---------------"<<endl;
    }
    sort(all(med));

    cout<<med[med.size()/2]<<endl;
        for(ll x : med){
            cout<<x<<" ";
        }
        cout<<endl;
    return 0;
}
*/

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int n, k;
  cin >> n >> k;
  int sum = 0;
  REP(i, n) {
    int x;
    cin >> x;
    sum += min(x * 2, (k - x) * 2); // 往復のため、* 2
    // cout << x * 2 << " " << (k - x) * 2 << endl;
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int l = s.size();
    int p = 0, g = 0;
    rep (i, l) {
        if (s[i] == 'p') p++;
        else g++;
    }
    if (l % 2) {
        int h = (l + 1) / 2;
        cout << g - h << endl;
    } else {
        int h = l / 2;
        cout << g - h << endl;
    }
    
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    string s;
    cin >> s;

    ll g = 0;
    ll p = 0;
    ll ans = 0;
    for(int i = 0; i < s.size(); i++ ){
        if(p < g){
            p ++;
            if(s[i] == 'g') ans ++;
        }
        else{
            g ++;
            if(s[i] == 'p'){
                ans --;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
int main() {
 
	ull N; cin >> N;
	int ans = 0;
	for(int i=2;i*1LL*i<=N;++i) {
		int cur = 0;
		while (N % i == 0) {
			cur++;
			N /= i;
		}
		for(int j=1;j<=cur;++j) {
			if (cur < j) break;
			ans++; cur -= j;
		}
	}
	if (N > 1) ans++;
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]++;
    }

    vl v(n+1);  // v[i] : i番目(iは0-index)の山の一番上の数
    v[n] = INF;
    rep(i, n) {
        // vの中でa[i]以上の値が現れる最初の位置posを二分探索で高速に求める
        auto pos = lower_bound(all(v), a[i]) - v.begin();  
        v[pos-1] = a[i];  // (pos-1)番目の山にa[i]を置く
    }
    
    ll ans = 0;
    rep(i, n) {
        if(v[i] > 0) {
            ans++;
        }
    }

    out(ans);
    re0;
}

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

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

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

    ll N,K; cin >> N >> K;

    cout << (N*500 >= K?"Yes":"No") << endl;

    return 0;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

S_ba = []
S_ab = []
for i in range(N):
    if A[i] < B[i]: S_ba.append(B[i] - A[i])
    elif A[i] > B[i]: S_ab.append(A[i] - B[i])

if sum(S_ba) > sum(S_ab):
    print(-1)
    exit()
    
ans = len(S_ba)
now = 0
rem = sum(S_ba)
S_ab.sort(reverse=True)
for i in range(len(S_ab)):
    if rem <= now: break
    now += S_ab[i]
    ans += 1

print(ans)


Measured memory_bytes: 24168
import sys

N, M = map(int, input().split())

# 壊れている床
a = [-1]

for i in range(M):
    a.append(int(input()))
    # 連続して壊れていたら辿り着けない
    if a[i+1] - a[i] == 1:
        print(0)
        sys.exit()
        
# フィボナッチ数値
def fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

# 階段を登る組み合わせ
combi = 1

for i in range(len(a) - 1):
    # 次の穴との距離
    dis = a[i+1] - a[i]
    combi *= fib(dis)

dis = N+1 - a[-1]
combi *= fib(dis)

print(combi % 1000000007)

Measured memory_bytes: 5012
#include <iostream>
#include <time.h>
#include <algorithm>
#include <stdio.h>
#include<string.h>

typedef long long LL;

using namespace std;

const int times = 20;
LL fac[1001];
int cnt;

LL mul(LL a, LL b, LL mod)
{
	LL ans = 0;
	while (b)
	{
		if (b & 1)
		{
			ans = (ans + a) % mod;
		}
		a = (a << 1) % mod;
		b >>= 1;
	}
	return ans;
}

LL pow(LL a, LL b, LL mod)
{
	LL ans = 1;
	while (b)
	{
		if (b & 1)
		{
			ans = mul(ans, a, mod);
		}
		b >>= 1;
		a = mul(a, a, mod);
	}
	return ans;
}

bool witness(LL a, LL n)
{
	LL temp = n - 1;
	int j = 0;
	while (temp % 2 == 0)
	{ // 其实就是得到 m
		j++;
		temp /= 2;
	}
	LL x = pow(a, temp, n);
	if (x == 1 || x == n - 1)
	{ // 判断a^m
		return true;
	}
	while (j--)
	{
		x = mul(x, x, n); // 进一步判断 a^(2m)  a^(4m) ...
		if (x == n - 1)
			return true;
	}
	return false;
}

bool miller_rabin(LL n)
{
	if (n == 2)
	{ //  如果是2肯定是素数
		return true;
	}
	if (n < 2 || n % 2 == 0)
	{ //如果小于2或者是大于2的偶数肯定不是素数
		return false;
	}
	for (int i = 0; i < times; i++)
	{ //随机化检验
		LL a = rand() % (n - 1) + 1;
		if (!witness(a, n))
			return false;
	}
	return true;
}

LL gcd(LL a, LL b)
{ // 这里的gcd和一般的gcd不一样
	if (a == 0)
	{ // pollard_rho的需要
		return 1;
	}
	if (a < 0)
	{ // 可能有负数
		return gcd(-a, b);
	}
	while (b)
	{
		LL t = a % b;
		a = b;
		b = t;
	}
	return a;
}

LL pollard_rho(LL n, LL c)
{                    // 找因子
	LL i = 1, k = 2; // 用来判断是否成环
	LL xx = rand() % n, y = xx;
	while (1)
	{
		i++;
		xx = (mul(xx, xx, n) + c) % n;
		LL d = gcd(y - xx, n);
		if (1 < d && d < n)
		{ // 找到一个因数
			return d;
		}
		if (y == xx)
		{ // 出现循环，那么查找失败
			return n;
		}
		if (i == k)
		{ // 相当一个优化？
			y = xx;
			k <<= 1;
		}
	}
}

void find(LL n)
{ // 通过因数来找质因子
	if (miller_rabin(n))
	{
		fac[cnt++] = n; // 记录质因子
		return;
	}
	LL p = n;
	while (p >= n)
		p = pollard_rho(p, rand() % (n - 1) + 1); //如果转了一圈还是p那么继续
	find(p);
	find(n / p);
}

int main()
{
	srand(251);
	LL a, b;
	cin>>a>>b;
    if(a==1||b==1){
        cout<<1;
        return 0;
    }
	if (miller_rabin(a))
	{
		if (b % a == 0)
			cout << 2;
		else
			cout << 1;
		return 0;
	}
	if (miller_rabin(b))
	{
		if (a % b)
			cout << 2;
		else
			cout << 1;
		return 0;
	}
	cnt = 0;
	find(a);
	LL fa[1001];
	memcpy(fa, fac, sizeof(fac));
	sort(fa, fa + cnt);
	int ss = cnt;
	cnt = 0;
	find(b);
	sort(fac, fac + cnt);
	int ans = 0;
	for (int i = 0; i < ss; i++) {
		if (i && fa[i] == fa[i - 1])continue;
		for (int j = 0; j < cnt; j++) {
			if (j && fac[j] == fac[j - 1])continue;
			if (fac[j] == fa[i])ans++;
		}
	}
	cout << ans+1;
	return 0;
}

Measured memory_bytes: 3664
// abc131_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll x = B - B / C - B / D + B / (C * D / gcd(C, D));
    A--;
    ll y = A - A / C - A / D + A / (C * D / gcd(C, D));
    print(x - y);

    return 0;
}


Measured memory_bytes: 256
typedef long long llong;

#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n; cin >> n;
	vector<int> a(3*n);
	for (int i = 0; i < 3*n; i++) cin >> a[i];

	sort(a.begin(), a.end());
	llong res = 0;
	for (int i = n; i < 3*n; i += 2) {
		res += a[i];
	}
	cout << res << endl;


	return 0;
}

Measured memory_bytes: 1408
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    N = len(S)
    for l in range(N):
        for r in range(l,N):
            if S[:l]+S[r:]=="keyence":
                print("YES")
                return
    print("NO")
if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


class EulerTourForVertex{
private:
  vector<Int> ls,rs;
  Int pos;

  void dfs(Int v,Int p){
    ls[v]=pos++;
    for(Int u:G[v])
      if(u!=p) dfs(u,v);
    rs[v]=pos;
  }
public:
  vector<vector<Int> > G;

  EulerTourForVertex(){}
  EulerTourForVertex(Int n):ls(n),rs(n),G(n){}

  void add_edge(Int u,Int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  void build(Int r=0){
    pos=0;
    dfs(r,-1);
  }

  Int idx(Int v){return ls[v];}

  template<typename F>
  void exec(Int v,F f){
    f(ls[v],rs[v]);
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,q;
  cin>>n>>q;
  EulerTourForVertex G(n);
  for(Int i=1;i<n;i++){
    Int a,b;
    cin>>a>>b;
    a--;b--;
    G.add_edge(a,b);
  }
  G.build(0);
  vector<Int> sm(n+1,0);
  for(Int i=0;i<q;i++){
    Int p,x;
    cin>>p>>x;
    p--;
    G.exec(p,[&](Int l,Int r){sm[l]+=x;sm[r]-=x;});
  }
  for(Int i=0;i<n;i++) sm[i+1]+=sm[i];
  for(Int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<sm[G.idx(i)];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
using namespace std;
int main(){

  int a[5],a1,a2,i,j;

  while(cin>>a1>>a2,a1){

    int b[5]={0,1,2,3,4};
    a[0]=a1+a2;
    for(i=1;i<5;i++){
      cin>>a1>>a2;
      a[i]=a1+a2;
    }

    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
        if(a[j]<a[j+1]){
            int blank;
            blank=a[j];
            a[j]=a[j+1];
            a[j+1]=blank;
            blank=b[j];
            b[j]=b[j+1];
            b[j+1]=blank;
        }
      }
    }
    char team;
    team='A'+b[0];
    cout<<team<<" "<<a[0]<<endl;

  }

  return 0;


}
          
    
      

Measured memory_bytes: 2972