akhauriyash/Code-Regression huggingface dataset:
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

signed main() {
    //input
    int a,b,n;cin>>a>>b>>n;
    check_input();

    //solve
    cout << (a*min(b-1, n))/b << endl;


    return 0; 
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

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

const ll mod = 1e9 + 7;



int main(){
    string S;
    cin >> S;
    int N = S.size();
    char bef = S[0];
    int cnt = 1;
    repf(i,1,N){
        if (S[i]!=bef){
            cnt++;
            bef = S[i];
        }
    }
    cout << cnt - 1 << endl;
}


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

int main() {
  int N, P;
  string S;
  cin >> N;
  vector<pair<pair<string, int>, int>> V(N);
  for (int i = 0; cin >> S >> P; i++) V.at(i) = {{S, -P}, i + 1};
  sort(V.begin(), V.end());
  for (auto v : V) cout << v.second << "\n";
}

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

int main() {
	long long n, tmp;
	scanf("%lld", &n);
	for (long long i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) tmp = i;
	}
	long long tmp2 = n / tmp;
	cout << tmp + tmp2 - 2 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int n = sc.nextInt();

		int sum = 0;

		for(int i = 0; i < n; i++) {
			sum += sc.nextInt();
		}

		if(sum >= h) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string b;
    cin >> b; 
    rep(i,b.size()){
        if(b.at(i)=='A') b.at(i) = 'T';
        else if(b.at(i)=='T') b.at(i) = 'A';
        else if(b.at(i)=='C') b.at(i) = 'G';
        else b.at(i) = 'C';
    }
    cout << b << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
ans = ""
for i in range(W + 2):
  ans += "#"
ans += "\n"

for i in range(H):
  ans += "#"
  ans += ans.join(input().split())
  ans += "#\n"

for i in range(W + 2):
  ans += "#"
ans += "\n"

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    long long int r[200001]={0}, i, j, n, max=-1000000000, c, prev=1000000001;
    scanf("%lld", &n);
    for(i = 0; i < n; i++){
        scanf("%lld", &r[i]);
    }
    for(i = 0; i < n; i++){
        while(i < n){
            if(prev <= r[i]){
                i++;
            } else {
                break;
            }
        }
        for(j = i + 1; j < n; j++){
            c = r[j] - r[i];
            if(c > max){
                max = c;
            }
            prev = r[i];
        }
    }
    printf("%lld\n", max);
    return 0;
}

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

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

    priority_queue<int> pq;

    for(int i=0; i<n; i++){
        int a; cin>>a;
        pq.push(a);
    }

    while(m>0){
        int t = (pq.top() / 2);
        pq.pop();
        pq.push(t);        
        m--;
    }

    ll sum = 0;

    while( !pq.empty()){
        sum += pq.top();
        pq.pop();
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 892
while 1:
  N,M,P=map(int,input().split())
  if not N and not M and not P:break
  X=[int(input()) for _ in range(N)]
  if not X[M-1]:r=0
  else:r=int(sum(X)*100*(100-P)/100/X[M-1])
  print(r)


Measured memory_bytes: 5624
# coding: utf-8
from math import ceil

A,B,AB,x,y = list(map(int,input().split()))
p = []
for i in range(0,max(x,y)*2+1,2):
    ab = i
    a = max(0,ceil(x - (1/2)*i))
    b = max(0,ceil(y - (1/2)*i))
    p.append(A*a+B*b+AB*ab)
print(min(p))

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

//cmdで g++ test.cpp とするとコンパイルできる

int main() {
  long N;
  cin>>N;
  vector<vector<int>> A(3,vector<int>(N));
  for(int j=0;j<3;j++){
    for(int i=0;i<N;i++){
      cin>>A.at(j).at(i);
    }
    sort(A.at(j).begin(),A.at(j).end());
  }
  long ans=0;

  for(int i=0;i<N;i++){
    long idx1=lower_bound(A.at(0).begin(),A.at(0).end(),A.at(1).at(i))-A.at(0).begin();
    long idx2=upper_bound(A.at(2).begin(),A.at(2).end(),A.at(1).at(i))-A.at(2).begin();
    ans+=idx1*(N-idx2);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int nbJours;
	cin >> nbJours;
	int meilleurValeur[nbJours + 1][3];
	int valeurJour[nbJours][3];
	for (int i = 0 ; i < nbJours ; i++)
	{
		for (int j = 0 ; j < 3 ; j++)
		{
			meilleurValeur[i + 1][j] = -1e9;
			cin >> valeurJour[i][j];
		}
	}
	meilleurValeur[0][0] = meilleurValeur[0][1] = meilleurValeur[0][2] = 0;
	for (int iJour = 0 ; iJour < nbJours ; iJour++)
	{
		for (int j = 0 ; j < 3 ; j++)
		{
			for (int k = 0 ; k < 3 ; k++)
			{
				if (j != k)
				{
					meilleurValeur[iJour + 1][j] = max(meilleurValeur[iJour + 1][j] ,
														meilleurValeur[iJour][k]);
				}
			}
			meilleurValeur[iJour + 1][j] += valeurJour[iJour][j];
		}
	}
	cout << max(meilleurValeur[nbJours][0] , max(meilleurValeur[nbJours][1] , meilleurValeur[nbJours][2])) << endl;
}

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

int main(void) {
  int N, X, pos = 0, ans = 1;
  cin >> N >> X;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
    pos += L[i];
    if (pos <= X) ans++;
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int d;
    cin >> d;
    string res = "Christmas";
    d -= 25;
    while (d < 0) {
    	res += " Eve";
    	d++;
    }
    cout << res << endl;
}


Measured memory_bytes: 3520
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n, m, s = nm()
N = n * 3001
G = [list() for _ in range(N)]
for _ in range(m):
    u, v, a, b = nm()
    u -= 1; v -= 1
    for j in range(0, N, n):
        if v + j - a * n >= 0:
            G[u + j].append((v + j - a * n, b))
        if u + j - a * n >= 0:
            G[v + j].append((u + j - a * n, b))
for u in range(n):
    c, d = nm()
    for j in range(0, N, n):
        G[u + j].append((min(u + j + c * n, u + N - n), d))

import heapq as hq

def dijkstra(G, s, t=None):
    """
    G[v] = [(x1, c1), (x2, c2), ...]
    """
    dist = [1<<60]*len(G)
    dist[s] = 0
    q = [(0, s)]
    while q:
        d, v = hq.heappop(q)
        if d > dist[v]: continue
        for x, c in G[v]:
            if dist[x] > d + c:
                dist[x] = d + c
                hq.heappush(q, (d + c, x))
    if t is None:
        return dist
    else:
        return dist[t]

dist = dijkstra(G, min(s, 3000) * n)
for i in range(1, n):
    print(min(dist[i::n]))


Measured memory_bytes: 115396
#include <cstdio>
using namespace std;
const int MAXN = 1e5;

int n, x;
int sol[2*MAXN];
bool bio[2*MAXN];

int main(){

    scanf("%d %d", &n, &x);

    if (x == 1 || x == 2*n - 1){
        printf("No");
        return 0;
    }

    sol[n-1] = x;
    sol[n-2] = 1;
    sol[n] = 2*n-1;
    bio[x] = 1;
    bio[1] = 1;
    bio[2*n-1] = 1;

    int cnt = 2;

    for (int i = 0; i < n-2; i++){

        while (bio[cnt]) cnt++;

        sol[i] = cnt;
        bio[cnt] = 1;

    }

    for (int i = n+1; i < 2*n-1; i++){

        while (bio[cnt]) cnt++;

        sol[i] = cnt;
        bio[cnt] = 1;

    }

    printf("Yes\n");
    for (int i = 0; i < 2*n-1; i++) printf("%d\n", sol[i]);

    return 0;

}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  ll N; cin>>N;
  if(N % 2LL == 0LL) {
    ll ans = 0;
    for(ll base = 5; base <= N; base *= 5LL) {
      ans += ((N / base ) / 2LL);
    }
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

int n;
int field[18][18];

void dfs(int y, int x, int cnt)
{
  if (cnt > n * n) return;

  if (x < 0){
    dfs(y, n - 1, cnt);
  } else if (n <= x){
    dfs(y, 0, cnt);
  } else if (n <= y){
    dfs(0, x, cnt);
  } else if (field[y][x]){
    dfs(y + 1, x - 1, cnt);
  } else {
    field[y][x] = cnt;
    dfs(y + 1, x + 1, cnt + 1);
  }
}

signed main()
{
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  
  for (; cin >> n, n;){
    memset(field, 0, sizeof(field));
    field[n / 2 + 1][n / 2] = 1;
    //printf("%d %d\n", n / 2 + 1, n / 2);
    dfs(n / 2 + 2, n / 2 + 1, 2);
    REP(i, n){
      REP(j, n){
        printf("%4d", field[i][j]);
      }
      puts("");
    }
  }

  return (0);
}

Measured memory_bytes: 1156
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors

N = int(input())

count = 0
for i in range(1, N+1):
    # print(len(make_divisors(i)), make_divisors(i))
    if i % 2 == 1 and len(make_divisors(i)) == 8:
        count += 1

print(count)

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

const int N = 505, INF = 1e9;
int a[N][N];
int dis[N][N];
bool valid[N][N], done[N][N];

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

queue<int> q;

void SPFA() {
    while(q.size()) {
        int x = q.front(); q.pop();
        int y = q.front(); q.pop();
        for (int dir = 0; dir < 4; dir++) {
            int nx = x + dx[dir];
            int ny = y + dy[dir];
            if (valid[nx][ny] && dis[nx][ny] > dis[x][y] + !done[nx][ny]) {
                dis[nx][ny] = dis[x][y] + !done[nx][ny];
                q.push(nx);
                q.push(ny);
            }
        }
    }
}

void print(int n) {
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            if (done[i][j]) cout<<"_ ";
            else cout<<dis[i][j]<<" ";
        }
        cout<<endl;
    }
}

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

    int n;
    cin>>n;

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) {
            dis[i][j] = INF;
            valid[i][j] = true;
        }
    }

    for (int i=1; i<=n; i++) {
        dis[1][i] = dis[i][1] = dis[n][i] = dis[i][n] = 1;
        q.push(1); q.push(i);
        q.push(i); q.push(1);
        q.push(n); q.push(i);
        q.push(i); q.push(n);
    }

    SPFA();
    int ans = 0;
    for (int i=1; i<=n*n; i++) {
        int z;
        cin>>z;

        int x = (z-1)/n+1;
        int y = (z-1)%n+1;
        ans += dis[x][y]-1;

//        print(n);
//        cout<<x<<" "<<y<<" ---> "<<dis[x][y]-1<<endl<<endl;


        done[x][y] = 1;
        dis[x][y]--;
        q.push(x); q.push(y);
        SPFA();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


int main() {
    int n;
    cin >> n;
    vector<P> ans;
    if (n % 2 == 0) {
        int s = n * (n + 1) / 2 - (n + 1);
        rep (i, 1, n + 1) {
            rep (j, i + 1, n + 1) {
                if (i + j == n + 1) continue;
                ans.emplace_back(make_pair(i, j));
            }
        }
    } else {
        int s = (n - 1) * n / 2;
        rep (i, 1, n) {
            ans.emplace_back(make_pair(i, n));
        }
        rep (i, 1, n) {
            rep (j, i + 1, n) {
                if (i + j == n) continue;
                ans.emplace_back(make_pair(i, j));
            }
        }
    }
    cout << ans.size() << endl;
    rep (i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}



Measured memory_bytes: 3700
#include <stdio.h>
#define MAX(x,y)	((x)>(y)?(x):(y))
#define MAX3(x,y,z)	((x)>(MAX(y,z)) ? (x):(MAX(y,z)))

int main(){
    int n, ans=0, l[100+1]={0};
    scanf("%d",&n);
    for(int i=0; i<n; i++){ scanf("%d", &l[i]); }

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if( l[i]==l[j] ){ continue; }
            for(int k=j+1; k<n; k++){
                if( l[i]==l[k] || l[j]==l[k] ){ continue; }
                if( ((l[i]+l[j]+l[k]) - MAX3(l[i],l[j],l[k])) <= MAX3(l[i],l[j],l[k]) ){ continue; }
                ans++;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	char c; cin >> c;
	cout << ((c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')?"vowel":"consonant");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

using namespace std;

int main() {

    int N, Ncopy;
    cin >> N;
    Ncopy = N;

    int c = 0;
    for (int i=0; i<10; i++) {
        N = N / 10;
        if (N != 0) {
            c += 1;
        }
        else {
            break;
        }
    }

    int d;
    int count = 0;
    if (c%2 == 0) { 
        d = c/2;
        for (int i=0; i<d;i++) {
            count += 9 * pow(10, (i*2));
        }
        count += (Ncopy - pow(10, c) + 1);  
    } else {
        d = c/2 + 1;
        for (int i=0; i<d;i++) {
            count += 9 * pow(10, (i*2));
        }
    }

    cout << count;


    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

if 0 in set(A):
    print(0)
    exit()

result = 1
for i in range(N):
    result *= A[i]
    if result > pow(10,18):
        print(-1)
        exit()

print(result)

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

int dp[81][81][14000];
int a[81][81], b[81][81];

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    rep(i, 80) rep(j, 80) rep(k, 6500) dp[i][j][k] = 0;

    int h, w;
    cin >> h >> w;

    rep(y, h) rep(x, w) cin >> a[y][x];
    rep(y, h) rep(x, w) cin >> b[y][x];

    int base = 7000;
    dp[0][0][base + (a[0][0] - b[0][0])] = 1;
    dp[0][0][base - (a[0][0] - b[0][0])] = 1;

    rep(y, h) rep(x, w) {
        if (y > 0) {
            rep(i, 14000) if (dp[y - 1][x][i]) {
                int z = a[y][x] - b[y][x];
                if (i + z < 14000) dp[y][x][i + (a[y][x] - b[y][x])] = 1;
                if (i - z >= 0)    dp[y][x][i - (a[y][x] - b[y][x])] = 1;
            }
        }
        if (x > 0) {
            rep(i, 14000) if (dp[y][x - 1][i]) {
                int z = a[y][x] - b[y][x];
                if (i + z < 14000) dp[y][x][i + (a[y][x] - b[y][x])] = 1;
                if (i - z >= 0   ) dp[y][x][i - (a[y][x] - b[y][x])] = 1;
            }
        }
    }

    int ans = 7000;
    rep(i, 14000) if (dp[h - 1][w - 1][i]) {
        ans = min(ans, abs(i - 7000));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 355968
#include <stdio.h>


int main(void)
{
  
  int liv[4][3][10];
  int i, j, k;
  
  for( i = 0; i < 4; i++ ){
    for( j = 0; j < 3; j++ ){
      for( k = 0; k < 10; k++ ){
        
        liv[i][j][k] = 0;
      }
    }
  }
   
  int n;
  scanf("%d", &n);
  
  int a;
  int num;
  
  for( a = 0; a < n; a++ ){
    scanf("%d %d %d %d", &i, &j, &k, &num);
    liv[i-1][j-1][k-1] += num;
  }
  
  
  for( i = 0; i < 4; i++ ){
    for( j = 0; j < 3; j++ ){
      for( k = 0; k < 10; k++ ){
        
        printf(" %d", liv[i][j][k] );
      
      }
      
      puts("");
    }
    
    if( i < 3 ){
      for( a = 0; a < 20; a++ ){
        printf("#");
      }
      puts("");
    }    

  }
  
  return 0;

 
} 

Measured memory_bytes: 612
x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())),reverse = True)
q = sorted(list(map(int,input().split())),reverse = True)
r = sorted(list(map(int,input().split())),reverse = True)
if x+y <= c:
    res = sorted(p[:x]+q[:y]+r[:x+y],reverse = True)
else:
    res = sorted(p[:x]+q[:y]+r[:c],reverse = True)
print(sum(res[:x+y]))

Measured memory_bytes: 22460
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for(int i = 1; i < n; i++) {
        if(a[i] < a[i - 1]) {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4756
while True:
    n, x = map(int, raw_input().split())
    if n == 0 and x == 0:
        break

    count = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            for k in range(j+1, n+1):
                if i+j+k == x:
                    count += 1
    print count

Measured memory_bytes: 4208
//program takes N, number of nodes (numbered from 0 to N-1) and K edges, where each edge is represented by (u,v,e)
//does DFS on it

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

//node struct (assumes weighted), if unweighted just take out E
struct Node
{
    int V;
};

//adjacency "list" (assume a large N for no problems)
vector<Node> adj[100000];

int N,K;
int vis[100000];

void dfs(int n)
{
    //prints out the current node n
    //cout<<n<<endl;
    //this goes through the nodes connected to n and only continues the DFS on the unvisited nodes
    for(int i=0; i<adj[n].size(); i++)
    {
        int v=adj[n][i].V;
        if(vis[v]==0){
            vis[v]=1;
            dfs(v);
        }
    }
}
int e[100000][2];
int main(){
    int res = 0;
    //input integers
    cin>>N>>K;
    //create graph and fill in edge list
    for(int i=0; i<K; i++){
        //input the edge
        int u,v;
        cin>>u>>v;
        //adds edge to edge list
        e[i][0] = u; e[i][1] = v;
        
    }

    //check each edge if removing it causes unconnectedness
    for(int i = 0; i < K; i++){
      int a = e[i][0]; int b = e[i][1];
      for( int ii = 0; ii <= N; ii++ ){
        adj[ii].clear();
      }
      //initializing the visited array
      for(int iii=1; iii<=N; iii++) vis[iii]=0;
      //make the rest of edges into graph then check if connected
      int x,y;
      for( int j = 0; j < K; j++ ){
        if( j != i ){
          x = e[j][0]; y = e[j][1];
          //this part creates a node (v,e)
          Node a;
          a.V=x;
          //this creates a node from u to v 
          adj[y].push_back(a);
          
          //this part is for undirected graphs -> we need to connect v to u as well
          a.V=y;
          adj[x].push_back(a);
        }
      }
      int start;
      if(i == 0) start = e[1][0];
      else start = e[0][0];
      vis[start] = 1;
      dfs(start);
      int temp = 0;
      for(int ind=1; ind<=N; ind++){
        if(vis[ind] == 1) temp++;
      }
      if(temp != N) res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 2560
package main

import (
	"fmt"
	"math"
)

func main() {
	var n float64
	fmt.Scan(&n)
	cnt := 0
	for c := float64(n - 1); c >= 1; c-- {
		max := math.Floor(math.Sqrt(n - c))
		for a := float64(1); a <= max; a++ {
			b := (n - c) / a
			if b == math.Floor(b) {
				if a != b {
					cnt += 2
				} else {
					cnt++
				}
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long

int m=1e9+7;


int32_t main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		
	}
	
	int dp[n+1][k+1]={0};
	
	for(int i=0; i<=n; i++)
	dp[i][0]=1;
	
	for(int i=1; i<=k; i++)
	dp[0][i]=0;
	
	
	for(int i=1; i<=n; i++)
	{
		int sum[k+1]={0};
		
		sum[0]=dp[i-1][0];
		
		for(int j=1; j<=k; j++ )
		sum[j]=(sum[j-1]%m+dp[i-1][j]%m)%m;
		
		
		for(int j=1; j<=k; j++)
		{
			/*for(int p=0; p<=min(a[i],j); p++ )
			{
				dp[i][j]+=dp[i-1][j-p];
				
				"for o(n*k^2) TC"
			}
			*/
			if((j-a[i]-1)>=0)
			dp[i][j]=(sum[j]%m-sum[j-a[i]-1]%m+m)%m;
			else
			dp[i][j]=sum[j]%m;
		}
	}
	
     cout<<dp[n][k]%m;
     
     
     
	 
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(int &a, int b){
  if(a > b)
    a = b;
}
void chmax(int &a, int b){
  if(a < b)
    a = b;
}

void llchmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void llchmax(ll &a, ll b){
  if(a < b)
    a = b;
}

ll modPow(ll a, ll n, ll p){
  if(n == 0)
    return 0;
  if(n == 1)
    return a % p;
  if(n % 2 == 1)
    return ((a * modPow(a, n-1, p))%p);
  ll t = modPow(a, n/2, p)%p;
  return t*t%p;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  int p = 1000000007;
  
  ll a_ue = 1, a_sita = 1;
  rep(i, 0, a){
    a_ue = a_ue*(n-i)%p;
    a_sita = a_sita*(i+1)%p;
  }
  
  ll a_sita_ = modPow(a_sita, p-2, p)%p;
  
  ll nCa = a_ue*a_sita_%p;
  
  ll b_ue = 1, b_sita = 1;
  rep(i, 0, b){
    b_ue = b_ue*(n-i)%p;
    b_sita = b_sita*(i+1)%p;
  }
  
  ll b_sita_ = modPow(b_sita, p-2, p)%p;
  
  ll nCb = b_ue*b_sita_%p;
  
  ll n_2 = modPow(2, n, p)%p;
  n_2 = (n_2-1)%p;
  
  ll ans = (n_2-(nCa+nCb)%p)%p;
  if(ans < 0)
    ans += p;
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3584
X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(X[int(input())-1])

Measured memory_bytes: 38412
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#define gc getchar()
#define pc putchar
#define re register
#define rep(i,x,p) for(re int i = x;i <= p;++ i)
#define sep(i,x,p) for(re int i = x;i >= p;-- i)
const int maxN = 2e5 + 7;

int a[maxN];
int cnt[23];

inline int read() {
	int x = 0,f = 1;char c = gc;
	while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}
	return x * f;
}

void add(int x) {rep(i , 0, 20)  if(x & (1 << i)) cnt[i] ++;}
bool calc() {rep(i , 0, 20) if(cnt[i] >= 2) return true;return false;}
void work(int x) {rep(i , 0, 20) if(x & (1 << i)) cnt[i] --;}

int main() {
	int n;
	n = read();
	rep(i , 1, n) a[i] = read();
	long long int ans = 0;
	int L = 1;
	rep(i , 1, n) {
		add(a[i]);
		while(calc() && L != i) {work(a[L]),L ++;}
		ans += i - L + 1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while ((line = br.readLine()) != null && !line.isEmpty()) {
            StringBuffer sb = new StringBuffer();
            Arrays.stream(line.split(" ")).map(Integer::parseInt).sorted(Comparator.reverseOrder()).forEach(v->{
               sb.append(v + " ");
            });
            System.out.println(sb.toString().trim());
        }
    }
}

Measured memory_bytes: 31000
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		sc.close();

		int ans = 0;
		for (int i = 1; i <= N; i++) {
			String s = String.valueOf(i);
			if (s.length() % 2 == 1) {
				ans++;
			}
		}
		out.println(ans);

	}

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


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

typedef long long int   ll;
#define cases           int t;cin>>t;while(t--)
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define scan(n)         scanf("%d",&n)
#define nl              "\n"
#define pb              push_back
#define vi              vector<int>
#define ii              pair<int,int>

using namespace std;
ll mod=1e9+7;
int main(){
    ll n,k;cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ll minsum=((i-1)*i)/2;
        ll maxsum=(n*(n+1)/2)-((n-i)*(n-i+1)/2);
        ans+=(maxsum-minsum+1);
        ans%=mod;
    }
    cout<<ans%mod<<endl;
}


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

int main() {
    int x, y;
    cin >> x >> y;
    if((x + y) % 2 ==  1){
        cout << ((x + y) / 2) + 1 << endl;
    }
    else{
        cout << (x + y) / 2 << endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        x = x * r - d;
        cout << x << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    while (t--) solve();
}

Measured memory_bytes: 256
import numpy as np

D=int(input())
c=[int(i) for i in input().split()]
s=[]
for d in range(D):
    s.append([int(i) for i in input().split()])

v = [0]*D
last = [[0 for i in range(26)] for d in range(D)]
t=[0]*D

for d in range(D):
    # d(>=1)日目以降は, 初期化としてd-1日目のlastをコピー
    if d>=1:
        last[d] = last[d-1][:]
    
    # 初期化
    last[d][0] = 1
    v=s[d][0] - sum([c[j]*(d+1 - last[d][j]) for j in range(26)])
    idx_best=0

    # d日目の時点で満足度最大となるidxを選ぶ(貪欲法)
    for i in range(1, 26):
        v_tmp=s[d][i] - sum([c[j]*(d+1 - last[d][j]) for j in range(26)])
        if v < v_tmp:
            v = v_tmp
            last[d][i] = i+1
            
            # lastの更新
            if d>=1:
                last[d][idx_best]=last[d-1][idx_best]
            else:
                last[d][idx_best]=0
            
            idx_best=i
    
    t[d]=idx_best + 1           # 1 <= t[d] <= 26 のため
    last[d][t[d] - 1] = d+1     # listの添え字にするときは -1 する

for d in range(D):
    print(t[d])

Measured memory_bytes: 27508
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,player;
struct cnm{
	int a,b;
}mem[100001];
int cmp(cnm x,cnm y)
{
	return x.b<y.b;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&mem[i].a,&mem[i].b);
	}
	sort(mem+1,mem+1+n,cmp);
	player=mem[1].a+mem[1].b;
	cout<<player;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

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

using namespace std;
using ll = long long;
const int mod = 1e9+7;

bool is_prime[200010];

void eratos(int n)
{
    rep(i,n+1){
        is_prime[i] = true;
    }
    reps(i,2,n+1){
        if(is_prime[i]){
            for(int j = 2 * i; j <= n; j += i)
            {
                is_prime[j] = false;
            }
        }
    }
}

int main(){

    int x;
    cin >> x;
    eratos(200000);

    reps(i,x,200000){
        if(is_prime[i]){
            cout << i << endl;
            break;
        }
    }


    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    String S_ = sc.next();

    sc.close();

    String[] S = S_.split("");

    int x = 0;
    int max = 0;

    for (int i = 0; i < S.length; i++) {
      if (S[i].equals("I")) {
        x++;
        max = Math.max(max, x);
      } else {
        x--;
      }
    }

    System.out.println(max);

  }

}

Measured memory_bytes: 21844
N, K = map(int, input().split())
S = input()

rights = []
lefts = []

for i in range(N):
    if i == 0:
        if S[i] == "L":
            now = "L"
            start = i
        else:
            now = "R"
            start = i
    else:
        if S[i] != now:
            end = i
            if now == "R":
                rights.append((start, end))
            else:
                lefts.append((start, end))
            start = i
            now = S[i]
            if i == N-1:
                if now == "R":
                    rights.append((i, i+1))
                else:
                    lefts.append((i, i+1))

n_inner_left = 0
n_inner_right = 0
for left in lefts:
    if (0 not in left) and (N not in left):
        n_inner_left += 1
for right in rights:
    if (0 not in right) and (N not in right):
        n_inner_right += 1
# unhappy
total = 0
if S[0] == "L":
    total += 1
if S[N-1] == "R":
    total += 1
for i in range(N-1):
    if S[i] == "R" and S[i+1] == "L":
        total += 2

rest = K
if n_inner_left > n_inner_right:
    reduce_2 = min(K, n_inner_left)
    total -= 2*reduce_2
    rest -= reduce_2
    if S[0] == "L" and rest > 0:
        total -= 1
elif n_inner_left < n_inner_right:
    reduce_2 = min(K, n_inner_right)
    total -= 2*reduce_2
    rest -= reduce_2
    if S[N-1] == "R" and rest > 0:
        total -= 1
else:
    reduce_2 = min(K, n_inner_left)
    total -= 2*reduce_2
    rest -= reduce_2
    if rest > 0:
        if S[0] == "L" and S[N-1] == "R":
            total -= 1
        if S[0] == "R" and S[N-1] == "L":
            total -= 1


print(N-total)

Measured memory_bytes: 77944
#include<bits/stdc++.h>
#define pb push_back
//#define int long long
#define mod 1000000007
#define fi first
#define se second
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
int main()
{
	fast;
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes";
	else
		cout<<"No";
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

using namespace std;
#define D 50
ll n,cnt[D],f[D],g[D],k;
int main(){
    cin>>n>>k;
    for(int i=0;i<D;i++)cnt[i]=0;
    for(int i=0;i<n;i++){
	ll a;cin>>a;
	for(ll j=0;j<D;j++){
	    if(a&(1LL<<j))cnt[j]++;
	}
    }
    f[D-1]=-1,g[D-1]=0;
    for(ll d=D-2;~d;d--){
	f[d]=g[d]=-1;
	if(~f[d+1])f[d]=f[d+1]+(1LL<<d)*max(cnt[d],n-cnt[d]);
	if(k&(1LL<<d)){
	    if(~g[d+1])f[d]=max(f[d],g[d+1]+(1LL<<d)*(cnt[d]));
	    if(~g[d+1])g[d]=max(g[d],g[d+1]+(1LL<<d)*(n-cnt[d]));
	}
	else{
	    if(~g[d+1])g[d]=max(g[d],g[d+1]+(1LL<<d)*(cnt[d]));
	}
	//cout<<f[d]<<" "<<g[d]<<endl;
    }
    cout<<max(f[0],g[0])<<endl;
    return 0;
}


Measured memory_bytes: 256
//https://www.facebook.com/profile.php?id=100015484067230
//In the name of 'ALLAH'
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s ;
    cin >> s ;
    map< char , ll > mp ;

    for( ll i = 0 ; i < s.size() ; i++ )
    {
        mp[s[i]]++;
    }

    for( auto u  : mp )
    {
        if( u.second%2!=0 )
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void) {
	long long int a, b, x, ans;
	scanf("%lld %lld %lld", &a, &b, &x);
	ans = (b / x + 1) - ((a - 1) / x + 1);
	if (a == 0)ans += (a - 1) / x + 1;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{  unsigned long long  a;
   double b;
   cin>>a>>b;
   b=b*1000;
   int c=b;
   //printf("a=%lld c=%d\n",a,c);
   cout<<a*c/1000;
    return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

	int P=0,Q=0,R=0;
	int min = 0;

	scanf("%d %d %d", &P, &Q, &R);

	if(P > Q){
		min = Q;
		if(P >= R){
			min += R;
		}
		else{
			min+= P;
		}
	}
	else{
		min = P;
		if(Q >= R){
			min += R;
		}
		else{
			min += Q;
		}

	}

	printf("%d", min);



	return 0;
}


Measured memory_bytes: 128
n = gets.to_i
@a = gets.split.map(&:to_i)

def calc_conbination(n, m)
  m.times.inject(1){ |ele| ele * n % 1000000007 }
end

def pattern1
    @a.sort.each_with_index do |v, i|
    if unmatch?(v, i, 1)
      puts 0
      exit
    end
  end
end

def pattern2
    @a.sort.each.with_index(1) do |v, i|
    if unmatch?(v, i)
      puts 0
      exit
    end
  end
end

def unmatch?(v, i, n = 0)
  v != (i / 2) * 2 + n
end

(n % 2).zero? ? pattern1 : pattern2
p calc_conbination(2, n / 2)

Measured memory_bytes: 9720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll m; cin >> n >> m;
  int v, p; cin >> v >> p;
  map<ll, int> mp;
  vector<ll> A(n);
  rep(i, n) {
    cin >> A[i];
    mp[A[i]]++;
  }
  sort(all(A));
  vector<ll> sum(n+1);
  rep(i, n) sum[i+1] = sum[i] + A[i];
  rrep(i, n) {
    ll margin = 0;
    ll t1 = upper_bound(all(A), A[i]) - begin(A);
    margin += t1 * m;
    ll t2 = upper_bound(all(A), A[i]+m) - begin(A);
    margin += (n-t2) * m;
    if(n-t2 >= p) {
      cout << n - i - 1 << endk;
      return 0;
    }
    ll rem = p - (n-t2);
    ll t3 = upper_bound(all(A), A[i]+m-1) - begin(A);
    margin += (rem-1) * m;
    if((t3-(rem-1)-t1) < 0) continue;
    margin += (A[i]+m) * (t3-(rem-1)-t1) - (sum[t3-(rem-1)]-sum[t1]);
    if(margin >= v * m) continue;
    else {
      cout << n - i - 1 << endk;
      return 0;
    }
  }
  cout << n << endk;
  return 0;
}


Measured memory_bytes: 11088
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int n; cin >>n;
    string s,t; cin >>s>>t;

    string ans = "";
    for (int i = 0; i < n; i++) {
        cout << s[i];
        cout << t[i];
    }
    
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> s; int cnt = 0;
	rep(i, 3)
	{
		if (s[i] == '1')
			s[i] = '9';
		else if(s[i]=='9')
			s[i]='1';
	}

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter


def rle(list):
    dict = {}
    for i in list:
        if i in dict.keys():
            dict[i] += 1
        else:
            dict[i] = 1
    return dict


n = int(input())
a = list(map(int, input().split()))
minus = Counter([i-a[i] for i in range(n)])
plus = Counter([i+a[i] for i in range(n)])

cnt = 0
for i in minus:
    if i in plus:
        cnt += minus[i] * plus[i]
print(cnt)


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

using namespace std;

#define ff(i, a, b) for(int i = (a); (i <= (b)); ++i)
#define FF(i, a, b) for(int i = (a); (i >= (b)); --i)
#define ll long long
#define sz(a) (int)a.size()

struct re {
    int x, y;
    const bool operator < (const re &a) const {
        if (x != a.x) return x < a.x;
            return y < a.y;
    }
};

const int M = 1000000000 + 7;
const int N = 100000 + 10;

int n, v, p, a[N];
ll m, sum[N];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("", "r" , stdin);
    //freopen("", "w", stdout);
    cin >> n >> m >> v >> p;
    ff(i, 1, n) cin >> a[i];
    sort(a + 1, a + 1 + n, std::greater<int>());
    ff(i, 1, n) {
        sum[i] = sum[i - 1] + a[i];
    }

    int res = p;
    int j = n;
    FF(i, n, p + 1) {
        j = min(j, i - 1);
        if (a[i] + m >= a[p]) {
            while (j >= p && a[j] <= a[i] + m) --j;
            ll surplus = (v - (n - (i - 1) + p - 1)) * m;
            ll empty_space = (a[i] + m) * (i - 1 - j) - (sum[i - 1] - sum[j]);
            //cout << i << " " << surplus << " " << empty_space << endl;
            if (surplus <= empty_space) {
                res++;
            }
        }
    }
    cout << res;
}
//This code belongs to s34vv1nd


Measured memory_bytes: 1536
#include<stdio.h>




int main(){
	
	int n;
	char a[100];
	char b[100];
	int i;
	int z=0;
	int x=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%s",a,b);
		if(strcmp(a,b)>0){
			
			
			z+=3;
			
			
			
		}else if(strcmp(a,b)<0){
			x+=3;
			
			
		}else if(strcmp(a,b)==0){
			
			
			x++;
			z++;
		}
		
		
		
		
		
		
	}
	printf("%d %d\n",z,x);
	
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <string>
// #include <map>
// #include <set>
// #include <iomanip>

// #define MOD 1000000007

using namespace std;
// typedef unsigned long long ull;
// typedef long long ll;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }

// template<typename T>
// ostream& operator<<(ostream& os, const vector<T>& v) {
//     os << "[";
//     for (const auto i : v) {
//         os << i << " ";
//     }
//     os << "]";
//     return os;
// }


int main(int argc, char const *argv[]) {
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#define N 1005
using namespace std;
typedef long long ll;
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        printf("%d\n",24-n+24);
    }
}


Measured memory_bytes: 764
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))
if c2[0]-c1[0]==c2[1]-c1[1]==c2[2]-c1[2] and c3[0]-c2[0]==c3[1]-c2[1]==c3[2]-c2[2] and c1[1]-c1[0]==c2[1]-c2[0]==c3[1]-c3[0] and c1[2]-c1[1]==c2[2]-c2[1]==c3[2]-c3[1]:
  print('Yes')
else:print('No')

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

char s[11];

int main(){
	scanf("%s", s);
	int ans = 0;
	int temp = 0;
	for(int i = 0; i < (int)strlen(s); i++) {
		if(s[i] == 'A' || s[i] == 'C' || s[i] == 'T' || s[i] == 'G') {
			temp++;
			ans = max(ans, temp);
		}else{
			temp = 0;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> G[114514];
int dfs(int v,int p){
  int res=0,cnt=0;
  for(int u:G[v]){
    if(u==p) continue;
    res^=dfs(u,v)+1;
    cnt++;
  }
  return res;
}
signed main(){
  int n;
  cin>>n;
  for(int i=0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  cout<<(dfs(0,-1)?"Alice":"Bob")<<endl;
  return 0;
}


Measured memory_bytes: 10752
n=int(input())
s=input()
t=s.count('E')
ans=10**9
e=0
w=0
for i in range(n):
  if s[i]=='E':
    e+=1
    ans=min(ans,t-e+w)
  elif s[i]=='W':
    w+=1
    ans=min(ans,t-e+w-1)
print(ans)

Measured memory_bytes: 3700
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            long iN = long.Parse(sS);
            List<long> lstNum = new List<long>();            
            for (int i = 0; i < 5; i++)
            {
                sS = System.Console.ReadLine().Trim();
                lstNum.Add(long.Parse(sS));
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstNum.Sort();                                                          // 移動可能人数の昇順
            long iSum = 0;
            iSum += iN / lstNum[0];
            iSum += iN % lstNum[0] == 0 ? 0 : 1;
            iSum += 4;

            // 出力
            System.Console.WriteLine("{0}", iSum.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13524