akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

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

ll const INF = 1000000000000000000;

int A, B, C, X;

int main() {
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &X);

  int count = 0;
  REP(i, A + 1) {
    REP(j, B + 1) {
      REP(k, C + 1) {
        if (i * 500 + j * 100 + k * 50 == X) count++;
      }
    }
  }
  printf("%d\n", count);
}


Measured memory_bytes: 128
X, Y, A, B, C = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

T = [(0, "r")] * (A+B+C)
for a in range(A):
    T[a] = (P[a], "r")
for b in range(B):
    T[b+A] = (Q[b], "g")
for c in range(C):
    T[c+A+B] = (R[c], "t")

T.sort(reverse=True)

countR = 0
countG = 0
countT = 0

ans = 0
i = 0
while countR + countG + countT < X + Y:
    v, color = T[i]
    if color == "r":
        if countR < X:
            ans += v
            countR += 1
    elif color == "g":
        if countG < Y:
            ans += v
            countG += 1
    else:
        ans += v
        countT += 1
    i += 1

print(ans)


Measured memory_bytes: 118636
#include <stdio.h>

int main(void){

  char s[100000+1];
  scanf("%s", s);

  int case_a = 0;
  int case_b = 0;
  int color = 1;

  for (int i = 0; s[i] == '0' || s[i] == '1'; i++) {
    color *= -1;
    if (color == -1) {
      if (s[i] == '0') {
        case_b++;
      } else {
        case_a++;
      }
    } else {
      if (s[i] == '0') {
        case_a++;
      } else {
        case_b++;
      }
    }
  }

  int answer = case_a;
  if (case_b < answer) {
    answer = case_b;
  }
  printf("%d\n", answer);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int M = (int)1e3+5;
const int Q = 301;
const int logN = 19;

double dp[M*3][M*3];
void solve() {
    int n;
    cin>>n;
    double p;
    dp[0][0] = 1;
    REP(i,1,n) {
        cin>>p;
        dp[i][0] = (1.0-p)*dp[i-1][0];
        REP(j,1,n) {
            dp[i][j] = (1.0-p)*dp[i-1][j] + p*dp[i-1][j-1];
        }
    }
    double ans = 0;
    REP(j,1,n) {
        if(j>n-j) {
            ans += dp[n][j];
        }
    }
    cout<<fixed<<setprecision(20)<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 70912
package main

import (
"fmt"
"strings"
)

func main() {
	var s1, t1 string
	s := make([]string, 200000)
	t := make([]string, 200000)
	_, _ = fmt.Scan(&s1, &t1)
	s1 = strings.ToLower(s1)
	t1 = strings.ToLower(t1)

	s = strings.Split(s1, "")
	t = strings.Split(t1, "")

	a := 0
	for i:=0; i<len(s); i++ {
		if s[i]!=t[i] {
			a++
		}
	}

	fmt.Println(a)
}

Measured memory_bytes: 10268
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    REP(i, T) { cin >> a[i]; }
    //一日に１個食べるけど
    int ma = *max_element(a.begin(), a.end());
    cout << max(0, 2 * ma - 1 - accumulate(a.begin(), a.end(), 0));
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip> //cout<<setprecision(n)
#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

int main() {
  int q;
  std::cin >> q;
  ll bsum = 0;
  std::priority_queue<ll, std::vector<ll>, std::less<ll> > left;
  std::priority_queue<ll, std::vector<ll>, std::greater<ll> > right;
  ll minheight = 0;
  rep(i,q) {
    int num;
    std::cin >> num;
    if(num==1) {
      ll a,b;
      std::cin >> a >> b;
      left.emplace(a);
      right.emplace(a);
      ll ltop,rtop;
      ltop = left.top();
      rtop = right.top();
      if(ltop > rtop) {
        left.pop();
        right.pop();
        left.emplace(rtop);
        right.emplace(ltop);
        minheight += ltop - rtop;
      }
      bsum += b;
    }
    else {
      std::cout << left.top() << ' ' << minheight + bsum << std::endl;
    }
  }
  return 0;
}

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



int main(void){
    int n;
    cin >> n;
    int dam[n+1];
    for(int i=1;i<=n;i++){
        int x;
        cin >> x;
        dam[i] = x;
    }
    int ans[n+1];
    for(int i=1;i<=n;i++){
        ans[i] = 0;
    }
    
    int sum = 0;
    for(int i=1;i<=n;i++){
        sum += dam[i];
    }
    int first=n-1;
    while(first){
        sum -= 2*dam[first];
        first-=2;
    }
    ans[1] = sum;
    
    for(int i=1;i<n;i++){
            ans[i+1] = dam[i]*2-ans[i];
    }
        
    for(int i=1;i<=n;i++){
        cout << ans[i] << " ";
    }
    
    
    return 0;
}
















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

int main() {
  int A,B;
  cin >>A>>B;
  string numstring;
  string backstring;
  int count=0;
  for(int i=0;i<B-A+1;i++){
    numstring=to_string(A+i);
    backstring=numstring;
    int l=numstring.size();
    for(int j=0;j<l;j++){
      backstring.at(j)=numstring.at(l-1-j);
    }
    if(numstring==backstring){
      count++;
    }
  }

  cout<<count<<endl;
    return 0;  
}





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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

const int MAXN = 200005;

int L, n, a[MAXN], b[MAXN];

/*
8 6 4 2 0 1 3 5 7
7 7 5 3 1 0 2 4 6
6 6 6 4 2 0 1 3 5
5 5 5 5 3 1 0 2 4
4 4 4 4 4 2 0 1 3
3 3 3 3 3 3 1 0 2
2 2 2 2 2 2 2 0 1
1 1 1 1 1 1 1 1 0
*/

/*
3 1 0 2
2 2 0 1
1 1 1 0
*/

ll sumr[MAXN], suml[MAXN], d[MAXN];

ll Solve() {
    b[0] = a[0];
    fto(i, 1, n-1)
        b[i] = a[i] - a[i-1];
    b[n] = L - a[n-1];

//    fto(i, 0, n) printf("%d ", b[i]);
//    puts("");

    d[0] = b[0];
    fto(i, 1, n) d[i] = d[i-1] + b[i];

    sumr[n-1] = 0;
    fdto(i, n-2, 0) {
        int k = (n-i)/2;
        sumr[i] = sumr[i+1] + d[n] - d[n-k];
    }

    suml[n-1] = d[n-1];
    fdto(i, n-2, 0) {
        int k = (n-i+1)/2;
        suml[i] = suml[i+1] + d[i] - (d[n-k] - d[i]);
    }

//    fto(i, 0, n-1)
//        printf("%lld %lld\n", suml[i], sumr[i]);

    ll res = suml[0] + sumr[0];
    fto(i, 0, n-1)
        res = max(res, suml[i] + sumr[i]);
    return res;
}

int main () {
    scanf("%d%d", &L, &n);
    fto(i, 0, n-1)
        scanf("%d", &a[i]);

    ll x1 = Solve();

    fto(i, 0, n-1)
        a[i] = L - a[i];
    reverse(a, a+n);

    ll x2 = Solve();

    cout << max(x1, x2);


    return 0;
}

/*
9 7 5 3 1 0 2 4 6 8
8 8 6 4 2 0 1 3 5 7
7 7 7 5 3 1 0 2 4 6
6 6 6 6 4 2 0 1 3 5
5 5 5 5 5 3 1 0 2 4
4 4 4 4 4 4 2 0 1 3
3 3 3 3 3 3 3 1 0 2
2 2 2 2 2 2 2 2 0 1
1 1 1 1 1 1 1 1 1 0
*/



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

int list[1000000];

int func(int n){
    if(n % 2 == 0) return n / 2;
    else return 3 * n + 1;
}

int main(){
    int s;
    cin >> s;
    int index = 1;
    while(list[s] == 0){
        index ++;
        list[s] ++;
        s = func(s);
    }
    cout << index << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a="ATCG";
int main()
{
    string s;
    cin >> s;
    int cnt=0,mx=0;
    for(int i=0;i<s.size();i++){
        if(a.find(s[i])!=-1){
            cnt++;
        }
        else cnt=0;
        mx=max(cnt,mx);
    }
    cout << mx << endl;
}


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

auto main () -> int
{
    std::string s;
    std::getline (std::cin , s);
    for (auto ite = s.rbegin (); ite != s.rend (); ++ ite)
    {
        std::cout << * ite;
    }
    std::cout << std::endl;
}

Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#define SIZE 200002
using namespace std;
int main(void){
    long long a[SIZE], s[SIZE], size = 0, begin_i;
    long long n, k, nk, pos[SIZE], bef[SIZE];
    vector<long long> ans;
    cin >> n >> k;
    nk = n * k;
    fill(pos, pos+SIZE, -1);
    fill(bef, bef+SIZE, -1);

    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n*2;i++){
        if(bef[i%n] != -1)continue;
        if(pos[a[i%n]] != -1){
            bef[i%n] = pos[a[i%n]];
        }
        pos[a[i%n]] = i%n;
    }
    int v = n-1;
    long long p = 1;
    while(true){
        int w =bef[v];
        if(v <= w){
            p++;
        }
        v = w-1;
        if(w == 0)break;
    }
    k %= p;
    //cout << p << endl;

    if(k == 0){
        cout << endl;
        return 0;
    }
    v = n-1;
    begin_i = -1;
    while(true){
        int w =bef[v];
        if(v <= w){
            p--;
            if(k == p){
                begin_i = w;
                break;
            }
        }
        v = w-1;
        if(w == 0)break;
    }
    if(begin_i == -1 || begin_i >= n)return 0;
    int nxt[SIZE];
    fill(nxt, nxt+SIZE, -1);
    for(int i=begin_i;i<n;i++){
        if(begin_i < bef[i] && bef[i] < i){
            nxt[bef[i]] = i;
        }

    }
    for(int i=begin_i;i<n;i++){
        if(nxt[i] == -1){
            ans.push_back(a[i]);
        }else{
            i = nxt[i];
        }

    }
    int y = ans.size();
    if(y==0)return 0;
    cout << ans[0];
    for(int i=1;i<y;i++){
        cout << " " << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 8688
#include <iostream>
using namespace std;
int main(void){
	int N, A, B;
	cin >> N;
	cin >> A;
	cin >> B;
	
	int sum = 0;
	int dgsum;
	int i, j;
	
	for(i=1;i<=N;i++){
		dgsum = 0;
		j = i;
		while(1){
			dgsum += j % 10;
			j = ( j - j % 10 ) / 10;
			if ( j == 0 ){
				break;
			}
		}
		if( A <= dgsum && dgsum <= B ){
			sum += i;
		}
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
"""
def f(char, start, end):
    global rgb
    return rgb[char][end] - rgb[char][start]

rgb = {'R':[0]*(n+1), 'G':[0]*(n+1), 'B':[0]*(n+1)}
for i in range(1, n+1):
    j = s[i-1]
    rgb['R'][i] = rgb['R'][i-1] + (j=='R')
    rgb['G'][i] = rgb['G'][i-1] + (j=='G')
    rgb['B'][i] = rgb['B'][i-1] + (j=='B')

print(rgb['R'])
print(rgb['G'])
print(rgb['B'])

print(f('R', 0,0) )
print(f('R', 0,1) )
print(f('R', 0,2) )
print(f('R', 0,3) )
print(rgb['R'][-1] * rgb['G'][-1] * rgb['B'][-1])
ans = rgb['R'][-1] * rgb['G'][-1] * rgb['B'][-1]
"""
rgb = {'R':0, 'G':0,'B':0}
for i in range(1, n+1):
    j = s[i-1]
    rgb[j] += 1
ans = rgb['R'] * rgb['G'] * rgb['B']
for j in range(1, n):
    for i in range(j):
        if j-i>(n-1)-j: continue
        if s[j]!=s[i] and s[j+(j-i)]!=s[j] and s[j+(j-i)]!=s[i] :
            ans -= 1

print(ans)


Measured memory_bytes: 73660
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    chrono::steady_clock clk;
    auto start = clk.now();
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    vector<bool> ss(n);
    for(int i=0;i<n;i++){
        ss[i] = s[i] == 'A';
    }
    bool flip = false, fflip = false;;
    int idx = 0;
    for(int i=0;i<k;i++){
        if(flip ^ ss[idx]){
            ss[idx] = !ss[idx];
        }else{
            flip = !flip;
            idx = (idx + 1) % n;
        }
        if(i % 1000000 == 0 && clk.now() - start > 1900ms){
            if(n % 2 && (k - i - 1) % 2){
                fflip = true;
            }
            break;
        }
    // for(int i=0;i<n;i++){
    //     cout << (flip ^ ss[(idx + i) % n] ? 'A' : 'B');
    // }
    // cout << '\n';
    }
    cout << (fflip ^ flip ^ ss[idx] ? 'A' : 'B');
    for(int i=1;i<n;i++){
        cout << (flip ^ ss[(idx + i) % n] ? 'A' : 'B');
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 888
program main
  implicit none
  integer :: i, n, cnt = 1
  integer, allocatable :: h(:)

  read *, n
  allocate (h(n))
  read *, h

  do i = 2, n
    if (check(h, i-1, i)) cnt = cnt + 1
  end do

  print '(i0)', cnt
contains
  recursive function check(h, i, k) result(visible)
    integer, allocatable :: h(:) 
    integer :: i, k
    logical :: visible

    if (i == 1) then
      visible = h(1) <= h(k)
    else if (h(i) > h(k)) then
      visible = .false.
    else
      visible = check(h, i-1, k)
    end if
  end function

end program

Measured memory_bytes: 768
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto h = s[2];
    auto w = s[3];

    if (H % h == 0 && W % w == 0) {
        writeln("No");
        return;
    }

    writeln("Yes");

    bool rot = false;
    if (H % h == 0) swap(H, W), swap(h, w), rot = true;
    auto ans = new int[][](H, W);

    int y = -10^^5;
    int z = H / h;
    int maxx = (-h + 1) * y;
    //int minx = (-H*y + z*y) / z;
    int x = maxx - 1;
    foreach (i; 0..H) {
        foreach (j; 0..W) {
            if (i % h == 0) ans[i][j] = x;
            else ans[i][j] = y;
        }
    }

    if (rot) {
        auto new_ans = new int[][](W, H);
        foreach (j; 0..W)
            foreach (i; 0..H)
                new_ans[j][i] = ans[i][j];
        foreach (i; 0..W) new_ans[i].map!(a => a.to!string).join(" ").writeln;
    } else {
        foreach (i; 0..H) ans[i].map!(a => a.to!string).join(" ").writeln;
    }

}


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

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

    map<int, long long> ball;
    for (int i = 0; i < n; i++) ball[a[i]]++;

    long long answer = 0;
    for (auto it = ball.begin(); it != ball.end(); it++) {
        long long count = it->second;
        answer += count * (count - 1) / 2;
    }
    for (int k = 0; k < n; k++) {
        long long count = ball[a[k]];
        long long decrease = (count * (count - 1) - (count - 1) * (count - 2)) / 2;
        cout << answer - decrease << endl;
    }
    return 0;
}


Measured memory_bytes: 11136
from operator import itemgetter


n, x, d = map(int, input().split())

a = [0] * n
for i in range(n - 1):
    a[i + 1] = a[i] + 1

ruiseki1 = [0] * (n + 1)
ruiseki2 = [0] * (n + 1)

for i in range(n):
    ruiseki1[i + 1] += ruiseki1[i] + a[i] 
for i in range(n):
    ruiseki2[i + 1] += ruiseki2[i] + a[n - i - 1] 

if d == 0 and x == 0:
    print(1)
    exit()
elif d == 0:
    print(n + 1)
    exit()
    
memo = {}

for i in range(n + 1):
    s_cnt = i
    geta = i * x
    div = geta // d
    mod = geta % d
    min_ = ruiseki1[i]
    max_ = ruiseki2[i]
    if mod not in memo:
        memo[mod] = []
    memo[mod].append((min_ + div, max_ + div + 1))

ans = 0
for i in memo:
    memo[i] = sorted(memo[i])
    r_max = -10**18
    for j in memo[i]:
        l, r = j
        if r - r_max < 0:
            continue
        ans += min(r - l, r - r_max)
        r_max = r
print(ans)


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

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

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

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0;
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'
#define fastio          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define file_io         freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#define ld_io           cout << setprecision(10) << fixed;

#undef pow
ll pow(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pow(a * a % mod, b / 2, mod) % mod;
    return pow(a * a % mod, b / 2, mod) % mod;
}

const ll MAXN  = 1e2 + 10;
const ll INF   = 8e18;
const ll MOD   = 1e9 + 7; // 998244353;
const ll LOG   = 32;      // log2(1e9)
const ll BLOCK = 320;     // sqrt(1e5)
const ld PI    = acos(-1);
const ld SADAT = 7.84e-17;  // The most important constant ever

ll n, a[MAXN], b[MAXN], c[MAXN], ans;

int main() {
    fastio
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (ll i = 1; i <= n; i++) {
        cin >> b[i];
    }
    for (ll i = 1; i <= n - 1; i++) {
        cin >> c[i];
    }
    ans = b[a[1]];
    for (ll i = 2; i <= n; i++) {
        ans += b[a[i]];
        if (a[i] - a[i - 1] == 1)
            ans += c[a[i - 1]];
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  vector<int> vec;
  int sl;
  sl=s.length();
  for(int i=0;i<sl;i++){
    if(s.at(i)=='0') vec.push_back(0);
    else if(s.at(i)=='1') vec.push_back(1);
    else {
      if(vec.empty()) continue;
      else vec.pop_back();
    }
  }
  for(int i=0;i<vec.size();i++){
    cout << vec[i];
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int n;
  cin >> n;
  int h[n][3];
  rep(i,n)rep(j,3) cin >> h[i][j];
  vvi dp(n, vi(3));
  dp[0][0] = h[0][0];
  dp[0][1] = h[0][1];
  dp[0][2] = h[0][2];
  for(int i=1; i<n; i++){
    rep(j,3){
      rep(k,3){
        if(j==k) continue;
        dp[i][j] = max(dp[i][j], dp[i-1][k] + h[i][j]);
      }
    }
  }
  int ans = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
  cout << ans << endl;
}


Measured memory_bytes: 9852
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int h, w;
	while(cin >> h >> w, h){
		vector<vi> in(h, vi(w));
		rep(i, h) rep(j, w) cin >> in[i][j];
		
		auto check = [&](int y, int x, int Y, int X){
			
			int omin = inf, imax = -1, isum = 0;
			for(int i = y; i <= Y; i++) for(int j = x; j <= X; j++){
				bool inner = (i != y && i != Y) && (j != x && j != X);
				if(inner){
					isum += in[i][j];
					imax = max(imax, in[i][j]);
				}
				else omin = min(omin, in[i][j]);
			}
			//dbg(omin, imax, isum);
			if(imax < 0 || omin <= imax) return -1;
			return omin * (Y - y - 1) * (X - x - 1) - isum;
		};
		int ans = 0;
		rep(Y, h) rep(y, Y) rep(X, w) rep(x, X) ans = max(ans, check(y, x, Y, X));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define ll long long int
#define modulo 1000000007
#define read(x) ll x; cin>>x;
using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    static const auto _ = []() {
        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        return 0;
    }();
    /*read(n); read(q);
    vector<ll> h(n),a(n);
    for(int i=1;i<n;i++)
    {
        ll x; cin>>x;
        h.push_back(x);
    }
    for(int i=1;i<n;i++)
    {
        ll x; cin>>x;
        a.push_back(x);
    }
    while(q--)
    {
        int a=0,b=0,c=0,sum=0;
        cin>>a>>b>>c;
        if(a==2)
        {

        }
    }*/
    read(n);
    int c=ceil(1.0*n/1000);

    int change=c*1000-n;
    cout<<change<<endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#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__)
const long long inf = 1LL << 60;
const int intinf = 1 << 30;
const long long mod = 1e9 + 7;

int n;

class TRUMP {
  public:
    char M;
    int N;
    TRUMP() {
        M = 'N';
        N = 0;
    }
    TRUMP(char mark, int number) {
        M = mark;
        N = number;
    }
};

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end())
            cout << " ";
    }
    cout << endl;
};

int partition(vector<TRUMP> &A, int p, int r) {
    TRUMP tmp;
    int x = A[r].N;
    int i = p - 1;
    for(int j = p; j < r; j++) {
        if(A[j].N <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);

    return i + 1;
}

void merge(vector<TRUMP> &A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<TRUMP> L(n1 + 1);
    vector<TRUMP> R(n2 + 1);
    rep(i, n1) L[i] = A[left + i];
    L[n1].N = intinf;
    rep(i, n2) R[i] = A[mid + i];
    R[n2].N = intinf;
    int i = 0, j = 0;
    rep(k, left, right) {
        if(L[i].N <= R[j].N) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}

void MergeSort(vector<TRUMP> &A, int left, int right) {
    if(left + 1 < right) {
        int mid = (left + right) / 2;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

void QuickSort(vector<TRUMP> &A, int p, int r) {
    if(p < r) {
        int q = partition(A, p, r);
        QuickSort(A, p, q - 1);
        QuickSort(A, q + 1, r);
    }
}
int main() {
    cin >> n;
    vector<TRUMP> A(n), B(n);
    rep(i, n) {
        cin >> A[i].M >> A[i].N;
        B[i] = A[i];
    }

    QuickSort(A, 0, n - 1);
    MergeSort(B, 0, n);

    bool St = true;
    rep(i, n) {
        if(A[i].M != B[i].M)
            St = false;
    }
    cout << (St ? "S" : "Not s") << "table\n";
    rep(i, n) { cout << A[i].M << " " << A[i].N << "\n"; }
}



Measured memory_bytes: 5100
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
  string s;
	cin>>s;
	int n=s.size();
	vector<ll>v(n+1);
	ll cur=0;
	rep(i,n){
		if(s[i]=='<')v[i+1]=max(v[i]+1,v[i+1]);
	}
	for(int i=n-1;i>=0;--i){
		if(s[i]=='>')v[i]=max(v[i],v[i+1]+1);
	}
	ll ans=0;
	rep(i,n+1)ans+=v[i];
	cout<<ans<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int i=0;
    while(c>0){
        i++;
        if(i%7==0){
            c=c-a-b;
        }
        else{
            c=c-a;
        }
    }
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,S=0;cin>>N;
  long long int A[N],B[N];
  for(int i=0;i<N;i++)cin>>A[i]>>B[i];
  for(int i=N-1;i>=0;i--)S+=(B[i]-(A[i]+S)%B[i])%B[i];
  cout<<S<<endl;
}

Measured memory_bytes: 1792
// Marcin Knapik
#include<bits/stdc++.h>
// #pragma GCC optimize("O3")
using namespace std;

typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
typedef long double             ld;

#define boost                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define szy                     first
#define gi                      second
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define REP(i, a, b)            for (int i = (a); i <= (b); i++)
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define TRAV(i, n)              for(auto&i:n)
#define beg(x)                  (*(x.begin()))
#define re(x)                   int x; cin >>x;   
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll T = 1 << 18;
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll  N = (1<<21) + 7;
const int LOG = 21;

ll n, m, k;

signed main(){
    boost;

    cin >> n;
    cout << n * n * n;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
 
using namespace std;
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
vector <set <int> > g;

 

int main()
{
    int n,m;
    cin>>n>>m;
    map <int,int> m1;
    bool test=1;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(x>n)
            test=0;
        if(n>1&&x==1&&y==0)
            test=0;
        if(m1.find(x)!=m1.end()&&m1[x]!=y)
            test=0;
        m1[x]=y;
    }

    if(!test)
    {
        cout<<"-1\n";
        return 0;
    }

    if(n==1)
    {
        if(m1.find(1)!=m1.end())
            cout<<m1[1]<<endl;
        else
            cout<<"0\n";
        return 0;
    }

    if(m1.find(1)!=m1.end())
            cout<<m1[1];
        else
            cout<<"1";

    for(int i=2;i<=n;i++)
    {
        if(m1.find(i)!=m1.end())
            cout<<m1[i];
        else
            cout<<"0";
    }
    cout<<endl;




    return 0;   
}
 
 


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{

    static final FastReader in = new FastReader();
    static final FastWriter out = new FastWriter();

    public static void main(String[] args) throws IOException{
        int n = in.nextInt();
        out.pl(48-n);
        out.close();
    }
}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    }
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 32788
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;





int main()
{
	int n;
	int a, b;
	int A, B;
	
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		
		A = 0;
		B = 0;
		
		for (int i=0; i<n; i++)
		{
			cin >> a >> b;
			
			//cout << "a = " << a << " : b = " << b << "\n";
			
			if (a > b)
			{
				A += a + b;
			} else if (a < b) {
				B += a + b;
			} else if (a == b) {
				A += a;
				B += b;
			}
		}
		
		cout << A << " " << B << "\n";
	}
	
	
}

Measured memory_bytes: 1160
#include<iostream>
#include<math.h>
using namespace std;

int main(void) {
	int D, N;
	int answer = 0;
	int times = 1;
	scanf("%d %d", &D, &N);
	for (int i = 0; i < D; i++) {
		times *= 100;
	}
	if (N < 100) {
		answer  = N * times;
	} else {
		answer  = 101 * times;
	}
	printf("%d\n", answer);
	return 0;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	string s;
	cin>>s;
	
	bool jud=true;
	for(int i=1;i<4;++i){
		if(s[i-1]==s[i]) jud=false;
	}
	
	if(jud) cout<<"Good"<<endl;
	else cout<<"Bad"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0); ios_base::sync_with_stdio(0);
    int n,ans=0;
    double d,x,y;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>

bool Fill(int G[3][3], int a[3], int b[3], int i, int j) {
  if (a[i] > -1 && b[j] > -1 && a[i] + b[j] != G[i][j]) {
    return false;
  } else if (a[i] > -1) {
    b[j] = G[i][j] - a[i];
    if (b[j] < 0) {
      return false;
    }
  } else if (b[j] > -1) {
    a[i] = G[i][j] - b[j];
    if (a[i] < 0) {
      return false;
    }
  }

  return true;
}

int main() {
  int G[3][3];
  for (int i = 0; i < 3; i++) {
    std::cin >> G[i][0];
    std::cin >> G[i][1];
    std::cin >> G[i][2];
  }

  for (int k = 0; k <= G[0][0]; k++) {
    int a[3] = {-1, -1, -1};
    int b[3] = {-1, -1, -1};
    a[0] = G[0][0] - k;
    b[0] = k;
    int ok = true;
    for (int x = 0; x < 3; x++) {
      if (!Fill(G, a, b, 0, x)) {
        ok = false;
        break;
      }
      for (int y = 0; y < 3; y++) {
        if (!Fill(G, a, b, y, x)) {
          ok = false;
          break;
        }
      }
    }
    if (ok) {
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }

  std::cout << "No" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int mergeSort(int left, int right)
{
  if(left + 1 < right) {
    int mid = (left + right) >> 1;
    return (mergeSort(left, mid) + mergeSort(mid, right) + right - left);
  } else {
    return (0);
  }
}
 
int main()
{
  int N, A[500000];
  scanf("%d", &N);
  for(int i = 0; i < N; i++) scanf("%d", &A[i]);
  sort(A, A + N);
  for(int i = 0; i < N; i++) {
    if(i > 0) putchar(' ');
    printf("%d", A[i]);
  }
  putchar('\n');
  printf("%d\n", mergeSort(0, N));
}


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

def main():
  N, constW = map(int, input().split())
  WV = [list(map(int, input().split())) for _ in range(N)]
  W0 = WV[0][0]
  L = [[] for _ in range(4)]
  for w, v in WV:
    w -= W0
    L[w].append(v)
  L[0].sort(reverse=True)
  L[1].sort(reverse=True)
  L[2].sort(reverse=True)
  L[3].sort(reverse=True)
  ans = 0
  for i in range(1, constW//W0 + 1):
    rest = constW - i*W0
    for j in range(min(rest//3, i) + 1):
      rest1 = rest - 3*j
      for k in range(min(rest1//2, i-j) + 1):
        rest2 = rest1 - 2*k
        for l in range(min(rest2, i-j-k) + 1):
          temp = sum(L[3][:j]) + sum(L[2][:k]) + sum(L[1][:l]) + sum(L[0][:i-j-k-l])
          ans = max(ans, temp)
  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 62808
count = gets.chomp.to_i
heights = gets.chomp.split
nowLength = 0
max = 0
(count-1).times do |i|
	i = count - i - 1
	if heights[i - 1].to_i < heights[i].to_i
		nowLength = 0
	else
		nowLength += 1
		if nowLength > max
			max = nowLength
		end
	end
end
puts max

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


ll gcd(ll a,ll b){
  if(a<b)swap(a,b);
  if(a%b==0)return b;
  return gcd(a%b,b);
}

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


int main()
{
  ll n, l=1, t;
  cin >> n;
  
  forll(i, 0, n){
	cin >> t;
	l = lcm(l, t);
  }
  cout << l << endl;
}


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

#define int long long

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

	int x, y;
	cin >> x >> y;

	if (y % 2 == 0 && y >= x * 2 && y <= x * 4) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;

typedef long long ll;
ll n, m, v, p, l, r, md, a[N];

bool f() {
	ll i, t, s;
	t = a[md] + m;
	s = m * (p - 1);
	if (a[n - p] > t) return 0;
	for (i = 0; i <= n - p; i++) {
		s += min(m, t - a[i]);
	}
	if (s < m * v) return 0;
	return 1;
}

int main()
{
	ll i;
	cin >> n >> m >> v >> p;
	for (i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	sort(a, a + n);
	l = 0, r = n - 1;
	while (l < r) {
		md = (l + r) / 2;
		if (f()) r = md;
		else l = md + 1;
	}
    cout << n - r << endl;
    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll sum = 0;
  rep(i,n) sum += a[i];
  set<ll> candidates;
  for (int i = 1; i*i <= sum; i++) {
    if (sum%i == 0) {
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    ll need;
    { // calc need
      vector<ll> r(n);
      rep(i,n) r[i] = a[i]%x;
      sort(r.begin(), r.end());
      ll B = 0;
      rep(i,n) B += x-r[i];
      ll A = 0;
      need = 1e18;
      rep(i,n) {
        A += r[i];
        B -= x-r[i];
        need = min(need, max(A,B));
      }
    }
    if (need <= k) ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
hash = {"A" => 1, "B" => 0, "C" => 0}
choice = []

while tmp = gets
  tmp = tmp.split(",").map(&:chomp)
  cng1 = hash[tmp[1]]
  cng2 = hash[tmp[0]]
  hash[tmp[0]] = cng1
  hash[tmp[1]] = cng2
  hash
end

puts hash.select{|_,v| v == hash.values.max}.keys



Measured memory_bytes: 6860
#include<stdio.h>
#include<iostream>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
#define P 998244353
const int N=5005;
int f[N][N],a,b,c,d;
int main(){ 
	scanf("%d%d%d%d",&a,&b,&c,&d);
	f[a][b]=1;
	for(it i=a,j;i<=c;++i)
		for(j=b;j<=d;++j){
			if(i==a&&j==b) continue;
			f[i][j]=(f[i][j]+(0ll+i)*f[i][j-1]+(0ll+j)*f[i-1][j]-(i-1ll)*(j-1ll)%P*f[i-1][j-1])%P,f[i][j]=(f[i][j]<0?f[i][j]+P:f[i][j]);
		}
	printf("%d",f[c][d]);
	return 0;
}


Measured memory_bytes: 50740
#include <stdio.h>
#include <stdio.h>

int main()
{
    int a, b;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    while (op != '?')
    {
        switch (op)
        {
        case '+':
            printf("%d\n", a + b);
            break;
        case '-':
            printf("%d\n", a - b);
            break;
        case '*':
            printf("%d\n", a * b);
            break;
        case '/':
            printf("%d\n", a / b);
            break;
        }
        scanf("%d %c %d", &a, &op, &b);
    }
    return 0;
}


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

string str;
int n;
int solve(char c, string str)
{
    string old = str;
    bool work = false;
    for (int k = 0; k < str.length(); ++k)
    {
        if (str[k] == c)
        {
            work = true;
            break;
        }
    }
    if (!work)
    {
        return old.length();
    }
    for (int i = old.length(); i > 1; --i)
    {
        bool done = true;
        for (int k = 0; k < i; ++k)
        {
            if (str[k] != c)
            {
                done = false;   break;
            }
        }
        if (done)
        {
            return old.length()-i;
        }
        string tmp(i-1, '0');
        for (int k = 0; k < tmp.size(); ++k)
        {
            if (str[k] == c || str[k+1] == c)
            {
                tmp[k] = c;
            }
        }
        str = tmp;
    }
    return old.length()-1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> str;
    int ans = str.length()-1;
    for (char c = 'a'; c <= 'z'; ++c)
    {
        ans = min(ans, solve(c, str));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(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=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;

using namespace std;

int main()
{
    int n;
    cin >> n;
    char c[n];
    rep(i, n) {
        cin >> c[i];
    }
    string str = string(c, n);
    int i = 0;
    while(1) {
        auto c = str.find(to_string(i));
        
        if (c == string::npos) {
            cout << i << endl;
            break;
        }
        ++i;
    }
    return EXIT_SUCCESS;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

int main()
{   
    int h, w, k;
    cin >> h >> w >> k;
    vs s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    rep(bi, (1<<h)) rep(bj, (1<<w)) {
        int cnt = 0;
        rep(i, h) rep(j, w) {
            if(bi&(1<<i) || bj&(1<<j)) continue;
            if(s[i][j]=='#') cnt++;
        }
        if(cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    int l,r;
    int sum;

    while(scanf("%d",&n) != EOF)
    {
        sum = 0;
        while(n--)
        {
            scanf("%d%d",&l,&r);
            sum += r-l+1;
        }
        printf("%d\n",sum);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;
 
int main() {
	int a [3][3];
	int b [3][3];
	int bingo =0;
	for (int i = 0; i<3; i++) {
		for (int j = 0; j <3; j++) {
			cin >> a[i][j];
			b[i][j] = 0;
		}
	}
	int n;
	cin >> n;
	int c;
	for (int k = 0; k <n; k++) {
		cin >> c;

		for (int i = 0; i<3; i++) {
			for (int j = 0; j <3; j++) {
				if (a[i][j] == c) {
					b[i][j] = 1;
				}
			}
		}
	}

	for (int i = 0; i<3; i++) {
		if (b[i][0] == 1 && b[i][1] == 1 && b[i][2] == 1) {
			bingo = 1;
		}
		if (b[0][i] == 1 && b[1][i] == 1 && b[2][i] == 1) {
			bingo = 1;
		}
	}
	if (b[0][0] == 1 && b[1][1] == 1 && b[2][2] == 1) {
		bingo = 1;
	}
	if (b[0][2] == 1 && b[1][1] == 1 && b[2][0] == 1) {
		bingo = 1;
	}

	if (bingo == 1) {
		cout << "Yes";
	} else {
		cout << "No";
	}


}


Measured memory_bytes: 256