akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 605
#define mod 1000000007

int n;

int main()
{
    cin >> n;
    int x, xx;
    x = xx = 0;
    for (int i = 0; i < n; i++)
    {
        int now;
        scanf("%d", &now);
        x += now;
        xx += now * now;
    }
    cout << (x * x - xx) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
def washall_floyd(graph):
    num_v = len(graph)
    for k in range(num_v):
        for i in range(num_v):
            for j in range(num_v):
                if graph[i][j] > graph[i][k] + graph[k][j]:
                    graph[i][j] = graph[i][k] + graph[k][j]
    return graph


n, m, r = map(int, input().split())
r_list = list(map(int, input().split()))
graph = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

graph = washall_floyd(graph)
result = float("inf")
import itertools
permi = itertools.permutations(r_list)
for per in permi:
    r = 0
    start = per[0] - 1
    for p in per[1:]:
        end = p - 1
        r += graph[start][end]
        start = p - 1
    result = min(r, result)
print(result)


Measured memory_bytes: 5568
<?php
// Your code here!
fscanf(STDIN,"%s",$s);

if (
   ($s=="keyence")
   or
   (preg_match("/^keyence.*/",$s))
   or
   (preg_match("/.*keyence$/",$s))
   or
   (preg_match("/^k.*eyence$/",$s))
   or
   (preg_match("/^ke.*yence$/",$s))
   or
   (preg_match("/^key.*ence$/",$s))
   or
   (preg_match("/^keye.*nce$/",$s))
   or
   (preg_match("/^keyen.*ce$/",$s))
   or
   (preg_match("/^keyenc.*e$/",$s))
   )
  echo "YES";
  else 
  echo "NO";


Measured memory_bytes: 3828
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda x: abs(X - int(x)), x))

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
        
if len(x) < 2:
    print(x[0])
else:
    D = gcd(x[0], x[1])
    for i in range(2, N):
        D = gcd(D, x[i])

    print(D)


