akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std;

//#define MAX 10000
#define MAX		1000000
#define INDEX	100000
//素数配列
int h_sosu[INDEX] = {0};

//----- 列挙関数 -----//
void f_sosu();


int main(void)
{
	//素数を列挙
	f_sosu();

	//入力変数
	int n = 0;

	while (true)
	{
		cin >> n;
		if (n == 0)	{	return 0;	}

		//答え変数(王が1払ってくれる)
		int ans = 0;
		//当たりくじ
		int atari = 0;
		//組
		int kumi = 0;

		//入力
		for (int i = 0; i < n; i++)
		{
			cin >> atari >> kumi;
			//ループ変数
			int j = atari - kumi;
			//終了
			int end = atari + kumi;
			//1は政府が支払う
			bool flag_in = false;

			int count = 0;
			//負数はいらない
			if (j < 0)	{	j = 0;	}
			//値が大きすぎるなら
			if (end >= MAX)	{end = MAX;	}
			while (h_sosu[count] < j && h_sosu[count] != 0)
			{
				count++;
			}
			while (h_sosu[count] <= end && h_sosu[count] != 0)
			{
				count++;
				ans++;
			}
			ans--;
		}

		cout << ans << endl;
	}

	return 0;
}



//*****----- 素数列挙(エラトステネスのふるい) -----*****//

void f_sosu()
{
	//2 , 3は加えておく
	register int count = 2;
	h_sosu[0] = 2 , h_sosu[1] = 3;
	//終了の値
	register int end = 0;
	//素数flag
	register bool flag_sosu = false;

	for (int i = 5; i < MAX; i += 2)
	{
		//flag初期化
		flag_sosu = true;
		//平方根までで良い
		end = sqrt((double)i);
		//カウント変数まで回す
		for (int j = 0; j < count; j++)
		{
			if (i % h_sosu[j] == 0)
			{
				flag_sosu = false;
				break;
			}
			if (h_sosu[j] > end)	{	break;	}
		}
		//素数なら
		if (flag_sosu == true)
		{
			h_sosu[count++] = i;
		}
	}
}

