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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 3000 + 5;

ll dp[N][N][3];
ll a[N];
int n;

ll sol(int l, int r, int turn) {
    if(l == r) return (turn == 1 ? a[l] : -a[l]);

    ll &ret = dp[l][r][turn];
    if(ret != -1) return ret;

    if(turn) ret = max(a[l] + sol(l + 1, r, 1 - turn), a[r] + sol(l, r - 1, 1 - turn));
    else ret = min(sol(l + 1, r, 1 - turn) - a[l], sol(l, r - 1, 1 - turn) - a[r]);

    return ret;
}
int main(){
    fIO

//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    memset(dp, -1, sizeof(dp));
    cin >> n;

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

    cout << sol(0, n - 1, 1);
}








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

int main(void)
{
    long long int n, m, sum, x;
    scanf("%lld%lld",&n,&m);
    if(m<=2*n)
        sum=m/2;
    else
    {
        sum = n;
        x = m - 2*n;
        sum = sum + x/4;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m),n){
		int ans=0;
		for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++){
			int k=m-i-j;
			if(j<k&&k<=n)ans++;
		}
		printf("%d\n",ans);
	}
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  ll x[N]; rep(i,N) cin >> x[i];
  c_fac(N);
  ll diff[N-1] = {}; rep(i,N-1) diff[i] = x[i+1] - x[i];
  // debug(diff,diff+N);

  ll result = 0;
  ll now = 0;
  rep(i,N-1) {
    now += fac[(N-1)]*inv(i+1); now %= MOD;
    result += now * diff[i]; result %= MOD;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int INF = 1e9 + 5;
const int ALPHABET = 26;
const char MIN_CHAR = 'a';

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    string A;
    cin >> A;
    int N = int(A.size());
    vector<vector<int>> first(N + 1, vector<int>(ALPHABET, INF));
    vector<int> dp(N + 1, 0);

    for (int i = N - 1; i >= 0; i--) {
        first[i] = first[i + 1];
        first[i][A[i] - MIN_CHAR] = i;
        dp[i] = INF;

        for (int c = 0; c < ALPHABET; c++)
            if (first[i][c] == INF)
                dp[i] = 0;
            else
                dp[i] = min(dp[i], 1 + dp[first[i][c] + 1]);
    }

    int current = 0;
    string ans;

    while (current < N) {
        int now = -1;

        for (int c = 0; c < ALPHABET; c++)
            if (first[current][c] == INF || dp[current] == 1 + dp[first[current][c] + 1]) {
                now = c;
                break;
            }

        assert(now >= 0);
        ans += char(MIN_CHAR + now);
        current = first[current][now] + 1;
    }

    cout << ans << '\n';
}


Measured memory_bytes: 30816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007

int main()
{
    int n;
    cin>>n;
    int maxi=INT_MIN;
      int db[100002]={0};
    ll sum=0;
    for(int i=0;i<n;i++)
    {   int k;
         cin>>k;
         maxi=max(maxi,k);
         db[k]++;
         sum+=k;
    }
    int q;
    cin>>q;

    for(int i=0;i<q;i++)
     {
         int b,c;
         cin>>b>>c;

         if(db[b]>0)
         {
             sum+=(c-b)*db[b];
             db[c]+=db[b];
             db[b]=0;
         }

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


Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    ll l,r; cin >> l >> r;
    ll dif = r - l;
    ll ans = 2019;
    if(dif > 2018){
        ans = 0;
    }else{
        for(ll i = l; i < r; ++i) for(ll j = i + 1; j <= r; ++j){
            ans = min(ans,((i * j) % 2019));
        }
    }
    cout << ans << '\n';
    return 0; 
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n;
long long dist[305][305];

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

    cin >> n;

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            cin >> dist[i][j];

    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (dist[i][k] + dist[k][j] < dist[i][j]) {
                    cout << -1;
                    return 0;
                }
            }
        }
    }

    long long sum = 0LL;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            bool noEdge = false;
            for (int k = 1; k <= n; ++k) {
                if (dist[i][k] + dist[k][j] == dist[i][j] && i != k && j != k && i != j)
                    noEdge = true;
            }

            if (noEdge == false)
                sum += dist[i][j];
        }
    }

    cout << sum / 2LL;

    return 0;
}


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

