akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321
#define MAXV 3000500


#define MOD 1234567

int N,M,T,K;
typedef struct Point{
    ll x,y,n;
} Point;

ll ccw(Point a, Point b, Point c){
    b.x -= a.x, b.y -= a.y;
    c.x -= a.x, c.y -= a.y;
    return b.x*c.y - c.x*b.y;
}

vector<Point> convex_hull(vector<Point> ps){
    if (ps.size() < 3)return ps;
    vector<Point> upper, lower;
    sort(ps.begin(), ps.end(),[](const Point &a, const Point &b) {
        if (a.x == b.x) return a.y < b.y; return a.x < b.x;
    });
    for(const auto &p : ps){ // ccw without `=` when include every point in convex hull
        while(upper.size() >= 2 && ccw(*++upper.rbegin(), *upper.rbegin(), p) >= 0)upper.pop_back();
        while(lower.size() >= 2 && ccw(*++lower.rbegin(), *lower.rbegin(), p) <= 0)lower.pop_back();
        upper.emplace_back(p);
        lower.emplace_back(p);
    }
    lower.insert(lower.end(), ++upper.rbegin(), --upper.rend());
    return lower;
}

ll die[100500];

double dist(Point p1, Point p2){
	double x = abs(p1.x-p2.x);
	double y = abs(p1.y-p2.y);
	return sqrt(x*x+y*y);
}

double ang(Point p1, Point p2, Point p3){
	double a = dist(p1,p2); 
	double b = dist(p2,p3);
	double c = dist(p1,p3);
	double ang = acos( (a*a+b*b-c*c) / (2.0*a*b) );
	return ang;
}

