akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    R = I()
    print(2 * R * math.pi)


if __name__ == '__main__':
    main()


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

#define ALPHABET 26
#define ASCII_a 97

long long n;
char name[100], nameAns[100];  

int main(){
    scanf("%lld",&n);
    
    long long tmpNo=n; 
    int mojiTmp, cnt=0;
    while(tmpNo>0){
        mojiTmp = tmpNo%ALPHABET;
        if(mojiTmp==0){
            name[cnt] = (char)(ASCII_a + 25);
            tmpNo = tmpNo/ALPHABET -1;
        }
        else{
            name[cnt] = (char)(ASCII_a + mojiTmp -1);
            tmpNo = tmpNo/ALPHABET;
        }
        cnt++;
    }
    for (int i = 0; i < cnt; i++){
        nameAns[i] = name[cnt-i-1];
    }
    nameAns[cnt] = '\0';   

    printf("%s\n",nameAns);  
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define REP(i, a, b) for (unsigned long long i = a; i <= b; ++i)
#define ull unsigned long long
#define ll long long
using namespace std;

ll n, k, ans;
ull a, b;

inline ll read(){												//快读 
	ull s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	n = read(), k = read();										//输入n和k 
	REP(i, k, n + 1){											//从k到n+1依次枚举 
		a = (i - 1) * i >> 1, b = (n + n - i + 1) * i >> 1;		//计算头和尾 
		ans += (b - a + 1) % 1000000007;						//计算答案 
		ans %= 1000000007;										//%模数 
	}
	printf("%lld\n", ans);										//输出答案 
}

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

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<pair<int64_t,int64_t>> W(N);
    rep(n,0,N){
        int64_t a,b; cin>>a>>b;
        W.at(n)=make_pair(b,a);
    }
    sort(ToEnd(W));

    int64_t t=0;
    string ans="Yes";
    for(auto w:W){
        t+=w.second;
        if(t>w.first){ans="No"; break;}
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3328
n,q=gets.split.map(&:to_i)
str=gets.chomp

s=Array.new(n+1){ 0 }
n.times do |i|
  if i+1<n && str[i]=="A" && str[i+1]=="C"
    s[i+1]=s[i]+1
  else
    s[i+1]=s[i]
  end
end

q.times do
  l,r=gets.split.map(&:to_i)
  r-=1
  l-=1
  puts s[r]-s[l]
end

Measured memory_bytes: 3324
#include <iostream>
#include <cmath>

using namespace std;

#define ll long long int

ll minAns(ll *arr,int num){
    ll *dp = new ll[num];
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    
    for(ll i=2;i<num;i++){
        dp[i]= min(dp[i-1] + abs(arr[i]-arr[i-1]) , dp[i-2] + abs(arr[i] - arr[i-2]));
    }
    
    return dp[num-1];
}

int main()
{
    ll num;
    cin>>num;
    ll *arr = new ll[num];
    for(int i=0;i<num;i++){
        cin>>arr[i];
    }
    
    cout<<minAns(arr,num);
    
    return 0;
}


Measured memory_bytes: 5172
package main

import (
	"io"
	"bufio"
	"strconv"
	"strings"
	"bytes"
	"reflect"
	"fmt"
	"os"
)

const SENTINEL = 2000000000

type Card struct {
	mark string
	number int
}

/***********************************************************************
関数merge:
	引数:
		配列A = 内部的にleftからmid-1までとmidからrightまでの二つに分かれている
		n = Aの長さ
		left = 統合される対象の配列のAにおける先頭インデックス
		mid = 統合される対象の配列のAにおける末尾インデックス
		right = 統合される対象の配列Aにおける末尾インデックス
***********************************************************************/
func merge(A []Card, n, left, mid, right int) {
	n1 := mid - left
	L := make([]Card, n1+1)
	n2 := right - mid
	R := make([]Card, n2+1)
	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}
	L[n1].number, R[n2].number = SENTINEL, SENTINEL
	i, j := 0 ,0
	for k := left; k < right; k++ {
		if L[i].number <= R[j].number {
			A[k] = L[i]
			i++
			continue
		}
		A[k] = R[j]
		j++
	}
}

/***********************************************************************
関数mergeSort:
	引数:
		配列A = 内部的にleftからmid-1までとmidからrightまでの二つに分かれている
		n = Aの長さ
		left = 統合される対象の配列のAにおける先頭インデックス
		right = 統合される対象の配列Aにおける末尾インデックス
***********************************************************************/
func mergeSort(A []Card, n, left, right int) {
	mid := 0
	if left+1 < right {
		mid = (left + right)/2
		mergeSort(A, n, left, mid)
		mergeSort(A, n, mid, right)
		merge(A, n, left, mid, right)
	}
}

/***********************************************************************
関数partation:
	引数:
		配列A = 分割される対象となる配列を部分として含む配列
		p = 分割される対象となる配列の先頭インデックス
		r = 分割される対象となる配列の末尾インデックス
***********************************************************************/
func partition(A []Card, p, r int) int {
	last := A[r]
	i := p - 1
	for j := p; j < r; j++ {
		if A[j].number <= last.number {
			i++
			A[i], A[j] = A[j], A[i]
		}
	}
	A[i+1], A[r] = A[r], A[i+1]
	return i+1
}

/***********************************************************************
関数quickSort:
	引数:
		配列A =ソートされる対象となる配列を部分として含む配列
		n = Aの長さ
		p = ソートされる対象となる配列の先頭インデックス
		r = ソートされる対象となる配列の末尾インデックス
***********************************************************************/
func quickSort(A []Card, n, p, r int) {
	q := 0
	if p < r {
		q = partition(A, p, r)
		quickSort(A, n, p, q-1)
		quickSort(A, n, q+1, r)
	}
}

func solve(reader io.Reader) string {
	scanner := bufio.NewScanner(reader)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	A, B := make([]Card, n), make([]Card, n)
	for i := range A {
		scanner.Scan()
		info := strings.Split(scanner.Text(), " ")
		A[i].mark = info[0]
		A[i].number, _ = strconv.Atoi(info[1])
		B[i].mark, B[i].number = A[i].mark, A[i].number
	}

	mergeSort(A, n, 0, n)
	quickSort(B, n, 0, n-1)

	var memo bytes.Buffer
	if reflect.DeepEqual(A, B) {
		memo.WriteString("Stable\n")
	} else {
		memo.WriteString("Not stable\n")
	}

	for i := range B {
		memo.WriteString(B[i].mark + " " + strconv.Itoa(B[i].number) + "\n")
	}
	return strings.TrimRight(memo.String(), "\n")
}

func main() {
	fmt.Println(solve(os.Stdin))
}


Measured memory_bytes: 17052
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(void){
long long int n,a,b;
scanf("%lld %lld %lld",&n,&a,&b);
long long int sum=0;

sum=sum+n/(a+b)*a;
n=n%(a+b);
if(a<=n){
printf("%lld",sum+a);
}
else{printf("%lld",sum+n);}
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4+5, M = 1e4+5, OO = 0x3f3f3f3f;
typedef long long ll;
#define PI 3.14159265358979323846
#define INF LONG_MAX
const int  MOD = 1e9+7;
int main()
{
  ll l,r; cin>>l>>r;
  if ((l-1)/2019 != r/2019) return cout<<0,0;
  l%=2019,r%=2019;
  ll mn=1e18;
  for (ll i = l; i<r; ++i)
    for (ll j = i+1; j<=r; ++j)
      mn = min(mn,(i*j)%2019);
  cout<<mn;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll n, k, a, b;
map<ll, ll> m;
sl s;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  FOR(i, 0, n){
    cin >> a >> b;
    if(m.find(a) == m.end()) m[a] = 0;
    m[a] += b;
    s.insert(a);
  }
  ll su = k;
  each(itr, s){
    k -= m[*itr];
    if(k <= 0){
      cout << *itr << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 7168
mod = 10**9+7
S = list(input())
Thankyou = 1
DP=[]
#DP[x][y] x+1文字目までを見たときの、
#y=0,1,2 : A,AB,ABCの登場回数
if S[0] == "A" or S[0]=="?":
    DP.append([1,0,0])
    if S[0]=="?":
        Thankyou = 3
else:
    DP.append([0,0,0])
for i,s in enumerate(S):

    if i==0:continue
    a,b,c = DP[i-1]
    if s=="A":
        DP.append([(a+Thankyou)%mod,b,c])
    elif s=="B":
        DP.append([a,(a+b)%mod,c])
    elif s=="C":
        DP.append([a,b,(b+c)%mod])
    else:
        DP.append([(Thankyou+3*a)%mod,(a+3*b)%mod,(b+3*c)%mod])
        Thankyou *= 3
        Thankyou %= mod
print(DP[len(S)-1][2]%mod)

Measured memory_bytes: 58744
if __name__ == '__main__':
    A, B, C, D, E, F = list(map(int, input().split()))

    # A+B のアリエル値
    a_plus_b = set()
    for i in range(0, 31, A):
        for j in range(0, 31, B):
            if not (i == 0 and j == 0):
                if i + j <= 30:
                    a_plus_b.add(i + j)

    c_plus_d = set()
    for i in range(0, F, C):
        for j in range(0, F, D):
            if i + j <= F:
                c_plus_d.add(i + j)

    max_concent = -1
    ans_sum = 0
    ans_sugar = 0
    # print(c_plus_d)
    # print(a_plus_b)
    for cd in c_plus_d:
        for ab in a_plus_b:
            if cd <= E * ab and cd <= F - 100 * ab:
                if max_concent <= cd / ab:
                    max_concent = cd / ab
                    ans_sum = 100 * ab + cd
                    ans_sugar = cd

    print(str(ans_sum) + " " + str(ans_sugar))


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

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

using ll = long long;
using namespace std;

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

    double a = l / 3.0;
    auto v = a*a*a;
    printf("%.8f\n", v);
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    
    int a,b,result;
    char op;
    
    while(1){
    std::cin >> a >> op >> b;
    
    if(op == '+')result = a + b;
    if(op == '-')result = a - b;
    if(op == '/')result = a / b;
    if(op == '*')result = a * b;
    if(op == '?')break;
    
    std::cout << result << "\n";
    }

    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int n; cin >> n;
  int a[n]; for(int i = 0; i < n; i++) cin >> a[i];
  vector<int> v; for(int i = 0; i < n; i++) v.push_back(a[i]);
  int maxi = 0, maxi2 = 0;
  for(int i = 0; i < n; i++){
    if(a[i] > a[maxi]) maxi = i;
  }
  int t = a[maxi];
  a[maxi] = 0;
  for(int i = 0; i < n; i++){
    if(a[i] > a[maxi2]) maxi2 = i;
  }
  a[maxi] = t;
  for(int i = 0; i < n; i++){
    if(i == maxi) cout << a[maxi2] << endl;
    else cout << a[maxi] << endl;
  }
  return;
}

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


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] c = new char[h][w];
        for (int i = 0; i < h; i++) {
            String s = sc.next();
            c[i] = s.toCharArray();
        }

        int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1};
        int[] dx = {-1, 0, 1, -1, 1, -1, 0, 1};
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                if (c[y][x] == '.') {
                    int b = 0;
                    for (int i = 0; i < 8; i++) {
                        int yy = y + dy[i];
                        int xx = x + dx[i];
                        if (yy < 0 || yy >= h || xx < 0 || xx >= w) {
                            continue;
                        }
                        if (c[yy][xx] == '#') {
                            b++;
                        }
                    }
                    c[y][x] = (char)('0' + b);
                }
            }
            System.out.println(new String(c[y]));
        }
    }
}

