akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll N,K,maxi=0,a,f,ans;
vector<ll> A,F;

ll max(ll aa, ll bb){
    if(aa>bb)return aa;
    else return bb;
}

bool check(ll minu){
    ll sum=0;
    rep(i,N)sum+=max(0,A[i]-(minu/F[i]));
    if(sum>K)return false;
    else return true;
    
}

int main(){
    cin>>N>>K;
    rep(i,N){
        cin>>a;
        A.push_back(a);
    }
    rep(i,N){
        cin>>f;
        F.push_back(f);
    }
    sort(ALL(A));
    sort(ALL(F),greater<ll>());
    rep(i,N)maxi=max(maxi,A[i]*F[i]);
    ll left=0,right=maxi;
    ll mid=(left+right)/2;
    while(left<=right){
        if(check(mid)){
            if(check(mid-1)==false){
                ans=mid;
                break;
            }
            right=mid-1;
        }
        else{
            left=mid+1;
        }
        mid=(left+right)/2;
    }
    out(mid);
}


Measured memory_bytes: 4848
#include<stdio.h>

int main(void){

int name[5];
  int k;
  int i;
  
  for(i=0;i<5;i++){
  	scanf("%d", &name[i]);
  }
int amari[5];
  
  for(k=0;k<5;k++){
  amari[k] = (name[k] % 10); 
  }
  
  int min= 9;
  int j=0;
  int count;
	for(j=0;j<5;j++){
 	 if(min > amari[j] && amari[j] != 0){
  	  min = amari[j];
  	  count = j;
  	}
	}
	int n = 0;
    int ans=0;
	for(n=0;n<5;n++){
		if(count != n && amari[n] !=0){
		name[n] = name[n] + 10 - amari[n];
        }
      ans = ans + name[n];
    }
   printf("%d",ans);
return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int a[1005];

int main()
{
//	cut here before submit 
//	freopen ("testcase.SCI", "r", stdin );
	int s;
	memset (a, 0, sizeof (a ) );
	a[0] = 1;
	for (int i = 1; i < 1005; i++ ){
		a[i] = a[i-1] + i+1;
	} // end for
/*
	rep (i, 1005 ){
		cout << ' ' << a[i];
	} // end rep
	cout << endl;
*/
	while (scanf ("%d", &s ), s ){
		int i = 0;
		int m = 2;
		int res = 0;
		while (s > a[i] ){
			if ((s - a[i] ) % m == 0 ) {
/*
				rep (j, m ){
					cout << ' ' << (s-a[i])/m + j;
				} // end rep
				cout << endl;
*/
				res++;
			} // end if
			i++; m++;
		} // end while		
		printf ("%d\n", res );
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N, X, D;
vector<ll> m, p, sz;
vector<ll> children[55];
const ll MAX = 50*50*26;
ll dp[MAX];

void dfs(int now) {
    sz[now] = 1;
    for(auto to : children[now]) {
        dfs(to);
        m[now] += m[to];
        sz[now] += sz[to];
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X >> D;
    m.resize(N), p.resize(N), sz.resize(N);
    cin >> m[0];
    for(int i = 1; i < N; i++) {
        cin >> m[i] >> p[i];
        p[i]--;
        children[p[i]].push_back(i);
    }
    dfs(0);
    for(int i = 0; i < MAX; i++) {
        dp[i] = 1e17;
    }
    for(int i = 0; ; i++) {
        if(i * sz[0] >= MAX) break;
        dp[i*sz[0]] = m[0] * i;
    }
    for(int i = 1; i < N; i++) {
        ll num = min(50LL, D);
        for(int j = 0; j < sz[i]; j++) {
            deque<l_l> deq;
            for(ll k = j; k < MAX; k += sz[i]) {
                //if(k < 60) cerr << i << " " << k << " " << dp[k] << " ";
                l_l tmp = {dp[k] - (k/sz[i]) * m[i], k + num * sz[i]};
                while(deq.size() and deq.back().first >= tmp.first) deq.pop_back();
                deq.push_back(tmp);
                if(deq.front().second < k) deq.pop_front();
                chmin(dp[k], deq.front().first + (k/sz[i]) * m[i]);
                //if(k < 60) cerr << "-> " << dp[k] << endl;
            } 
        }
    }
    D -= 50;
    chmax(D, 0LL);
    /*
    for(int i = 0; i <= 60; i++) {
        cerr << i << " " << dp[i] << endl;
    }
    */
    ll ans = 0;
    vector<l_l> v;
    for(int i = 0; i < N; i++) {
        v.push_back({sz[i], m[i]});
    }
    sort(v.begin(), v.end(), [](l_l a, l_l b) {
        return a.first * b.second > a.second * b.first;
    });
    //for(auto tmp : v) cerr << tmp.first << " " << tmp.second << endl;
    for(int i = 0; i < MAX; i++) {
        if(dp[i] > X) continue;
        ll score = i;
        ll rest = X - dp[i];
        for(auto tmp : v) {
            ll num = rest / tmp.second;
            if(tmp.first != N) chmin(num, D);
            score += num * tmp.first;
            rest -= num * tmp.second;
        }
        chmax(ans, score);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
# https://beta.atcoder.jp/contests/abc086/tasks/arc089_a

# t[i] から t[i+1]で到達可能か
def ableToAchieve(x, y, t, i)
  dt = t[i+1] - t[i]
  dist = (x[i+1] - x[i]).abs + (y[i+1]-y[i]).abs
  return false if dist > dt
  if dt%2 != dist%2 then
    return false
  end
  return true
end

N = gets.chomp.to_i
ts = []
x_pos = []
y_pos = []
N.times do |n|
  ts[n], x_pos[n], y_pos[n] = gets.chomp.split.map(&:to_i)
end
ts.unshift(0)
x_pos.unshift(0)
y_pos.unshift(0)

flag= true
N.times do |n|
  if !ableToAchieve(x_pos, y_pos, ts, n) then
    flag = false
    break;
  end
end
flag ? print("Yes") : print("No")

Measured memory_bytes: 4632
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 214748364700000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
   ll N;string S;cin >> N >> S;
   ll ans = 0;
   rep(i,N-2){
       if(S.substr(i,3) == "ABC"){
           ans++;
       }
   }
   cout << ans << endl;
}

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

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

int main()
{
  int a[5]; rep(i, 5) cin >> a[i];
  int k; cin >> k;

  cout << (a[4]-a[0]<=k ? "Yay!" : ":(") << endl;
}

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

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

    vector<int> h(n);

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

    vector<int> dp(n);

    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for(int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
    }

    cout << dp[n - 1];

    return 0;
}

Measured memory_bytes: 3992
#include <iostream>

int main()
{
	int a, b;
	
	std::cin >> a >> b;

	if (a < b) std::cout << "a < b" << std::endl;
	else if (a > b) std::cout << "a > b" << std::endl;
	else std::cout << "a == b" << std::endl;

	return 0;
}

Measured memory_bytes: 1156
#! -*- coding:utf-8 -*-

import sys

line_count = 0
next_count = 0
convert_dic = {}
inputs = []
status = 0
for line in sys.stdin:
    line = line.rstrip()
    if status == 0:
        next_count = int(line)
        status = 1
        continue
    if status == 1:
        x1, x2 = line.split(" ")
        convert_dic[x1] = x2
        next_count -= 1
        if next_count == 0:
            status = 2
            continue
    if status == 2:
        next_count = int(line)
        status = 3
        continue
    if status == 3:
        if convert_dic.get(line) is not None:
            line = convert_dic[line]
        inputs.append(line)
        next_count -= 1
        if next_count == 0:
            print "".join(inputs)
            inputs = []
            status = 0
            convert_dic = {}

Measured memory_bytes: 5272
import math
from itertools import accumulate

def is_prime(n):
    if n == 1: return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return 0
    return 1

Q = int(input())
L = [0]*Q
R = [0]*Q

for j in range(Q):
    L[j],R[j] = [int(i) for i in input().split()]

min_L = min(L)
max_R = max(R)

li = []
for i in range(min_L,max_R+1,1):
    if i%2 == 1:
        li.append(is_prime(i) * is_prime((i+1)//2))
    else:
        li.append(0)

ans = [0]
ans += list(accumulate(li))


for i,j in zip(L,R):
    print(ans[j-min_L+1] - ans[i-min_L])


Measured memory_bytes: 15560
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

int n;

LL solve(vector<pair<LL, LL>> a) {
  sort(a.begin(), a.end());
  LL cur = 0;
  multiset<LL> st;
  for (auto item : a) {
    LL p = item.first;
    LL w = item.second;
    while (p <= st.size() && st.size() > 0) { 
      auto iter = st.begin();
      if(*iter > w) {
        break;
      }
      cur -= *iter;
      st.erase(iter);
    }
    if (p > st.size()) {
      st.insert(w);
      cur += w;
    }
  }
  return cur;
}

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    LL ans = 0;
    vector<pair<LL, LL>> a, b;
    for (int i = 0; i < n; i++) {
      LL l, r, k;
      cin >> k >> l >> r;
      ans += min(l, r);
      if (l > r){
        a.push_back({k, l - r});
      }
      if (l < r) {
        b.push_back({n - k, r - l});
      }
    }
    ans += solve(a);
    ans += solve(b);
    cout << ans << endl;
  }

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 12708
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
vector<int> v[200005];
int main(){
    int h,w,n;
    scanf("%d %d %d",&h,&w,&n);
    int a=max(h,w);
    printf("%d\n",(n+a-1)/a);
}
/*
2 6
5 7
7 5
4 3
6 4
7 3
6 5
5 7
3 6
4 7
*/
//a+a+1=10a+1
//3a+2=10a+2

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int N, K;
  scanf("%d%d", &N, &K);

  int d, x;
  vi f(N, 0);
  rep(i, 0, K) {
    scanf("%d", &d);
    rep(j, 0, d) {
      scanf("%d", &x);
      f[--x]++;
    }
  }

  int ans = 0;
  rep(i, 0, N)
    if (!f[i])
      ans++;
  printf("%d\n", ans);
    
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}



Measured memory_bytes: 3680
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 1001000
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL p;
    LL ans=1;
    vector<LL> unique_num(MAX, 0);
    cin >> n >> p;
    LL tmp=p;
    for(LL i=2; i*i<=tmp; i++){
        while(tmp%i==0){
            tmp/=i;
            unique_num[i]++;
        }
    }

    for(LL i=2; i<=MAX; i++){
        while(unique_num[i]>=n){
            ans*=i;
            unique_num[i]-=n;
        }
    }
    if(n==1){
        ans*=tmp;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10984
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

typedef long long LL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define SZ(a) (int)((a).size())

const int MAXN = 100007;
const int INF = 1000000007;
const LL LINF = INF * (LL)INF;

LL A[MAXN], DP[MAXN], T1[4 * MAXN], T2[4 * MAXN];

LL query(int v, int tl, int tr, int l, int r, LL * const T)
{
	if (l > r) return LINF;
	if (l == tl && r == tr) return T[v];
	int tm = (tl + tr) / 2;
	return min(query(v * 2, tl, tm, l, min(r, tm), T), query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, T));
}

void update(int v, int tl, int tr, int pos, LL val, LL * const T)
{
	if (pos < tl || pos > tr) return;
	if (tl == tr)
	{
		T[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	update(v * 2, tl, tm, pos, val, T);
	update(v * 2 + 1, tm + 1, tr, pos, val, T);
	T[v] = min(T[v * 2], T[v * 2 + 1]);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int n, e, t;
	cin >> n >> e >> t;
	FOR(i, 1, n + 1)
		cin >> A[i];
	DP[0] = A[0] = 0;
	update(1, 0, n, 0, -2 * A[1], T1);
	FOR(i, 1, n + 1)
	{
		int j = lower_bound(A, A + i, A[i] - t / 2) - A;
		if (j) --j;
		DP[i] = 3 * A[i] + query(1, 0, n, 0, j - 1, T1);
		DP[i] = min(DP[i], A[i] + t + query(1, 0, n, j, i - 1, T2));
		update(1, 0, n, i, DP[i] - A[i] - 2 * A[i + 1], T1);
		update(1, 0, n, i, DP[i] - A[i], T2);
	}
	cout << DP[n] + e - A[n];
	return 0;
}

Measured memory_bytes: 7936
n=gets.to_i
prices=[]
n.times do
	prices << gets.to_i
end
i=0
j=0
biggest=100
while i < n do
	if biggest < prices[i] then
		biggest = prices[i] 
		j=i
	end
	i+=1
end
prices[j] /= 2
puts prices.inject(0) {|sum,x| sum + x }

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<vector>
using namespace std;
vector<string> v;
string buf[5002],s;

int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
		for(int j=i;j<s.size() && j<i+6;j++) {
			v.push_back(s.substr(i,j-i+1));
		}
	sort(v.begin(),v.end());
	int k;
	cin>>k;
	k--;
	v.erase(unique(v.begin(),v.end()),v.end());
	cout<<v[k];
	return 0;
}

Measured memory_bytes: 1916
# -*- coding: utf-8 -*-
# import math   # math.infが使えない？(3.5から。AtCoderは3.4)

# 解説見ながら記述
# 延長魔法は、合成前・合成後で実施しても等価。
# 合成魔法が使えないパターンにのみ延長魔法を使うようにして全探索するみたい

N, A, B, C = map(int, input().split())
ls = [int(input()) for i in range(N)]
INF = 10 ** 10  # int32.max = 2*10^9より大きくしている

def rec(cur, a, b, c):
    """
    cur: 現在のlsのindex
    a: 合成中の1本目の長さ
    b: 合成中の1本目の長さ
    c: 合成中の1本目の長さ
    """
    if cur == N:
        if min(a, b, c) > 0:
            # 合成1回目：1本目は選ぶだけで合成する必要ないので10*3を引いておく
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            # 1回も合成していない場合は無効
            # return math.inf
            return INF
    else:
        r0 = rec(cur+1, a, b, c)    # ls[cur]に対して何もしない
        r1 = rec(cur+1, a+ls[cur], b, c) + 10    # ls[cur]をaに合成
        r2 = rec(cur+1, a, b+ls[cur], c) + 10    # ls[cur]をbに合成
        r3 = rec(cur+1, a, b, c+ls[cur]) + 10    # ls[cur]をcに合成
        return min(r0, r1, r2, r3)

r = rec(0, 0, 0, 0)

print(r)


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

lli r[4001] = {};
lli g[4001] = {};
lli b[4001] = {};

int main(void) {

	lli n;
	cin >> n;
	string s;
	cin >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r[i] += 1;
		}
		if (s[i] == 'G') {
			g[i] += 1;
		}
		if (s[i] == 'B') {
			b[i] += 1;
		}
		r[i + 1] += r[i];
		g[i + 1] += g[i];
		b[i + 1] += b[i];
	}

	lli answer = 0;

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {

			char c = 'R' + 'G' + 'B' - s[i] - s[j];

			if (2 * j - i < n && s[2 * j - i] == c) {
				answer--;
			}

			switch (c) {
			case 'R':
				answer += r[n] - r[j];
				break;
			case 'G':
				answer += g[n] - g[j];
				break;
			case 'B':
				answer += b[n] - b[j];
				break;
			}

		}
	}


	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 3692
fun main(args: Array<String>) {
    val text = readLine()!!
    var result = "NO"

    var tempText = text
    while(tempText != replace(tempText)) {
        if (replace(tempText) == "") {
            result = "YES"
            break
        }
        tempText = replace(tempText)
    }
    print(result)
}

fun replace(text: String): String {
    return if (text.endsWith("dream")) {
        text.substring(0, text.length - "dream".length)
    } else if (text.endsWith("dreamer")) {
        text.substring(0, text.length - "dreamer".length)
    } else if (text.endsWith("erase")) {
        text.substring(0, text.length - "erase".length)
    } else if (text.endsWith("eraser")) {
        text.substring(0, text.length - "eraser".length)
    } else {
        text
    }
}

Measured memory_bytes: 118808
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;

int main()
{
	int n;
	cin >> n;
	int arr[n], alice = 0, bob = 0;
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr,arr+n);
	for(int i = n-1; i >= 0; i -= 2)
		alice += arr[i];
	for(int i = n-2; i >= 0; i -= 2)
		bob += arr[i];
	cout << alice - bob;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  ll a,b,x;
  cin>>a>>b>>x;

  if(a==0){
    cout<<b/x+1<<endl;
  }else{
    cout<<b/x-(a-1)/x<<endl;
  }
  return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int i, j, n, w;
        int[] v, vv;
        int[][] dp;
        n = sc.nextInt(); w = sc.nextInt();
        v = new int[n]; vv = new int[n]; dp = new int[n + 1][w + 1];
        for(i = 0;i < n;i++){
          v[i] = sc.nextInt(); vv[i] = sc.nextInt();
        }
        for(i = 0;i < n;i++) {
        	for(j = 0;j <= w;j++){
        		if(dp[i + 1][j] < dp[i][j])
        			dp[i + 1][j] = dp[i][j];
        		if(j + vv[i] <= w && dp[i][j] + v[i] > dp[i + 1][j + vv[i]])
        			dp[i + 1][j + vv[i]] = dp[i][j] + v[i];
        	}
        }
        System.out.println(dp[n][w]);
        sc.close();
    }
}



Measured memory_bytes: 31004
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  //    String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int[] num=new int[6];
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
int C=Integer.parseInt(nyu);
//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

if(C==1){

System.out.println("Hello World") ;
}else{
String ny=sc.nextLine();
int A=Integer.parseInt(ny);
ny=sc.nextLine();
int B=Integer.parseInt(ny);
System.out.println(A+B) ;

}
	}
}

