akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

#define int long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> matrix;

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x;}
inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x;}
inline int mul(int x, int y) { return ((x % mod) * (y % mod)) % mod;}
inline int power(int a, int b) {
	int x = 1;
	while (b) {
		if (b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a) { return power(a, mod - 2);}

const int N = 5005;
int n, dp[N][N];
pii a[N];

bool cmp(pii one, pii two) {
	return (one.fi + one.se < two.fi + two.se);
}

#undef int
int main() {
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	clock_t start = clock();

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].fi >> a[i].se;
	}
	sort(a + 1, a + n + 1, cmp);

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = inf;
		}
	}

	dp[1][1] = a[1].se;
	int ans = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			if (dp[i - 1][j - 1] > a[i].fi) dp[i][j] = dp[i - 1][j];
			else {
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + a[i].se);
				ans = max(ans, j);
			}
		}
	}


	cout << ans << endl;

	clock_t end = clock();
	cerr << "Time: " << (double)(end - start) / CLOCKS_PER_SEC << " seconds" << endl;

	return 0;
}

Measured memory_bytes: 195968
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    x, y = map(int, input().split())
    for i in range(x+1):
        if (i * 2) + (x-i) * 4 == y:
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    main()

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

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt_a = 0
cnt_b = 0
for i in range(n):
    if i%2 == 0:
        cnt_a += a[i]
    else:
        cnt_b += a[i]
print(cnt_a-cnt_b)

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */
int n;
vector<lint> a;

lint solve(int f){
    vector<lint> b(n); lint sum = 0;
    rep(i, n){
        if(i == 0){
            if(f) b[0] = max(1LL, a[0]);
            else b[0] = min(-1LL, a[0]);
            continue;
        }
        sum += b[i-1];
        lint m, M;
        if(sum < 0){
            m = -sum+1;
            if(i < n-1) M = -sum-a[i+1]-1; else M = INF;
            if(m > M) M = INF;
        }
        else{
            M = -sum-1;
            if(i < n-1) m = -sum-a[i+1]+1; else m = -INF;
            if(m > M) m = -INF;
        }

        if(a[i] < m) b[i] = m;
        else if(a[i] <= M) b[i] = a[i];
        else b[i] = M;
    }
    lint res = 0;
    rep(i, n) res += abs(a[i] - b[i]);
    return res;
}

int main(){
    cin >> n;
    rep(i, n){
        lint x; cin >> x; a.push_back(x);
    }
    out(min(solve(0),solve(1)));
}


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

int main(){

  int n, i, num, max, min;
  int gray, brown, green, lightblue, blue, yellow, orange, red, tmp;
  gray = brown = green = lightblue = blue = yellow = orange = red = tmp = 0;

  cin >> n;
  for(i = 0; i < n; i++){
    cin >> num;
    if(num >= 1 && num <= 399){
      if(gray == 0) gray++;
    }else if(num >= 400 && num <= 799){
      if(brown == 0) brown++;
    }else if(num >= 800 && num <= 1199){
      if(green == 0) green++;
    }else if(num >= 1200 && num <= 1599){
      if(lightblue == 0) lightblue++;
    }else if(num >= 1600 && num <= 1999){
      if(blue == 0) blue++;
    }else if(num >= 2000 && num <= 2399){
      if(yellow == 0) yellow++;
    }else if(num >= 2400 && num <= 2799){
      if(orange == 0) orange++;
    }else if(num >= 2800 && num <= 3199){
      if(red == 0) red++;
    }else{
      tmp++;
    }
  }
  max = gray + brown + green + lightblue + blue + yellow + orange + red;
  min = gray + brown + green + lightblue + blue + yellow + orange + red;
  max += tmp;
  if(min == 0 && tmp >= 1) min = 1;
  cout << min << " " << max << endl;
  return 0;
}


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

int main() {
	int A, B;
	cin >> A >> B;

	int count = 0;

	for( int i = A; i <= B; ++i ) {
		string s = to_string( i );

		if( s[0] == s[4] && s[1] == s[3] ) {
			count++;
		}
	}

	cout << count << endl;
}