double ans[100500];
int main(){
	geti(N);
	repp(i,N) die[i] = true;
	vector<Point> v; 	
	repp(i,N){
		ll a,b; scanf("%lld%lld",&a,&b);
		v.push_back({a,b,i});
	}
	v = convex_hull(v);

	for(auto e : v) die[e.n] = false;

	for(int i=0;i<sz(v);i++){
		int n = v[i].n;

		int l = (i-1+sz(v))%sz(v);
		int r = (i+1%sz(v))%sz(v);

		double pi = acos(-1);

		ans[n] = (pi-ang(v[l],v[i],v[r]))/(2.0*pi);

	}

	repp(i,N){
		if( die[i] ) printf("0\n");
		else printf("%.10f\n",ans[i]);
	}

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust"<<endl;
	else cout<<"win"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N;
	int even = 0;
	int odd = 0;
	int ans = 0;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		int A;
		cin >> A;
		if (A % 2 == 0)
			even++;
		else
			odd++;

		if (odd == 2)
		{
			odd = 0;
			even++;
		}
	}

	if (odd == 1)
	{
		if (0 < even)
			ans = 0;
		else
			ans = 1;
	}
	else
	{
		if (0 < even)
			ans = 1;
		else
			ans = 0;
	}

	if (ans == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a_tentou = [0 for i in range(n)]
a_tentou2 = [0 for i in range(n)]
mod = 10 **9 + 7

for i in range(n):
    tentou_count = 0
    for j in range(i+1, n):
        if a[i] > a[j]:
            tentou_count += 1
    a_tentou[i] = tentou_count

for i in range(n):
    tentou2_count = 0
    for j in range(n):
        if a[i] > a[j]:
            tentou2_count += 1
    a_tentou2[i] = tentou2_count

answer = 0
for i in range(n):
    answer += a_tentou[i] * k
    answer += a_tentou2[i] * (k - 1) * k // 2
    answer = answer % mod
print(answer)

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

int main(){
    int n; cin >> n;
    double p[n]; loop(i, 1, n+1) cin >> p[i];

    double dp[n+1][n+1];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    loop(i, 1, n+1)rep(j, i+1){
        if(!j) dp[i][j] = dp[i-1][j]*(1 - p[i]);
        else dp[i][j] = dp[i-1][j]*(1 - p[i]) + dp[i-1][j-1]*p[i];
    }

    double ans = 0;
    loop(i, n/2+1, n+1) ans += dp[n][i];
    printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 70528
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int a, b, k;
    scanf("%d %d %d", &a, &b, &k);
     int imax = max(a, b);
     int cnt = 0;
     for(int i = imax; i >= 1; --i)
     {
         if(a % i == 0 && b % i == 0)
             cnt++;
         if(cnt == k)
         {
             printf("%d\n", i);
             break;
         }
     }
     return 0;
 }

Measured memory_bytes: 256
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int a,b;
	cin>>a>>b;
	if( (a == 1 && b == 2) || (a == 2 && b == 1 )){
		cout<<"3"<<endl;
	}else if( (a == 1 && b == 3) || (a == 3 && b == 1 ) ){
		cout<<"2"<<endl;
	}else{
		cout<<"1"<<endl;
	}
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
// 区間更新、区間最小クエリ
template <typename F,typename T>
struct DST{
  T identity;
  F merge;
  int size;
  vector<T> dat,delay;
  
  DST(F f,T id):merge(f),identity(id){}

  void eval(int k,int l,int r){
    if(delay[k] != -1){
      dat[k] = delay[k];
      if(k<size-1){
	delay[2*k+1] = delay[2*k+2] = delay[k];
      }
      delay[k]=-1;
    }
  }

  void init(int n){
    size = 1;
    while(size<=n) size *= 2;
    dat.resize(size*2-1,identity);
    delay.resize(size*2-1,-1);    
  }

  void build(vector<T> vec){
    rep(i,vec.size()) dat[size-1+i] = vec[i];
    dfs(0);
  }

  T dfs(int k){
    if(k>=size-1) return dat[k];
    else return dat[k] = merge(dfs(2*k+1),dfs(2*k+2));
  }

  void update(int a,int b,T x,int k,int l,int r){
    eval(k,l,r);

    if(r<=a||b<=l) return ;
    if(a<=l&&r<=b){
      delay[k] = x;
      eval(k,l,r);
    }
    else{
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      dat[k] = merge(dat[2*k+1],dat[2*k+2]);
    }
  }

  T query(int a,int b,int k,int l,int r){
    eval(k,l,r);
    if(r<=a||b<=l) return identity;

    if(a<=l&&r<=b) return dat[k];
    else return merge(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
  }

  void all_eval(){
    rep(i,2*size-1){
      eval(i,0,0);
    }
  }

  T get(int k){ return dat[size-1+k];}
  
  void show(){
    int index = 0;
    int num = 1;
    while(index<size){
      rep(i,num){
	if(dat[i+index]==identity) cout << "e ";
	else cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
    index = 0;
    num = 1;
    while(index<size){
      rep(i,num){
	cout << delay[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
  }
  

  
};
int main()
{
  int n,q;cin >> n >> q;
  vector<ll> c(q),s(q),t(q),x(q);
  rep(i,q){
    cin >> c[i];
    if(c[i]==0) cin >> s[i] >> t[i] >> x[i];
    else cin >> s[i] >> t[i];
  }

  auto f = [&](ll a,ll b){ return min(a,b);};
  ll id = (1LL<<31)-1;
  DST<decltype(f),ll> dst(f,id);
  dst.init(n);
  rep(i,q){
    if(c[i]==0) dst.update(s[i],t[i]+1,x[i],0,0,dst.size);
    else cout << dst.query(s[i],t[i]+1,0,0,dst.size) << "\n";
  }
  
  return 0;
}



Measured memory_bytes: 9972
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;

int a[5];

int main(void)
{

    int n;

    cin>>n;
    while(n--)
    {
        char s[11];
        scanf("%s",s);
        switch(s[0])
        {
        case 'A':
            a[0] ++;
            break;
        case 'C':
            a[1] ++;
            break;
        case 'R':
            a[2] ++;
            break;
        case 'M':
            a[3] ++;
            break;
        case 'H':
            a[4] ++;
            break;
        }


    }
    LL sum = 0;
    for(int i = 0; i < 5; ++ i)
        for(int j = 0; j < 5&&i != j ; ++ j)
            for(int k = 0; k < 5&&i != k &&j != k; ++ k)
            {
                if(a[i]&&a[j]&&a[k])
                {
                    sum += (LL)a[i]*(a[j])*(a[k]);
                }
            }
    cout<<sum<<endl;
    return 0;
}


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

l=sorted([int(input()) for _ in range(n)])

lst=[0]*(n-1)

temp=0
for i in range(n-1):
    temp=l[i+1]-l[i]
    lst[i]=temp

ll=[0]*(n)
temp=0
for ii in range(n-1):
    temp+=lst[ii]
    ll[ii+1]=temp

#print(lst)
#print(ll)
ans=10**9    
for j in range(n-k+1):
    ans=min(ans,ll[j+k-1]-ll[j])
print(ans)

Measured memory_bytes: 14860
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
 
signed main(){
    int n,a,b,c,d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;

    if(c < d){
        for(int i = b-1;i < d-1;i++){
            if((s[i] == '#') && (s[i+1] == '#')){
                cout << "No" << endl;
                return 0;
            }
        }
        for(int i = a-1;i < c-1;i++){
            if((s[i] == '#') && (s[i+1] == '#')){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }else{
        for(int i = b-1;i < d-1;i++){
            if((s[i] == '#') && (s[i+1] == '#')){
                cout << "No" << endl;
                return 0;
            }
        }
        int c = 0;
        for(int i = b-2;i < d-1;i++){
            if((s[i] == '.') && (s[i+1] == '.') && s[i+2] == '.'){
                c = 1;
            }
        }
        if(c == 0){
            cout << "No" << endl;
            return 0;
        }
        for(int i = a-1;i < c-1;i++){
            if((s[i] == '#') && (s[i+1] == '#')){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }

   
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://agc034.contest.atcoder.jp/tasks/agc034_b

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

using namespace std;

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vb vector<bool>
#define mii map<int,int>
#define swap(a,b) int c=a;a=b;b=c;
// min max heap
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >

#define gcd(x,y) __gcd(x,y)

#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x) // count zeros before first one
#define mod 1000000007
#define inf 1e18
#define fl(i,start,end) for(int i=start;i<=end;i++)
#define input(arr,start,end) for(int i=start;i<=end;i++) cin>>arr[i];
#define printArray(arr,start,last) for(int i=start;i<=last;i++) cout<<arr[i]<<" ";cout<<endl;
// set precesion
#define ps(x,y) fixed<<setprecision(y)<<x


pii ext_eucl(int a, int b) {
	if (b == 0)
		return make_pair(1, b);

	pii pr = ext_eucl(b, a % b);
	return make_pair(pr.ss, pr.ff - (a / b) * pr.ss);
}



int main() {

	int n;
	cin >> n;

	int a[n], b[n], c[n];
	int ans[n + 1][3];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	ans[0][0] = ans[0][1] = ans[0][2] = 0;

	for (int i = 1; i < n + 1; i++) {
		ans[i][0] = max(ans[i - 1][1], ans[i - 1][2]) + a[i - 1];
		ans[i][1] = max(ans[i - 1][0], ans[i - 1][2]) + b[i - 1];
		ans[i][2] = max(ans[i - 1][1], ans[i - 1][0]) + c[i - 1];
	}

	cout << max(ans[n][0], max(ans[n][1], ans[n][2])) << endl;
	return 0;
}

Measured memory_bytes: 5932
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    int n;
    ll a[200010];
    ll sum = 0;
    cin >> n;
    rep(i, n){
        cin >> a[i];
    }

    ll asum[200010];
    asum[0] = 0;
    rep(i, n){
        asum[i+1] = asum[i] + a[i];
    }

    ll res = inf;
    reps(i, 1, n-1){
        res = min(res, abs(asum[n]-asum[i] - asum[i]));
    }

    //adeb(asum, n);

    cout << res << endl;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int n, k; string s;
    cin >> n >> k >> s;
    s[k-1] += 'a'-'A';
    cout << s << endl;
}

Measured memory_bytes: 256
import sys

n = int(input())
ab = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
abd = [(a + b, a, b) for a, b in ab]
abd.sort(reverse=True)
# print(abd)
print(sum(x[1] for x in abd[::2]) - sum(x[2] for x in abd[1::2]))


Measured memory_bytes: 27976
#include <iostream>

using namespace std;

int main(void){
  int H, N, A, i;
  cin >> H >> N;
  for(i = 0; i < N; i++){
    cin >> A;
    H -= A;
    if(H <= 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i,a,c;
    int x,b,f,n,p;
    int room[5][4][11]={0};
    
    scanf("%d",&x);
    for(i=0;i<x;i++){
        scanf("%d %d %d %d",&b,&f,&n,&p);
        room[b-1][f-1][n-1]+=p;
    }
    
    for(i=0;i<4;i++){
        for(a=0;a<3;a++){
            for(c=0;c<10;c++){
                printf(" %d",room[i][a][c]);
            }
            printf("\n");
        }
        if(i<3)printf("####################\n");
    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int R;
    cin >> R;
    cout << R * R << endl;
    return 0;
};


Measured memory_bytes: 256
S = input().split(" ")
N = int(S[0])
M = int(S[1])

ARR = []

for i in range(M):
    ARR.append([int(s) for s in input().split(" ")])

def calculate(n, m, arr):
    dict1 = [0 for i in range(n)]
    if n > 1:
        dict1[0] = 1
    dict2 = [False for i in range(n)]
    res = True
    for ar in arr:
        if n > 1 and ar[0] == 1 and ar[1] == 0:
            res = False
            break

        if dict2[ar[0] - 1] == True:
            if dict1[ar[0] - 1] != ar[1]:
                res = False
                break

        dict1[ar[0]-1] = ar[1]
        dict2[ar[0] - 1] = True

    if res == False:
        print(-1)
    else:
        print("".join([str(s) for s in dict1]))


calculate(N, M, ARR)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <string>
 
class List
{
    int* data_;
    int begin_;
    int end_;
public:
    List()
    {
        data_  = new int[2000000];
        begin_ = 1999999;
        end_   = 1999999;
    }
    void Insert(int X)
    {
        --begin_;
        data_[begin_] = X;
    }
    void Delete(int X)
    {
        int Index = end_;
        for(int i = begin_; i < end_; ++i){
            if(X == data_[i]){
                Index = i;
                break;
            }
        }
        if(Index == end_) return;
        for(int i = Index; i < end_; ++i){
            data_[i] = data_[i+1];
        }
        end_--;
    }
    void DeleteFirst()
    {
        begin_++;
    }
    void DeleteLast()
    {
        end_--;
    }
    void Show()const
    {
        printf("%d", data_[begin_]);
        for(int i = begin_ + 1; i < end_; ++i){
            printf(" %d", data_[i]);
        }
        printf("\n");
    }
};
 
int main()
{
    List list;
    int n, X;
    std::scanf("%d\n", &n);
    char com[1024];
    for(int i = 0; i < n; ++i){
        std::fgets(com, 1024, stdin);
        if(com[6] == 'F'){
            list.DeleteFirst();
        }else
        if(com[6] == 'L'){
            list.DeleteLast();
        }else{
            int v = 0;
            
            int len = std::strlen(com) - 8;
            switch (len) {
                case 10: v += (com[len - 3] -  '0') * 1000000000;
                case 9:  v += (com[len - 2] -  '0') * 100000000;
                case 8:  v += (com[len - 1] -  '0') * 10000000;
                case 7:  v += (com[len    ] -  '0') * 1000000;
                case 6:  v += (com[len + 1] -  '0') * 100000;
                case 5:  v += (com[len + 2] -  '0') * 10000;
                case 4:  v += (com[len + 3] -  '0') * 1000;
                case 3:  v += (com[len + 4] -  '0') * 100;
                case 2:  v += (com[len + 5] -  '0') * 10;
                case 1:  v += (com[len + 6] -  '0');
            }
            // for(int j = 7; com[j] >= '0' && com[j] <= '9'; ++j){
            //     v = v*10 + (com[j] - '0');
            // }
            if(com[0] == 'i'){
                list.Insert(v);
            }else
            if(com[0] == 'd'){
                list.Delete(v);
            }
        }
    }
    list.Show();
    return 0;
}

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



int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(int(s[i])+n >90){
            cout << char('A'+ (int(s[i])+n-91));
        }else{
            cout << char(s[i]+n);
        }
    }


    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int count = 0;
    vector <int> a(10);
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
        {
            count++;
        }
        else
        {
            a.push_back(count);
            count=0;
        }
        if(i==s.size()-1)
        {
            a.push_back(count);
        }
    }
    sort(a.rbegin(),a.rend());
    cout<<a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int M=10000000;
		for(;;)
		{
			int n=in.nextInt(),m=in.nextInt();
			int s=in.nextInt(),g1=in.nextInt(),g2=in.nextInt();
			if((n|m|s|g1|g2)==0)
				return;
			int war[][]=new int[n+1][n+1];
			int ans=M;
			for(int i=0;i<=n;i++)
				Arrays.fill(war[i], M);
			for(int i=0;i<=n;i++)
				war[i][i]=0;
			for(int i=0;i<m;i++)
				war[in.nextInt()][in.nextInt()]=in.nextInt();
			
			//ワーシャルフロイド j->kと行くのにiを通った方が良いか
			for (int i=0;i<=n;i++)
				for(int j=0;j<=n;j++)
					for(int k=0;k<=n;k++)						
						war[j][k]=Math.min(war[j][k], war[j][i]+war[i][k]);
			for(int i=0;i<=n;i++)
				ans=Math.min(ans, war[s][i]+war[i][g1]+war[i][g2]);	
			System.out.println(ans);
		}
	}
}

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

using namespace std;

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

    vector<int> p(n), q(n);
    for (int i=0; i<n; i++) cin >> p[i];
    for (int i=0; i<n; i++) cin >> q[i];

    vector<int> s;
    for (int i=0; i<n; i++) s.emplace_back(i+1);

    int a = 0, b = 0, counter = 1;
    
    do {
        //for (int i=0; i<n; i++) cout << s[i] << " ";
        //cout << "\n";
        
        bool check1 = true, check2 = true;

        for (int i=0; i<n; i++) {
            if (p[i]!=s[i]) check1 = false;
            if (q[i]!=s[i]) check2 = false;
        }

        if (check1) a = counter;
        if (check2) b = counter;
        counter += 1;
        
    } while (next_permutation(s.begin(), s.end()));

    cout << abs(a-b) << "\n";

    return 0;
}

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

int main(){
    string s;
    cin>>s;
    if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x;
  x=a+b+c;
  if(x>=22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}

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

SUM = sum(A)

ans = 0
node = 1
for i,leaf in enumerate(A):
    if i == 0:
        non_leaf = 1 - leaf
        ans += 1
        if non_leaf <0:
            print(-1)
            exit()
    else:
        left,right = non_leaf,non_leaf*2
        if SUM < left or non_leaf <= 0:
            print(-1)
            exit()
        node = min(right,SUM)
        ans += node
        non_leaf = node - leaf
        SUM -= leaf
        if non_leaf < 0:
            print(-1)
            exit()

print(ans)

Measured memory_bytes: 19976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    string K;
    int D;
    cin >> K >> D;

    int N = K.length();
    static int dp[10001][100][2];
    dp[0][0][1] = 1;
    for (int i = 0; i < N; ++i) {
        int num = K[i] - '0';
        for (int j = 0; j < D; ++j) {
            for (int k = 0; k < 10; ++k) {
                int nxt = (j + k) % D;
                (dp[i + 1][nxt][0] += dp[i][j][0]) %= MOD;
                if (k < num)
                    (dp[i + 1][nxt][0] += dp[i][j][1]) %= MOD;
                else if (k == num)
                    (dp[i + 1][nxt][1] += dp[i][j][1]) %= MOD;
            }
        }
    }

    int ans = (dp[N][0][0] + dp[N][0][1] - 1) % MOD;
    cout << (ans < 0 ? ans + MOD : ans) << endl;

    return 0;
}


Measured memory_bytes: 11480
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convert(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i]-'0');
	}
	return d;
}
ll N;
ll A[10000000], sz[10000000];
int main()
{
	cin >> N;
	rep(i, N) {
		cin >> A[i];
		sz[A[i]]++;
	}
	ll sum = 0;
	rep(i, N+1) {
		sum += sz[i] * (sz[i] - 1) / 2;
	}
	
	rep(i, N) {
		cout << sum - sz[A[i]] + 1 << endl;
	}
	

}

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

using namespace std;

const int mod=1000000007;
int n,m,ans,f[4005][4005],a[300000],b[300000];

int main(){
	scanf("%d",&n); m=4000;
	f[0][0]=1;
	for (int i=0;i<=m;++i)
		for (int j=0;j<=m;++j){
			if (i>0) f[i][j]=(f[i][j]+f[i-1][j])%mod;
			if (j>0) f[i][j]=(f[i][j]+f[i][j-1])%mod;
		}
	for (int i=1;i<=n;++i){
		scanf("%d%d",a+i,b+i);
		ans=(ans-f[a[i]*2][b[i]*2]+mod)%mod;
	}
	memset(f,0,sizeof f);
	for (int i=1;i<=n;++i) ++f[2000-a[i]][2000-b[i]];
	for (int i=0;i<=m;++i)
		for (int j=0;j<=m;++j){
			if (i>0) f[i][j]=(f[i][j]+f[i-1][j])%mod;
			if (j>0) f[i][j]=(f[i][j]+f[i][j-1])%mod;
		}
	for (int i=1;i<=n;++i) ans=(ans+f[2000+a[i]][2000+b[i]])%mod;
	printf("%lld\n",(long long)ans*(mod+1)/2%mod);
	
	return 0;
}
			

Measured memory_bytes: 64768
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

int gcd(int a, int b){
	return (b == 0 ? a : gcd(b, a % b));
}

signed main(){
	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, n)cin >> a[i];

	int va = a[0];
	range(i, 1, n)
		va = gcd(va, a[i]);

	if(k % va == 0 && k <= *max_element(all(a)))
		cout << "POSSIBLE" << endl;
	else
		cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1024
N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort(reverse=True)


dp = {X: 1}

for i, n in enumerate(numbers):
    tmp_dp = {}
    for k, v in dp.items():
        if k < n:
            tmp_dp[k] = (tmp_dp.get(k,0)+v*(N-i))
        else:
            tmp_dp[k]=(tmp_dp.get(k,0)+v*(N-i-1)) 
            tmp_dp[k%n]=(tmp_dp.get(k%n,0)+v) 
    dp = tmp_dp.copy()
        
ans = 0
for k, v in dp.items():
    ans += k *  v

print(ans % MOD)
        
    

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; ++i){
        cin >> d[i];
    }
    sort(begin(d), end(d));
    cout << max(0, d[n/2] - d[n/2-1]) << "\n";
    return 0;
}

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

int main() {
	int l, r, d;
	cin >> l >> r >> d;

	int ans = 0;
	for(int i = l; i<= r; i++) {
        if(i % d == 0)
            ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3592
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        if (n <= 4) { Console.WriteLine(0); goto exit; }
        var p = GeneratePrime(n/2);
        var a = new int[p.Count()];
        for (int i = 2; i <= n; i++) getA(a, p, i);
        var ans = getAns(a);
        Console.WriteLine(ans);
        exit:;
    }
    static int getAns(int[] a)
    {
        var k = new int[] { 2, 4, 14, 24, 74 };
        var d = new Dictionary<int, int>();
        foreach (var x in k) d[x] = 0;
        foreach (var x in a)
            foreach (var y in k)
                if (x >= y) d[y]++;
        var a1 = d[74];
        var a2 = d[24] * (d[2] - 1);
        var a3 = d[14] * (d[4] - 1);
        var a4 = d[4] * (d[4] - 1) / 2 * (d[2] - 2);
        return a1 + a2 + a3 + a4;
    }
    static void getA(int[] a, List<int> p, int t)
    {
        var tp = t;
        var pc = p.Count();
        for (int i = 0; i < pc; i++)
        {
            if (p[i] > t) break;
            while (true)
                if (tp % p[i] == 0) { tp /= p[i]; a[i]++; }
                else break;
        }
    }
    public static List<int> GeneratePrime(int m)
    {
        var a = new List<int>();
        int p;
        var sqrtMax = Math.Sqrt(m);
        var s = Enumerable.Range(2, m - 1).ToList();
        do
        {
            p = s.First();
            a.Add(p);
            s.RemoveAll(n => n % p == 0);
        }
        while (p < sqrtMax);
        a.AddRange(s);
        return a;
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 40005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int deg[5];
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	int a,b;
	for(int i = 1 ; i <= 3 ; ++i) {
		read(a);read(b);
		++deg[a];++deg[b];
	}
	for(int i = 1 ; i <= 4 ; ++i) {
		if(deg[i] >= 3) {puts("NO");return 0;}
	}
	puts("YES");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int ordena(const void *a, const void *b) {
    int x=*((int*) a);
    int y=*((int*) b);

    if(x>y) {
        return -1;
    } else {
        return 1;
    }
}

int main () {

    int N[102];
    int X,b,n;

    scanf("%d", &n);

    for(int i=0; i<n; i++) {
        scanf("%d", &N[i]);
    }

    qsort(N,n,sizeof(int),ordena);

    /*for(int i=0; i<n; i++) {
        printf("%d", N[i]);
    }*/

    printf("%d\n", N[0]-N[n-1]);



    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(void){
	
	int H,W,i,j,k,l;
	while(1){
	scanf("%d %d",&H,&W);
		if((H==0)&&(W==0)){
			break;
		}
	for(i=1;i<=H;i++){
		if(i==1){
			for(j=1;j<=W;j++){
				printf("#");
			}
			printf("\n");
		}
		if((i>=2)&&(i<H)){
			printf("#");
			for(k=1;k<=W-2;k++){
				printf(".");
			}
			printf("#\n");
			
		}
		if(i==H){
			for(l=1;l<=W;l++){
				printf("#");
			}
			printf("\n");
		}
		
		
		
	}
		printf("\n");
	}
	return 0;
	
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 100000000
using namespace std;
int main()
{
 	ll n;cin>>n;
 	vector<ll> d(n);
 	rep(i,0,n) cin>>d[i];
 	sort(d.begin(),d.end());
 	ll mid=(n-1)/2,res=d[mid+1]-d[mid];
 	cout<<res;
 	
	
	
 return 0;
}

Measured memory_bytes: 1024
answer=[]
D=[]
def initRMQ(nn):
    global n
    n = 1
    while n < nn:
        n*=2
    for i in range(2*n-1):
        D.append(2147483647)

def update(k,a):
    k += n-1
    D[k] = a
    while k>0:
        k = (k-1)//2
        D[k] = min(D[k*2+1] , D[k*2+2])
        
def findMin(a,b):
    return query(a,b+1,0,0,n)

def query(a,b,k,l,r):
    if r <= a or b <= l:
        return 2147483647
    if a <= l and r <= b:
        return D[k]
    
    vl = query(a, b, (k*2)+1, l, (l+r)//2)
    vr = query(a, b, (k*2)+2, (l+r)//2, r)
    return min(vl,vr)


inn,q = map(int,input().split())
initRMQ(inn)
while True:
    try:
        o,x,y = map(int,input().split())
    except:
        break
    else:
        if o == 0:
            update(x,y)
        else:
            answer.append(findMin(x,y))
            
for i in range(len(answer)):
    print(answer[i]) 


Measured memory_bytes: 10488
N,M = map(int,input().split())
ans = [0]*N
pen = [0]*N
for _ in range(M):
  p,S = input().split()
  P = int(p)
  if ans[P-1] == 1:
    continue
  elif ans[P-1] == 0:
    if S == 'AC':
      ans[P-1] += 1
    elif S == 'WA':
      pen[P-1] += 1
      
A = 0
B = 0 
for i in range(N):
  if ans[i] == 1:
    A += 1
    B += pen[i]
print(A,B)

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

using namespace std;

int main()
{
    long int a,b,c,k,m1=0,m=0,ans=0;

    cin>>a>>b>>c>>k;

    m1=max(a,b);

    m=max(m1,c);

    ans=a+b+c-m+(m*pow(2,k));

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int dr[4][2] = {{0, 1}, {1, 0}, {1, 1}, {1, -1}};
int mat[4][4];
bool vi[4][4];

void yes() {
	cout << "Yes\n";
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> mat[i][j];

	int n;
	cin >> n;
	for(int i = 0, inp; i < n; i++) {
		cin >> inp;
		for(int a = 0; a < 3; a++)
			for(int b = 0; b < 3; b++)
				if(inp == mat[a][b]) vi[a][b] = 1;
	}

	for(int i = 0; i < 3; i++, LOG << '\n')
		for(int j = 0; j < 3; j++) LOG << vi[i][j];
	for(int i = 0; i < 3; i++) {
		if(vi[i][0] && vi[i][1] && vi[i][2]) yes();
		if(vi[0][i] && vi[1][i] && vi[2][i]) yes();
	}

	if(vi[0][0] && vi[1][1] && vi[2][2]) yes();
	if(vi[2][0] && vi[1][1] && vi[0][1]) yes();
	cout << "No\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  vector<bool> isPrime(55556, true);
  vector<int> ans;
  isPrime[1] = false;
  for (int i = 2; i <= 55555; i++) {
    if (isPrime[i]) {
      // i is prime
      if (i % 5 == 1) {
        ans.push_back(i);
      }

      int x = i * 2;
      while (x <= 55555) {
        isPrime[x] = false;
        x += i;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i];
    if (i < n - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
<?php
  list($k , $s) = explode(" ", fgets(STDIN));
  $cnt = 0;
  for($x = 0; $x <= $k; $x++){
    for($y = 0; $y <= $k; $y++){
      $z = $s - $x - $y;
      if(0 <= $z && $z <= $k){
        $cnt++;
      }
    }
  }
  echo $cnt;
?>

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

typedef pair<int,int> P;

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

int HP, HPm;
int H, W;
char G[100][100];
int D[256];
vector<P> v;
vector<int> p;

string solve() {
  int x = 0;
  int y = 0;
  vector<int> damage;
  for(int i = 0; i < v.size(); ++i) {
    for(int j = 0; j < v[i].second; ++j) {
      int nx = x + dx[v[i].first];
      int ny = y + dy[v[i].first];
      if(nx < 0 || nx >= W) break;
      if(ny < 0 || ny >= H) break;
      x = nx;
      y = ny;
      if(D[G[y][x]] > 0) damage.push_back(D[G[y][x]]);
    }
  }
  vector<P> add;
  for(int s = 0; s < (1<<p.size()); ++s) {
    int sum = 0;
    for(int i = 0; i < p.size(); ++i) {
      if(s & (1<<i)) sum += p[i];
    }
    add.push_back(make_pair(sum, s));
  }
  sort(add.begin(), add.end());
  int bit = (1<<p.size())-1;
  for(int i = 0; i < damage.size(); ++i) {
    if(HP <= damage[i]) {
      if(damage[i] >= HPm) return "NO";
      int need = damage[i] - HP + 1;
      int j = distance(add.begin(), lower_bound(add.begin(), add.end(), make_pair(need, 0)));
      while(j < add.size() && (add[j].second & bit) != add[j].second) ++j;
      if(j == add.size()) return "NO";
      bit = bit & ~add[j].second;
      HP = min(HP + add[j].first, HPm);
    }
    HP -= damage[i];
  }
  return "YES";
}

int main() {
  while(cin >> HP >> HPm && (HP || HPm)) {
    v.clear();
    p.clear();
    fill(D,D+256,0);
    cin >> H >> W;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	cin >> G[i][j];
      }
    }
    int T;
    cin >> T;
    for(int i = 0; i < T; ++i) {
      char c; int d;
      cin >> c >> d;
      D[c] = d;
    }
    int S;
    cin >> S;
    for(int i = 0; i < S; ++i) {
      char c; int n, d;
      cin >> c >> n;
      if(c == 'U') d = 3;
      if(c == 'D') d = 1;
      if(c == 'L') d = 2;
      if(c == 'R') d = 0;
      v.push_back(make_pair(d,n));
    }
    int P;
    cin >> P;
    for(int i = 0; i < P; ++i) {
      int h;
      cin >> h;
      p.push_back(h);
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  
  // 3 4
  // 2 3
  if (abs(a-b) % 2 == 0) {
    cout << abs(a-b)/2 << endl;
  } else {
    ll res = 1000000000000000000;
    res = min(res, abs(max(a, b) - 1)); //always win
    res = min(res, abs(min(a, b) - n)); //always lose
    
    // first to win, then merge if even
    ll leftPad = min(a, b)-1;
    ll wa = a-leftPad;
    ll wb = b-leftPad;
    if (abs(wa-wb) % 2 != 0) {
      // win again so range is even
      res = min(res, 1+leftPad+abs(wa-(wb-1))/2);
    } else {
      res = min(res, leftPad+abs(wa-wb)/2);
    }
    
    // first to lose, then merge if even
    ll rightPad = n-max(a, b);
    ll la = a-rightPad;
    ll lb = b-rightPad;
    if (abs(la-lb) % 2 != 0) {
      // lose again so range is even
      res = min(res, 1+rightPad+abs((la+1)-lb)/2);
    } else {
      res = min(res, rightPad+abs(la-lb)/2);
    }
    
    cout << res << endl;
  }
  return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int a, b; cin >> a >> b;
  cout<<(a<=b?a:a-1)<<endl;

    return 0;
}


Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
x_li = list(map(int, input().split()))
y_li = list(map(int, input().split()))

if max(x_li) < min(y_li):
    for i in range(max(x_li)+1, min(y_li)+1):
        if x < i and y >= i:  
            print("No War")
            break
    else:
        print("War")
else:
    print("War")

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] a = new int[N];
        for (int i=0; i<N; i++) {
            a[i] = scan.nextInt();
        }

        int sum = 0;
        for (int i=0; i<N; i++) {
            sum += a[i];
        }

        for (int i=0; i<N; i++) {
            a[i] = Math.abs(N * a[i] - sum);
        }

        int min = 999999;
        int ans = 0;
        for (int i=0; i<N; i++) {
            if (a[i] < min) {
                min = a[i];
                ans = i;
            }
        }

        System.out.println(ans);
    }
}


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

using P = pair<int, int>;

int main()
{
    int n, m; cin >> n >> m;
    vector<P> v(n);
    for (int i = 0; i < n; i++) cin >> v[i].second >> v[i].first;
    sort(v.begin(), v.end(), greater<P>());

    int ans = 0;
    set<int, greater<int>> st;
    for (int i = 0; i < m; i++) st.insert(i);
    for (int i = 0; i < n; i++) {
        auto it = st.lower_bound(m - v[i].second);
        if (it != st.end()) {
            ans += v[i].first;
            st.erase(it);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<string.h>
int main()
{
    char arr[30];
    int i,s;
    gets(arr);
    s=strlen(arr);
    for(i=s-1;i>=0;i--)
    {
        printf("%c",arr[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << #x << "]: " << (x) << endl;

constexpr ll MOD = 1e9+7;
ll bin_pow(ll a, ll b) {
    ll ans = 1;
    for ( ; b>0; b/=2) {
        if (b&1) ans = ans*a % MOD;
        a = a*a % MOD;
    }
    return ans;
}

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

    int n;
    cin >> n;
    if (n == 1) cout << "0\n";
    else {
        ll ans = bin_pow(10, n) - 2 * bin_pow(9, n) + bin_pow(8, n);
        ans = (ans % MOD + MOD) % MOD;
        cout << ans << "\n";
    }
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdlib>
#include <cmath>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include <bits/stdc++.h>
using namespace std;

int main()
{   
    int x, y;
    cin >> x >> y;

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


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;
int ans;

void dfs(int n, int m, int q, vector<vector <int>> &scores, vector<int> A){

    if(A.size() == n+1){
        int now = 0;
        for(int i=0; i<q; i++){
            if(A[scores[i][1]] - A[scores[i][0]] == scores[i][2]){
                now += scores[i][3];
            }
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= m){
        dfs(n, m, q, scores, A);
        A.back()++;
    }
}

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> scores;
    for(int i=0; i<q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        vector<int> line = {a, b, c, d};
        scores.push_back(line);
    }
    vector<int> A(1, 1);
    dfs(n, m, q, scores, A);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616