Measured memory_bytes: 22612
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, m, n) for(int i = m; i >= n; i--)

int gcd(int u, int v){
	while(u > 0){
		if(u < v) swap(u, v);
		u %= v;
	}
	return v;
}
int main(){
	int a, b;
	while(cin >> a >> b){
		cout << gcd(a, b) << endl;
	}
	return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll md = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int n;
    cin >> n;
    VI V(n);
    int x = 0;
    REP(i, n) {
        cin >> V[i];
        x = x ^ V[i];
    }
    REP(i, n) {
        cout << (x ^ V[i]) << "\n";
    }

}

Measured memory_bytes: 3976
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char s[1000];int i=0;
	cin>>s;
	while(i<strlen(s)/2)
	{
		if(s[i]!=s[strlen(s)-i-1]){cout<<"No";return 0;}
		i++;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<(x)<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)1e6+5;
vector<string> input;
vector<char> ans;
char a='A',b='B',c='C';

map<char,int> num;
string not_zero(){
    if(num[a]==1)return "A";
    if(num[b]==1)return "B";
    if(num[c]==1)return "C";
    return "";
}
void mod(char a,char b){
    num[a]++,num[b]--;
    ans.push_back(a);
}
int main(){
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n>>num[a]>>num[b]>>num[c];
    while(n--){
        string s;cin>>s;input.push_back(s);
    }
    if(num[a]+num[b]+num[c]==0){puts("No");return 0;}
    if(num[a]+num[b]+num[c]==1){
        for(auto ss:input){
            if(ss.find(not_zero())!=ss.npos){
                int tmp=(int)ss.find(not_zero());
                //debug(tmp);
                mod(ss[1-tmp],ss[tmp]);
               
            }else{
                puts("No");
                return 0;
            }
        }
        puts("Yes");
        for(auto ss:ans){ cout<<ss<<endl;}
    }else{
        auto t=input.front();
        if(num[t[0]]+num[t[1]]==0){puts("No");return 0;}
        for (int i=0;i<input.size();i++){
            auto ss=input[i];
            if(num[ss[0]]==0)mod(ss[0],ss[1]);
            else if(num[ss[1]]==0)mod(ss[1],ss[0]);
            else if(num[ss[0]]==1||num[ss[1]]==1){
                if(i==input.size()-1){
                    mod(ss[0],ss[1]);
                }else{
                    auto nxt=input[i+1];
                    char c1=ss[0],c2=ss[1];
                    if(num[ss[1]]==1)swap(c1,c2);
                    if(nxt.find(c1)!=nxt.npos)mod(c1,c2);
                    else mod(c2,c1);// 1 1
                } 
            }else{
               mod(ss[0],ss[1]);
            }
        }
        puts("Yes");
        for(auto ss:ans){ cout<<ss<<endl;}
    }
}
/* 
new: string, char, find, npos
type: construct& code
0 0 1
0 1 1
0 0 2
0 0 3

hard 1638
3 1 0 0
AB
BC
AB

3 1 0 0
AB
BC
CA
5 2 0 0 
AB
AB 
AB
AB
AB

3 1 0 0
AB
BC
AB

 */