Measured memory_bytes: 256
text = input()
n = int(input())

for t in range(n):
    order = list(input().split())

    if "replace" == order[0]:
        left = int(order[1])
        right = int(order[2])
        text = text[:left] + order[3] + text[right + 1:]
    elif "reverse" == order[0]:
        left = int(order[1])
        right = int(order[2])
        text = text[:left] + text[left:right + 1][::-1] + text[right + 1:]
    elif "print" == order[0]:
        print(text[int(order[1]): int(order[2]) + 1])



Measured memory_bytes: 5612
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    int n;
    long long int h,w,a,b;
    int ans=0;
    scanf("%d %lld %lld\n",&n,&h,&w);
    REP(i,n){
        scanf("%lld %lld",&a,&b);
        if(a>=h&&b>=w)ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    map<char,ll>maps;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        maps[s[i]]++;
    }
    for(auto i:maps){
        if(i.ss%2==1){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3604
n, w = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]

dp = [[0]*(w+1) for i in range(n+1)]

for i in range(n):
    weight, val = info[i]
    for j in range(w+1):
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        if j - weight >= 0:
            dp[i+1][j] = max(dp[i][j-weight] + val, dp[i+1][j])

print(max(dp[n]))

Measured memory_bytes: 120172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;n--;
  string ans;
  while(n>-1) {
    ll x=n/26,rem=n%26;
    ans+='a'+rem;
    n=x-1;
  }
  reverse(ALL(ans));print(ans);
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector< vector<int> > g;
vector< vector<int> > gw;
vector<bool> done;
vs32 ans;

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

    int N;
    cin >> N;

    g.resize(N);
    gw.resize(N);
    done.resize(N, false);
    ans.resize(N);
    int u, v, w;
    rep (i, N - 1)
    {
        cin >> u >> v >> w;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);
        gw[u - 1].push_back(w);
        gw[v - 1].push_back(w);
    }

    ans[0] = 0;
    queue<int> q;
    q.push(0);

    while (!q.empty())
    {
        int root = q.front();
        q.pop();
        done[root] = true;

        rep (i, g[root].size())
        {
            int leaf = g[root][i];
            if (done[leaf]) continue;
            int dist = gw[root][i];
            if (dist & 1) ans[leaf] = ans[root] ^ 1;
            else ans[leaf] = ans[root];
            q.push(leaf);
        }
    }

    rep (i, N) cout << ans[i] << "\n";
    return 0;
}



Measured memory_bytes: 11904
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int N, X;
	int L[104];
	cin >> N >> X;
	for (int i = 0; i < N; i++)
	{
		cin >> L[i];
	}

	int D = 0;
	int ans = 1;
	for (int i = 0; i < N; i++)
	{
		if (D + L[i] <= X)
		{
			ans++;
			D += L[i];
		}
		else
			break;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
bool is_prime(int N) {
  for (long i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      return false;
    }
  }
  return N != 1;
}

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

  int answer = 0;
  int count = 0;
  bool flg = true;

  while (flg) {
    if(is_prime(X + count)) {
      flg = false;
      answer = X + count;
    } else {
      count++;
    }
  }

  cout << answer << endl;
 
}

Measured memory_bytes: 256
import scala.io.StdIn._

object Main {

  object Dice{
    private val north = List(2,6,3,4,1,5).map(_-1)
    private val east = List(4,2,1,6,5,3).map(_-1)
    private val ccw = List(3,2,6,1,5,4).map(_-1)
  }

  case class Dice(pip: List[Int]) {
    def north = Dice(Dice.north.map(pip))
    def east = Dice(Dice.east.map(pip))
    def south = north.north.north
    def west = east.east.east
  }

  def main(args: Array[String]): Unit = {
    val pip = readLine.split(" ").map(_.toInt).toList
    val commands = readLine

    var dice = Dice(pip)

    for(com <- commands){
      dice = com match {
        case 'N' => dice.north
        case 'E' => dice.east
        case 'S' => dice.south
        case 'W' => dice.west
        case _ => dice
      }
    }
    
    println(dice.pip(0))
  }
}

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

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