Measured memory_bytes: 14252
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,i,a[1000],q,k,b,e,cnt,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++)	{
		scanf("%d %d %d",&b,&e,&k);
		cnt=0;
		for(j=b;j<e;j++)	{
			if(a[j]==k)cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  vi A(N+1);
  int ans=1;
  REP(i,2,N){
    int K=i;
    int j=3;
    while(1){
      if(K%2==0){
        A[2]++;
        K/=2;
      }
      else
        break;
    }
    while(j<=K){
      if(K%j==0){
        A[j]++;
        K/=j;
        }
      else
        j+=2;
      }
    }
  REP(i,2,N){
    ans*=A[i]+1;
    ans%=MOD;
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
N = int(input())
t = [0]
x = [0]
y = [0]
for i in range(N):
    a = input().split()
    t.append(int(a[0]))
    x.append(int(a[1]))
    y.append(int(a[2]))

bool = True
for i in range(N):
    d_t = abs(t[i+1]-t[i])
    d_xy = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
    if d_t < d_xy:
        bool = False
    elif d_t % 2 != d_xy % 2:
        bool = False

if bool == True:
    print("Yes")
else:
    print("No")

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

int main() {
    ll n,sum=0;
    cin>>n;
    vector<ll> a(3*n);
    for(int i=0; i<3*n; i++) cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=n; i<3*n; i++) {
        sum += a[i];
        i++;
    }
    cout<<sum<<"\n";
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aizu
{
	class Program
	{
		static void Main(string[] args)
		{
			var datas = new List<List<int>>();

			while(true)
			{
				datas.Add(Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToList());
				if(datas[datas.Count - 1][0] == 0 && datas[datas.Count - 1][1] == 0)
				{
					break;
				}
			}

			datas.RemoveAt(datas.Count - 1);


			foreach(var data in datas)
			{
				var count = 0;
				for (var i = 1; i <= data[0] - 2; i++)
				{
					for(var j = i + 1; j <= data[0] - 1; j++)
					{
						for(var k = j + 1; k <= data[0]; k++)
						{
							if(i + j + k == data[1])
							{
								count++;
							}
						}
					}
				}

				Console.WriteLine(count);
			}
		}
	}
}



Measured memory_bytes: 18460
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int tmp, count = 0;
    for(int i=0;i<N;i++){
        cin >> tmp;
        if(tmp != i + 1) count++;
    }
    if(count <= 2) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
	int n;
  cin>>n;
  int d[2*n],count=0;
  for(int i=0;i<(2*n);i++)
    cin>>d[i];
  for(int i=0;i<(2*n);i+=2)
  {
    if(d[i]==d[i+1])
      count++;
    else if(d[i]!=d[i+1])
      count=0;
    if(count==3)
      break;
  }
  if(count==3)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}



Measured memory_bytes: 3632
//This sourcecode is under GPLv3
//http://yeguanghao.xyz
#include <bits/stdc++.h>
#define rep(name,start,end,step) for(int name=start;name<=end;name+=step)
using namespace std;
#define Pn(x) printf("%d\n",x)
#define Ps(x) printf("%d ",x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PROB
inline void R(int &x) {
	x=0; int f=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
void Redirect() {
	freopen(PROB".in","r",stdin);
#ifndef YGHDEBUG
	freopen(PROB".out","w",stdout);
#endif
}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n,m,k;
int main() {
	R(n); R(m); R(k);
	puts((n*100+10*m+k)%4==0 ? "YES":"NO");
}



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

int main(void) {
    int N,K; cin >> N >> K;
    vector<ll> H;
    ll ans = 0;
    for(int i=0; i<N; i++) {
        ll x; cin >> x;
        H.push_back(x);
    }
    sort(H.begin(),H.end(),greater<>());
    for(int i=K; i<N; i++) ans += H[i];
    cout << ans << endl;
}

Measured memory_bytes: 5296
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked

int inp() {
	int x = 0, f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

ll inp_ll() {
	ll x = 0; int f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

template<class T>
bool read(T &x)
{
	x = 0;
	char ch = getchar();
	if (ch == EOF) return 0;
	for(; !isdigit(ch); )
	{
		ch = getchar();
		if (ch == EOF) return 0;
	}
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return 1;
}

template<class T>
void write(T x)
{
	static char s[22];
	static char *it = s+20;
	static char *end = s+20;
	if (!x)
		*-- it = '0';
	while (x)
	{
		*-- it = x%10+'0';
		x /= 10;
	}
	for (; it < end; ++ it)
		putchar(*it);
}

template<class T>
void writeln(T x)
{
	write(x);
	putchar('\n');
}

const int MOD = 1000000007;
const int INF = 100000000;
const int MAXN = 1010;
const int MAXV = 500510;
const int K = 3;
const f80 eps = 1e-10;
const f64 alpha = 0.75;

int main()
{
	
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
	
	return 0;
}


Measured memory_bytes: 256
H, W, A, B = map(int, input().split())

hbar = H - B
wbar = W - A

s = '0' * A + '1' * wbar
sbar = '1' * A + '0' * wbar
for i in range(B):
  print(s)
for i in range(hbar):
  print(sbar)

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

int main() {
  string S,T,A;
  cin >> S >> T;
  if (T == S + T.substr(T.size() - 1)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
#define met(a,x) memset(a,x,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
const int mod =1e9+7;
const int N=1e5+10;
int r, c, n;
stack<int>s;
struct node
{
    int u, v, f;
} aa[N*2];
bool cmp(node a, node b)
{
    return a.u<b.u;
}
int check(int x, int y)
{
    if(x==0)
        return y;
    else if(y==c)
        return  c+x;
    else if(x==r)
        return r+c+c-y;
    else if(y==0)
        return r+r+c+c-x;
    else
        return -1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i,j,k,x,y,num=0;
    cin>>r>>c>>n;
    for(i=0; i<n; i++)
    {
        int a, b, cc, d;
        cin>>a>>b>>cc>>d;
        x=check(a, b);
        y=check(cc, d);
        if(x==-1 || y==-1)
            continue;
        if(x>y)
            swap(x, y);
        aa[num].f=1;
        aa[num].u=x;
        aa[num++].v=y;
        aa[num].f=2;
        aa[num].u=y;
        aa[num++].v=x;
    }
    sort(aa, aa+num, cmp);

    for(int i=0; i<num; i++)
    {
        if(aa[i].f==1)
            s.push(aa[i].v);
        else if(s.top()==aa[i].u)
            s.pop();
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 2816
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
//#include<assert.h>
#include<algorithm>
//#include<iostream>
using namespace std;

int n,a,b;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if ((int)fabs(a-b)&1) puts("Borys");
	else puts("Alice");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	cout<<(x2-(y2-y1))<<" "<<(y2+(x2-x1))<<" "<<(x1-(y2-y1))<<" "<<(y1+(x2-x1)); 
} 



Measured memory_bytes: 384
(n,m,p),*l=[list(map(int,s.split()))for s in open(0)];I=float('inf');d=[0]*2+[I]*n
for i in range(n*2):
 for a,b,c in l:
  if d[b]>d[a]-c+p:d[b]=[min(d[b],d[a]-c+p),-I][i>n]
 if i==n:x=d[n]
print([max(-d[n],0),-1][d[n]!=x])

Measured memory_bytes: 47692
#include<stdio.h>

int main(){
    int a, b;
    scanf("%d %d", &a, &b);

   while(1){
        if(a == 0 && b == 0) break;
        if(a < b){
            printf("%d %d\n",a ,b);
        }
        else{
            printf("%d %d\n",b ,a);
        }
        scanf("%d %d", &a, &b);
    }
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"


template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef cc_hash_table<int, int, hash<int > > ht;


#define int long long 
#define  st first
#define  nd second

const int M = 1000000007;
const int  maxn = 100001;
const int  inf =  1e16;


void solve(){
  int n ; 
  cin >> n ;
  cout << !n;
  

}
int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int te ; 
 // cin >> te ;
  te = 1; 
  while(te--){
    solve();
  }
  
  }

  
  

Measured memory_bytes: 3588
a,b = input().split()
a = int(a)
x = 0
for i in range(4):
    if i == 1: continue
    c = int(b[i])
    if i == 0: x += 100 * c
    elif i == 2: x += 10 * c
    else: x += c
ans = a * x
ans //= 100
print(ans)

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

const long long mod=998244353;
int K,n;
char s[305];
int a[305];
long long dp[305][305],s1[305][305],s2[305][305];
int main()
{
	int i,j,k,l;
	scanf("%s",s+1);
	scanf("%d",&K);
	K=min(K,300);
	for(i=1,n=1;s[i];i++)
	{
		if(s[i]=='1')
			a[n]++;
		else n++;
	}
	for(i=0;i<=300;i++)
		dp[i][i]=1;
	for(i=2;i<=n;i++)
	{
		for(j=0;j<=300;j++)
		{
			s1[j][0]=dp[j][0];
			for(l=1;l<=j;l++)
				s1[j][l]=(s1[j-1][l-1]+dp[j][l])%mod;
		}
		for(j=0;j<=300;j++)
		{
			s2[j][0]=dp[j][0];
			for(l=1;l<=300;l++)
				s2[j][l]=(s2[j][l-1]+dp[j][l])%mod;
		}
		for(j=0;j<=300;j++)
			for(l=0;l<=j;l++)
				dp[j][l]=s1[j][l];
		for(j=0;j<=300;j++)
			for(l=0;l<=min(300-a[i],j);l++)
				dp[j][l]=(dp[j][l]+s2[j][l+a[i]]-s2[j][l]+mod)%mod;
	}
	long long ans=0;
	for(i=0;i<=K;i++)
		ans=(ans+dp[i][0])%mod;
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    for (int i = k; i < n; ++i)
    {
        if (a[i] > a[i - k])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 4784
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;


int main(void) {

	int sx, sy, tx, ty;

	cin >> sx >> sy >> tx >> ty;

	for (int l = 0; l < 2; l++) {

		if (l == 1)
			cout << "L";

		for (int i = 0; i < abs(sy - ty) + l; i++) {
			cout << "U";
		}

		for (int i = 0; i < abs(sx - tx) + l; i++) {
			cout << "R";
		}
		if (l == 1) {
			cout << "D";
			cout << "R";
		}

		for (int i = 0; i < abs(sy - ty) + l; i++) {
			cout << "D";
		}

		for (int i = 0; i < abs(sx - tx) + l; i++) {
			cout << "L";
		}

		if (l == 1)
			cout << "U";

	}

	cout << endl;


	return 0;
}


Measured memory_bytes: 256
n, m, x, y = gets.split.map(&:to_i)
xx = gets.split.map(&:to_i)
yy = gets.split.map(&:to_i)
xx << x
yy << y
xx = xx.sort
yy = yy.sort
puts xx[-1] < yy[0] ? "No War" : "War"

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const ll N = 1005;

int n;
int d[N][N];


main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int I = 0; (1 << I) < n; I++){
        int ind = I + 1;
        vector < int > v1, v2;
        int B = (1 << I);
        for (int i = 0; i < n; i++)
            if ((i & B) > 0)
                v1.pb (i);
            else
                v2.pb (i);
        for (int i : v1)
        for (int j : v2){
            d[i][j] = ind;
            d[j][i] = ind;
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++)
            cout << d[i][j] << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2432
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - AC or WA
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  if (n == m) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "sstream"
#include "string"
#include "cstring"
#include "cstdio"
#include "cstdlib"
#include "cmath"
#include "algorithm"
#include "utility"
#include "vector"
#include "map"
#include "unordered_map"
#include "set"
#include "bitset"
#include "unordered_set"
#include "list"
#include "deque"
#include "functional"
#include "ctime"
#include "cctype"
#include "tuple"
#include "memory"
#include "limits"
#include "climits"
#include "stack"
#include "forward_list"
#include "iterator"
#include "array"
#include "random"
#include "queue"


using namespace std;

// Functions
vector<string> StrSplit(string work, char delim, int rep);

template <typename T, typename Display> 
void print_vector(const vector<T>& vec, Display disp);

vector<string> StrSplit(string work, char delim, int rep = 0) {
    // rep == 1: Also insert empty strings
    vector<string> flds;
    if (!flds.empty()) flds.clear();  // empty vector if necessary
    string buf = "";
    int i = 0;
    while (i < work.size()) {
        if (work[i] != delim)
            buf += work[i];
        else if (rep == 1) {
            flds.push_back(buf);
            buf = "";
        } else if (!buf.empty()) {
            flds.push_back(buf);
            buf = "";
        }
        i++;
    }
    if (!buf.empty())
        flds.push_back(buf);
    cout << flds.size() << endl;
    return flds;
}

template <typename T, typename Display> 
void print_vector(const vector<T>& vec, Display disp) {
    for (const auto& val:vec) {
        disp(val);
    }
}

class Point {
public:
    typedef int pos_type;
    pos_type x,y;
    explicit Point(pos_type x_in, pos_type y_in):x(x_in), y(y_in) {}
    explicit Point():x(), y() {}
    bool operator < (const Point& other) const {
        if (x != other.x) return x < other.x;
        return y < other.y;
    }
    bool operator == (const Point& other) const {
        return x == other.x && y == other.y;
    }
    void print() {
        // for debug
        cout << "(" << x << "," << y << ")";
    }
};

#define MP make_pair
#define debug false
#define UNM unordered_map
#define UNS unordered_set
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FOR_REV(i, a, b) for(int i = a; i >= b; --i)

typedef vector<int> VI;
typedef vector<VI> Mat;
typedef pair<int,int> PI;

class Solution {
public:
    void solve() {
        int k, c;
        while (cin >> k >> c) {
            vector<int> arr;
            FOR(i, 0, c) {
                int tmp;
                scanf("%d", &tmp);
                arr.push_back(tmp);
            }
            sort(arr.begin(), arr.end());
            int sum = 0;
            for (const auto& val: arr) sum += val;
            int max_val = arr[c - 1];
            int other_sum = sum - max_val;
            if (max_val <= other_sum + 1) {
                cout << 0 << endl;
                continue;
            }
            int diff = max_val - other_sum - 1;
            cout << diff << endl;
        }
    }
};


int main() {
    Solution sol;
    sol.solve();
    return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())
check = 1
for i in range(n+1):
  for j in range(n-i+1):
    if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
      print(i, j, n-i-j)
      check = 0
      break
  else:
    continue
  break
if check:
  print(-1, -1, -1)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int n;
int s[110];

int main() {
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sum += s[i];
	}
	sort(s, s + n);
	if (sum % 10 == 0) {
		for (int i = 0; i < n; i++) {
			if (s[i] % 10 != 0) {
				sum -= s[i];
				break;
			}
			else if (i == n - 1) {
				sum = 0;
			}
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define wh while
#define db double
#define pb .push_back
#define sz .size()
#define vc vector
#define vcd vector <double>
#define vcf vector <float>
#define vci vector <int>
#define vcs vector <string>
#define sti set <int>
#define fi .first
#define se .second
#define yes true
#define no false
#define bg .begin()
#define ed .end()
#define ad a,b,c,d
#define till n i<n.size();
set <int> A;
vector <int> B;
vector <int> C;
vector <int> D;
sti G;
bool t;
bool f;
int cnt=0;
int main(){
    float a,b;
    cin>>a>>b;
    if(ceil(a/2)>=b){
        cout<<"YES";
    }
    else
        cout<<"NO";






}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String args[] ) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] origin = br.readLine().split("");
		String[] serch = br.readLine().split("");


		for(int i = 0; i < origin.length; i++){

			if(origin[i].equals(serch[0])){
				int ans = i;
                int wordlength = 0;
                 for(int j = 0 ; j < serch.length;j++  ){

                	 if(i+j < origin.length){
                	   if(serch[j].equals(origin[i+j]) ){
                		 wordlength++;
                	  }
                	 }
                 }

                 if( wordlength == serch.length ){
                     System.out.println(ans);
                 }
			}


		}





	}

}

Measured memory_bytes: 25348
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long A,B,K;
    std::cin >> A >> B >> K;
    
    for (int i = 1; i <= K; i++) {
        /* code */
        B = (A / 2) + B;
        A = A / 2;
        if(i == K){
            break;
        }
        i++;
        A = (B / 2) + A;
        B = B / 2;
    }
    std::cout << A <<" "<< B << std::endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,ans=0;
int32_t main(){
CODE_START;
cin>>n;
ans=n*(n+1)/2;
for(ll i=2;i<=n;i++)
{
    for(ll j=i;j<=n;j+=i){
        ans=ans+j;
    }
}
cout<<ans<<endl;
}


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

using ll = long long;

int main() {
  string s;
  ll k;
  cin >> s >> k;
  
  bool ok = true;
  char keep;
  for(int i = 0; i < min((ll) s.size(), k); i++){
    if(s.at(i) != '1'){
      ok = false;
      cout << s.at(i) << endl;
      break;
    }
  }
  
  if(ok) cout << '1' << endl;
}

Measured memory_bytes: 256
#B - Coins
A = int(input()); B = int(input()); C = int(input()); X = int(input())
cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500 * i + 100 * j + 50 * k == X:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi

x=1
n.times do |i|
  x=x.lcm a[i]
end

ans=0
n.times do |i|
  ans+=(x/a[i])%MOD
end

puts ans%MOD

Measured memory_bytes: 51564
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Roaming
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

int fs[MAX_N + 1], invfs[MAX_N + 1];

/* subroutines */

int powmod(int a, int n) {  // a^n % MOD
  int pm = 1;
  while (n > 0) {
    if (n & 1) pm = (ll)pm * a % MOD;
    a = (ll)a * a % MOD;
    n >>= 1;
  }
  return pm;
}

inline int nck(int n, int k) {  // nCk % MOD
  return (ll)fs[n] * invfs[n - k] % MOD * invfs[k] % MOD;
}

inline int nhk(int n, int k) {  // nHk % MOD
  return nck(n + k - 1, k);
}

void prepare_fracs(int n) {
  fs[0] = invfs[0] = 1;
  for (int i = 1; i <= n; i++) {
    fs[i] = (ll)fs[i - 1] * i % MOD;
    invfs[i] = powmod(fs[i], MOD - 2);
  }
}

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  prepare_fracs(n);

  int maxm = min(n - 1, k);
  int sum = 0;
  for (int m = 0; m <= maxm; m++)
    sum = (sum + (ll)nck(n, m) * nhk(n - m, m) % MOD) % MOD;

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main() {

  int K, S;
  cin>>K>>S;

  long long ans = 0;
  for(int i = 0; i<=K; i++){
    for(int j = 0; j<=K; j++){
      if(i + j + K >= S && i + j <= S) ans++;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define PI 3.141592653589

int main(void)
{
  int x,y,z;
  char c;
  int flg=0;

  while(1)
    {
      scanf("%d %s %d",&x,&c,&y);

      switch(c)
	{
	case '+':
	  z=x+y;
	  break;
	  
	case '-':
	  z=x-y;
	  break;

	case '*':
	  z=x*y;
	  break;

	case '/':
	  z=x/y;
	  break;

	case '?':
	  flg=1;
	  break;
	}

      if(flg==1)
	{
	  break;
	}

      printf("%d\n",z);

    }

  return 0;

}

Measured memory_bytes: 1028
# coding: utf-8

N, M = list(map(int, input().split(' ')))
A = [int(input()) for i in range(N)]

for k in range(1, M+1):
    i = 1
    while i != N:
        if A[i-1]%k > A[i]%k:
            A[i-1], A[i] = A[i], A[i-1]
        i += 1

for a in A: print(a)


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

const int MOD = 1e9 + 7;
const int MAXN = 112345;

int qas[MAXN];
int qbs[MAXN];

int qat[MAXN];
int qbt[MAXN];

int main(){
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	string s, t;
	cin >> s >> t;
	
	for(int i = 0 ; i < (int)s.size() ; i ++){
		
		if(i){
			qas[i] = qas[i - 1];
			qbs[i] = qbs[i - 1];
		}
		
		if(s[i] == 'A') qas[i]++;
		else qbs[i]++;
	}
	
	for(int i = 0 ; i < (int)t.size() ; i ++){
		
		if(i){
			qat[i] = qat[i - 1];
			qbt[i] = qbt[i - 1];
		}
		
		if(t[i] == 'A') qat[i]++;
		else qbt[i]++;
	}
	
	int q;
	cin >> q;
	while(q--){
		
		int ls, rs;
		int lt, rt;
		
		cin >> ls >> rs >> lt >> rt;
		--ls; --rs; --lt; --rt;
		
		int xs = qas[rs] - (ls ? qas[ls - 1] : 0);
		int ys = qbs[rs] - (ls ? qbs[ls - 1] : 0);
		
		int xt = qat[rt] - (lt ? qat[lt - 1] : 0);
		int yt = qbt[rt] - (lt ? qbt[lt - 1] : 0);
		
		int d0 = xs - ys;
		int d1 = -MOD, d2 = -MOD;
		if(ys > 0) d1 = d0 + 3;
		if(xs > 0) d2 = d0 - 3;
		
		int dt = xt - yt;
		
		int delta = d0 - dt;
		if((d0 - dt) % 3 == 0){
			cout << "YES\n";
			continue;
		}
		
		if((d1 != -MOD) && ((d1 - dt) % 3 == 0)){
			cout << "YES\n";
			continue;
		}
		
		if((d2 != -MOD) && ((d2 - dt) % 3 == 0)){
			cout << "YES\n";
			continue;
		}
		
		cout << "NO\n";
	}
	
	return 0;
}

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

//typedef
//------------------------------------------
typedef int64_t LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define EACH(i,c) for(decltype((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) whole(sort, c)
#define RSORT(c) rwhole(sort, c)

//constant
//--------------------------------------------
constexpr double EPS = 1e-10;
constexpr double PI  = M_PI;
constexpr int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

template<class T,class U> void chmax(T&a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T&a,U b){if(b<a)a=b;}
LL gcd(LL a, LL b) { return b?gcd(b,a%b):a;}
LL lcm(LL a, LL b) { return a/gcd(a,b)*b;}

//main code

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == s[i-1]) {
			cout << i << " " << i+1 << endl;
			return 0;
		}
	}
	for (int i = 2; i < s.size(); i++) {
		if (s[i] == s[i-2]) {
			cout << i-1 << " " << i+1 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 300005
using namespace std;
void mod1(string s, int a) 
{
    int res = 0; 
    for (int i = 0; i < (int)(1e6); i++){
         res = (res*10 + 7) %a; 
         if(res == 0){
            cout << i + 1 << '\n' ;
            return ;
        }
     }
    cout << -1; 
} 

int main()
{
    FLASH
    int k;
    cin >> k ;
    string s = "7";
    mod1(s,k);
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  string c1;
  string c2;
  cin >> c1 >> c2;
  bool result = true;
  for (int j = 0; j < 2 ; j++) {
    if (!result) break;
    if(c1[j] != c2[2 - j]) result = false;
    if(c2[j] != c1[2 - j]) result = false;
  }

  if (result) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  if(s=="AAA" || s=="BBB" ){
    pri("No");
  }
  else{
    pri("Yes");
  }

}

Measured memory_bytes: 256
// !Start && !End 
//  0 se divide
//https: //www.youtube.com/watch?v=6Nb-prB-4P0&list=RD6Nb-prB-4P0&start_radio=1

// https: //www.youtube.com/watch?v=eYDI8b5Nn5s
// Electrify my OOOoooooOOOoooOOOOOoooooOOOooo!
#pragma optimise GCC(-O2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll,ll>
#define ve(x) vector<x>
#define f(a,b,c) for(ll a=b;a<c;a++)
#define foto(x,v) for(auto x:v)
#define read(t) ll t; cin>>t;
#define reads(t) string t; cin>>t;
#define readarr(arr,n) ll arr[n]; f(i,0,n) cin>>arr[i];
#define forstl(i,v) for(auto &i: v)
#define ln endl
#define Endl endl
#define dbg(x) cout<<#x<<" = "<<x<<ln;
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<ln;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it<<ln;} cout<<ln;
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cout<<ln;
#define dbgarr(v,s,e) cout<<#v<<" = "; f(i,s,e) cout<<v[i]<<", "; cout<<ln;
#define addEdge(tr,k) f(i,0,k) { ll x,y; cin>>x>>y, tr[x].push_back(y), tr[y].push_back(x);}
#define all(v) v.begin(),v.end()

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); }

//														GLOBAL VARS
ll INF =LLONG_MAX;
const ll M= 1000000007;

//														USEFUL FUNCTIONS
ll powm(ll ,ll);


ll foo(ll a ,ll b)
{
    ll z = a*a*a*a + a*a*a*b + a*a*b*b +a*b*b*b +b*b*b*b;
    return z;
}





// 														MAIN
int main()
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    //It gets easier day by day, but the hard part is to........
    read(n)
    readarr(a,n)
    map<ll,ll> mp;
    ll ans = 0;
    f(i,0,n)
    {
        ll req = i- a[i];
        ans += mp[req];
        mp[(i+a[i])]++;
    }
    cout<<ans;
}










//													FUNCTIONS DECLARATIONS
ll powm(ll a, ll b) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%M;
		a=(a*a)%M;
		b>>=1;
	}
	return res;
}


Measured memory_bytes: 27720
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

const double PI = acos(-1.0);
int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double alpha = (H * 60 + M) / 720 * (PI * 2);
    double beta = M / 60 * (PI * 2);
    double theta = alpha - beta;
    double res = sqrt(A*A + B*B - 2.0*A*B*cos(theta));
    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 4268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int c = 0;
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();

		for(int i = 0; i < s.length; i++) {
			c += s[i] != t[i] ? 1 : 0;
		}

		System.out.println(c);
	}
}

Measured memory_bytes: 42180
#include "bits/stdc++.h"
#define int long long

using namespace std;

const int MOD = 1000000007;

signed main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<pair<int, int>> d;
    for(auto i = 0LL; i < A; i++){
        int t;
        cin >> t;
        d.push_back(make_pair(t, 2));
    }
    for(auto i = 0LL; i < B; i++){
        int t;
        cin >> t;
        d.push_back(make_pair(t, 1));
    }
    for(auto i = 0LL; i < C; i++){
        int t;
        cin >> t;
        d.push_back(make_pair(t, 0));
    }
    sort(d.begin(), d.end(), greater<pair<int, int>>());
    int ans = 0, count = 0, ac = 0, bc = 0;
    for(auto i = d.begin(); i != d.end(); i++){
        if(X+Y <= count)
            break;
        switch(i->second) {
        case 0: // C
            count++;
            ans += i->first;
            break;
        case 1: // B
            if(bc < Y){
                count++;
                bc++;
                ans += i->first;
            }
            break;
        case 2: // A
            if(ac < X){
                count++;
                ac++;
                ans += i->first;
            }
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;
    cin >> t;
    vector<lli> v;
    lli n = t;
    lli c = 0;
    while (t--)
    {
        lli a;
        cin >> a;
        v.pb(a);
        // s += a;
        // mi = min(mi, a);
    }
    sort(v.rbegin(), v.rend());
    lli ans = 0;
    ans += v[0];
    int i = 1;
    c += 1;

    while (c < n - 1)
    {
        // cout << ans << " " << c << " " << i << endl;

        c += 1;
        ans += v[i];
        if (c < n - 1)
        {
            c += 1;
            ans += v[i];
            i += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MOD = 998244353;
const ll INF = 1e18;
const ll MAXN = 100100;

int N,A[MAXN];
int B[MAXN],K;
multiset<ll> M;
int ans;
map<int,int> P;
int par(int x){return (x==P[x])?x:P[x] = par(P[x]);}

int main(){
	cin>>N;
	for (int i=1;i<=N;++i){
		cin>>A[i];
	}

	for (int i=1;i<=N;++i){
		cin>>B[i];
		K ^= A[i];
		if (A[i] == B[i])continue;
		M.insert(B[i]);
		++ans;
	}

	ll t = SZ(M);
	if (M.find(K) != M.end()){
		M.erase(M.find(K));
		ans--;
	}

	for (int i=1;i<=N;++i){
		if (A[i]==B[i])continue;
		if (M.find(A[i]) != M.end()){
			// cout<<"Erase "<<A[i]<<'\n';
			M.erase(M.find(A[i]));
		}
	}

	if (SZ(M)){
		cout<<-1;
		return 0;
	}

	for (int i=1;i<=N;++i)if (A[i] !=B[i]){
		P[B[i]+1] = B[i]+1;
	}

	for (int i=1;i<=N;++i)if (A[i]!=B[i]){
		if (P[A[i]+1] == 0)continue;
		// Draw edge from P[A[i]] to P[B[i]]
		int a = par(A[i]+1);
		int b = par(B[i]+1);
		P[a] = b;
	}

	int extra = 0;
	// for (auto x:P)cout<<x.f<<' '<<x.s<<'\n';
	for (auto i : P)if (i.f==i.s&&i.s)++extra;

	cout<<ans+extra;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x; scanf("%d%d%d%d",  &a, &b, &c, &x);
    int cnt = 0;
    for(int i=0; i<=a;++i)
        for(int j=0;j<=b;++j)
            for(int k=0;k<=c;++k)
                if(i*500+j*100+k*50==x)
                    ++cnt;
    printf("%d\n", cnt);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <iterator>
#include <map>
#include <set>
using namespace std;
typedef pair<vector<char>, int> VCI;
bool check(vector<char> worm){
  for(int i = 1; i < worm.size(); ++i){
    if(worm[0] != worm[i]){
      return false;
    }
  }
  return true;
}
map<pair<char, char>, char> table;
int bfs(string s){
  vector<char> worm;
  copy(s.begin(), s.end(), back_inserter(worm));
  int N = worm.size();
  queue<VCI> q;
  set<vector<char> > visited;
  q.push(make_pair(worm, 0));
  while(!q.empty()){
    VCI vci = q.front(); q.pop();
    vector<char> w = vci.first;
    int step = vci.second;
    if(check(w)){
      return step;
    }
    if(visited.find(w) != visited.end()){
      continue;
    }
    visited.insert(w);
    for(int i = 0; i < N-1; ++i){
      if(w[i] == w[i+1]){
        continue;
      }
      vector<char> nw;
      copy(w.begin(), w.end(), back_inserter(nw));
      nw[i] = nw[i+1] = table[make_pair(nw[i], nw[i+1])];
      q.push(make_pair(nw, step+1));
    }
  }
  return -1;
}

int main(){
  table[make_pair('r', 'b')] = table[make_pair('b', 'r')] = 'g';
  table[make_pair('r', 'g')] = table[make_pair('g', 'r')] = 'b';
  table[make_pair('b', 'g')] = table[make_pair('g', 'b')] = 'r';
  string s;
  while(true){
    cin >> s;
    if(s == "0"){
      break;
    }
    int ans = bfs(s);
    if(ans == -1){
      cout << "NA" << endl;
    }
    else{
      cout << bfs(s) << endl;
    }
  }
  return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a, b, c;
  for (int i = 0; i < n; i ++) {
    int t; cin >> t;
    if (t % 4 == 0) a.push_back(t);
    else if (t % 2 == 0) b.push_back(t);
    else c.push_back(t);
  }

  string ans;
  if (a.size()+1 == c.size() && a.size()+c.size() == n) ans = "Yes";
  else if (a.size() >= c.size()) ans = "Yes";
  else ans = "No";

  cout << ans << endl;
}


Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int k;
    int a, b;
    int ans =0;
    cin >> k >> a >> b;
    
    for(int i=a;i<=b;i++){
        if(i%k==0) {
            ans=1;
            break;
        }
    }
    
    if(ans) cout << "OK" << endl;
    else cout << "NG" << endl;
    
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
	char s[4];
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2])cout << "No";
	else cout << "Yes";
	return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,A,B,H,W;
string S,T;

int main(){
  cin >>N>>A>> B;
  if((B-A)%2==0){
    cout  << (B-A)/2 << endl;
  }
  else{
    ll K=(B-A-1)/2+A;
    ll T=(B-A-1)/2+N-B+1;
    cout << min(K,T) << endl;
  }
}

Measured memory_bytes: 256