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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int INF = 1'000'000'100;
int N, A[3];
int ls[10];
int sum[1<<8];
int dp[3][1<<8];

int rec(int i, int s){
    if(i == 3){
        return 0;
    }

    if(dp[i][s] != -1){
        return dp[i][s];
    }

    int res = INF;

    for(int t=1;t<(1<<N);++t){
        if(t & s){
            continue;
        }

        res = std::min(res, 10 * (__builtin_popcount(t) - 1) + std::abs(A[i] - sum[t]) + rec(i + 1, s | t));
    }

    return dp[i][s] = res;
}

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

    std::cin >> N;

    for(int i=0;i<3;++i){
        std::cin >> A[i];
    }

    for(int i=0;i<N;++i){
        std::cin >> ls[i];
    }

    for(int i=0;i<(1<<N);++i){
        for(int j=0;j<N;++j){
            if(i >> j & 1){
                sum[i] += ls[j];
            }
        }
    }

    memset(dp, -1, sizeof(dp));

    int minCost = rec(0, 0);
    std::cout << minCost << std::endl;
}


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

int main() {
	int a,b,c,sum=3;
	cin>>a>>b>>c;
	if(a==b){
	    sum--;
	}
	if(a==c){
	    sum--;
	}
	if(b==c){
	    sum--;
	}
        if(sum==0){
           sum=1;
        }
	cout<<sum<<'\n';
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map{it.toLong()}
    println(a*b/gcd(a, b))
}

fun gcd(a: Long, b: Long) : Long {
    return if (b == 0L) a else gcd(b, a % b)
}

Measured memory_bytes: 38032
#include<stdio.h>
int main(void){
	int H, W;
	int i, j;
	while(1){
		//数値を2つ入力
		scanf("%d %d", &H, &W);
		//数値が2つとも0なら終了
		if(H == 0 && W == 0){
			break;
		}
		//長方形を出力
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(j == (W - 1)){
					printf("#\n");
				}else{
					printf("#");
				}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
import sys
from collections import Counter
M = {}
N = int(input())
ans = 0
for _ in range(N):
  S = input()
  S = ''.join(sorted(S))
  if S not in M:
    M[S] = 1
  else:
    ans += M[S]
    M[S] += 1
print(ans)

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


import fractions
import functools


def gcds(xs):
    return functools.reduce(fractions.gcd, xs)


def max_d(x, ys):
    return abs(gcds(y - x for y in ys))


def main():
    n, x = (int(z) for z in input().split())
    ys = [int(z) for z in input().split()]
    print(max_d(x, ys))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16324
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[200000];
	ll goukei = 0;
	rep(i, N) goukei += (A[i] = getint());


	ll kotae = 1e18;

	int q = 1, s = 3;
	ll P[4];
	P[0] = A[0];
	P[1] = A[1];
	P[2] = A[2];
	P[3] = goukei - P[0] - P[1] - P[2];
	for (int r = 2; r < N - 1; r++) {
		while (abs(P[0] - P[1]) > abs(P[0] - P[1] + 2 * A[q])) {
			P[0] += A[q];
			P[1] -= A[q];
			q++;
		}
		while (abs(P[2] - P[3]) > abs(P[2] - P[3] + 2 * A[s])) {
			P[2] += A[s];
			P[3] -= A[s];
			s++;
		}
		ll kari = *max_element(P, P + 4) - *min_element(P, P + 4);
		kotae = min(kotae, kari);

		P[1] += A[r];
		P[2] -= A[r];
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
def main():
    k=int(input())
    a, b= map(int,input().split())

    if b-a > k:
        print('OK')
        return

    else:
        for i in range(a, b+1):
            if i % k == 0:
                print('OK')
                return
                break

        print('NG')


if __name__ == '__main__':
    main()

Measured memory_bytes: 61668
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int K,S;
    cin>>K>>S;
    int sum=0;
    
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            if(S-x-y>=0 && S-x-y<=K){
                sum+=1;
            }
        }
    }
    
    cout<<sum;
}


Measured memory_bytes: 256
#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;
#define MOD 1000000007
#define ll long long int
#define pi pair <ll,ll>
#define vi vector <ll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>       //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/


 
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll i,j,m,t,l=0,x,prev=0,max1=0,flag=0,cnt=0,y,min1,q,sum=0,r,n,k,p,flag2=0,ind=0,b;
    cin>>n>>k;
    ll a[n];
    ll dp[n];
    for(i=0;i<n;i++){
        dp[i]=INT_MAX;
    }
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0]=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<=i+k&&j<n;j++){
            dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
        }
       
    }
    cout<<dp[n-1];
    
 
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define max_ans 13

int num;
int cache[max_ans + 1];