int main() {
	int n, max_w;
	cin >> n >> max_w;
	vector<int> v(n), w(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	
	vector<int> dp(max_w + 1, 0);
	
	for (int i = 0; i < n; i++) {
		for (int sum_w = 0; sum_w <= max_w; sum_w++) {
			if (sum_w + w[i] <= max_w) {
				chmax(dp[sum_w + w[i]], dp[sum_w] + v[i]);
			}
		}
	}
	
	cout << dp[max_w] << endl;
	
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;



int N, K, ans = 0;
int counter = 0;
vector<lli> A;

lli calc(int pos)
{
	int need = K + pos - 1;
	if (need > N - 1) {
		return LIMIT;
	}
	int dist = 0;
	if (pos < counter) {
		if (need < counter) {
			return min({ abs(A[pos]), calc(pos + 1) });
		}
		//cerr << abs(A[pos] * 2) + abs(A[need]) << endl;
		return min({ abs(A[pos] * 2) + abs(A[need]),abs(A[need] * 2) + abs(A[pos]), calc(pos + 1) });
	}
	else {
		//cerr << abs(A[need]) << endl;
		return abs(A[need]);
	}
}


int main()
{
	
	scanf("%d %d", &N, &K);
	A = vector<lli>(N);
	
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		if (A[i] < 0) {
			counter++;
		}
	}
	if (K == 1) {
		if (counter == 0) {
			cout << A[counter] << endl;
			return 0;
		}
		cout << min(abs(A[counter - 1]), A[counter]) << endl;
		return 0;
	}

	cout << calc(0) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	int i, j,k;
	string s;
	cin >> s;
	char first;
	char last;
	int moji = 0;
	first = s[0];
	last = s[s.size()-1];
	for (i = 0; i < s.size(); ++i) {
		++moji;
	}
	cout << first <<moji-2<< last;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
S = L()
a = list(Counter(S))
if len(a) == 3:
    print("Three")
else:
    print("Four")


Measured memory_bytes: 10176
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define INF               1e18
#define ff                first
#define ss                second
#define vi                vector<int>
#define pii               pair<int,int>
#define mii               map<int,int>
#define endl              "\n"
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define debug(x)          cout<<#x<<" is "<<(x)<<endl
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(long long i=a;i<b;i++)
#define sp(ans,p)         fixed <<setprecision(p)<<ans;
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// constexpr int N=;
void solve()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans = 0;
    int ptr1 = 0, ptr2 = s.length() - 1;
    while (ptr1 < ptr2)
    {
        if (s[ptr1] == 'W' and s[ptr2] == 'R')
        {
            swap(s[ptr1], s[ptr2]);
            ans++;
        }
        if (s[ptr1] == 'R') ptr1++;
        if (s[ptr2] == 'W') ptr2--;
    }
    cout << ans << endl;

    return;
}

signed main()
{
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // sieve();
    int t = 1;
    // cin >> t;
    while (t--)   solve();
    return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
struct node
{
    int x,y;
    int p;
} a[N];
struct NODE
{
    int pos;
    int f;
    int type;
} b[N*5];
int cmp(NODE a,NODE b)
{
    if(a.pos==b.pos)
    {
        if(a.type==b.type)
            return a.f<b.f;
        return a.type<b.type;
    }
    return a.pos<b.pos;
}
multiset<int> st;

int main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].p);
        a[i].x=max(a[i].x-a[i].p,0);
        a[i].y=max(a[i].y-a[i].p,0);
    }
    int res=0;
    for(int i=1;i<=n;i++)
    {
        b[++res].pos=a[i].x;
        b[res].type=0;
        b[res].f=a[i].p;


        b[++res].pos=a[i].y;
        b[res].type=1;
        b[res].f=a[i].p;
    }
    while(q--)
    {
        int d;
        scanf("%d",&d);
        b[++res].pos=d;
        b[res].type=2;
    }
    sort(b+1,b+res+1,cmp);
    //for(int i=1;i<=res;i++)
    //    printf("%d %d %d\n",b[i].pos,b[i].type,b[i].f);
    st.clear();
    for(int i=1;i<=res;i++)
    {
        if(b[i].type==2)
        {
            if(st.empty())
                printf("-1\n");
            else
                printf("%d\n",*st.begin());
        }

        else if(b[i].type==0)
            st.insert(b[i].f);
        else
            st.erase(st.find(b[i].f));
    }
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 22656
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> a(n), b(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
	}

	ll ans = 0LL;
	for(int i = n - 1; i >= 0; i--) {
		a[i] += ans;
		
		if( a[i] % b[i] != 0 ) {
			ans += b[i] - (a[i] % b[i]);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var s, t string

	_, err := fmt.Scanf("%s\n%s", &s, &t)
	if err != nil {
		return
	}

	sLen := len(s)
	tLen := len(t)

	if sLen == 0 || tLen == 0{
		fmt.Printf("0\n")
		return
	}
	
	//如果这两个字符串长度相等
	if sLen == tLen {
		cnt := 0
		for i:=0;i<sLen;i++{
			if s[i] != t[i]{
				cnt++
			}
		}
		fmt.Printf("%d\n", cnt)
		return
	}

	min := tLen
	for i:=0;i<sLen-tLen;i++ {
		cnt := 0
		for j:=0;j<tLen;j++ {
			if s[i+j] != t[j]{
				cnt++
			}
		}
		if cnt < min {
			min = cnt
		}
	}
	fmt.Printf("%d\n", min)

}



Measured memory_bytes: 1852
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

#define ll long long
#define ull unsigned long long

ll func(ll);

using namespace std;
int main(void) {

	ll N = 0;

	scanf("%lld", &N);
	printf("%lld\n", func(N));
	
	return 0;
}

ll func(ll N) {
	if (N < 6)
		return N;
	else {
		ll ans = 0;
		ll a = 0;

		while (N >= pow(9, ++a));
		ans = func(N - pow(9, a - 1));

		a = 0;
		while (N >= pow(6, ++a));
		ans = min(func(N - pow(6, a - 1)),ans);

		return ans + 1;
		
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int[][] area = new int[12][12];

		while(sc.hasNextLine()) {
			int count = 0;

			for(int i = 0;i < 12 ;i++) {
				char[] nums = sc.nextLine().toCharArray();
				for(int j = 0;j < 12;j++) {
					area[i][j] = Character.getNumericValue(nums[j]);
				}
			}

			for(int i = 0;i < 12 ;i++) {
				for(int j = 0;j < 12;j++) {
					if(area[i][j] == 1 ) {
						count++;
						area = checkIsland(area, i , j);

					}
				}
			}
			if(sc.hasNextLine()) {
				sc.nextLine();
			}

			System.out.println(count);
		}

	}


	public static int[][] checkIsland(int[][] area,int i,int j) {
		area[i][j] = 0;

		if(j < 11) {
			if(area[i][j + 1] == 1) {
				area = checkIsland(area, i,j + 1);
			}
		}
		if(i < 11) {
			if(area[i + 1][j] == 1) {
				area = checkIsland(area,i + 1, j);
			}
		}
		if(j > 0) {
			if(area[i][j - 1] == 1) {
				area = checkIsland(area, i,j - 1);
			}
		}
		if(i > 0) {
			if(area[i - 1][j] == 1) {
				area = checkIsland( area, i - 1, j);
			}
		}

		return area;

	}
}

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

const int N = 220000;

int a[N], b[N];

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	
	int ans = 0;
	for (int j = 28; j >= 0; j--) {
		sort(a, a + n);
		sort(b, b + n);
		long long cnt = 0;
		for (int i = 0; i < n; i++) {
			int l = (1 << j) - a[i], r = (1 << j + 1) - a[i];
			if (l >= 0) cnt += lower_bound(b, b + n, r) - lower_bound(b, b + n, l);
			else cnt += n - (lower_bound(b, b + n, l + (1 << j + 1)) - lower_bound(b, b + n, r));
		}
		if (cnt & 1) ans ^= 1 << j;
		for (int i = 0; i < n; i++) if (a[i] >> j & 1) a[i] ^= 1 << j;
		for (int i = 0; i < n; i++) if (b[i] >> j & 1) b[i] ^= 1 << j;
	}
	cout << ans << "\n";
	
	return 0;
}


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