Measured memory_bytes: 1464
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  	int a,b,c,n;
  	cin >> a >> b >> c;
  	cin >> n;
  
  	if(max(a,max(b,c)) == a){
      cout << a*(pow(2,n)) + b + c << endl;
      
    }
  	else if(max(a,max(b,c)) == b){
      cout << b*(pow(2,n)) + a + c << endl;
    }
  	else{
      cout << c*(pow(2,n)) + b + a << 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;
typedef long long ll;

int main() {
    int n, q;
    cin >> n;
    int s[n];
    rep(i, n) cin >> s[i];

    int ans = 0;
    cin >> q;
    rep(i, q) {
        int a;
        cin >> a;
        int l = 0, r = n;
        while (l < r) {
            int mid = (l + r) / 2;
            if (s[mid] == a) {
                ans++;
                break;
            } else if (s[mid] > a)
                r = mid;
            else if (s[mid] < a)
                l = mid + 1;
        }
    }

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



Measured memory_bytes: 3480
/*
* Author : Omkar Deshmukh
*/
#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

#define int long long
#define ll long long
#define endl '\n'
#define all(v) v.begin(), v.end()
#define intvect vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define boolv vector<bool>
#define ld long double
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define ub upper_bound
#define bs binary_search
#define lb lower_bound
#define ull unsigned long long

const ll mod = 1e9 + 7;
const ll N = (ll)5e5 + 4;
template <typename... T>
void read(T &... args)
{
    ((cin >> args), ...);
}

template <typename... T>
void write(T &&... args)
{
    ((cout << args), ...);
}

void vjudge()
{
#ifndef ONLINE_JUDGE
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int add(int a, int b)
{
    return (a % mod + b % mod) % mod;
}

void solve()
{
    int x;
    read(x);
    if (x == 0)
    {
        cout << 1 << '\n';
    }
    else if (x == 1)
    {
        cout << 0 << '\n';
    }
}
int32_t main()
{
    vjudge();
    int t = 1;
    // read(t);
    while (t--)
        solve();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	cat N;
	cin >> N;
	cat val[3][2];
	for(int i = 0; i < 6; i++) cin >> val[i%3][i/3];
	int dif_mask = 0;
	for(int i = 0; i < 3; i++) if(val[i][0] > val[i][1]) dif_mask |= 1<<i;
	if(dif_mask == 0 || dif_mask == 7) { // O(N)
		if(dif_mask == 7) for(int i = 0; i < 3; i++) swap(val[i][0], val[i][1]);
		vector<cat> ans(N+1);
		for(int i = 0; i <= N; i++) ans[i] = i;
		for(int i = 0; i <= N; i++) for(int j = 0; j < 3; j++)
			if(i >= val[j][0]) ans[i] = max(ans[i], ans[i-val[j][0]]+val[j][1]);
		cout << ans[N] << "\n";
		return 0;
	}
	for(int k = 0; k < 2; k++) { // O(max_val^2)
		cat MX = 1;
		for(int i = 0; i < 3; i++)
			if(val[i][1-k] > val[i][k]) MX *= val[i][k];
		vector<cat> incr(MX+1, 0);
		for(int i = 0; i <= MX; i++) for(int j = 0; j < 3; j++)
			if(i >= val[j][k]) incr[i] = max(incr[i], incr[i-val[j][k]]+val[j][1-k]);
		cat N_inc = 0;
		for(int i = 0; i <= min(N, MX); i++) for(int j = 0; j < 3; j++) {
			cat N_nw = (N-i)/val[j][k] * val[j][1-k] + (N-i) % val[j][k] + incr[i];
			N_inc = max(N_inc, N_nw);
		}
		N = N_inc;
	}
	cout << N << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 33024
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
  int n, t;
  cin >> n >> t;
  int a[n], b[n];
  rep(i, n) cin >> a[i] >> b[i];
  int mi = 1000000;
  bool en = false;
  rep(i, n)
  {
    if(b[i]<=t){
      mi = min(mi, a[i]);
      en = true;
    }
  }
  if(en)cout<<mi<<endl;
  else cout<<"TLE"<<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;
const int INF = 2147483647;
using ll = long long;
// cout << typeid('変数').name() << endl;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    for (int i=0;i<n;i++){
        cin >> h.at(i);
    }
    vector<vector<int>> way(n);

    for (int i=0;i<m;i++){
        int a;
        int b;
        cin >> a >> b;
        a--;
        b--;
        way.at(a).push_back(b);
        way.at(b).push_back(a);
    }
    // for (int i=0;i<n;i++){
    //     for (int j=0;j<way.at(i).size();j++){
    //         cout << i << ": " << way.at(i).at(j) << endl;
    //     }
    // }
    int cnt=0;
    for (int i=0;i<n;i++){
        int high = true;
        for(int j=0;j<way.at(i).size();j++){
            int now = way.at(i).at(j);
            if(h.at(i)>h.at(now)) continue;
            else {
                high = false;
                break;
            }
        }
        if(high) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void AGC019A()
{
	vl p(4);
	cin >> p[0] >> p[1] >> p[2] >> p[3];
	ll N;
	cin >> N;
	map<ll, int> price;
	for (int i = 0; i < 4; ++i)
		price[(p[i] * (8 >> i))] = i;


	N *= 4;
	vl amt(4);
	for (int i = 0; i < 4; ++i)
		amt[i] = 1 << i;
	ll cost = 0;
	ll res = N;
	for (auto q = price.begin(); q != price.end(); ++q)
	{
		int i1 = q->second;
		int n1 = res / amt[i1];
		cost += n1 * p[i1];
		res -= n1 * amt[i1];
		if (res == 0)
			break;
	}
	cout << cost << endl;
}

int main()
{
	AGC019A();
	return 0;
}


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

int main()
{
    int i,j,k,l,m,n;
    cin>>n;
    int a[n+10][5];
    int dp[n+10][5];

    memset(dp,0,sizeof dp);

    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)cin>>a[i][j];
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

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

    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

vector<int> vec;

bool check(int x){
    int num = x;
    while(num!=0){
        int t = num%10;
        for(int y:vec){
            if(t==y)return false;
        }
        num /= 10;
    }
    return true;
}

int main(){
    int n,k,t;
    cin >> n >> k;
    REP(i,k){
        cin >> t;
        vec.push_back(t);
    }
    int i = n;
    while(1){
        if(check(i)){
            COUT(i);
            break;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  long double a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  long double A=sqrt((a-c)*(a-c)+(b-d)*(b-d)),
  B=sqrt((a-e)*(a-e)+(b-f)*(b-f)),
  C=sqrt((e-c)*(e-c)+(f-d)*(f-d)),
  s=(A+B+C)/2,
  S=sqrt(s*(s-A)*(s-B)*(s-C)),
  r=2*S/(A+B+C);
  cout<<fixed<<setprecision(16)<<max({A,B,C})/(2.0+max({A,B,C})/r)<<endl;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < signed(n); i++)
#define rrep(i, n) for(int i = signed(n) - 1; i >= 0; i--)
#define all(co) co.begin(), co.end()
#define int long long
//using LL = long long;
//using P = pair < int, int > ;
//using PI = pair < P, int > ;
typedef pair<int, int> P;
typedef long long LL;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
const int INF = 1 << 29;
const LL LINF = 1ll << 62ll;

struct edge{ int from, to, cost; };

int dr[] = { -1, 0, 1, 0 };
int dc[] = { 0, 1, 0, -1 };

template<typename T = int>
vector<vector<T>> vvector(int h, int w, T def = T()){ return move(vector<vector<T>>(h, vector<T>(w, def))); }
class range {
private: struct I{ int x; int operator*(){ return x; }bool operator!=(I& lhs){ return x < lhs.x; }void operator++(){ ++x; } }; I i, n;
public:range(int n) :i({ 0 }), n({ n }){}range(int i, int n) :i({ i }), n({ n }){}I& begin(){ return i; }I& end(){ return n; }
};

signed main()
{
	int h, w;
	while (cin >> h >> w && h)
	{
		int n; cin >> n;
		auto stage = vvector<int>(h, w);
		rep(i, h)rep(j, w) cin >> stage[i][j];
		auto dp = vvector(h + 1, w + 1);

		dp[0][0] = n - 1;
		rep(i, h)
		{
			rep(j, w)
			{
				bool rem = dp[i][j] % 2;
				dp[i][j + 1] += dp[i][j] / 2 + (rem ? stage[i][j] : 0);
				dp[i + 1][j] += dp[i][j] / 2 + (rem ? !stage[i][j] : 0);
			}
		}

		rep(i, h) rep(j, w) stage[i][j] = (stage[i][j] + dp[i][j]) % 2;
		P now = P(0, 0);
		while (now.first != h && now.second != w)
		{
			if (stage[now.first][now.second]) now.second++;
			else now.first++;
		}
		cout << now.first + 1 << " " << now.second + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 16904
#include<algorithm> // sort,reverse,min,lower_bound
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

li powMOD(li a,li b){
  if(b==0)return 1;
  if(b%2)return (a*powMOD(a,b-1))%MOD;
  li c=powMOD(a,b/2);
  return c*c%MOD;
}


int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  vector<li> c(n);
  li temp=powMOD(2,2*(n-1));
  for(li& x: c) cin >>x;
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  rep(i,n) {
    (c.at(i)*=i+2)%=MOD;
    (c.at(i)*=temp)%=MOD;
  }
  li s=0;
  if(df)printf("%ld\n",temp);
  rep(i,n){
    (s+= c.at(i))%=MOD;
  }
  if(df)printf("\n");
  cout << s;
}

/// confirm df==0 ///


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

int main() {
  
  int X=0;
  
  cin >> X;
  
  if(X==3 || X==5 || X==7) {
    
    cout << "YES" << endl;
    
  } else { 
    
    cout << "NO" << endl;
    
  }
  
}

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

using namespace std;
int main()
{
    int D, T, S;
    cin >> D >> T >> S;

    int dist = T * S;
    if(D-dist <= 0)
        cout << "Yes";
    else
        cout << "No";
        
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m;
  cin >> n >> m;

  ll suki[m]={};
  for(ll i=0;i<n;i++){
    ll k;
    cin >> k;
    for(ll j=0;j<k;j++){
      ll a;
      cin >> a;
      suki[a-1]++;
    }
  }
  ll s=0;
  for(ll i=0;i<m;i++)if(suki[i]==n)s++;

  cout << s << endl;

}

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

// N >= M なら最初に全部置けばよいので0
// N < M ならXiを小さい順に並び替える
// Xi(i+1)-Xi(i)のうち小さい方からM-Nこ選んでその距離の合計が回数になる

int N, M;
vector<int> Xi; 
vector<int> dist;

int main() {
  cin >> N >> M;
  Xi = vector<int>(M);
  dist = vector<int>(M-1);
  for (int i=0;i<M;i++){
    cin >> Xi.at(i);
  }

  int ans = 0;
  if (N>=M){
    ans=0;
  } else {
    sort(Xi.begin(),Xi.end());
    for(int i=0;i<M-1;i++){
      dist.at(i) = Xi.at(i+1)-Xi.at(i);
    }
    sort(dist.begin(),dist.end());
    for(int i=0;i<M-N;i++){
      ans += dist.at(i);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
S = int(input())
ans = "NA"
up2 = (S // 100) % 100
du2 = S % 100

if 0 < up2 < 13 and 0 < du2 < 13:
    ans = "AMBIGUOUS"
elif up2 > 12 and 0 < du2 < 13:
    ans = "YYMM"
elif du2 > 12 and 0 < up2 < 13:
    ans = "MMYY"
elif du2 == 0 and 0 < up2 < 13:
    ans = "MMYY"
elif up2 == 0 and 0 < du2 < 13:
    ans = "YYMM"
else:
    ans = "NA"

print(ans)


Measured memory_bytes: 3060
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int N = s.length();
        int K = sc.nextInt();
        String[] sub = new String[N * K];
        Arrays.fill(sub, "zzzzzz");
        int cnt = -1;
        for(int i = 1; i <= Math.min(N, K); i++)
            for(int j = 0; j < N - i + 1; j++)
                sub[++cnt] = s.substring(j, j + i);
        Arrays.sort(sub);
        String ans = "";
        int count = 0;
        for(int i = 0; i < N * K; i++){
            if(!sub[i].equals(ans)){
                ans = sub[i];
                count++;
            }
            if(count == K) break;
        }
        System.out.println(ans);   
    }
}

Measured memory_bytes: 26964
#!/usr/bin/env python3


def main():
    a, b = input_line(int, int)
    if a > 9 or b > 9:
        print(-1)
    else:
        print(a * b)


def input_line(*types):
    if len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
def main(N,M,a):
    dp = [-1]*N
    dp[0] = 1
    if N != 1:
        dp[1] = 2
    for i in a:
        if i == 1:
            dp[0] = 0
            dp[1] = 1
        else:
            dp[i-1] = 0
    for i in range(2,N):
        if dp[i] != 0:
            dp[i] = dp[i-1] + dp[i-2]
    return dp[-1]
N,M = map(int, input().split())
a = list(int(input()) for i in range(M))

print(main(N,M,a) % 1000000007)

Measured memory_bytes: 460020
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define  all(v)            v.begin(), v.end()
#define  sz(x)             (int)x.size()
#define  debug(x)          cout << '>' << #x << ':' << x << endl;
#define  rep(i,n)          for(int i = 0; i <  n ; i++)
#define  reps(i,n)         for(int i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  rot(v)            rotate(v.begin(), v.begin() + k, v.end());
#define  rmv(v,a)          v.erase(remove(v.begin(),v.end(), a), v.end());
#define  max(x,y)          ((x>y)?x:y)
#define  min(x,y)          ((x<y)?x:y)
#define  pb                push_back
#define  eb                emplace_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second
#define  ajs(a)            (a<0)?(-1*a):a
using namespace std;
typedef long long          ll;
// use count() instead of find() in sets.
const ll MOD = 1e9 + 7;
const double PI  = acos(-1.0);
const double EPS = (1e-10);
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = { -1, 0, 1, 0};
const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}
int dcp(double A, double B){return fabs(A-B)<=EPS ? 0 : A<B ? -1:1;}


ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m ){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}




int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;cin>>n;
ll a[n+1],b[n+1],c[n+1];

reps(i,n){
cin>>a[i]>>b[i]>>c[i];
}

ll dp[n+1][4];
memset(dp,0,sizeof(dp));
for(ll i = 1; i<= n ;i++){
    dp[i][1] = max(dp[i-1][2] + a[i] , dp[i-1][3] + a[i]);
     dp[i][2] = max(dp[i-1][1] + b[i] , dp[i-1][3] + b[i]);
      dp[i][3] = max(dp[i-1][1] + c[i] , dp[i-1][2] + c[i]);


}


ll ans = max(dp[n][1] ,max(dp[n][2] , dp[n][3]) );
cout<<ans;

}





Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int)1e6 + 34;
//const ll INF = (ll)1e18 + 41;
const int INF = (int)1e9 + 41;
const ll MD = (ll)1e9 + 7;

int dp[N];
void solve() {
    int n, md, sum = 0;
    scanf("%d%d", &n, &md);
    map<ll, int> m;
    ll ans = 0;
    m[0] = 1;

    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        sum = (sum + x) % md;
        ans += m[sum];
        m[sum]++;
    }

    cout << ans << "\n";
}

int main() {
#ifdef MADE_BY_SERT
    freopen("a.in", "r", stdin);
    solve();
    solve();
#endif // MADE_BY_SERT
    solve();
}


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

int main(){

  int A[2001]={1};

  int a, n, key, q;
  int i, j;

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

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



Measured memory_bytes: 2052
N, M = map(int, input().split())
l, r = 1, N
for i in range(M):
    L, R = map(int, input().split())
    l, r = max(l, L), min(r, R)
if r - l >= 0:
    print(min(r - l + 1, N))
else:
    print(0)

Measured memory_bytes: 9004
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			string[] sar = s.Split(' ');
			int[] a = new int[n];
			long sum = 0;
			for (int i = 0; i < n; i++)
			{

				a[i] = int.Parse(sar[i]);
				sum += a[i];
			}
			Array.Sort(a);
			Console.WriteLine("{0} {1} {2}", a[0].ToString("D"), a[n-1].ToString("D"), sum.ToString("D"));
		}
	}
}

Measured memory_bytes: 9964
import sys
N = int(input())
work = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
work_soted = sorted(work, key=lambda x:(x[1], -x[0]))

bool = True
time = 0
for i in range(N):
    time += work_soted[i][0]
    if time > work_soted[i][1]:
        bool = False
        break
    
if bool:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 74112
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(a) (int)a.size()-1
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=2e5+10;
int nxt[M],to[M],head[M],cnt,id[M];
void add(int x,int y,int p){
	nxt[++cnt]=head[x]; id[cnt]=p; to[cnt]=y; head[x]=cnt;
}
bool vv[M],vis[M],st[M];
vector<pair<int,int> > ans;
int n,m;
void dfs(int x,int fa,int ddd){
////	cout<<x<<"\n";
	vv[x]=1;
	int de=0,rr=0;
	for (int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if (vv[y]) continue;
		dfs(y,x,i);		
	}
	for (int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if (y==fa) continue;
		if (vis[y] && st[id[i]]) de++;
		if (!vis[y]) st[id[i]]=1,ans.pb(make_pair(y,x));
	}
	vis[x]=1;
	if (!fa) return ;
	if (de&1) ans.pb(make_pair(x,fa));
	else st[id[ddd]]=1,ans.pb(make_pair(fa,x));
}
int main(){
	n=read(); m=read();
	if (m&1) return puts("-1"),0;
	F(i,1,m){
		int x=read(),y=read();
		add(x,y,i); add(y,x,i);
	}
	dfs(1,0,0);
	F(i,0,SZ(ans)) cout<<ans[i].first<<" "<<ans[i].second<<"\n";
	return 0;
}



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

#define FileIO freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout);  ios_base::sync_with_stdio(0);
#define IO ios_base::sync_with_stdio(0);  cin.tie(0);  cout.tie(0); 
#define ll long long
#define endl "\n"
#define mod 1000000007

int main()
{
    IO;
    set<int> out;
    for(int i = -3; i <= 200; i++)
    {
        out.insert(i);
    }
    int n,x;
    cin>>x>>n;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        out.erase(a[i]);
    }
    n = out.size();
    int arr[n]={};
    int j = 0;
    for(int i : out)
    {
        arr[j++] = i;
    }
    int idx[3]={};
    idx[0] = lower_bound(arr, arr+n, x) - arr;
    idx[1] = idx[0] + 1;
    idx[2] = idx[0] - 1;
    
    int diff[3]={};
    diff[0] = abs(x - arr[idx[0]]);
    diff[1] = abs(x - arr[idx[1]]);
    diff[2] = abs(x - arr[idx[2]]);

    int ans = arr[idx[0]], d = INT_MAX;
    j = 0;
    for(int i : diff)
    {
        if(i < d)
        {
            d = i;
            ans = arr[idx[j]];
        }
        if(i == d)
        {
            ans = min(arr[idx[j]], ans);
        }
        j++;
    }

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

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int main(){
	int n;
	cin>>n;
	int m=101;
	int sum=0;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		if(t%10!=0){
			m=min(m,t);
		}
		sum+=t;
	}
	if(sum%10==0){
		sum=sum-m;
	}
	if(m==101){
		sum=0;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
// 2014/07/16 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int a, b;
		char op;
		cin >> a >> op >> b;

		if(op=='?')
			break;

		switch(op){
		case '+':
			cout << a+b << endl;
			break;
		case '-':
			cout << a-b << endl;
			break;
		case '*':
			cout << a*b << endl;
			break;
		case '/':
			cout << a/b << endl;
			break;
		default:
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

int main() {
  /* code */
  int N;
  cin >> N;
  int x, y, z;
  x = N /100;
  y = N /10 - x*10;
  z = N -(x*100 + 10*y);

  if(x==7||y==7||z==7) cout << "Yes";
  else cout << "No";

  return 0;
}


Measured memory_bytes: 3628
//                                               KEEP GRINDING
#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; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>   new_data_set;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define int long long
#define ld long double
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<"\n========================================\n";
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define PQ priority_queue
#define LB lower_bound  
#define UB upper_bound   

#define fr first
#define sc second

#define MAXN 500010
#define INF 9223372036854775807
int fac[MAXN],MOD=1000000007;
int power(int x, int y, int m=MOD) { 
    if (y == 0) 
        return 1; 
    int p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
}  
int nCr(int n,int r,int M=MOD){
    int num=fac[n],den=(fac[r]*fac[n-r])%MOD;
    den = power(den,M-2,M);
    int ans = (num*den)%M;
    return ans;
}
void solve(){
	int n,m;
	cin>>n>>m;
	int A=0,B=0;
	A=(nCr(m,n)*fac[n])%MOD;
	f(i,0,n+1){
		B +=( ( ( nCr(n,i) * nCr(m-i,n-i) )%MOD * fac[n-i] )%MOD * ( i&1 ? -1 : 1) )%MOD + MOD;
		B %= MOD ;
	}
	A=(A*B)%MOD;
	cout<<A;
}
signed main(){
    fastio
    int t=1;
    fac[0]=1;
    f(i,1,MAXN)	fac[i]=(fac[i-1]*i)%MOD;
    for(;t--;solve());
}

Measured memory_bytes: 7528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N,M;
  cin>>N>>M;
  VI L(M),R(M);
  rep(i,M) cin>>L[i]>>R[i];
  VI X(N+1);
  rep(i,M){
    X[L[i]-1]++;
    X[R[i]]--;
  }
  int ans=0;
  rep(i,N){
    if(i) X[i]+=X[i-1];
    if(X[i]==M) ans++;
  }
  cout<<ans<<endl;
}


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 2e5+5;

int n;
pair<ll,ll>a[N];

bool cmp(const pair<ll,ll> &x,const pair<ll,ll> &y){
    return x.second<y.second;
}

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

    for(int i=1;i<=n;i++){
        cin>>a[i].first>>a[i].second;
    }

    sort(a+1,a+1+n,cmp);
    ll t=0;

    for(int i=1;i<=n;i++){
        t+=a[i].first;
        if(t>a[i].second){
            cout<<"No";
            return 0;
        }
    }

    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;
using ll = long long;

#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == x)return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

ll N, M;
string S;
vector<edge> X[100010];
bool B[100010];
int D[100010];

int main() {
    cin >> N;
    int sum4 = 0, sum2 = 0, sumo = 0;
    REP(i, N) {
        int a;
        cin >> a;
        if (a % 4 == 0)sum4++;
        else if (a % 2 == 0)sum2++;
        else sumo++;
    }
    if (sum2 > 0)sumo++;
    if ((sum4 + 1) < sumo)PRI("No")
    else
        PRI("Yes");
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


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



int n;
string S;
string SS[4] = { "dream", "dreamer", "erase", "eraser" };
bool dfs(int cur) {
	if (cur == n) return true;

	bool ret = false;

	rep(i, 0, 4) {
		int nn = cur + SS[i].length();
		if (n < nn) continue;
		bool ok = true;
		rep(j, 0, SS[i].length()) {
			if (S[cur + j] != SS[i][j]) ok = false;
		}
		if (!ok) continue;
		
		ret |= dfs(cur + SS[i].length());
	}

	return ret;
}
//-----------------------------------------------------------------
int main() {
	cin >> S;
	n = S.length();
	
	if (dfs(0))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

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

int main(){
  int t1, t2, t3, t4, n1, n2, n3, n4;
  cin>>t1>>n1>>t2>>n2>>t3>>n3>>t4>>n4;
  if(t1 == 1)cout<<6000 * n1<<endl;
  if(t1 == 2)cout<<4000 * n1<<endl;
  if(t1 == 3)cout<<3000 * n1<<endl;
  if(t1 == 4)cout<<2000 * n1<<endl;
  if(t2 == 1)cout<<6000 * n2<<endl;
  if(t2 == 2)cout<<4000 * n2<<endl;
  if(t2 == 3)cout<<3000 * n2<<endl;
  if(t2 == 4)cout<<2000 * n2<<endl;
  if(t3 == 1)cout<<6000 * n3<<endl;
  if(t3 == 2)cout<<4000 * n3<<endl;
  if(t3 == 3)cout<<3000 * n3<<endl;
  if(t3 == 4)cout<<2000 * n3<<endl;
  if(t4 == 1)cout<<6000 * n4<<endl;
  if(t4 == 2)cout<<4000 * n4<<endl;
  if(t4 == 3)cout<<3000 * n4<<endl;
  if(t4 == 4)cout<<2000 * n4<<endl;

  return 0;
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  llong k, a, b;
  cin >> k >> a >> b;

  llong ans = 0;

  if(b - a <= 2){
    cout << k+1 << endl;
    return 0;
  }else{
    if(k - a < 0){
      cout << k+1 << endl;
      return 0;
    }
    llong res = k - (a+1);
    ans += b;
    if(res % 2 == 0){
      ans += res / 2 * (b-a);
    }else{
      ans += (res-1) / 2 * (b-a);
      ans++;
    }
  }

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
ll n,k;
ll  a[200005];
int main()
{
	int i,j,k;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i+k<n;i++)
	{
		if(a[i]<a[i+k])
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl; 
	}
    return 0;
    
}

Measured memory_bytes: 5168
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    struct P {
        ll l, r;
    };
    V<P> ps(n);
    ll lw = -1, up = TEN(9) + 10;
    for (int i = 0; i < n; i++) {
        cin >> ps[i].l >> ps[i].r; ps[i].r++;
        lw = max(lw, ps[i].l);
        up = min(up, ps[i].r);
    }

    ll ans = 0;
    if (lw < up) {
        ll di = up - lw;
        ans += 2 * di;
        for (int i = 0; i < n; i++) {
            ps[i].r -= di;
        }
    }

    sort(ps.begin(), ps.end(), [&](P a, P b) {
        return a.l < b.l;
    });

    multiset<ll> ls, rs;
    for (int i = 0; i < n; i++) {
        ls.insert(ps[i].l);
        rs.insert(ps[i].r);
    }

    ll ma = 0;
    lw = -1; up = TEN(9) + 10;
    for (int i = 0; i < n - 1; i++) {
        lw = max(lw, ps[i].l);
        up = min(up, ps[i].r);
        ls.erase(ls.find(ps[i].l));
        rs.erase(rs.find(ps[i].r));
        ll lw1 = *ls.rbegin();
        ll up1 = *rs.begin();
        ll buf = 0;
        buf += max(0LL, up - lw);
        buf += max(0LL, up1 - lw1);
        ma = max(ma, buf);
    }
    for (int i = 0; i < n; i++) {
        ma = max(ma, ps[i].r - ps[i].l);
    }

    cout << ans + ma << endl;
    return 0;
}


Measured memory_bytes: 11264
N = int(input())
W_list = list(map(int, input().split()))

S1 = 0
S2 = sum(W_list)
res = abs(S2 - S1)
for i in range(N):
    S1 += W_list[i]
    S2 -= W_list[i]
    r = abs(S2 - S1)
    if r < res:
        res = r

print(res)

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

bool cmp(pair<long long,int>one,pair<long long ,int>two){
    return one.first>two.first;
}
//status unsolved
int main(){
    long long x,y,A,B,C;
    cin>>x>>y>>A>>B>>C;
    vector<pair<long long,int>>apple(300010);

    rep(i,(A+B+C)){
        int color;
        if(i<A)color=1;
        else if(i<A+B)color=2;
        else color=3;

        long long taste;
        cin>>taste;
        apple[i]=make_pair(taste,color);
    }
    sort(apple.begin(),apple.end(),cmp);
    //reverse(apple.begin(),apple.end());

    int cn=0,cx=0,cr=0;
    long long ans=0;
    rep(i,A+B+C){
        
        int cl=apple[i].second;
        if((cl==1 && cx==x) || (cl==2 && cr==y) )continue;

        ans+=apple[i].first;
        if(cl==1){
            cx++;
        }
        else if(cl==2){
            cr++;
        }
        else{
            cn++;
        }

        if(cx+cr+cn==x+y)break;

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

}
/*


*/


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a, b;
void f(int from, int to, int mask){
	if(__builtin_popcount(mask) == n-1){
		printf("%d %d ", from, to);
		return;
	}
	int c = -1, e = -1;
	for(int i=0; i<n; i++) if(!(mask>>i&1)){
		if(c == -1 && (from>>i&1) != (to>>i&1)) c = i;
		else e = i;
	}
	f(from, from^(1<<e), mask^(1<<c));
	f(from^(1<<e)^(1<<c), to, mask^(1<<c));
}
int main(){
	scanf("%d%d%d", &n, &a, &b);
	if(__builtin_popcount(a^b)%2 == 0) puts("NO");
	else{
		puts("YES");
		f(a,b,0);
	}
}

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

int main() {
    int N, K, x, num=0;
    
    cin >> N >> K;

    for(int i=0;i<N;i++) {
        cin >> x;
        if(x < K-x) num += 2*x;
        else num += 2*(K-x);
    }

    cout << num << endl;
}

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;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<ll> div(n);
  for(int i=1; i<=n; ++i) {
    for(int j=i; j<=n; j+=i) {
      div[j]++;
    }
  }
  ll ans=0;
  for(int i=1; i<=n; ++i) {
    ans += i * div[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81376
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ary = []
for _ in range(n):
    ary.append(list(map(int, input().split())))
ary.sort()

res = 0
for (a, b) in ary:
    if m-b>0:
        m -= b
        res += a*b
    else:
        res += a*m
        break
print(res)

Measured memory_bytes: 56540
#include <stdio.h>

int main()
{
	long long N;
	scanf("%lld", &N);
	
	int i;
	char name[100] = {};
	for (i = 50; N > 0; N = (N - 1) / 26) name[--i] = 'a' + (N - 1) % 26;
	printf("%s", &(name[i]));
	fflush(stdout);
	return 0;
}

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

int main(void) {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> L(N);
  rep(i, N) cin >> L[i];
  sort(L.rbegin(), L.rend());
  int answer = 0;
  rep(i, K) answer += L[i];
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3648
import sys

x, y, z, k = map(int, sys.stdin.readline().split())

xlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(x, k)]
ylist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(y, k)]
zlist = sorted(list([int(i)
                     for i in sys.stdin.readline().split()]), reverse=True)[:min(z, k)]


anslist = [0]
for i in range(min(x, k)):
    for j in range(min(y, k)):
        for l in range(min(z, k)):
            if (i+1)*(j+1)*(l+1) <= k:
                anslist.append(xlist[i] + ylist[j] + zlist[l])
            else:
                break

anslist = sorted(anslist, reverse=True)
for i in range(k):
    print(anslist[i])


Measured memory_bytes: 50496
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;

int main(){
    int K;
    cin>>K;
    
    queue<long long> q;
    for(int i=1;i<10;i++){
        q.push(i);
    }

    int cnt=0;
    long long node;
    while(!q.empty()){
        node=q.front();q.pop();
        cnt++;
        if(cnt==K){
            cout<<node<<endl;
            break;
        }
        int tmp=node%10;
        if(tmp!=0){
            q.push(node*10+tmp-1);
        }
        q.push(node*10+tmp);
        if(tmp!=9){
            q.push(node*10+tmp+1);
        }
    }
    

    return 0;
}

Measured memory_bytes: 5076
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    int t;
    while (n--) {
        cin >> t;
        a.push_back(t);
    }
    int sum = 0;
    for( int i=0; i<a.size(); i++ ){
        for( int j=i+1; j<a.size(); j++ ){
            sum += a[i]*a[j];
        }
    }
    cout << sum;
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> b(n,0);
    rep(i,n-1){
        int ai; cin >> ai;
        ai--;
        b[ai]++;
    }

    rep(i,n){
        cout << b[i] << endl;
    }
}


Measured memory_bytes: 4048
#include<stdio.h>

int main(){
	int n,m,q,i,j,a[128],d,maxs,e;
	while(1){
		scanf("%d %d",&n,&q);
		if(n==0&&q==0)break;
		for(i=0;i<128;i++)a[i]=0;
		maxs=0;e=0;
		for(i=0;i<n;i++){
			scanf("%d",&m);
			for(j=0;j<m;j++){
				scanf("%d",&d);
				a[d]++;
			}
		}
		for(i=0;i<128;i++){
			if(a[i]>=q){
				if(a[i]>maxs){
					maxs=a[i];
					e=i;
				}
			}
		}
		printf("%d\n",e);
	}
	return 0;
}

Measured memory_bytes: 1028
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define fi first
#define se second
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200020;
const double pi = 3.141593; const double EPS = 1e-12;
const ll INF = 2e18;
const int INT_INF = 1e9;
typedef pair<double, double>Pd;
double dist(P& p1, P& p2) {
	return sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
}
double dist(Pd& p1, Pd& p2) {
	return sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
}

//10^7までの素数を列挙する
bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 100000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i * (j + 2)] = 0;
			}
		}
	}

	for (ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			c++;
		}
	}
}

void solve() {
	int x; cin >> x;
	if (x < 1200)print("ABC");
	else print("ARC");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>

inline void
rep(int n, std::function<void(int)> f) {
    for (int i = 0; i < n; i++) {
        f(i);
    }
};

typedef std::pair<int, int> P;

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	
	int n, r = 0, b = 0;
	std::string s;
	
	std::cin >> n;
	std::cin.ignore();
	std::cin >> s;
	std::cin.ignore();
	
	//int index = static_cast<int>(s.find("AC"));
	for (const auto& e : s) {
		if (e == 'R') {
			r++;
		}
		else if (e == 'B') {
			b++;
		}
	}
	if (r > b) {
		std::cout << "Yes" << '\n';
	}
	else {
		std::cout << "No" << '\n';
	}
	return 0;
}



Measured memory_bytes: 256