Measured memory_bytes: 7428
#include <bits/stdc++.h>
#include <atcoder/convolution>
using namespace atcoder;

typedef long long ll;
const int MAXC = 1e5 + 19, MOD = 998244353;

int qpow(int a, int b){
	int res = 1;
	while(b){
		if(b & 1) res = (ll)res * a % MOD;
		a = (ll)a * a % MOD, b >>= 1;
	}
	return res;
}

int n, t[MAXC];
std::vector<int> r[MAXC];

int fact[MAXC];
int binom(int n, int m){
	return (ll)fact[n] * qpow((ll)fact[n - m] * fact[m] % MOD, MOD - 2) % MOD;
}
int pair_count(int n){
	return (ll)binom(n * 2, n) * fact[n] % MOD * qpow(qpow(2, n), MOD - 2) % MOD;
}

struct Node{
	int x;
	bool operator>(const Node &b)const{return r[x].size() > r[b.x].size();}
};
std::priority_queue<Node, std::vector<Node>, std::greater<Node> > q;

int main(){
	std::scanf("%d", &n);
	for(int i = 1; i <= n * 2; ++i){
		int z; std::scanf("%d", &z);
		++t[z];
	}
	fact[0] = 1;
	for(int i = 1; i <= 100000; ++i)
		fact[i] = (ll)fact[i - 1] * i % MOD;
	for(int i = 1; i <= 100000; ++i)
		if(t[i] >= 1){
			r[i] = {1};
			for(int j = 2; j <= t[i]; j += 2)
				r[i].push_back((ll)binom(t[i], j) * pair_count(j / 2) % MOD);
			q.push((Node){i});
		}
	while(q.size() > 1){
		int a = q.top().x; q.pop();
		int b = q.top().x; q.pop();
		r[a] = convolution(r[a], r[b]);
		std::vector<int>().swap(r[b]);
		q.push((Node){a});
	}
	std::vector<int> res(r[q.top().x]);
	int ans = 0;
	for(int i = 0; i < res.size(); ++i){
		if(i > n) break;
		res[i] = (ll)res[i] * pair_count(n - i) % MOD;
		if(i & 1) ans = (ans - res[i]) % MOD;
		else ans = (ans + res[i]) % MOD;
	}
	std::printf("%d\n", (ans + MOD) % MOD);
}