bool judge(int x,int y,int z){
  if((z%x==0) && (z%y==0)) return true;
  else return false;
}

int main(){
  int a,b;
  cin >> a >> b;
  if(a>b)swap(a,b);
  int64_t ans = b;
  for(int i=1;i<b;i++) {
    ans = (int64_t)b*i;
    if(ans % a == 0)break;
  }
    cout <<  ans;
  
}

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n;
    cin >> n;

    vi a(n);
    for (auto& x : a) {
        cin >> x;
    }

    vi dp(n, 0);
    for (int i = n - 2; i >= 0; --i) {
        if (a[i] >= a[i + 1]) {
            dp[i] = 1 + dp[i + 1];
        }
    }

    cout << *max_element(all(dp)) << '\n';
    
    return 0;
}


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

int main() {
    string SA, SB, SC;
    cin >> SA >> SB >> SC;
    
    int A_cnt = 0, B_cnt = 0, C_cnt = 0, turn = 0;
    while (true) {
        if (turn == 0) {
            if (A_cnt == SA.size()) {
                cout << "A\n";
                return 0;
            }
            turn = SA[A_cnt] - 'a';
            ++A_cnt;
        } else if (turn == 1) {
            if (B_cnt == SB.size()) {
                cout << "B\n";
                return 0;
            }
            turn = SB[B_cnt] - 'a';
            ++B_cnt;
        } else {
            if (C_cnt == SC.size()) {
                cout << "C\n";
                return 0;
            }
            turn = SC[C_cnt] - 'a';
            ++C_cnt;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    while(1){
        cin>>n>>m;
        if(n==0 && m==0){break;}
        int t[101],h[101];
        int sumt=0,sumh=0,co=0;
        for(int i=0;i<n;i++){
            cin>>t[i];
            sumt+=t[i];
        }
        for(int j=0;j<m;j++){
            cin>>h[j];
            sumh+=h[j];
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if((sumt-t[i]+h[j])==(sumh-h[j]+t[i])){
                    cout<<t[i]<<" "<<h[j]<<endl;
                    co=1;
                    break;
                }
            }
            if(co==1){
                break;
            }
        }
        if(co==0){
            cout<<-1<<endl;
        }
    }
    return 0;
}




Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = (ll)(1e9) + 7;
int n;

int getbit(ll s,int k){
    return  (s >> k) & 1;
}
int main(){

    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    vector<ll> bit(70);
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    for (int pos = 0; pos < 60; pos++){
        ll cnt1 = 0;
        for (int i = 0; i < n; i++)
            if (getbit(a[i],pos)) cnt1++;
        bit[pos] = ((ll)(n - cnt1)*cnt1) % Mod;
    }    

    ll ans = 0;
    ll pw2 = 1;
    for (int i = 0; i < 60; i++){
        ans = (ans + (bit[i]*pw2) % Mod) % Mod;
        pw2 = (pw2*2LL) % Mod; 
    }
    cout << ans;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int r, g, b;
    cin >> r >> g >> b;
    if ((g * 10 + b) % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main(){

  long long ans=1, num;
  int N,mx=0;
  cin >> N;
  int D[N], T[N];
  for(int i=0; i<N; i++) T[i]=0;
  for(int i=0; i<N; i++) {
    cin >> D[i];
    T[D[i]]++;
    mx = max(mx,D[i]);
  }
  if(D[0]!=0){
    cout << "0" << endl;
    return 0;
  }
  //cout << "s" << endl;
  for(int i=1; i<N; i++) {
    if(D[i]==0){
      cout << "0" << endl;
      return 0;
    }
  }
  //cout << "t" << endl;
  for(int i=1; i<=mx; i++) {
    if(T[i]==0){
      cout << "0" << endl;
      return 0;
    }
  }
  for(int i=1; i<=mx; i++){
    num = 1;
    for(int j=0; j<T[i]; j++) {
      num *= T[i-1];
      num %=998244353;
    }
    ans *= num;
    ans %= 998244353;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
k, x = list(map(int, input().split()))

show_data_list = []

for i in range(x, x + k):
    show_data_list.append(i)

for i in range(x - k + 1, x):
    show_data_list.append(i)

number = len(show_data_list) - 1
for i, data in enumerate(sorted(show_data_list)):
    print(data, end='')
    if number != i:
        print(' ', end='')

Measured memory_bytes: 38256
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

void next(string& s, int pos = 0) {
  if (pos == s.length()) {
    s.push_back('1');
    return;
  }
  if (s[pos] != '9' && (pos + 1 == s.length() || s[pos] <= s[pos + 1]))++s[pos];
  else {
    next(s, pos + 1);
    for (int i = pos; i >= 0; --i)
      s[i] = max(+'0', s[i + 1] - 1);
  }
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int K;
  cin >> K;
  string ans = "0";
  for (int i = 0; i < K; ++i)next(ans);
  reverse(begin(ans), end(ans));
  cout << ans << endl;
}

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

struct fruit {
	string name;  // 名前
	int price; // 価格
};

int main() {

	int i, j, k = 0;
	int n, m;
	string s, s2;
	int b, c;
	int flag = 0;
	while (std::cin >> n) {

		vector<fruit> fruits(n);
		vector<fruit> fruits2(n);
		for (i = 0; i < n; i++) {
			std::cin >> fruits.at(i).name >> fruits.at(i).price;
			fruits2.at(i).name = fruits.at(i).name;
			fruits2.at(i).price = fruits.at(i).price;
		}

		sort(fruits.begin(), fruits.end(),
			[](const fruit& x, const fruit& y) {if (x.name == y.name) { return x.price > y.price; }
			else return x.name < y.name; });

		for (i = 0; i < n; i++) {
			s = fruits.at(i).name;
			c = fruits.at(i).price;
			for (j = 0; j < n; j++) {
				s2 = fruits2.at(j).name;
				b = fruits2.at(j).price;
				if (s2 == s && b == c) { std::cout << j + 1 << std::endl; break; }
			}
		}
	std::cout << std::endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
const double EPS = 1e-8;

double dist(double x1, double y1, double x2, double y2){
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
bool f[30][30];
bool d[1 << 25];

int bitnum(int n){
    int res = 0;
    while(n > 0){
        if(n % 2 == 1) res++;
        n /= 2;
    }
    return res;
}

int main(){
    int n;
    while(cin >> n, n){
        rep(i, 0, 1 << n) d[i] = false;
        vector<double> x(n), y(n), r(n);
        vector<int> c(n);
        rep(i, 0, n){
            cin >> x[i] >> y[i] >> r[i] >> c[i];
        }
        rep(i, 0, n){
            rep(j, i + 1, n){
                f[i][j] = false;
                double tmp = dist(x[i], y[i], x[j], y[j]);
                if(tmp < r[i] + r[j] - EPS){
                    f[i][j] = true;
                }
            }
        }
        d[0] = true;
        for(int mask = 0; mask < (1 << n); mask++){
            if(!d[mask]) continue;
            rep(i, 0, n){
                if(mask & (1 << i)) continue;
                bool cani = true;
                rep(j, 0, n){
                    if(mask & (1 << j)) continue;
                    if(f[j][i]){
                        cani = false;
                        break;
                    }
                }
                if(!cani) continue;
                rep(j, i + 1, n){
                    if(mask & (1 << j)) continue;
                    if(c[i] != c[j]) continue;
                    bool canj = true;
                    rep(k, 0, n){
                        if(mask & (1 << k)) continue;
                        if(f[k][j]){
                            canj = false;
                            break;
                        }
                    }
                    if(canj){
                        d[mask | (1 << i) | (1 << j)] = true;
                    }
                }
            }
        }
        int ans = 0;
        rep(i, 0, 1 << n){
            if(!d[i]) continue;
            int tmp = bitnum(i);
            ans = max(ans, tmp);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 19612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,n;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&n);
	if(b-1<=n) printf("%lld",(a*(b-1))/b-a*((b-1)/b));
	else printf("%lld",(a*n)/b-a*(n/b));
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h, w, n;
    cin >> h >> w >> n;
    int m = max(h, w);
    int ans = n / m;
    if (n % m) ans++;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, t, a, h int
	fmt.Scan(&n, &t, &a)
	m := 0.0
	j := -1
	for i := 0; i < n; i++ {
		fmt.Scan(&h)
		x := float64(t) - float64(h)*0.006
		d := math.Abs(x - float64(a))
		if j == -1 || d < m {
			m = d
			j = i
		}
	}
	fmt.Println(j + 1)
}


Measured memory_bytes: 512
use std::io;
use std::io::BufRead;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let s: String = sc.next().unwrap();
    let mut res = std::usize::MAX;
    for i in 0..26 {
        let c: char = char::from('a' as u8 + i);
        let v = s.split(c).map(|s| s.len()).max().unwrap();
        if res > v {
            res = v;
        }
    }
    println!("{}", res);
}

/// Scanner
///
/// # Example
/// ```
/// use contest::io::scanner;
/// let mut sc = scanner::Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
/// assert_eq!("1".to_string(), sc.next::<String>().unwrap());
/// assert_eq!(2, sc.next().unwrap());
/// assert_eq!(3.5, sc.next().unwrap());
/// assert_eq!(None, sc.next::<i32>());
/// ```

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

impl<R: io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> Option<T>
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: "))
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	N := readInt()
	h := make([]int, N)

	var maxh int
	for i := range h {
		h[i] = readInt()
		maxh = max(maxh, h[i])
	}

	var ans int
	for i := 0; i < maxh; i++ {
		var doing bool
		for j := range h {
			if i < h[j] {
				if !doing {
					ans++
					doing = true
				}
			} else {
				doing = false
			}
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------


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

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

    int n;
    cin >> n;
    
    int mi = 1, bef = -1;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if((bef == a) or (bef > a)){
            mi++;
        }

        bef = a;
    }

    cout << mi << endl;
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 3220
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Work{
  int a;
  int b;
  bool operator<(const Work &another) const
  {
      return b< another.b;
  };
};

int main(){
  int n,i,t;
  cin>>n;
  vector<Work> w(n);
  for(i=0;i<n;i++){
    cin>>w[i].a>>w[i].b;
  }
  sort(w.begin(),w.end());
  t=w[n-1].b;
  for(i=0;i<n;i++){
    t=(t>w[n-1-i].b)? w[n-1-i].b: t;
    t-=w[n-1-i].a;
    if(t<0) break;
  }
  if(i==n) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

constexpr char newl = '\n';

P calc(const string& s) {
    P res(0, 0);
    for (char c : s) {
        if (c == '(') ++res.second;
        else --res.second;
        res.first = min(res.first, res.second);
    }
    return res;
}

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

    int n;
    cin >> n;

    vector<P> v(n);
    int all_sum = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        v[i] = calc(s);
        all_sum += v[i].second;
    }

    if (all_sum != 0) {
        cout << "No\n";
        return 0;
    }

    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i1, int i2){
        int d1 = max(-v[i1].first, -v[i1].second - v[i2].first);
        int d2 = max(-v[i2].first, -v[i2].second - v[i1].first);
        return d1 < d2;
    });

    int sum = 0;
    for (int i : ids) {
        sum += v[i].first;
        if (sum < 0) {
            cout << "No\n";
            return 0;
        }

        sum += v[i].second - v[i].first;
        if (sum < 0) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 14928
A = int(input())#500
B = int(input())#100
C = int(input())#50
X = int(input())#total

c=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500+j*100+k*50==X:
                c+=1
print(c)                
            


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

int main(){
	int n,w,x,y;
	int p[10001] = {};
	for(int i = 0;i < 10001;i++)p[i] = 0;
	cin >> n >> w;
	for(int i = 0;i < n;i++){
		cin >> x >> y;
		for(int j = y;j <= w;j++){
			p[j] = max(p[j],p[j-y]+x);
		}
	}
	cout << p[w] << endl;
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll long long int
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
 
 
 
// typedef __int128 bign;
 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			1000011
#define LN 			14
#define fftmod      998244353
#define EPS         (double)1e-10
 
ll md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){ll r=1LL;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
	return l+rng()%(r-l+1);
}
ll a[M],b[M];

int main(){
 
 
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p,T;string s1,s2;ll q;ll x,y;
    cin>>n;
    vector<pii> v;
    lp(1,n){
    	cin>>a[i]>>b[i];
    	v.pb({b[i],a[i]});
    }
    sort(all(v));
    t=v[v.size()-1].F;
    for(i=n-1;i>=0;--i){
    	t=min(t-v[i].S,v[i].F-v[i].S);
    }
    if(t>=0)cout<<"Yes\n";
    else cout<<"No\n";





 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 11632
import math

a, b, x = [int(i) for i in input().split()]
s = x / a
ans = 0
a2 = 0

if s == a * b:
    # 既に満タン
    ans = 0
else:
    if s > a * b / 2:
        # 台形
        bu = 2 * s / a - b  # 上底 bu
        s -= a * bu
        b -= bu
        # a2 = a とするとコーナーケースを考慮する必要がなくなる
        a2 = 2 * s / b
    else:
        # 三角形の時
        a2 = 2 * s / b
    # アークタンジェント計算（結果はラジアン）
    r = math.atan(b / a2)
    # ラジアン - 角度変換
    ans = r * (180.0 / math.pi)
print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;


int main() {
	int N, D, X, A;
	cin >> N >> D >> X;
	for (int i = 0; i < N; i++) {
		cin >> A;
		X += (D-1) / A + 1;
	}
	cout << X << endl;
}

Measured memory_bytes: 3592
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=1e5+5;

struct DSU{
	vi par,siz;
	ll cntt=0;
	DSU(int n){
		for(int i=0; i<n+1; i++){
			par.pb(i);
			siz.pb(1);
		}
		cntt = ll(n)*ll(n-1)/2;
	}
	ll cnt(){
		return cntt;
	}
	int rt(int u){
		if(par[u]!=u)par[u]=rt(par[u]);
		return par[u];
	}
	void merge(int u, int v){
		u=rt(u); v=rt(v);
		if(u==v)return;
		if(siz[v]<siz[u])swap(u,v);
		par[u]=v;
		cntt -= ll(siz[u] * siz[v]);
		siz[v] += siz[u];
		return;
	}
	bool sameset(int u, int v){
		if(rt(u)==rt(v))return 1;
		return 0;
	}
};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,m,u,v;
	cin >> n >> m;
	vll ans; DSU dsu(n);
	vector<ii>edge;
	for(int i=0; i<m; i++){
		cin >> u >> v;
		edge.pb({u,v});
	}
	ans.pb(dsu.cnt());
	for(int i=m-1; i>0; i--){
		u = edge[i].fi;
		v = edge[i].se;
		if(!dsu.sameset(u,v)){
			dsu.merge(u,v);
		}
		ans.pb(dsu.cnt());
	}
	reverse(all(ans));
	for(ll x:ans)cout << x << endl;
}	


Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	string s;
	cinl(s);
	int n='a'-'A';
	for(int i=0;i<s.size();i++){
		int x=s[i]-'a';
		if(x>=0&&x<=26){
			s[i]=s[i]-n;
		}
	}
	cout<<s<<endl;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 1; j < n; j++)

using ll = long long;
using namespace std;

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

    int n; cin >> n;
    int array[n]; REPI(i, n) cin >> array[i];

    sort(array, array + n);

    double ans = array[0];

    REPJ(j, n)
        ans = (ans + array[j]) / 2;
    cout << ans;
}


Measured memory_bytes: 256