signed main(void)
{
	long long x, sum, cnt;
	cin >> x;
	sum = cnt = 0;
	if (x <= 6)
		cnt++;
	else
	{
		sum = x / 11;
		cnt += 2 * sum;
		sum *= 11;
		if (0 < x - sum && x - sum <= 6)
			cnt++;
		else if (6 < x - sum)
			cnt += 2;
	}
	cout << cnt << endl;
	return 0;
}


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;
const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);
//string = to_string(数値)
//int = stoi(文字列)
//(int)(char-'0')
//string = itoa(int)
//円周率: M_PI


int main() {
    int n; cin>>n;
    n%=10;
    if(n==3) cout<< "bon" << endl;
    else if(n==0 or n==1 or n==6 or n==8) cout<<"pon"<<endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int cnt1 = 0, cnt2 = 0;
    for(int i = 0; i < 4; i++)
    {
        if('+' == s[i])
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }

    cout << cnt1 - cnt2;
    return 0;
}


Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll ans=0,n;
  string s;
  cin >> n;
  map<ll,ll> m;
  for(int i=0; i<n; i++) {
    cin >> s;
    if(s[0]=='M') {
      m[0]++;
    }
    if(s[0]=='A') {
      m[1]++;
    }
    if(s[0]=='R') {
      m[2]++;
    }
    if(s[0]=='C') {
      m[3]++;
    }
    if(s[0]=='H') {
      m[4]++;
    }
  }
  for(int i=0; i<5; i++) {
    for(int j=i+1; j<5; j++) {
      for(int k=j+1; k<5; k++) {
        ans+=m[i]*m[j]*m[k];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
"""全探索：全列挙
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja
"""

def solve():
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 0:
            break

        ans = 0
        for i in range(1, n+1):
            for j in range(i+1, n+1):
                if j < (x-i-j) <= n:
                    ans += 1
        print(ans)


if __name__ == "__main__":
    solve()



Measured memory_bytes: 5616
package main

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

type Row []string

type Data []Row

func main() {
	nextReader = newScanner()
	N := nextInt64()
	K := nextInt64()
	min := N % K

	if (min-K)*-1 < min {
		fmt.Print((min - K) * -1)
	} else {
		fmt.Print(min)
	}
}

var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	// r.Split(bufio.ScanLines)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func CustomScan(data []byte, atEOF bool) (advance int, token []byte, err error) {
	for i := 0; i < len(data); i++ {
		if data[i] == ' ' {
			return i + 1, data[:i], nil
		}
	}
	fmt.Println(data)
	return 0, data, bufio.ErrFinalToken
}

func nextStrings() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	// r.Split(bufio.ScanWords)
	r.Split(CustomScan)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
map<string,bool>Map;
string a[105],now,last;
long long n;
int main()
{
	cin>>n;
	for(int s=0;s<n;s++)
	{
		cin>>a[s];
		now=a[s];
		if(last!=""&&last[last.size()-1]!=now[0]||Map[a[s]]==1)
		{
			puts("No");
			return 0;
		}
		Map[a[s]]=1;
		last=a[s];
	}
	puts("Yes");
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	table = map[string]string{"A": "T", "T": "A", "C": "G", "G": "C"}
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	if !sc.Scan() {
		panic(nil)
	}

	b := sc.Text()

	max := 0
	seq := 0
	for i := 0; i < len(b); i++ {
		switch string(b[i]) {
		case "A", "C", "T", "G":
			seq++
		default:
			if seq > max {
				max = seq
			}
			seq = 0
		}
	}
	if seq > max {
		max = seq
	}

	fmt.Printf("%d\n", max)

}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(void) {
	int p, q;
	while((scanf("%d %d", &p, &q)) == 2) {
		if(q > p) swap(p, q);
		while(q != 0)
			swap(p %= q, q);
		printf("%d\n", p);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
//#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 21474836

int X[3];

int main() {

	cin >> X[0] >> X[1] >> X[2];
	
	bool ans = false;
	if ((X[0] == X[1]) && (X[1] != X[2]))ans = true;
	if ((X[0] == X[2]) && (X[1] != X[2]))ans = true;
	if ((X[1] == X[2]) && (X[0] != X[1]))ans = true;

	if(ans)cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 166 (https://atcoder.jp/contests/abc166)
// Problem: D: I hate Factorization (https://atcoder.jp/contests/abc166/tasks/abc166_d)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    int x; cin >> x;
    array<ll, 256> a{};
    reps(i, -127, 128)
        a[i + 127] = (ll)i * i * i * i * i;
    rep(i, 256)
        rep(j, 256)
            if (a[i] - a[j] == x)
                cout << (i - 127) << ' ' << (j - 127) << '\n', exit(0);

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) 
    cin >> v.at(i);
  
  sort(v.begin(), v.end());
  
  int ans = 1;
  for (int i = 0; i < N - 1; i++) {
    if (v.at(i) != v.at(i + 1))
      ans++;
    if (v.at(i) == v.at(i + 1))
      continue;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char s[200000];
  scanf("%s",&s);
  int i = 0,j = strlen(s);
  while(s[i] != 'A'){
    i++;
  }
  while(s[j] != 'Z'){
    j--;
  }
  printf("%d",j - i + 1);
  return 0;
}

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

void solve() 
{
    int k;cin>>k;
    REP(i,k)cout<<"ACL";cout<<endl;
}

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

Measured memory_bytes: 3652
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 10)

int a[MAXN];
int n;
int sum;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int ret = MAXN * MAXN * MAXN;
	int ind = -1;
	for (int i = 0; i < n; i++) {
		int cur = abs(n * a[i] - sum);
		if (cur < ret) {
			ret = cur;
			ind = i;
		}
	}
	cout << ind << endl;
	return 0;
}


Measured memory_bytes: 3532
#include<stdio.h>
int main()
{
    int H,N,A,i;
    scanf("%d%d",&H,&N);
    if((H>=1 && H<=1000000000) && (N>=1 && N<=100000))
    {
        for(i=1;i<=N;i++)
        {
            scanf("%d",&A);
            if(A>=1 && A<=10000)
            {
                H=H-A;
            }
            else
                printf("Not within limit");
        }
        if(H<1)
            printf("Yes");
        else
            printf("No");
    }
    else
        printf("Not within limit ");
    return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    for_(i,0,N) cin >> A[i];

    vector<int> ans(N, 0);
    segtree<int, op, e> seg(300005);
    for_(i,0,N) {
        int L = max(0, A[i] - K);
        int R = min(A[i] + K, 300000);
        ans[i] = seg.prod(L, R + 1) + 1;
        if (seg.get(A[i]) < ans[i]) seg.set(A[i], ans[i]);
    }

    // for_(i,0,N) cerr << ans[i] << " ";
    // cerr << endl;

    cout << *max_element(ALL(ans)) << endl;
}

Measured memory_bytes: 10908
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

int n,m;
ll matome[16];

ll calc(priority_queue<int> &q, int cnt, int pos) {
	//cout << n << "," << cnt << "," << pos << endl;
	if(cnt>=n) return 0;

	cnt++;

	int temp = q.top();q.pop();
	int q_num = (temp>>2)*-1;
	int q_pos = (temp&0b11);

	if(q_pos==pos) {
		return calc(q,cnt,pos);
	}
	if(q_pos==1) {
		return calc(q,cnt,pos^0b10)+1LL+matome[n-cnt-1];
	}else {
		ll rest = calc(q,cnt,pos);
		rest += 2LL + matome[n-cnt-1]*2LL;
		return rest;
	}
}

int main() {
	matome[0] = 2;
	for(int i = 0; i < 15; i++) {
		matome[i+1] = matome[i]*3+2;
	}

	while(true) {
		cin >> n >> m;
		if(n==0) break;

		priority_queue<int> q;
		for(int i = 0; i <= 2; i++) {
			int cnt;
			cin >> cnt;
			for(int j = 0; j < cnt; j++) {
				int cup;
				cin >> cup;
				cup*= -1;
				q.push((cup<<2)|i);
			}
		}
		ll ans = 0;
		{
			int temp = q.top();
			int num = (temp>>2)*-1;
			int pos = (temp&0b11);
			if(pos==0 || pos==2) {
				q.pop();
				ans = calc(q,1,pos);
			}else {
				priority_queue<int> q2(q);
				ll an1 = calc(q,0,0);
				ll an2 = calc(q2,0,2);
				ans = min(an1,an2);
			}
		}
		//cout << ans << endl;
		if(ans<=m) {
			cout << ans << endl;
		}else {
			cout << -1 << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3144
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007
 
#define ARRAY_MAX 100005
 
int main(){

    int n;
    cin >> n;
    REP(i,n){
        set<string> st;
        string s;
        cin >> s;
        for(int j = 1;j <= s.length()-1;j++){
            string first = s.substr(0,j);//先頭からj文字の部分列
            string after = s.substr(j,s.length()-j);
            for(int hoge = 0;hoge <= 1;hoge++){
                //hoge == 0ならfirst+second、hoge == 1ならsecond+first
            


                for(int rev1 = 0;rev1 <= 1;rev1++){
                    string tmp1 = first;
                    //rev1 == 0ならfirstはそのまま、rev1 == 1ならfirstを逆順
                    if(rev1 == 1){
                        reverse(tmp1.begin(),tmp1.end());
                    }
                    for(int rev2 = 0;rev2 <= 1;rev2++){
                        string tmp2 = after;
                        //rev2 == 0ならsecondはそのまま、rev2 == 1ならsecondを逆順
                        if(rev2 == 1){
                            reverse(tmp2.begin(),tmp2.end());
                        }
                        if(hoge == 0){
                            st.insert(tmp1+tmp2);
                        }else{
                            st.insert(tmp2+tmp1);
                        }
                    }
                }
            }
        }
        cout << st.size() << endl;
    }

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;

    int LIKE_NUM = 753;
    int minVal = 1000;

    for (int i = 0; i < s.size() - 2; i++) {
        int num = stoi(s.substr(i, 3));
        minVal = min(minVal, abs(LIKE_NUM - num));
    }

    cout << minVal << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	string str;
	int n;
	int ac = 0, tle = 0, wa = 0, re = 0;
	cin >> n;

	for(int i=0;i<n;i++){
		cin >> str;
		if(str=="AC")
			ac++;
		if(str=="TLE")
				tle++;
		if(str=="WA")
				wa++;
		if(str=="RE")
				re++;
	}
	cout << "AC x " << ac <<endl;
	cout << "WA x " << wa <<endl;
	cout << "TLE x " << tle <<endl;
	cout << "RE x " << re <<endl;
}


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

int main(){
  int n;
  cin >> n;
  int a, b, c;
  for (int i = n;i < 1000; i++){
    a = i/100;
    b = (i/10)%10;
    c = i%10;
    if (a == b && b == c){
      cout <<i;
      break;
    }
    else
      continue;
  }
}
    
 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;


int main(){
  int n;
  char c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c;
    if(c=='Y'){cout<<"Four"<<endl;return 0;}
  }
  cout<<"Three"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

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

    bool flag=true;
    for(int i=0; i<s.size(); i++){
        if(i==a){
            if(s[i]!='-') flag=false;
        }else{
            if(s[i]=='-') flag=false;
        }
    }

    std::cout << ((flag==true)?("Yes"):("No")) << "\n";
    return 0;
}


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

int main(){
	int a[5];
	for(int i = 0; i < 5; i++){
		cin >> a[i];
	}
	sort(a, a+5, greater<int>());

	cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << " " << a[4] << endl;
}

Measured memory_bytes: 1180
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

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

  std::vector<int> res(n);
  for (size_t i = 0; i < k; ++i) res[i] = s;
  int t = 1000000000;
  if (s == t) --t;
  for (size_t i = k; i < n; ++i) res[i] = t;

  for (size_t i = 0; i < n; ++i)
    printf("%d%c", res[i], i+1<n? ' ': '\n');
}


Measured memory_bytes: 1664
// https://atcoder.jp/contests/abc056/tasks/abc056_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  char a, b, r;

  cin >> a >> b;

  r = a == b ? 'H' : 'D';

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


Measured memory_bytes: 256
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
const int N = 1e5 + 1;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
int dp[(int)1e5+1];
int v[(int)100+1];
bool brute(int k){
	if(k < 0){
		return 0;
	}
	if(k == 0){
		return 1;
	}
	if(dp[k] != -1){
		return dp[k]^1;
	}
	bool ans = 0;
	for(int i=0;i<n;i++){
		ans = ans||(brute(k-v[i]));
	}
	// cout<<k<<" "<<flag<<" "<<ans<<"\n";
	dp[k] = ans;
	return ans^1;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	memset(dp,-1,sizeof dp);
	brute(k);
	if(dp[k])
		cout<<"First";
	else cout<<"Second";
    return 0;
}
//.........

Measured memory_bytes: 4224
#include<stdio.h>
int main(){
    int n[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf("%d",&k);
    printf("%d",n[k-1]);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define N 2000
int kaneko[N+1];
int main(void){
    int n,k,q,key,sum=0;
    int i,j;

    kaneko[0]=1;
    scanf("%d",&n);
    for(i=0;i<n;i++){
	scanf("%d",&k);
	sum+=k;
	for(j=sum-k;j>=0;j--){
	    if(kaneko[j]) kaneko[j+k]=1;
	}
    }

    scanf("%d",&q);
    for(i=0;i<q;i++){
	scanf("%d",&key);
	if(kaneko[key]) printf("yes\n");
	else printf("no\n");
    }

    return 0;
}



Measured memory_bytes: 2108
#include <iostream>

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

    while (a > 0 && c > 0)
    {
        c -= b;
        a -= d;
    }

    if (c <= 0) std::cout << "Yes";
    else std::cout << "No";
}


Measured memory_bytes: 3660
from collections import deque
n,m=map(int,input().split())
to=[[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    to[x-1].append(y-1)
    to[y-1].append(x-1)
dist=[None]*n    

que=deque([0])
while que:
    v=que.pop()
    for i in to[v]:
        if(dist[i] is None):
            dist[i]=v+1
            que.appendleft(i)
        
print("Yes")
for i in dist[1:]:
    print(i)    


Measured memory_bytes: 37644
import string
h,w=map(int,input().split())
s=[]
for _ in range(h):
    s.append(list(input().split()))
for y in range(h):
    if 'snuke' in s[y]:
        I1=y
        I2=s[y].index('snuke')
        break
a=list(string.ascii_uppercase)
print(a[I2]+str(I1+1))


Measured memory_bytes: 3836
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define SPACEREP(lst,itr) for(auto itr=lst.begin(); itr!=lst.end();++itr){cout<<*itr<<(++itr!=anslist.end()?" ":"\n");itr--;}
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define LEN 100001

int main(){
    int n,a,b,ans=0;
    cin >> n;
    vector<int> ary(LEN+1);
    REP(i,0,LEN+1){
        ary[i]=0;
    }
    REP(i,0,n){
        cin >> a;
        cin >> b;
        ary[a]+=1;
        ary[b+1]+=-1;
    }
    /**
    REP(i,1,LEN+1){
        cout << ary[i] <<" ";
    }
    
    cout << endl;
    **/
    REP(i,1,LEN+1){
        ary[i]+=ary[i-1];
    }
    /**
    REP(i,1,LEN+1){
        cout << ary[i] << " ";
    }
    cout << endl;
    **/

    RREP(i,1,LEN+1){
        if(ary[i] >= i-1){
            ans=i-1;
            break;
        }
    }
    p(ans);

}


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

int a[101],n,p,q;

bool cmp(int x,int y)
{
    return x>y;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        q+=a[i];
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i+=2)
        p+=a[i];
    cout<<p-q+p<<endl;
}

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


int main() {
    int N, K;
    cin >> N >> K;
    int h[N];
    for (int i = 0; i < N; i++) {
      cin >> h[i];
    }
    int c[N];
    c[0] = 0;
    for (int i = 1; i < N; i++) {
      int c_tmp = 1e9;
      for (int j = 1; j <= K; j++) {
        if (j > i) {
          break;
        }
        c[i] = min(c[i - j] + abs(h[i] - h[i - j]), c_tmp);
        c_tmp = c[i];
      }
    }
    cout << c[N - 1] << endl;
}


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

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n;
    cin>>n;
    vector<int> l(n);
    rep(i,0,n){
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    ll ans=0;
    rep(a,0,n){
        int b=a;
        rep(c,a+1,n){
            while(b<n&&l[b]<l[a]+l[c])++b;
            ans+=b-(c+1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    string t;
    cin >> t;
    int i=0;
    while( s[i] == t[i] ){
        i++;
    }
    
    if(i== s.length()) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#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>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  string S; int K; cin>>S>>K;
  int ans=0;
  if(S.size()<K)
    ans=0;
  else{
  if(K==1){
    ans=9*(S.size()-1)+S[0]-'0';
  }
  else if(K==2){
    ans=(S[0]-'1')*9*(S.size()-1);
    bool flag=1;
    rep(i,1,S.size()){
      if(flag){
        if(S[i]!='0'){
          flag=0;
          ans+=S[i]-'0';
        }
      }
      else
        ans+=9;
    }
    ans+=(S.size()-1)*(S.size()-2)/2*9*9;
  }
  else{
    ans=(S[0]-'1')*9*9*(S.size()-1)*(S.size()-2)/2;
    bool flag=1;
    rep(i,1,S.size()-1){
      if(flag){
        if(S[i]!='0'){
          flag=0;
          bool flag2=1;
          rep(j,i+1,S.size()){
            ans+=(S[i]-'1')*9;
            if(flag2){
              if(S[j]!='0'){
                flag2=0;
                ans+=S[j]-'0';
              }
            }
            else{
              ans+=9;
            }
          }
        }
      }
      else{
        rep(j,i+1,S.size())
          ans+=9*9;
      }
    }
    ans+=(S.size()-1)*(S.size()-2)*(S.size()-3)/6*9*9*9;
  }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n;
string s;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    n = s.length();
    if (n % 2 == 0) {
        bool flag = true;
        for (int i = 0; i < n; i += 2) {
            if (s[i] != 'h' || s[i + 1] != 'i') {
                flag = false;
                break;
            }
        }
        if (flag) cout << "Yes" << E;
        else cout << "No" << E;
    }
    else cout << "No" << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){
	string s;
	cin>>s;
	int len=s.length();
	int cnt=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]=='1') cnt++;
	}
	cout<<cnt<<endl;




    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
long long dp[30];
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		dp[i]=0;
	dp[0]=1;
	dp[1]=2;
	dp[2]=4;
	for(int i=3;i<n;i++){
		dp[i]+=dp[i-3]+dp[i-2]+dp[i-1];
	}
	cout<<(dp[n-1]/3650)+1<<endl;
	}
    return 0;
}
 

Measured memory_bytes: 1152
// ConsoleApplication7.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;

int main()
{
	int A, B, C;
	cin >> A;
	cin >> B;
	cin >> C;
	if (A == B)
		cout << C << endl;
	if (A == C)
		cout << B << endl;
	if (B == C)
		cout << A << endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-

S = input()

S1 = S[0:2]
S2 = S[2:4]

S1_flg = False
S2_flg = False
if "01" <= S1 and S1 <= "12":
    S1_flg = True
if "01" <= S2 and S2 <= "12":
    S2_flg = True
if   S1_flg == False and S2_flg == False:
    print("NA")
elif S1_flg == False and S2_flg == True:
    print("YYMM")
elif S1_flg == True  and S2_flg == False:
    print("MMYY")
else:
    print("AMBIGUOUS")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
using namespace std;
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
	
int32_t main() {
	fast;
	string s, t; 
	cin>>s>>t;
	int n = s.size(), m = t.size();
	int mx = 0;
	for(int i=0; i + m - 1<n; i++){
		int j, cnt = 0;
		for(j = 0; j<m; j++)
			if(s[i+j] == t[j])
				cnt++;
		mx = max(cnt, mx);
	}
	cout<<m - mx;
	
}




Measured memory_bytes: 3656
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2 << endl;
    return 0;
}


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

#define LLINF (1LL<<60)
typedef long long ll;

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int P,Q,R;
    cin >>P>>Q>>R;

    //-----------------------------------
    int ans=P+Q;
    chmin(ans,Q+R);
    chmin(ans,R+P);

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

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL h = 0, w, n = 0, m, s, ans = 0, a[1000000] = {}, sum = 0, pos[2][2] = {}, dp[1000][1000] = {};
int flag = 0;
string str;
vector<LL>num[10000];
int main() {
	cin >> str;
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'a')a[0]++;
		else if (str[i] == 'b')a[1]++;
		else a[2]++;
	}
	if (abs(a[0] - a[1]) < 2 && abs(a[1] - a[2]) < 2 && abs(a[0] - a[2]) < 2)
		cout << "YES"<<endl;
	else cout << "NO" << endl;
	return 0;
}


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

int main(void) {
    string s;
    cin >> s;
    set<char> c;
    for (int i=0; i<s.size(); i++) {
        c.insert(s[i]);
    }
    if ( c.size() == 26) {
        cout << "None" << endl;
        return 0;
    }
    char tmp = 'a';
    auto itr = c.begin();
    for (auto itr = c.begin(); itr != c.end(); ++itr) {
        if (tmp != *itr) {
            cout << tmp << endl;
            return 0;
        }
        tmp++;
    }
    cout << tmp << endl;
    return 0;
}


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

int main() {
    int n;
    while (cin >> n, n) {
        string s[n];
        for (int i = 0; i < n; i++) cin >> s[i];
        for (int i = 0; i < n; i++) {
            int idx = 0;
            if (s[i][0] != '.') continue;
            for (int j = 0; j < s[i].size(); j++) {
                if (s[i][j] == '.')
                    s[i][j] = ' ';
                else if (j - 1 >= 0 && s[i][j] != '.') {
                    s[i][j - 1] = '+';
                    idx = j - 1;
                    break;
                }
            }
            for(int k = i - 1; k >= 0 && s[k][idx] == ' '; k--){
                s[k][idx] = '|';
            }
        }
        for (int i = 0; i < n; i++) cout << s[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, smax=-1, f=0;
    string s[200100];
    map<string, long long> mp;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> s[i];
        mp[s[i]]++;
    }
    for(i=0;i<n;i++){
        smax=max(smax, mp[s[i]]);
    }
    sort(s, s+n);
    for(i=0;i<n;i++){
        if(f==1 && s[i]!=s[i-1]){
            f=0;
        }
        if(mp[s[i]]==smax && f==0){
            cout << s[i] <<endl;
            f=1;
        }
    }
    return 0;
}

Measured memory_bytes: 26752
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

int main()
{
	int n, m;
	cin >> n >> m;
	auto ab = vector<pair<ll, int>>(n);
	for(auto& p : ab) cin >> p.first >> p.second;
	sort(ab.begin(), ab.end());
	ll cost = 0;
	for(auto p : ab){
		auto a = p.first;
		auto b = p.second;
		cost += (a * min(m, b));
		m -= b;
		if(m <= 0) break;
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 1792
def f(): return map(int,raw_input().split())
n,q=f()
a0,v0=0,0
A=[0]*(n+1)
for _ in range(q):
  a,v=f()
  A[a]+=v
  c=A[a]
  if a==a0 and c<v0:
    v0=max(A)
    a0=A.index(v0)
  elif c>v0: a0,v0=a,c
  elif c==v0 and a<a0: a0=a
  print a0,v0

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

#define MAX 3	//TODO

int N, M;
int s[MAX];
char c[MAX];

int first() {
	int ans;
	if (N == 1) {
		ans = 0;
	} else {
		ans = 1;
		for (int i = 0; i < N - 1; i++) {
			ans *= 10;
		}
	}
	return ans;
}

int end() {
	int ans = 1;
	for (int i = 0; i < N; i++) {
		ans *= 10;
	}
	return ans;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> s[i] >> c[i];
	}
	for (int i = first(); i < end(); i++) {
		string str = to_string(i);
		bool flg = true;
		for (int j = 0; j < M; j++) {
			if (str[s[j] - 1] != c[j]) {
				flg = false;
				break;
			}
		}
		if (flg) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
// AOJ 0658 Bitaro the Brave
// 2019.3.28 bal4u

#include <stdio.h>
#include <stdlib.h>

//// 入力の高速化
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()    // 整数の入力（負数非対応）
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s)  // 文字列の入力　スペース以下の文字で入力終了
{
	do *s = gc();
	while (*s++ > ' ');
	*(s - 1) = 0;
}

#define MAX 3005
int H, W;
char map[MAX][MAX];
short sO[MAX][MAX];
int   sI[MAX];

int main()
{
	int r, c;
	long long ans;

	H = in(), W = in();
	for (r = 0; r < H; r++) {
		ins(map[r]);
		for (c = W - 1; c >= 0; c--) sO[r][c] = sO[r][c + 1] + (map[r][c] == 'O');
	}
	ans = 0;
	for (c = 0; c < W; c++) {
		for (r = H - 1; r >= 0; r--) sI[r] = sI[r + 1] + (map[r][c] == 'I');
		for (r = 0; r < H; r++) if (sI[r]) {
			if (map[r][c] == 'J') ans += sO[r][c] * sI[r];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
    vector<int> antenna(5);
    int k;
    rep(i, 5) cin >> antenna[i];
    cin >> k;
    
    bool judge = true;
    rep(i, 5) rep(j, 5) {
        if (antenna[i] - antenna[j] > k) judge = false;
    }
    if (judge) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int n = S.size();
  int lp = 0;
  int rp = (n - 1) / 2 - 1;
  while (lp <= rp) {
    if (S[lp] != S[rp]) {
      cout << "No" << endl;
      return 0;
    }
    lp++;
    rp--;
  }
  lp = (n + 3) / 2 - 1;
  rp = n - 1;
  while (lp <= rp) {
    if (S[lp] != S[rp]) {
      cout << "No" << endl;
      return 0;
    }
    lp++;
    rp--;
  }
  lp = 0;
  rp = n - 1;
  while (lp <= rp) {
    if (S[lp] != S[rp]) {
      cout << "No" << endl;
      return 0;
    }
    lp++;
    rp--;
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=1e9+7;
ll a[N];
//ll sum[N][N];
//ll pre[N],x,y,k;
//map<ll,ll> mp;
struct node{
    ll t,x,y;
}p[N];

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

    int n;
    cin >>n;
    bool flag=true;
    for(int i=1;i<=n;i++)   cin >> p[i].t>>p[i].x>>p[i].y;
    p[0].t=p[0].x=p[0].y=0;
    for(int i=0;i<=n-1;i++){
        ll dis=abs(p[i].x-p[i+1].x)+abs(p[i].y-p[i+1].y);
        if(( p[i+1].t-p[i].t)>=dis  &&   (( p[i+1].t-p[i].t)-dis)%2==0){

        }
        else{
            flag=false;
            break;
        }
    }
    if(!flag)   cout << "No"<<endl;
    else    cout <<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  string s,t; cin>>s>>t;
	vector<string> ans;
	int n=s.size(), m=t.size();
	rep(i,n-m+1){
		cerr << i SP s[i] << endl;
		rep(j,m){
			if(s[i+j]!='?'&&s[i+j]!=t[j]) j=m;
			if(j==m-1){
				cerr << i SP "found" <<endl;
				string kouho = s;
				for(int k=i;k<i+m;k++) kouho[k]=t[k-i];
				cerr << kouho << endl;
				rep(k,n) if(kouho[k]=='?') kouho[k]='a';
				ans.PB(kouho);
				cerr << kouho << endl;
			}
		}
	}
	if(ans.size()){
		sort(ALL(ans)); cout<<ans[0]<<endl;
	}else{
		cout<<"UNRESTORABLE"<<endl;
	}
  return 0;
}


Measured memory_bytes: 256