Measured memory_bytes: 9964
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000000
char f[MAX];
void getprime(int s)
{
  int i,j,c=0;
  for(i=2;i*i<=s;i++){
    if(!f[i]){
      for(j=i+i;j<=s;j+=i){
        f[j]=1;
      }
    }
  }
}
int main(void)
{
  int n;
  getprime(MAX);
  for(;;){
    scanf("%d",&n); if(!n)break;
    while(f[n]||f[n-2]||f[n-6]||f[n-8])n--;
    printf("%d\n",n);
  }
  return 0;
}

Measured memory_bytes: 9000
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int n;
int groupE[200010], groupF[200010];
vector<int> E[200010], F[200010];
map<pair<int, int>, int> mp;

void dfs(int u, vector<int> M[], int group[], int id) {
    group[u] = id;
    for (int v : M[u]) {
        if (!group[v]) dfs(v, M, group, id);
    }
}

void makeGroup(int m, vector<int> M[], int group[]) {
    int x, y;
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        M[x].push_back(y);
        M[y].push_back(x);
    }

    int id = 1;
    for (int i = 1; i <= n; i++) {
        if (group[i]) continue;
        dfs(i, M, group, id);
        id++;
    }
}

int main() {
    int k, l;
    cin >> n >> k >> l;

    makeGroup(k, E, groupE);
    makeGroup(l, F, groupF);

    for (int i = 1; i <= n; i++) {
        mp[{groupE[i], groupF[i]}]++;
    }

    for (int i = 1; i <= n; i++) {
        cout << mp[{groupE[i], groupF[i]}] << ' ';
    }
}