int dfs(int depth, int max_depth)
{
	if (cache[depth] == num) // correct ans
		return 1;
	if (depth == max_depth) // reach max depth,break;
		return 0;
	int max_value = cache[0];
	for (int i = 1; i <= depth; i++) // find current max power
	{
		max_value = (((max_value) > (cache[i])) ? (max_value) : (cache[i]));
	}
	if ((max_value << (max_depth - depth)) < num) //return false if max_value*2^(left depth) still can't reach num.
		return 0;                                 //which means impossible to reach target num
	for (int i = depth; i >= 0; i--)
	{
		cache[depth + 1] = cache[depth] + cache[i];
		if (dfs(depth + 1, max_depth) == 1)
			return 1;
		cache[depth + 1] = cache[depth] - cache[i];
		if (dfs(depth + 1, max_depth) == 1)
			return 1;
	}
	return 0;
}

int main(int argc, char const *argv[])
{
	for (int input, output; scanf("%d", &input) && input != 0; printf("%d\n", output))
	{
		num = input;
		output = -1;
		if (input == 1)
			output = 0;
		else
		{
			cache[0] = 1;
			for (int i = 0; i < max_ans; i++)
			{
				if (dfs(0, i) == 1)
				{
					output = i;
					goto b1;
				}
			}
			if (output == -1)
				output = max_ans;
		b1:
			output = output;
		}
	}
	return 0;
}



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