Measured memory_bytes: 35688
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    string s;
    cin >> s;

    stringstream ss;

    for(int i=0; i<s.length(); i+=2){
        ss << s[i];
    }

    p(ss.str());
    
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
signed main() {
  int n;
  cin >> n;
  vector<int> t(n), a(n);
  vector<bool> one(n, false);
  one[0] = one[n - 1] = true;
  for (auto&& w : t) cin >> w;
  for (auto&& w : a) cin >> w;
  bool flg = true;
  if (t[0] > a[0]) flg = false;
  if (t[n - 1] < a[n - 1]) flg = false;

  for (int i = 0; i < n - 1; i++) {
    if (t[i + 1] < t[i]) flg = false;
    if (t[i + 1] > t[i]) {
      one[i + 1] = true;
      if (t[i + 1] > a[i + 1]) flg = false;
    }
  }
  for (int i = n - 1; i >= 1; i--) {
    if (a[i - 1] < a[i]) flg = false;
    if (a[i - 1] > a[i]) {
      one[i - 1] = true;
      if (t[i - 1] < a[i - 1]) flg = false;
    }
  }
  if (!flg) cout << 0 << endl, exit(0);
  int ans = 1;

  for (int i = 0; i < n; i++) {
    if (one[i]) continue;
    (ans *= min(t[i], a[i])) %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(long long  i = 0; i < n; i++)
#define rep2(i,a,n) for(long long  i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

using namespace std;

int main() 
{
    ll n; cin >> n;
    vector<pair<ll, ll> > a(n);
    vector<ll> index(n);

    rep(i,n) { 
        ll tmp;
        cin >> tmp; 
        a[i] = make_pair(tmp, i);
    }

    sort(a.begin(), a.end());

    rep(i,n) {
        index[a[i].second] = i;   
        //cout << vec.first << "," << vec.second << endl;
    }

    rep(i,n) {
        //cout << index[i] << endl; 
        if(index[i] < (n/2)) {
            cout << a[n/2].first << endl;
        } else {
            cout << a[n/2-1].first << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 6912
import java.util.*;

public class Main {

    static long[] a,b,c;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int k = sc.nextInt();
         a = new long[x];
         b = new long[y];
         c = new long[z];
        for (int i = 0; i < x; i++) a[i] = sc.nextLong();
        for (int i = 0; i < y; i++) b[i] = sc.nextLong();
        for (int i = 0; i < z; i++) c[i] = sc.nextLong();
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        PriorityQueue<Pack> q = new PriorityQueue<>((p1,p2) -> Long.compare(p2.sum, p1.sum));
        Pack fir = new Pack(0, 0, 0, a[x-1] + b[y-1] + c[z-1]);
        q.add(fir);
        Set<Pack> set = new HashSet<>();
        set.add(fir);
        StringBuilder ans = new StringBuilder();
        Pack ap, bp, cp;
        for (int i = 0; i < k; i++) {
            Pack pre = q.poll();
            ans.append(pre.sum).append("\n");
            int ai = pre.aidx;
            int bi = pre.bidx;
            int ci = pre.cidx;
            if(ai+1<x) {
                ap = new Pack(ai+1, bi, ci, a[x-1-(ai+1)] + b[y-1-bi] + c[z-1-ci]);
                if (!set.contains(ap)) {
                    q.add(ap); set.add(ap);
                }
            }
            if(bi+1<y){
                bp = new Pack(ai, bi+1, ci, a[x-1-ai] + b[y-1-(bi+1)] + c[z-1-ci]);
                if(!set.contains(bp)){
                    q.add(bp); set.add(bp);
                }
            }
            if(ci+1<z){
                cp = new Pack(ai, bi, ci+1, a[x-1-ai] + b[y-1-bi] + c[z-1-(ci+1)]);
                if(!set.contains(cp)){
                    q.add(cp); set.add(cp);
                }
            }
        }

        System.out.println(ans.toString());
        sc.close();
    }

}

class Pack{
    public long sum;
    public int aidx;
    public int bidx;
    public int cidx;

    public Pack(int aidx, int bidx, int cidx, long sum){
        this.aidx = aidx;
        this.bidx = bidx;
        this.cidx = cidx;
        this.sum = sum;
    }

    @Override
    public boolean equals(Object o) {
        if(this == o) return true;
        if(o == null || getClass() != o.getClass()) return false;
        Pack p = (Pack)o;
        return this.aidx == p.aidx && this.bidx == p.bidx && this.cidx == p.cidx;
    }

    @Override
    public int hashCode() {
        return Objects.hash(aidx, bidx, cidx);
    }
}


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

vector<pair<int, int> > solve(int n, vector<ll> const & d) {
    map<ll, int> index;
    REP (i, n) {
        index[d[i]] = i;
    }

    int root = index.begin()->second;
    vector<pair<int, int> > edges;
    vector<int> size(n, 1);
    vector<ll> d1(n, 0);
    for (auto it = index.rbegin(); ; ++ it) {
        ll d_i; int i; tie(d_i, i) = *it;
        if (i == root) break;
        ll d_parent = d_i - n + 2 * size[i];
        if (not index.count(d_parent)) {
            return vector<pair<int, int> >();
        }
        int parent = index[d_parent];
        edges.emplace_back(parent, i);
        size[parent] += size[i];
        d1[parent] += d1[i] + size[i];
    }

    if (d1[root] != d[root]) {
        return vector<pair<int, int> >();
    }
    return edges;
}

int main() {
    int n; cin >> n;
    vector<ll> d(n);
    REP (i, n) cin >> d[i];
    auto edges = solve(n, d);
    if (edges.empty()) {
        cout << -1 << endl;
    } else {
        for (auto edge : edges) {
            int i, j; tie(i, j) = edge;
            cout << i + 1 << ' ' << j + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9596
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    long ai[n];
    for(int i = 0; i < n; i++){
        scanf("%ld", &ai[i]);
    }
    
    int i = 0;
    char iJudge = 1;
    long iKabu = 0;
    long iMoney = 1000;
    while(i < n){
        if(iJudge == 1){//購入
            if(i == n-1){
                break;
            }
            if(ai[i] >= ai[i+1]){
                i++;
                continue;
            }
            else{
                iKabu = iMoney / ai[i];
                iMoney %= ai[i];
                iJudge = 2;
                i++;
                continue;
            }
        }
        else{//売却
            if(i == n-1){
                iMoney += ai[i] * iKabu;
                iKabu = 0;
                break;
            }
            if(ai[i] <= ai[i+1]){
                i++;
                continue;
            }
            else{
                iMoney += ai[i] * iKabu;
                iKabu = 0;
                iJudge = 1;
                i++;
                continue;
            }
        }
    }
    
    printf("%ld", iMoney);
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	if (k == 1) cout << 0 << endl;
	else cout << n-k << endl;

}



Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
p_asc = sorted(p)
diff = 0

for i_p, i_pa in zip(p, p_asc):
    if i_p != i_pa:
        diff += 1
    if diff > 2:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;

int a;
string s;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> s;
    if (a < 3200) {
        cout << "red\n";
    }
    else {
        cout << s << '\n';
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n;
	cin >> n;
	i64 x=0, y=0;
	vector<int> a(n);
	ff(i, 0, n) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	ff(i, 0, n - 1) {
		if (a.at(i) == a.at(i + 1)) {
			y = x;
			x = a.at(i);
			i++;
		}
	}
	i64 ans = x * y;
	cout << ans << endl;
	return 0;
}


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

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

    if (K % 2 == 0) {
        cout << (K / 2) * (K / 2) << endl;
    } else {
        cout << (K / 2) * (K / 2 + 1) << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

ans = 0
for i in range(0, n):
    ans += b[a[i] - 1]
for i in range(0, n - 1):
    if a[i + 1] == a[i] + 1:
        ans += c[a[i] - 1]
print(ans)

Measured memory_bytes: 9048
#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
long long n,k,a[100005],b[100005],ans,mx,mn;
long long f_p(long long base, long long power) 
{
    long long result=1;
    while(power>0) 
    {
        if(power%2==1) 
        {
            result=(result*base)%mod;
        }
        base=(base*base)%mod;
        power=power/2;
    }
    return result;
}
int main()
{
	cin>>n>>k;
	for (int i=1; i<=n; i++)
	{
		cin>>a[i];
	}
	b[0]=1;
	b[1]=1;
	for (int i=2; i<=n; i++)
	{
		b[i]=b[i-1]*i;
		b[i]%=mod;
	}
	sort(a+1, a+n+1);
	for (int i=1; i<=n; i++)
	{   
		mn=0;
		mx=0;
		if (i>=k) 
		{
			// C (n, k) = n!   / k! * (n-k)!
			// C (i-1,k-1) i-1! / k-1!  *  i-1-k+1
			mx=(b[i-1]*f_p(b[k-1],mod-2)%mod*f_p(b[i-k],mod-2)%mod)%mod;
		}
		
		if (i<=n-k+1)
		{
			// C (n-i, k-1)  n-i!  /  k-1!  n-i-k+1=n-i-k+1   
			mn=(b[n-i]*f_p(b[k-1],mod-2)%mod*f_p(b[n-i-k+1],mod-2)%mod)%mod;;
		}
		ans+=mx*a[i];
		ans%=mod;
		ans-=mn*a[i];
		ans%=mod;
	}	
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define N 200005
using namespace std;
int vis[N],da,i,j,k,l,r,d,n,m,ans[N],last[N][27],f[27];
char c[N];
struct node {
	int x,y,last;
}q[N];
inline void print(int x,int y) {
	ans[++da]=y;
	while (x) ans[++da]=q[x].x,x=q[x].last;
	for (int i=da;i;i--) printf("%c",char(96+ans[i]));
}
int main() {
	scanf("%s",c+1);
	l=strlen(c+1);
	int L=l;
	for (i=1;i<=26;i++) last[l][i]=l+1,f[i]=l+1;
	f[c[l]-96]=l;
	for (i=l-1;i;i--) {
		f[c[i]-96]=i;
		for (j=1;j<=26;j++) last[i][j]=last[i+1][j];
		last[i][c[i+1]-96]=i+1;
	}
	int l=0,r=26;
	for (i=1;i<=26;i++) {
		if (f[i]>L) {
			printf("%c",char(96+i)); return 0;
		}
		q[i].x=i,q[i].y=f[i],q[i].last=0;
		vis[f[i]]=1;
	}
	while (l<=r) {
		++l;
		for (int i=1;i<=26;i++) if (last[q[l].y][i]>L) {	
			print(l,i); return 0;
		}
		else if (!vis[last[q[l].y][i]]) q[++r].x=i,q[r].last=l,q[r].y=last[q[l].y][i],vis[last[q[l].y][i]]=1;	
	}
} 


Measured memory_bytes: 25344
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

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

  int ans = 0;
  int current = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      current++;
    } else {
      current--;
    }

    ans = max(ans, current);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <string>
//#include <string.h>
#include <set>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	while( n-- > 0 ){
		string str;
		cin >> str;
		set<string> s;
		for( size_t i = 1; i < str.length(); i++ ){
			string s1 = str.substr( 0, i );
			string s2 = str.substr( i );
			s.insert( s1 + s2 );
			s.insert( s2 + s1 );
			reverse( s1.begin(), s1.end() );
			s.insert( s1 + s2 );
			s.insert( s2 + s1 );
			reverse( s2.begin(), s2.end() );
			s.insert( s1 + s2 );
			s.insert( s2 + s1 );
			reverse( s1.begin(), s1.end() );
			s.insert( s1 + s2 );
			s.insert( s2 + s1 );
		}
		cout << s.size() << endl;
		s.clear();
	}
}

Measured memory_bytes: 1292
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<cassert>
#include<queue>
#define F first
#define S second
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;


int main(){
  int N,M;
  string s;
  map<string,bool> Lock;

  cin >> N;
  rep(i,N){
    cin >> s;
    Lock[s] = true;
  }
  cin >> M;
  bool state = false;
  rep(i,M){
    cin >> s;
    if(!Lock[s])cout << "Unknown " << s << endl;
    else if(Lock[s] && state){
      cout << "Closed by " << s << endl;
      state = false;
    }
    else if(Lock[s] && !state){
      cout << "Opened by " << s << endl;
      state = true;
    }
  }


  return 0;
}
 

Measured memory_bytes: 1240
program main
  implicit none
  integer(8) :: n, k, mi, ma, md, i
  integer(8), allocatable :: a(:)
  read *, n, k
  allocate (a(n))
  read *, a(:)
  call quicksort(a)

  ! 積がthres以下になるペアがk個以上ある最小のthres
  mi = -1 * 10_8 ** 18 - 1  ! NG
  ma = 1 * 10_8 ** 18 + 1  ! OK
  do i = 1, 70
    md = mi + (ma - mi) / 2
    if (isok(md)) then
      ma = md
    else
      mi = md
    end if
    if (ma - mi <= 1) exit
  end do

  print "(i0)", ma

  contains

  logical function isok(x)
    ! 積がx以下になるペアがk個以上ある
    integer(8), intent(in) :: x
    integer(8) :: i, cnt
    cnt = 0
    do i = 1, n
      cnt = cnt + count_lower(i, x)
    end do
    isok = (cnt >= k)
  end function isok

  integer(8) function count_lower(i, x)
    ! a(i) * a(j) <= x となるj>iの数
    integer(8), intent(in) :: i, x
    integer(8) :: j, mi, md, ma
    if (a(i) >= 0) then
      ! a(i) * a(j) <= x となる最大のjを求める
      mi = i  ! ok
      ma = n + 1  ! ng
      do j = 1, 30
        md = mi + (ma - mi) / 2
        if (a(i) * a(md) <= x) then
          mi = md
        else
          ma = md
        end if
        if (ma - mi <= 1) exit
      end do
      count_lower = mi - i
    else
      ! a(i) * a(j) <= x となる最小のjを求める
      mi = i  ! ng
      ma = n + 1  ! ok
      do j = 1, 30
        md = mi + (ma - mi) / 2
        if (a(i) * a(md) <= x) then
          ma = md
        else
          mi = md
        end if
        if (ma - mi <= 1) exit
      end do
      count_lower = n - (ma - 1)
    end if
  end function count_lower

  recursive subroutine quicksort(a)
    integer(8), intent(inout) :: a(:)
    integer(8) :: pivot, i, j, k, tmp, n
    real(8) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1_8, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot <= a(i))
        i = i + 1
      end do
      do while (.not. a(j) <= pivot)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort
end program main


Measured memory_bytes: 2304
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,m,*t=map(int,open(0).read().split());c=0\n"
"for a,b in sorted(zip(t[::2],t[1::2])):c+=a*min(m,b);m=max(0,m-b)\n"
"print(c)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 25616
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
#define N_MAX 50000
#define M_MAX 20
#define NIL 1000000000

int DP[N_MAX + 1][M_MAX + 1];
int C[M_MAX + 1];

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

    for(int i = 1; i <= m; i++){
        scanf("%d", &C[i]);
    }
    
    for(int i = 0; i <= n; i++){
        for(int k = 0; k <= m; k++){
            DP[i][k] = NIL;
        }
    }
    for(int k = 0; k <= m; k++){
        DP[0][k] = 0;
    }

    for(int k = 1; k <= m; k++){
        for(int i = 0; i <= n; i++){
            if(i - C[k] < 0){
                DP[i][k] = DP[i][k - 1];
            }else{
                DP[i][k] = min(DP[i][k - 1], DP[i - C[k]][k] + 1);
            }
            //printf("DP[%d][%d]: %d\n", i, k, DP[i][k]);
        }
    }

    printf("%d\n", DP[n][m]);
}



Measured memory_bytes: 7288
import sys 

N = int(input())
A = [int(N) for N in input().split()]

if min(A)==0:
  print("0")
  sys.exit()
if max(A) > 10**18:
  print("-1")
  sys.exit()

ans = 1
for i in range(0,N):
  ans = ans*int(A[i])
  if ans > 10**18:
    print("-1")
    sys.exit()

print(ans)

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

using namespace std;

int main(void){
    string S, ZF, OF;
    cin>>S;

    int cnt1 = 0;
    int cnt2 = 0;
    ZF.resize(S.size());
    OF.resize(S.size());

    for(unsigned int i=0; i<S.size(); i++){
        if(i%2==0)ZF[i] = '0';
        else ZF[i] = '1';
    }

    for(unsigned int i=0; i<S.size(); i++){
        if(i%2==0)OF[i] = '1';
        else OF[i] = '0';
    }

    for(unsigned int i=0; i<S.size(); i++){
        if(S[i]!=ZF[i])cnt1++;
    }

    for(unsigned int i=0; i<S.size(); i++){
        if(S[i]!=OF[i])cnt2++;
    }

    if(cnt1 <= cnt2)cout<<cnt1<<endl;
    else cout<<cnt2<<endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

int main(){
  vector<int> v;
  int tmp;
  for(int i=0;i<4;i++){
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  if(v[0]==1&&v[1]==4&&v[2]==7&&v[3]==9)puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b; cin >> a >> b;
  string s; cin >> s;
  bool acceptable = 1;
  set<char> numbers;
  numbers.insert('0');
  numbers.insert('1');
  numbers.insert('2');
  numbers.insert('3');
  numbers.insert('4');
  numbers.insert('5');
  numbers.insert('6');
  numbers.insert('7');
  numbers.insert('8');
  numbers.insert('9');
  for(int i = 0; i < a + b + 1; i++) {
    if(i == a) {
      if(s.at(i) != '-') {
        acceptable = 0;
      }
    }
    else{
      if(!(numbers.count(s.at(i)))) {
        acceptable = 0;
      }
    }
  }
  if(acceptable) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll H, n , count = 0 ,ans = 1;
    cin>>H;
    while(H/2){
        count++;
        H=H/2;
    }
    for(int i = 0 ;i<count+1;i++)
    {
        ans = ans * 2;
    }
    cout<<ans-1;
	return 0;
}

Measured memory_bytes: 3656
n,m,a,b=list(map(int,input().split()))
#n,m,a,b=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
print("No War" if (max(x)<min(y) and a<b and a<min(y) and b>max(x)) else "War")


Measured memory_bytes: 2940
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	ll A, B,K ;
	
	cin >> A>>B>>K;
	
	if (A >= K) {
		cout << A - K << " " << B << endl;
	}
	else {
		cout << 0 << " " << max(B-(K-A),ll(0))<< endl;
	}
	
	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;

int main() {
    ll n;
    cin >> n;
    ll y=n;
    map<int,int> m;
    for (int i=2;i<=sqrt(n)+1;i++){
        while(true){
            if (y%i!=0) break;
            m[i]++;
            y/=i;
        }
    }
    if (y!=1) m[y]++;
    int ans=0;
    for (auto it=m.begin();it!=m.end();++it){
        int u=1,v=it->second;
        while(true){
            if (v<u) break;
            ans++;
            v-=u;
            u++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3728
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int A, B, C, X;
int main() {
	while (cin >> A >> B >> C >> X) {
		int res = 0;
		REP(i, A+1) {
			REP(j, B+1) {
				REP(k, C+1) {
					if (500 * i + 100 * j + 50 * k == X)
						++res;
				}
			}
		}
		cout << res << endl;
	}
}

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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    int N;cin>>N;
    VI A(N);
    REP(i, N)
    {
        cin >> A.at(i);
    }
    
    int min_cost=INF;
    FOR(i, -100, 101)
    {
        int cost = 0;
        REP(j, N)
        {
            cost += pow((i-A.at(j)), 2);
        }
        min_cost = min(min_cost, cost);
    }
    cout << min_cost << endl;

    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <complex>
#include <iomanip>
#include <cassert>
#include <map>
#include <string>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll INF = 1e15;
const ll MOD = (1e9)+7;
const ll MAX_N = 1 << 17;
 
int main(){
	ll N;
	cin >> N;
	vector<ll> v(N*3);
	for(int i=0;i<N*3;i++){
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	ll ans=0;
	for(int i=N;i<N*3;i+=2){
		ans+=v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

ll dp[55][55][3000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,a;
  cin >> n >> a;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  
  memset(dp,0,sizeof(dp));
  dp[0][0][0]=1;
  rep(i,n){
    rep(j,n+1){
      rep(k,n*a+1){
        if(dp[i][j][k] == 0) continue;
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
        dp[i+1][j][k] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for(int j=1;j<=n;j++)ans+=dp[n][j][j*a];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 71168
#include <iostream>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <cstring>
#include <climits>
#include <iomanip>

#define EPS 1e-7
#define LLMAX 9223372036854775807
#define INTMAX 2147483647
#define ULLMAX 18446744073709551615
#define precision(n) cout << setprecision(n) << fixed
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rforr(i, t, n) (int i = n-1; i>=t; --i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 1024;

//STRUCTS


//OPERATORS


//GLOBALS


//FUNCTIONS


//PROBLEM: 
//LINK: 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
		int n;
		cin >> n;
		pii a[n];
		forn(i, n)
		{
			cin >> a[i].first;
			a[i].second = i+1;
		}
		sort(a, a+n);
		forn(i, n)
		{
			cout << a[i].second << " ";
		}



	return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std ;
int h(string x){return x=="AC";}
int main()
{
	int n , m ;
	cin >> n >> m ;
	int sol = 0 , pen = 0 ;
	map<int , int > mp ;
	for(int i = 0 ; i < m ; i++)
	{
		string res ;
		int pro ;
		cin >> pro >> res ;
		if(mp[pro]==int(1e8)) continue ;
		if(h(res)){  sol++; pen += mp[pro] ;mp[pro] = 1e8 ;}
		else mp[pro] += 1 ;
	}
	cout << sol << " " << pen << '\n' ;

}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long  int
#define all(x) (x).begin(), (x).end()
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
// #define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
// getting string line
// getline(cin,word);
// -> priority_queue < int > pq; // max_heap
// -> priority_queue < int , vector < int > , greater < int > > pq; // min_heap


ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}

template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}

struct comp {
    bool operator()(int const &i, int const &j) const {
        return i > j;
    }
};

struct Triplet{
    ll x,y,z;
};


int main(){
    FastIO;
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ll n;
    cin>>n;
    vc<ll> arr(n);
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(all(arr));
    reverse(all(arr));
    ll ans = 0;
    queue<pll> q;
    pll x = {arr[0],arr[0]};
    q.push(x);
    for(ll i=1;i<n;i++){
        pll u = q.front();
        q.pop();
        ans+=min(u.first,u.second);
        pll x = {u.first,arr[i]};
        pll y = {arr[i],u.second};
        q.push(x);
        q.push(y);
    }
    cout<<ans<<endl;
    return 0;
}
    

Measured memory_bytes: 8180
#include<iostream>
using namespace std;
long sum[4001],p,q;
int n,e;
int E[1000],u[4001];
main()
{
	while(cin>>n,n)
	{
		for(int i=0;i++<4000;)sum[i]=u[i]=0;
		for(int i=0;i<n;i++)
		{
			cin>>e>>p>>q;
			sum[e]+=p*q;
			E[i]=e;
		}
		bool f=0;
		for(int i=0;i<n;i++)
		{
			if(sum[E[i]]>=1e6)
			{
				if(u[E[i]])continue;
				u[E[i]]=1;
				f=1;
				cout<<E[i]<<endl;
			}
		}
		if(!f)cout<<"NA"<<endl;
	}
}



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


int main()
{
  int r,g,b;
  cin >> r >> g >> b;

  int ret = 100 * r + 10 * g + b;
  if(ret % 4 == 0){
    cout << "YES" << endl;
  }else if(ret % 4 != 0){
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#require 'pp'

n = gets.to_i
f_n = Array.new(n)
p_n = Array.new(n)
n.times do |i|
    f_n[i] = gets.split.join.to_i(2)
end
n.times do |i|
    p_n[i] = gets.split.map(&:to_i)
end

#pp f_n
#pp p_n

memo = {}
n.times do |i|
    memo[i] = {}
end

ans = -99999999999999
(1..1023).each do |i|
    sum = 0
    f_n.each_with_index do |f, j|
        x = i & f
        s = x.to_s(2)
        if memo[j][s]
            memo[j][s]
        else
            memo[j][s] = p_n[j][s.chars.count {|ch| ch == '1' }]
        end

        sum += memo[j][s]
    end

    if sum > ans
        ans = sum
    end
end

puts ans


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

int main()
{
	int n;
	cin>>n;
	vector<int>v(n,0),v1(n,0);
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v[i]=x;
	}
	v1[0]=0;
	v1[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++)
		v1[i]=min(v1[i-2]+abs(v[i-2]-v[i]),v1[i-1]+abs(v[i-1]-v[i]));
	cout<<v1[n-1];
}

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

int main(){
  int x,y,z,a,b;
  cin >> x >> y >> z;
  cout << z << ' ' << x << ' ' << y << endl;
}
  

Measured memory_bytes: 256