Measured memory_bytes: 27904
function main(input) {
    var data = input.split(' ');
    var low = parseInt(data[0]);
    var high = parseInt(data[1]);
    var number = parseInt(data[2]);
    var countDivisor = 0;
    for (var divisor = low; divisor <= high; divisor++) {
        if ((number % divisor) === 0) {
            countDivisor += 1;
        }
    }
    console.log(countDivisor);
}

process.stdin.resume();
var input = '';  
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  main(input);
});

Measured memory_bytes: 15672
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n;
	cin >> n;
	int t;
	int ans = n;
	int cnt = 2;
	int a1, a2, a4;
	a1 = a2 = a4 = 0;
	bool f = false;
	rep(i, n) {
		cin >> t;
		if (t % 4 == 0) {
			a4++;

		}
		else if (t % 2 == 0) {
			a2++;

		}
		else {
			a1++;
		}
	}

	if (a2 == 0) {
		if (a1 <= a4 + 1) {
			f = true;
		}
	}
	else {
		if (a1 <= a4) {
			f = true;
		}
	}

	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

int N, K;
int h[100005];
int IMF = 1000000000;

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

    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> h[i];

    sort(h, h+N);

    int ans = IMF;
    for (int i = 0; i < N-K+1; i++) {
        ans = min(ans, h[i+K-1]-h[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
n, k = map(int, input().split())

if 2*k-1 > n:
    print(-1)
    exit()

l = (n+1)//2

if n % 2 != 0:
    a = []
    b = []
    c = []
    for x in range(k, k+2*l-2+1,2):
        a.append(x)
    for x in range(k+1, k+2*l-2, 2):
        a.append(x)

    for x in range(k+3*l-2, k+2*l-2, -1):
        b.append(x)
    for x in range(k+4*l-3, k+3*l-2, -1):
        b.append(x)

    for x in range(k+4*l-2, k+6*l-3):
        c.append(x)
    for i in range(n):
        print(a[i], b[i], c[i])
else:
    a = []
    b = []
    c = []
    for x in range(k, k+2*l-2+1, 2):
        a.append(x)
    for x in range(k+1, k+2*l, 2):
        a.append(x)

    for x in range(k+3*l-1, k+2*l-1, -1):
        b.append(x)
    for x in range(k+4*l-1, k+3*l-1, -1):
        b.append(x)

    for x in range(k+4*l, k+6*l):
        c.append(x)
    for i in range(n):
        print(a[i], b[i], c[i])


Measured memory_bytes: 52000
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random

data class Node(val p:Int, val n:Int)

fun main() {
    val sc = Scanner(System.`in`)
    var n = sc.nextInt()
    var arr = Array(n){""}
    var m = Array(n){IntArray(2)}
    val list = ArrayList<Node>()
    var start = 0
    var end = 0

    fun createP(n:Int): String {
        val sb = StringBuilder()
        val c = arrayOf('(',')')
        for(i in 0 until n) {
            sb.append(c[Random.nextInt(0, 100) % 2])
        }
        return sb.toString()
    }
    fun createRand() {
        n = (7000).toInt()
        arr = Array(n){""}
        for(i in 0 until n) {
            val len = Random.nextInt(1, 2200)
            arr[i] = createP(len)
        }
        m = Array(n){IntArray(2)}
    }

    for(i in 0 until n) {
        arr[i] = sc.next()
        arr[i] = arr[i].trim()
    }

//    createRand()

    for(i in 0 until n) {
        var k = 0
        var minus = 0
        var plus = 0
        for(c in arr[i]) {
            if(c == '(') {
                if(k < 0) {
                    minus += k
                    k = 0
                }
                ++k
            } else if(c==')'){
                --k
            }
        }
        if(k > 0) {
            plus += k
        } else if(k < 0) {
            minus += k
        }

        if(minus == 0 || plus == 0) {
            start += plus
            end += minus
        } else {
            list.add(Node(plus, minus))
        }
        m[i][0] = minus
        m[i][1] = plus
    }

    val pq = PriorityQueue<Node>(kotlin.Comparator { o1, o2 ->
        val v1 = o1.n + o1.p
        val v2 = o2.n + o2.p
        return@Comparator v2.compareTo(v1)
    })

    list.sortByDescending { it.n }

    var idx = 0
    var isSuccess = true

    while (isSuccess && idx < list.size) {
        while(idx < list.size && list[idx].n <= start) {
            pq.add(list[idx++])
        }
        while (pq.isNotEmpty()) {
            val node = pq.poll()
            start += node.n
            if(start < 0) {
                isSuccess = false
                break
            }
            start += node.p
        }
    }
    if(isSuccess) {
        val ret = start + end
        isSuccess = ret == 0
    }

    if(isSuccess) {
        print("Yes")
    } else {
        print("No")
    }



}

Measured memory_bytes: 164792
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, A, B = MI()

    if A > B:
        print(0)
        return

    if A != B and N == 1:
        print(0)
        return

    min_v = A * (N - 1) + B
    max_v = A + B * (N - 1)
    print(max_v - min_v + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long int ll;

int main()
{
    
    int N, K;
    int  h[100000];
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> h[i];

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (h[i] >= K) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 640
#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];
    vector<vector<long long>> dp(n+1,vector<long long>(n+1,0));
    for(int i=n-1;i>=0;i--){
        for(int j=i;j<n;j++){
            if(i==j){
                dp[i][j] = a[i];
            }else{
                dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
            }
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;

string S;
int cc,p;
ll T[2019],res;

int main(){
	cin>>S;
	T[0]++;
	reverse(S.begin(),S.end());
	p=1;
	for(char c:S){
		cc+=p*(c-'0');
		cc%=2019;
		T[cc]++;
		p*=10;
		p%=2019;
	}
	for(int i=0;i<2019;i++){
		res+=T[i]*(T[i]-1)/2;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

using P =pair<int,int>;
int main(void){
    // Your code here!
    int A,B,M; cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    // map<P,int> mp;
    int res = INF;
    rep(i,M){
        int x,y,c; cin >> x >> y >> c;
        // P pair = {x-1,y-1};
        // mp[pair] = c;
        x--;y--;
        int cur = a[x]+b[y]-c;
        res = min(res,cur);
    }
    int nok = MIN(a)+MIN(b);
    res = min(res,nok);
    cout << res << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(void){
    char S[1000000],T[1000000];
    int count=0,i;
    scanf("%s",S);
    scanf("%s",T);
    int l=strlen(S);
    for(i=0;i<l;i++){
        if(S[i]!=T[i]){
            count++;
        }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 2132
# ABC128 C - Switches
n,m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    i = format(i, "b").zfill(n)
    for j in range(len(s)):
        tmp = 0
        for k in s[j][1:]:
            tmp += int(i[k - 1])
		
        if p[j] != tmp % 2:
            break
        if j == len(s) - 1:
            ans += 1

print(ans)

Measured memory_bytes: 3064
N, K = map(int, input().split())
A = list(map(int, input().split()))
dp = [False] * (K+1)

for i in range(K+1):
    for j in range(N):
        if i - A[j] >= 0 :
            dp[i] = dp[i] | (not dp[i-A[j]])

if dp[K]:
    print('First')
else:
    print('Second')

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


int main(){
  int k, t;
  cin >> k >> t;
  int a[100];
  int max_a = 0;
  for(int i=0; i<t; ++i){
    cin >> a[i];
    max_a = max(max_a, a[i]);
  }
  int ans;
  ans = 2 * max_a - k - 1;
  cout << max(ans, 0) << endl;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k,q,a,b,c,d;
    map<long long,long long>mp;
    
    cin>>n>>k>>q;
    long long arr[n+2];
    for(long long i=0; i<q; i++)
    {
        cin>>a;

        mp[a]++;

    }
    for(long long i=1; i<=n; i++)
    {
        arr[i]=k-(q-mp[i]);

    }
    for(long long i=1; i<=n; i++)
    {
        if(arr[i]>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }


}


Measured memory_bytes: 7680
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////

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

    ll ans = 0;
    ans += a/500 * 1000;
    a %= 500;
    ans += a/5 * 5;
    P(ans);
    return  0;
}


Measured memory_bytes: 256
h,w,k = map(int,input().split())
lst = []
cut1 = []
for i in range(h):
    l = input()
    if '#' in l:
        cut1.append(i)
    lst.append(l)
res = [[float('inf')]*w for _ in range(h)]

cut2 = []
for c in cut1:
    tmp_cut = []
    for j in range(len(lst[c])):
        if lst[c][j]=='#':
            tmp_cut.append(j)
    cut2.append(tmp_cut)

cnt = 1
for e,i in enumerate(cut1):
    for j in cut2[e]:
        res[i][j] = cnt
        cnt += 1

for r in res:
    mn = min(r)
    mx = max(r)
    if (mn==mx) and (mn==float('inf')):
        pass
    else:
        mx = max(set(r) - {float('inf')})
        if mn==mx:
            for i in range(w):
                if r[i] == float('inf'):
                    r[i] = mn
        else:
            for i in range(w):
                if r[i] == float('inf'):
                    r[i] = mn
                else:
                    mn = min(mx, r[i])

for i in range(w):
    tmp = []
    for j in range(h):
        if res[j][i] != float('inf'):
            tmp.append(res[j][i])
    num = min(tmp)
    for j in range(h):
        if res[j][i] == float('inf'):
            res[j][i] = num
        else:
            num = res[j][i]

for r in res:
    print(*r)

Measured memory_bytes: 8656