int main() {
	string S,T;
	cin>>S>>T;
	int count=0;
	for(int i=0;i<3;i++){
		if(T.at(i)==S.at(i)){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self, labels):
        self.labels = labels
    def east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    def west(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[2], self.labels[5], self.labels[3], self.labels[0]
    def north(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[1], self.labels[5], self.labels[4], self.labels[0]
    def south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]

dice = Dice(list(map(int, input().split())))

for n in range(int(input())):
    top, foward = map(int, input().split())
    south_cnt = 0

    while True:
        #print(dice.labels[0], dice.labels[1], dice.labels[2], dice.labels[4], dice.labels[3])
        if foward == dice.labels[1] and top == dice.labels[0]:
            break
        if foward == dice.labels[1]:
            dice.east()
        elif top == dice.labels[0]:
            dice.south()
            dice.east()
            dice.north()
        else:
            if south_cnt == 3:
                dice.east()
            else:
                dice.south()
                south_cnt += 1
    print(dice.labels[2])




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

#define ub              upper_bound
#define lb              lower_bound
#define isrt            insert
#define clr             clear
#define rsz             resize
#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mkp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<int>
#define mii             map<lli,lli>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define INF             1e9
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define endl            "\n"


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

lli maxm(lli a, lli b)
{
    return (a >= b ? a : b);
}


lli minm(lli a, lli b)
{
    return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
    lli res = 1;

    x = x % p;
    if (x == 0)
        return 0;

    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;


        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
    if (r == 0)
        return 1;
    if (r == 1)
        return n;


    lli pro = 1, k = n;
    while (k > r)
    {
        pro *= k;
        pro %= p;
        --k;
    }

    k = 2;
    while (k <= (n - r))
    {
        pro *= power(k, (p - 2), p);
        pro %= p;
        ++k;
    }

    return pro;
}


string num_str(lli n, lli k)
{
    string str = "";
    lli x = n;
    while (x != 0)
    {
        string s = to_string(x % k);
        str = s + str;
        x /= k;
    }

    return str;
}


lli first_big(lli n, lli k, lli arr[])
{
    lli l = 0;
    lli r = n - 1;

    lli leftGreater = n;

    while (l <= r) {
        lli m = l + (r - l) / 2;

        if (arr[m] > k) {
            leftGreater = m;
            r = m - 1;
        }

        else
            l = m + 1;
    }

    return leftGreater;
}

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main()
{
    c_p_c();

    int n;
    cin >> n;
    string str;
    vector<int> cnt(4);

    for (int i = 0; i < n; ++i)
    {
        cin >> str;
        if (str == "AC")
            ++cnt[0];
        if (str == "WA")
            ++cnt[1];
        if (str == "TLE")
            ++cnt[2];
        if (str == "RE")
            ++cnt[3];
    }

    cout << "AC x " << cnt[0] << endl;
    cout << "WA x " << cnt[1] << endl;
    cout << "TLE x " << cnt[2] << endl;
    cout << "RE x " << cnt[3] << endl;

    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
const int INF = 2147483647;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, K;
int x[55];
int y[55];

int main()
{
	cin >> n >> K;
	for (int i = 0;i < n;i++) {
		cin >> x[i] >> y[i];
	}

	ll ans = 9223372036854775807;

	for(int x1 = 0;x1<n;x1++)
		for (int x2 = 0;x2<n;x2++)
			for (int y1 = 0;y1<n;y1++)
				for (int y2 = 0;y2 < n;y2++) {

					int l = std::min(x[x1], x[x2]);
					int r = std::max(x[x1], x[x2]);
					int d = std::min(y[y1], y[y2]);
					int u = std::max(y[y1], y[y2]);

					int temp = 0;

					for (int i = 0;i < n;i++) {
						if (l <= x[i] && x[i] <= r && d <= y[i] && y[i] <= u) temp++;
					}
					
					if (temp >= K) {
						ll menseki = (ll)(r - l) * (ll)(u - d);
						if (ans > menseki) ans = menseki;
						
					}
				}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

from collections import Counter
c = Counter(rs())
f = False
if (c['N'] > 0 and c['S'] > 0) or (c['N'] == 0 and c['S'] == 0):
    if (c['W'] > 0 and c['E'] > 0) or (c['W'] == 0 and c['E'] == 0):
        f = True
print('Yes' if f else 'No')

Measured memory_bytes: 9136
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}


int main() {
    
    string s;
    cin >> s;
    string t;
    
    while(1){
        t = "";
        
        while (t != "dream" && t != "dreamer" && t != "erase" && t != "eraser" && t.size() < 8 && s.size() != 0){
            t.insert(t.begin(),s.back());
            s.pop_back();
        }
        
        if (t.size() == 8) { ///該当パターンなし
            cout << "NO" << endl;
            return 0;
        }
        
        if (s.size() == 0){ ///端まで到達。
            
            if (t != "dream" && t != "dreamer" && t != "erase" && t != "eraser"){
                cout << "NO" << endl;
                return 0;
            }
            else{
                cout << "YES" << endl;
                return 0;
            }
            
        }
    }
    
    return 0;
    
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int[] a = {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};
		System.out.println(a[x-1]);
	}
}

Measured memory_bytes: 23124
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    A,B=map(int,input().split())
    for i in range(1,100000):
        if int(i*0.08)==A and int(i*0.1)==B:
            print(i)
            exit()
    print(-1)

if __name__ == '__main__':
    main()


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

const int sz=1e5 + 4;
int n , a[sz];
long long  mokh[sz];

long long _try(int stone ){
    if (stone==n-1){
        return 0;
    }
    if (stone>n-1){
        return 2e9;
    }
    if (mokh[stone]!=-1){
        return mokh[stone];
    }

    long long ans1 = abs(a[stone] - a[stone+1]) + _try(stone+1);

    long long ans2 = abs(a[stone] - a[stone+2]) + _try(stone+2);

    return mokh[stone] = min (ans1 , ans2);

}

int main (){
    scanf("%d" , &n);
    for (int i=0 ; i<n ; i++){
        scanf("%d" , &a[i]);
    }
    memset(mokh , -1 , sizeof mokh);
    printf("%d\n",_try(0));

return 0;}


Measured memory_bytes: 4480
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int N, R, p, c;

int main()
{
	while (cin >> N >> R && N) {
		vector<int> A(N+1, 0);
		
		for (int i = 0; i < N; i++) {
			A[i] = N - i;
		}

		for (int i = 0; i < R; i++) {
			cin >> p >> c;
			rotate(A.begin(), A.begin() + p - 1, A.begin() + p + c - 1);	
		}

		cout << A[0] << endl;
	}

    return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
	int N;
	cin >> N;
	long ans=0;
	for(int i=1;i<=N;i++){
		if(i%3 != 0 && i%5 != 0)ans += i; 
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
    int n,i;
    int m[5];
    m[0]=m[1]=m[2]=m[3]=m[4]=0;
    char s[11];
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%s",s);
        switch(s[0]) {
            case 'M':
                m[0]++;
                break;
            case 'A':
                m[1]++;
                break;
            case 'R':
                m[2]++;
                break;
            case 'C':
                m[3]++;
                break;
            case 'H':
                m[4]++;
                break;
            default:
                break;
        }
    }
    int j,k;
    long long count = 0;
    for (i=0;i<5;i++) {
        for (j=i+1;j<5;j++) {
            for (k=j+1;k<5;k++) {
                if (!m[i] || !m[j] || !m[k]) {
                    continue;
                }
                count += (long long)m[i] * m[j] * m[k];
            }
        }
    }
    printf("%lld\n",count);
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

const int MAX_N = 100000 + 10;
int par[MAX_N];
int tree_rank[MAX_N];
int cnt[MAX_N];

inline ll comb(ll a) {
  return a*(a-1LL)/2LL;
}

inline ll change(ll o1, ll o2, ll n) {
  return comb(n)-comb(o1)-comb(o2);
}

void init(const int n) {
  REP(i,n) {
    par[i] = i;
    tree_rank[i] = 0;
    cnt[i] = 1;
  }
}

int find(const 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(tree_rank[x] < tree_rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if(tree_rank[x] == tree_rank[y]) tree_rank[x]++;
  }
}

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

int main() {
  int N, M; cin>>N>>M;
  vector<ll> ans(1, comb(N));
  init(N);
  vector<pint> data(M);
  REP(i,M) {
    int a, b; cin>>a>>b; 
    data[M-1-i].first = a-1;
    data[M-1-i].second = b-1;
  }
  REP(i,M) {
    ll tmp = ans.back();
    int a = data[i].first;
    int b = data[i].second;
    if(!same(a, b)) {
      int o1 = cnt[find(a)];
      int o2 = cnt[find(b)];
      int n = o1 + o2;
      unite(a, b);
      cnt[find(a)] = n;
      //      cout << "Change" << " " << o1 << " " << o2 << "->" << n <<  endl;
      tmp -= change(o1, o2, n);
    }
    ans.push_back(tmp);
  }
  for(int i = ans.size() - 2; i >= 0; i--) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4212
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n= sc.nextInt();
    int AC= 0;
    int WA= 0;
    int TLE= 0;
    int RE= 0;
    for(int i = 0; i<n;i++){
      String a= sc.next();
      if(a.equals("AC")){
        AC++;
      }
      if(a.equals("WA")){
        WA++;
      }
      if(a.equals("TLE")){
        TLE++;
      }
      if(a.equals("RE")){
        RE++;
      }
      
    }
    System.out.println("AC x " +AC);
    System.out.println("WA x " +WA);
    System.out.println("TLE x " +TLE);
    System.out.println("RE x " +RE);
  }
}



Measured memory_bytes: 58908
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    Arrays.sort(a);
    int m = (int)a[n - 1];
    int[] b = new int[m + 1];
    int ans = 1;
    if((n > 1) && (a[0] == a[1])) ans = 0;
    for(int i = 0; i < n; i++) {
      if(b[(int)a[i]] == 0) {
        for(int j = (int)(2 * a[i]); j < m + 1; j += ((int)a[i])) {
          if(b[j] == 0) b[j] = 1;
        }
      }
    }
    for(int i = 1; i < n; i++) {
      if(a[i] != a[i - 1]) {
        if(i == (n - 1)) {
          if(b[(int)a[i]] == 0) ans++;
        } else if(a[i] != a[i + 1]) {
          if(b[(int)a[i]] == 0) ans++;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 63568
# ABC045B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
def main():
    A, B, C = tuple(list(input().rstrip()) for _ in range(3))
    cards = {"A": A, "B": B, "C": C}
    cur = cards["A"].pop(0).capitalize()
    while True:
        if not cards[cur]:
            print(cur)
            return
        cur = cards[cur].pop(0).capitalize()


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) {
 if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> a(N-1), b(N-1);
  rep(i, N-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  vector<int> p(Q), x(Q);
  rep(i, Q) {
    cin >> p[i] >> x[i];
    p[i]--;
  }
  vector<vector<int>> to(N);
  rep(i, N-1) {
    to[a[i]].push_back(b[i]);
    to[b[i]].push_back(a[i]);
  }
  vector<int> node(N);
  rep(i, Q) node[p[i]] += x[i];
  queue<pair<int, int>> que;
  que.push({0, -1});
  while(!que.empty()) {
    pair<int, int> tmp = que.front();
    que.pop();
    rep(j, to[tmp.first].size()) {
      if(to[tmp.first][j] == tmp.second)
        continue;
      node[to[tmp.first][j]] += node[tmp.first];
      que.push({to[tmp.first][j], tmp.first});
    }
  }
  rep(i, N) {
    if(i)
      cout << " ";
    cout << node[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 19444
#include <stdio.h>

int
main()
{
	for (;;) {
		int w, h;
		scanf("%d %d", &h, &w);

		if (w == 0 && h == 0)
			break;

		int x, y;
		for (y = 0; y < h; y++)
		{
			for (x = 0; x < w; x++)
			{
				putchar('#');
			}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

vector<int> diff(vector<int> X){
    vector<int> Y;
    REP(i,X.size()-1){
        Y.push_back(abs(X[i]-X[i+1]));
    }
    return Y;
}

int two[1114514]={};
int twof[1114514]={};

int nCr(int n,int r){
    int R=0;
    R+=twof[n];
    R-=twof[r];
    R-=twof[n-r];
    return R==0;
}

signed main(void){
    int N;
    string a;
    vector<int> A;
    cin >> N;
    cin >> a;
    REP(i,N){
        A.push_back(a[i]-'0');
    }
    /*
    REP(i,A.size()){
        cout << A[i] << " ";
    }cout << endl;*/
    
    REP(i,N+1){
        if(i==0)continue;
        if(i%2==0)two[i]=1+two[i/2];
    }
    REP(i,N+1){
        if(i==0)continue;
        twof[i]=twof[i-1]+two[i];
    }
    
    vector<int> B = diff(A);
    if((B.size())%2==0){
        B = diff(B);
    }
    if(B.size()==1){
        cout << B[0] << endl;
        return 0;
    }
    
    
    
    
    bool one = false;
    REP(i,B.size()){
        if(B[i]==1)one=true;
    }
    
    if(one==false){
        int zero=0;
        REP(i,B.size()){
            if(nCr(B.size()-1,i)){
                zero^=B[i];
            }
        }
        
        if(zero==0){
            cout << 0 << endl;
        }else{
            cout << 2 << endl;
        }
    }else{
        REP(i,B.size()){
            if(B[i]==2){
                B[i]=0;
            }
        }
        
        int zero=0;
        REP(i,B.size()){
            if(nCr(B.size()-1,i)){
                zero^=B[i];
            }
        }
        
        if(zero==0){
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 47604
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  string s;
  cin >> s;
  int l = (int)s.size();
  bool a[26];
  for (int i = 0; i < 26; i++) a[i] = false;
  for (int i = 0; i < l; i++) a[s[i]-'a'] = true;
  if (l < 26) {
    int i = 0;
    while (a[i] == true) i++;
    s.push_back('a'+i);
    dump(s);
    return 0;
  }
  else {
    while (1) {
      a[s.back()-'a'] = false;
      s.pop_back();
      if (s.size() == 0) {
	dump(-1);
	return 0;
      }
      for (int i = 0; i < 26; i++) {
	if (s.back() < 'a'+i && a[i] == false) {
	  s.back() = 'a'+i;
	  dump(s);
	  return 0;
	}
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int A = scn.nextInt();
    int B = scn.nextInt();

    boolean found = false;
    for (int i = 0; i < Math.max(A, B); i++) {
      if (Math.abs(A - i) == Math.abs(B - i)) {
        System.out.println(i);
        found = true;
        break;
      }
    }
    if (!found) {
      System.out.println("IMPOSSIBLE");
    }
  }
}

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

const ll MAX = 1e5+3;
ll n;

struct knap
{
    ll a,b;
}val[102];

ll dp[102][MAX];

int main()
{
    ll n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
    {
        cin>>val[i].a>>val[i].b;
    }
    for(int i=1;i<=100;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j>=val[i].a)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-val[i].a]+val[i].b);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 78336
#include <stdio.h>

int main(){

  int i,n;
  int odd[100000],eve[100000],cou0=0,cou1=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    if(i%2==0) scanf("%d",&eve[cou0++]);
    else scanf("%d",&odd[cou1++]);
  }

  if(n%2!=0){
    for(i=cou0-1;i>=0;i--)printf("%d ",eve[i]);
    for(i=0;i<cou1;i++)printf("%d ",odd[i]);
  }else{
    for(i=cou1-1;i>=0;i--)printf("%d ",odd[i]);
    for(i=0;i<cou0;i++)printf("%d ",eve[i]);
  }

  printf("\n");

  return 0;

}



Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long W, H, x, y;

    cin >> W >> H >> x >> y;

    cout << (double) W * H / 2 ;

    if (W == 0 || H == 0) {
        cout << " 0" << endl;
    } else if (2*x == W && 2*y == H) {
        cout << " 1" << endl;
    } else {
        cout << " 0" << endl;
    }

}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	static HashMap<Long, Long> map = new HashMap<>();
	static final long MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();
		
		System.out.println(dfs(n+1));
	}

	static long dfs(long n){
		if(n == 1) return 1;
		if(n == 0) return 0;
		if(map.containsKey(n)) return map.get(n);
		long ret;
		if(n % 2 ==  1){
			ret = (2*dfs(n/2) + dfs(n/2+1)) % MOD;
			map.put(n, ret);
		}else{
			ret = (2*dfs(n/2) + dfs(n/2-1)) % MOD;
			map.put(n, ret);
		}
		return ret;
	}

}


Measured memory_bytes: 22612
import collections
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, P = ZZ()
    S = input()
    output = 0

    if P in {2, 5}:
        for i in range(N):
            if int(S[i])%P == 0: output += i+1
        print(output)
        return

    dp = [0] * (N+1)
    ex = 1
    for i in range(N):
        dp[i+1] = (int(S[-1-i])*ex + dp[i]) % P
        ex *= 10
        ex %= P

    d = collections.defaultdict(int)
    for i in range(N+1): d[dp[i]] += 1

    for i in d.keys(): output += (d[i] * (d[i]-1) // 2)
    print(output)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 11996
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int sgn(int x){return (x>0)-(x<0);}
int abs(int x){return x>0?x:-x;}
int a,b;
int main()
{
    scanf("%d%d",&a,&b);
    if(!a){if(b>=0)cout<<b<<endl;else cout<<1-b<<endl;return 0;}
    if(!b){if(a>0)cout<<a+1<<endl;else cout<<-a<<endl;return 0;}
    int ans=abs(abs(a)-abs(b));
    if(sgn(a)!=sgn(b))cout<<ans+1<<endl;
    else
    {
        if(a>b)cout<<ans+2<<endl;
        else cout<<ans<<endl;
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define maxn 203050

using namespace std;
typedef long long ll;
ll a[maxn],n,b[505][505],mx,c,o,r;
int p[maxn];
vector<ll> h[maxn];
bool vis[maxn];
ll lcm(ll x,ll y){
    return x/__gcd(x,y)*y;
}
map<ll,int> f;

int main(){
    cin >> n;
    //for (int i=0;i<n*n/2;i++) a[c++]=i+1;
    //for (int i=0;i<c;i++)cout<<a[i]<<' ';cout<<endl;
    //random_shuffle(a,a+c);
    o=3;
    for (int i=1;i<=n;i+=4)
        for (int j=1;j<=n;j+=2){
            b[i][j]=o;
            if (i<n&&j<n) b[i+1][j+1]=o*2;
            o+=2;
        }
    int pos=3; while (pos+4<=n) pos+=4;
    for (int i=pos;i>0;i-=4){
        for (int j=1;j<=n;j+=2){
            b[i][j]=o; o+=2;
            if (i<n&&j<n) b[i+1][j+1]=o*2;
        }
    }
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) f[b[i][j]]=1;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++) if ((i+j)%2==1){
            r=1;
            if (i>1) r=lcm(r,b[i-1][j]);
            if (i<n) r=lcm(r,b[i+1][j]);
            if (j>1) r=lcm(r,b[i][j-1]);
            if (j<n) r=lcm(r,b[i][j+1]);
            long long s=1;
            while (f[r*s+1]) s++;
            b[i][j]=r*s+1; f[b[i][j]]=1;
        }
    for (int i=1;i<=n;i++)
    for (int j=1;j<n;j++){
        ll x,y;
        x=max(b[i][j],b[i][j+1]);
        y=min(b[i][j],b[i][j+1]);
        assert(x%y==1);
    }
    for (int i=1;i<n;i++)
    for (int j=1;j<=n;j++){
        ll x,y;
        x=max(b[i][j],b[i+1][j]);
        y=min(b[i][j],b[i+1][j]);
        assert(x%y==1);
    }
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) mx=max(mx,b[i][j]);
    //cout<<mx<<endl;
    assert(mx<=1000000000000000ll);

    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++)cout<<b[i][j]<<' ';cout<<endl;
    }
    //cout << mx << endl;
}


Measured memory_bytes: 26496
// -_-
#include <bits/stdc++.h>
#define int long long
#define read(a) int a; cin >> a;
#define readarr(a, n) int a[(n) + 1] = {}; fori(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori(i, 1, n) {fori(j, 1, m) cin >> a[i][j];}
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define  sort1(v) sort(v.begin(), v.end()) 
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;


const long long inf2 = (long long)1e18;
const long long mod = (long long)(1e9+7);
const long long inf1 =(long long)(1e6+1);

vi h, a, tree;

int query (int v, int start, int end, int l, int r)
{
	if (r < start || l > end)
		return 0;
	
	if (l <= start && r >= end)
		return tree[v];
	
	int mid = (start + end)/2;
	return max(query(2*v, start, mid, l, r), query(2*v + 1, mid + 1, end, l, r));
}

void update (int v, int start, int end, int index, int val)
{
	if (start == end) tree[v] = val;
	else
	{
		int mid = (start + end)/2;
		if (index <= mid)
			update(2*v, start, mid, index, val);
		else 
			update(2*v + 1, mid + 1, end, index, val);
		tree[v] = max(tree[2*v], tree[2*v + 1]);
	}
}



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

	read(n);
	h.rz(n+1); a.rz(n+1); tree.rz(4*n + 1);

	fori(i, 1, n) cin >> h[i];
	fori(i, 1, n) cin >> a[i];

	fori(i, 1, n)
	{
		int temp = query(1, 1, n, 1, h[i] - 1);
		update(1, 1, n, h[i], a[i]+temp);
	}
	cout << tree[1];
	return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    string s,k;
    int x;
    cin>>s>>x;
    for(int i=0;i<SZ(s);i+=x)
    {
        k+=s[i];
    }
    cout<<k<<NL;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    string a,b;
    cin >> a >> b;
    bool flag = false;
    int c = stoi(a + b);
    for(int i = 1;i * i <= c;i++){
        if(i * i == c){
            flag = true;
        }
    }
    cout << ((flag) ? "Yes" : "No") << endl;
}


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

int mcxiToInt(string str) {
  int res = 0;
  int add = 1;
  for (int i = 0; i < str.size(); ++i) {
    if (str[i] == 'm') {
      res += add * 1000;
      add = 1;
    }
    else if (str[i] == 'c') {
      res += add * 100;
      add = 1;
    }
    else if (str[i] == 'x') {
      res += add * 10;
      add = 1;
    }
    else if (str[i] == 'i') {
      res += add;
      add = 1;
    }
    else {
      add = str[i] - '0';
    }
  }
  return res;
}

char dig[4] = {'m', 'c', 'x', 'i'};
string intToMcxi(string str) {
  string res = "";
  for (int i = 0; i < str.size(); ++i) {
    if (str[i] == '0') {
      continue;
    }
    else if (str[i] == '1') {
      res += dig[i];
    }
    else {
      res += str[i];
      res += dig[i];
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  for (int abc = 0; abc < n; ++abc) {
    string s, t;
    cin >> s >> t;
    int a = mcxiToInt(s);
    int b = mcxiToInt(t);
    //cout << a << ", " << b << endl;
    int res = a + b;
    stringstream ss; ss << res;
    string sres = ss.str();
    while (sres.size() < 4) sres = "0" + sres;
    cout << intToMcxi(sres) << endl;
  }
}


Measured memory_bytes: 1224
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>//"geometry.cpp"
//#include <iostream>
//#include <cstdio>
//#include <iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
//#include <queue>
//#include <string>//"reverse((s's iterator), (s's iterator))"
//#include <vector>
//#include <utility>
//#include <set>
//#include <map>
//#include <algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
//#include <functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
//#include <cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back//Can be used for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;//Add other types in the same way.

#define MAX_N 10000
#define MAX_H 100
#define MAX_W 100

int main(){//C++11
	int h,w,n,a[MAX_N];
	cin>>h>>w>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	int x=0,y=0,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0},dir=0,ind=0,c[MAX_H][MAX_W];
	bool f[MAX_H][MAX_W];
	for(int i=0;i<h;++i) fill(f[i],f[i]+w,false);
	for(int k=0;k<h*w;++k){
		c[x][y]=ind+1;
		f[x][y]=true;
		if((--a[ind])==0) ++ind;
		for(int l=0;l<4;++l){
			int nx=x+dx[dir],ny=y+dy[dir];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&!f[nx][ny]){
				x=nx;
				y=ny;
				break;
			}
			++dir;
			dir%=4;
		}
	}
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			cout<<c[i][j];
			if(j!=w) cout<<" ";
		}
		cout<<endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005  //check the limits, man
int main()
{
    int i,n,x;
    string str;
    llin(str);
    n=str.size();
    string ans;
    ans.resize(n);
    for(i=0;i<n;i+=2)
        ans[i]='g';
    for(i=1;i<n;i+=2)
        ans[i]='p';
    x=0;
    rep(i,n)
    {
        if(str[i]=='g' && ans[i]=='p')
            x++;
        else if(str[i]=='p' && ans[i]=='g')
            x--;
    }
    out(x);

}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
int main(){
  fast();
  vector<int> d(100000,0);
    int x,l,t;
  cin>>x>>l;
  fr(i,l){
  cin>>t;
    d[t] = 1;
  }
  for(int i=x;i<100001;i++){
  string s = to_string(i);
    fr(j,s.size()){
    if(d[s[j]-'0'])goto y;
    }
    cout<<s;
    break;
    y:;
  }
  return 0;
  
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>

using namespace std;

#define int long long

int func(int a,int b){
    if(a==-1){
        return 0;
    }
    return a/b+1;
}

signed main(){
    int a=0,b=0,x=0;
    cin >> a >> b >> x;
    cout << func(b,x)-func(a-1,x) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n; cin >> n;
    int a[3 * n];
    for (int i = 0; i < 3 * n; ++i) {
        cin >> a[i];
    }
    sort(a, a + 3 * n, greater<int>());
    long long ans = 0;
    for (int i = 0; i < 2 * n; ++i) {
        if (i % 2 != 0) ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ON_SEGMENT = 0;
static const int ONLINE_FRONT = 2;
static const int ONLINE_BACK = -2;
const double EPS = 1e-10;

bool equals(double a, double b) {
	return fabs(a - b) < EPS;
}

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}

	Point operator + (Point p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double k) {
		return Point(k * x, k * y);
	}
	Point operator / (double k) {
		return Point(x / k, y / k);
	}

	double norm() {
		return x * x + y * y;
	}
	double abs() {
		return sqrt(norm());
	}

	bool operator < (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

class Segment {
public:
	Point p1, p2;
	Segment(Point p1, Point p2): p1(p1), p2(p2) {};

	Point project(Point p) {
		Vector a = Vector(p.x - p1.x, p.y - p1.y);
		Vector b = Vector(p2.x - p1.x, p2.y - p1.y);
		return p1 + p2 * (dot(a, b) / b.norm());
	}

	Point refrect(Point p) {
		Point pro = project(p);
		return pro * 2 - p;
	}
};

int check(Vector v0, Vector v1) {
	double c = cross(v0, v1);
	if (equals(c, 0)) {
		if (dot(v0, v1) < 0) return ONLINE_BACK;
		else if (v1.norm() > v0.norm()) return ONLINE_FRONT;
		else return ON_SEGMENT;
	} else if (c > 0) {
		return COUNTER_CLOCKWISE;
	} else {
		return CLOCKWISE;
	}
}

int intersect(Segment s1, Segment s2) {
	Point p1 = s1.p1, p2 = s1.p2, p3 = s2.p1, p4 = s2.p2;
	Vector v0 = Vector((p2 - p1).x, (p2 - p1).y);
	Vector v1 = Vector((p3 - p1).x, (p3 - p1).y);
	Vector v2 = Vector((p4 - p1).x, (p4 - p1).y);
	Vector v3 = Vector((p4 - p3).x, (p4 - p3).y);
	Vector v4 = Vector((p1 - p3).x, (p1 - p3).y);
	Vector v5 = Vector((p2 - p3).x, (p2 - p3).y);
	if (check(v0, v1) * check(v0, v2) == 0) return 1;
	if (check(v0, v1) * check(v0, v2) == -4) return 1;
	if (check(v0, v1) * check(v0, v2) == -1) {
		if (check(v3, v4) * check(v3, v5) > 0) return 0;
		else return 1;
	}
	return 0;
}

int main() {
	int q;
	cin >> q;
	int x0, y0, x1, y1, x2, y2, x3, y3;
	for (int i = 0; i < q; i++) {
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		Segment s1 = Segment(Point(x0, y0), Point(x1, y1));
		Segment s2 = Segment(Point(x2, y2), Point(x3, y3));
		cout << intersect(s1, s2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n,k = map(int,input().split())
a = list(map(int, input().split()))
al = [0]*(n+1)
pl = [0]*(n+1)
ans = 0
for i in range(n):
  al[i+1] = al[i] + a[i]
  pl[i+1] = pl[i]
  if a[i] > 0: pl[i+1] += a[i]
for r in range(k,n+1):
  l = r-k
  cur = pl[l] + max(0, al[r] - al[l]) + pl[n] - pl[r]
  if ans < cur: ans = cur
print(ans)

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int a,b,c,x,y;

int main(){
	cin >> a >> b >> c >> x >> y;
	Int ans = 0;
	if(c*2 < a+b){
		ans += c * min(x,y) * 2;
		if(x < y && c*2 > b){
			ans += b * (y-x);
		}
		else if(x > y && c*2 > a){
			ans += a * (x-y);
		}
		else ans += c * 2 * abs(x-y);
	}
	else{
		ans += a * x + b * y;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char rbuf[2800014];
char wbuf[699997];
int rbufl, wbufl;

#define getchar_unlocked() rbuf[rbufl++]
#define putchar_unlocked(c) wbuf[wbufl++]=(c)

uint32_t nextpint(void){ char c=getchar_unlocked(); uint32_t x=0; while('0'<=c){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printpint(int32_t x){ if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

int edge[200000][2];

int qmem[400000];

int *e[100001];
int el[100001];

int prev[100001];

int s[100000];
int sl, sr;

int main(void){
	read(STDIN_FILENO, rbuf, sizeof(rbuf));
	int n=nextpint();
	int m=nextpint();
	for(int i=0; i<m; i++){
		int A=nextpint();
		int B=nextpint();
		edge[i][0]=A;
		edge[i][1]=B;
		el[A]++;
		el[B]++;
	}
	int ne=0;
	for(int i=1; i<=n; i++){
		e[i]=&qmem[ne];
		ne+=el[i];
		el[i]=0;
	}
	for(int i=0; i<m; i++){
		int A=edge[i][0];
		int B=edge[i][1];
		e[A][el[A]++]=B;
		e[B][el[B]++]=A;
	}
	int k=0;
	prev[1]=1;
	s[sr++]=1;
	while(sl<sr){
		k++;
		int from = s[sl++];
		for(int i=0; i<el[from]; i++){
			int to = e[from][i];
			if(prev[to]==0){
				prev[to]=from;
				s[sr++]=to;
			}
		}
	}
	if(k==n){
		putchar_unlocked('Y');
		putchar_unlocked('e');
		putchar_unlocked('s');
		putchar_unlocked('\n');
		for(int i=2; i<=n; i++){
			printpint(prev[i]);
		}
		write(STDOUT_FILENO, wbuf, wbufl);
	}else{
		puts("No");
	}
}


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

int main(){
  int N;
  int count = 0;
  cin >> N;
  if(N<10){
    count += N;
  }
  if(N>=10&&N<100){
    count += 9;
  }
  if(N>=100&&N<1000){
    count += N-90;
  }
  if(N>=1000&&N<10000){
    count += 909;
  }
  if(N>=10000&&N<100000){
    count += N-9090;
  }
  if(N==100000){
    count += 90909;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int A, B;
	scanf("%d %d", &A, &B);
	if (A > 8){
		printf(":(\n");
	}
	else if (B > 8){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
	return 0;
}

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

int main()
{
    int a, b, c, x, y, i, j, k;
    cin>>x>>y>>a>>b>>c;
    long long p[a], q[b], r[c];
    for(i=0;i<a;i++) cin>>p[i];
    for(i=0;i<b;i++) cin>>q[i];
    for(i=0;i<c;i++) cin>>r[i];
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    reverse(p,p+a);
    reverse(q,q+b);
    reverse(r,r+c);
    for(i=x-1, j=y-1, k=0;(i>=0 || j>=0) && k<c;--i, --j)
    {
        if(i>=0 && j>=0){
        if(p[i]<=q[j])
        {
            if(p[i]<r[k])
            {
                p[i]=r[k];
                r[k]=0;
                k++;
                j++;
            }
        }
        else if(p[i]>q[j])
        {
            if(q[j]<r[k])
            {
                q[j]=r[k];
                r[k]=0;
                k++;
                i++;
            }
        }
        }
        else if(i<0)
        {
            if(q[j]<r[k])
            {
                q[j]=r[k];
                r[k]=0;
                k++;
            }
        }
        else if(j<0)
        {
            if(p[i]<r[k])
            {
                p[i]=r[k];
                r[k]=0;
                k++;
            }
        }
    }
    long long int sum=0;
    for(i=0;i<x;i++) sum=sum+p[i];
    for(i=0;i<y;i++) sum=sum+q[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 2560
n,k=map(int,input().split())
max=0
l=list(map(int,input().split()))

for i in range(k-1):
  s=l[i+1]-l[i]
  if s>max:
    max=s

s=n-l[-1]+l[0]
if s>max:
  max=s
print(n-max)  

Measured memory_bytes: 26444