akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
template<class T>
T gcd(T x, T y) {
	return y ? gcd(y, x % y) : x;
}

template<class T>
vector<T> enum_div(T n) {
	vector<T> ret;
	for (T i = 1; i * i < n; ++i) {

		if (n % i == 0) {
			ret.push_back(i);

			if (i != 1 && i * i != n) {
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}

template<class T>
long long C(T n, T r) {
	static map<pair<T, T>, long long> _map;
	if (n < r) return 0;

	if (n == r || r == 0) {
		_map[make_pair(n, r)] = 1ll;
	}
	else if (_map[make_pair(n, r)] == 0) {
		_map[make_pair(n, r)] = (C(n - 1, r) + C(n - 1, r - 1));
	}

	_map[make_pair(n, r)] %= MOD;
	return _map[make_pair(n, r)];
}

int main() {
	map<string, int> S;
	S["SUN"] = 7;
	S["MON"] = 6;
	S["TUE"] = 5;
	S["WED"] = 4;
	S["THU"] = 3;
	S["FRI"] = 2;
	S["SAT"] = 1;

	string s;
	cin >> s;

	cout << S[s] << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
struct edge { int to, cost; };
vector<edge> G[100000];
int d[100000];
int main() {
	int k; cin >> k;
	rep(i, k - 1) {
		G[i].push_back({ i + 1,1 });
	}
	G[k - 1].push_back({ 0,1 });
	rep(i, k) {
		G[i].push_back({ i * 10 % k,0 });
	}
	priority_queue<P, vector<P>, greater<P>> q;
	q.push({ 1,1 });
	fill(d, d + k, (int)MOD);
	d[1] = 1;
	while (!q.empty()) {
		P p = q.top(); q.pop();
		int v = p.second;
		if (p.first > d[v])continue;
		int len = G[v].size();
		rep(j, len) {
			edge e = G[v][j];
			if (e.cost + d[v] < d[e.to]) {
				d[e.to] = e.cost + d[v];
				q.push({ d[e.to],e.to });
			}
		}
	}
	cout << d[0] << endl;
	return 0;
}

Measured memory_bytes: 6904
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
def main():
	N, X = map(int, input().split(" "))
	L = input().split(" ")
	L = [int(s) for s in L]
	
	if N == 1:
		print(abs(L[0]-X))
		sys.exit()
	
	L.sort()
	tmp = bisect_left(L, X)
	
	max1 = 2000000001
	if tmp < len(L):
		max1 = L[tmp]
	
	min1 = 2000000001
	if tmp != 0:
		min1 = L[tmp-1]
	
	seed = 0
	mark = -1
	if abs(max1-X) < abs(X-min1):
		seed = abs(max1-X)
		mark = tmp
	else:
		seed = abs(X-min1)
		mark = tmp-1
	
	ans = 2000000001
	for i, val in enumerate(L):
		if i == mark:
			continue
		tmp = abs(L[i] - L[mark])
		ans_tmp = gcd(tmp, seed)
		if ans > ans_tmp:
			ans = ans_tmp
	
	print(ans)
		
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 14612
#include <cstdio>

int gcd(int a, int b) {
	if (a > b) return gcd(b, a);
	if (a == 0) return b;
	return gcd(b % a, a);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

int main() {
	int X; scanf("%d", &X);
	printf("%d", lcm(X, 360) / X);
	return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

//----------------------------------------


int main(void)
{
	
	char a;
	cin >> a;

	a++;

	cout << a << endl;
}



Measured memory_bytes: 256
#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())
map<string,int>sad;
int a[100005];
int main()
{
    _SAD()
    int n,m,cnt=0,mx=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        a[m]++,a[m-1]++,a[m+1]++;
    }
    SRT(a,100005);
    cout<<a[100005-1]<<NL;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        // Your code here!
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int H = a[0];
        int W = a[1];
        char[,] matrix = new char[H,W];
        
        for(int h = 0; h < H; h++)
        {
            string line = Console.ReadLine();
            
            for(int w = 0; w < W; w++)
            {
                matrix[h, w] = line[w];
            }
        }
        
        //シミュレーション
        for(int h = 0; h < H; h++)  //行を消す
        {
            int flag = 0;
            for(int w = 0; w < W; w++)
            {
                if(matrix[h, w] == '#' )//黒があったら
                {
                    flag = 1;
                    break;
                }
            }
            if(flag == 0) //h行目が全部白ならば
            {
                //h行目を全部消す
                for(int w = 0; w < W; w++)
                {
                    matrix[h, w] = 'o';
                }
            }
        }
        
        for(int w = 0; w < W; w++)  //列を消す
        {
            int flag = 0;
            for(int h = 0; h < H; h++)
            {
                if(matrix[h, w] == '#' )//黒があったら
                {
                    flag = 1;
                    break;
                }
            }
            if(flag == 0) //w列目が全部白ならば
            {
                //w列目を全部消す
                for(int h = 0; h < H; h++)
                {
                    matrix[h, w] = 'o';
                }
            }
        }
        
        
        for(int h = 0; h < H; h++) //出力
        {
            bool newLine = false;
            for(int w = 0; w < W; w++)
            {
                if(matrix[h, w] != 'o')
                {
                    Console.Write(matrix[h,w]);
                    newLine = true;
                }
                
                
            }
            if(newLine == true)
            {
                Console.WriteLine();
            }
        }
        
        /*
        for(int h = 0; h < H; h++) //出力
        {
            for(int w = 0; w < W; w++)
            {
                Console.Write(matrix[h,w]);
                
            }
            Console.WriteLine();
        
            
        }
        */
    }
}

Measured memory_bytes: 13368
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

void die() {
  cout << "Impossible\n";
  exit(0);
}

void solve() {
  int n;
  cin >> n;
  vector<int> v;
  v.resize(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  if(2*v[0] < v[n-1]) die();
  int diam = v[n-1];
  for(int a = 0; a <= diam; a++) {
    int b = diam - a;
    int want = max(a, b);
    bool found = false;
    for(int i = 0; !found && i < v.size(); i++) {
      if(v[i] == want) {
        v.erase(v.begin() + i);
        found = true;
      }
    }
    if(!found) die();
  }
  while(v.size()) {
    bool found = false;
    for(int a = 0; a <= diam; a++) {
      int b = diam - a;
      int now = max(a+1, b+1);
      if(now == v.back()) found = true;
    }
    if(found) v.pop_back();
    else die();
  }
  cout << "Possible\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding("utf8");
let input = "";
process.stdin.on("data", function(chunk) {input += chunk;});
process.stdin.on("end", function() {main(input.split("\n"));});

function allocNode(key) {
	const p = {};
	p.key = key;
	p.left = null;
	p.right = null;
	return p;
}

function insert(p,c) {
	if (p === null) return c;
	if (c.key < p.key) {
		p.left = insert(p.left,c);
	}	else {
		p.right = insert(p.right,c);
	}
	return p;
}

function find(p,key) {
	if (p !== null && p.key !== key) {
		if (key < p.key) p = find(p.left,key);
		else p = find(p.right,key);
	}
	return p;
}

function inset(p,ary) {
	if (p === null) return;
	inset(p.left,ary);
	ary.push(p.key);
	inset(p.right,ary);
}

function preset(p,ary) {
	if (p === null) return;
	ary.push(p.key);
	preset(p.left,ary);
	preset(p.right,ary);
}

function dump(p,setfunc) {
	const ary = [];
	setfunc(p,ary);
	console.log(ary.map(x => ` ${x}`).join(""));
}

function main(lines){
	const n = Number(lines[0]);
	let p, key, line, root = null;

	for (let i = 0; i < n; i++) {
		line = lines[i+1].split(" ");
		switch(line[0][0]) {
		case "i":
			key = Number(line[1]);
			p = allocNode(key);
			root = insert(root,p);
			break;
		case "p":
			dump(root,inset);
			dump(root,preset);
			break;
		case "f":
			key = Number(line[1]);
			if (find(root,key) !== null) console.log("yes");
			else console.log("no");
			break;
		}
	}
}



Measured memory_bytes: 215336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  string s;
  int k;

  cin >> s >> k;

  vector<string> v;

  for(int i = 0; i < s.size(); i++){
    if(i + k < s.size()){
      v.push_back(s.substr(i, k));
    } else {
      v.push_back(s.substr(i, s.size() - i));
    }
  }

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

  for(vector<string>::iterator i = v.begin(); i != v.end(); i++){
    if((*i).size() < k){
      if((*i) != (*(i+1)).substr(0, (*i).size())){
        k -= (*i).size();
      }
    } else {
      cout << (*i).substr(0, k) << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

#define N 1001
#define inf 1000000
#define whi 0
#define gra 1
#define bra 2

void dijk(void);

int n,G[N][N];

int main()
{
  int u,k,v,c,i,j;
  
  scanf("%d",&n);

  for(i=0; i<n; i++)
    for(j=0; j<n; j++)
      G[i][j]=inf;
  
  for(i=0; i<n; i++)
    {
      scanf("%d%d",&u,&k);
      for(j=0; j<k; j++)
	{
	  scanf("%d%d",&v,&c);
	  G[u][v]=c;
	}
    }

  dijk();

  return 0;
}

void dijk(void)
{
  int col[N],d[N],u,v,x,i,j;

  for(i=0; i<n; i++)
    {
      d[i]=inf;
      col[i]=whi;
    }

  d[0]=0;
  col[0]=gra;

  while(1)
    {
      x=inf;
      u=-1;

      for(i=0; i<n; i++)
	{
	  if(x>d[i] && col[i] != bra)
	    {
	      u=i;
	      x=d[i];
	    }
	}

      if(u==-1) break;

      col[u]=bra;

      for(v=0; v<n; v++)
	{
	  if(col[v] != bra && G[u][v] != inf && d[v]>d[u]+G[u][v])
	    {
	      d[v]=d[u]+G[u][v];
	      col[v]=gra;
	    }
	}
    }

  for(i=0; i<n; i++)
    {
      printf("%d %d\n",i,d[i]);
    }
}



Measured memory_bytes: 2176
import sys
n,k=map(int,input().split())
a=list(map(lambda x:int(x)-1,input().split()))

x=[-1]*n
x[0]=0
now=0

if k<=n:
    for _ in range(k):
        now=a[now]
    print(now+1)
    sys.exit()

for i in range(1,n+1):
    now=a[now]
    if x[now]==-1:
        x[now]=i
    else:
        k=(k-x[now])%(i-x[now])
        break
for i in range(k):
    now=a[now]
print(now+1)

Measured memory_bytes: 92160
# coding: utf-8

import math
import itertools

N = int(input())

P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

n = list(itertools.permutations(range(1, N + 1)))

a = n.index(tuple(P))
b = n.index(tuple(Q))

print(abs(a - b))

Measured memory_bytes: 8052
local x = io.read("*n")
for a = 0, 1000 do
  for b = 0, a - 1 do
    if a * a * a * a * a - b * b * b * b * b == x then
      print(a .." " .. b)
      os.exit()
    end
  end
end
for a = 0, 100 do
  for b = -100, 100 do
    if a * a * a * a * a - b * b * b * b * b == x then
      print(a .." " .. b)
      os.exit()
    end
  end
end


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

vector<ll> dp(110000, 0);
int main(){

    int n, m;
    cin >> n >> m;

    vector<int> a(m);
    rep(i, m) cin >> a[i];

    int idx = 0;
    dp[0] = 1; dp[1] = 1;
    if(m != 0 and a[0] == 1){
        dp[1] = 0;
        ++idx;
    }

    for(int i = 2; i <= n; ++i){
        if(idx < m and i == a[idx]){
            ++idx;
            continue;
        }
        dp[i] = dp[i-2]+dp[i-1];
        dp[i] %= MOD;
    }
    ppp(dp[n]);


    return 0;
}


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

int main(){
    int N,W,i,j;
    cin>>N>>W;
    vector<vector<int>> A(N,vector<int>(2));//重さ、価値の順にする
    vector<vector<int>> dp(N,vector<int>(W+1));
    for(i=0;i<N;i++)cin>>A[i][1]>>A[i][0];
    sort(A.begin(),A.end());
    for(j=A[0][0];j<=W;j++)dp[0][j]=dp[0][j-A[0][0]]+A[0][1];
    for(i=1;i<N;i++){
        for(j=0;j<=W;j++){
            if(j-A[i][0]<0){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-A[i][0]]+A[i][1]);
            }
        }
    }
    cout<<dp[N-1][W]<<endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    if (N & 1) {
        for (int i = 1; i <= M; ++i)
            cout << i << " " << (N - i) << endl;
    } else {
        for (int i = 1; i <= M; ++i) {
            int tmp = N - i;
            if (N - 2 * i <= N / 2) --tmp;
            cout << i << " " << tmp << endl;
        }
    }
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main()
{
    int a[3],b[4],r;
    cin>>b[0];
    b[3]=b[0]%10;
    b[2]=b[0]/10%10;
    b[1]=b[0]/100%10;
    b[0]=b[0]/1000%10;
    for(a[0]=0;a[0]<2;a[0]++)
      for(a[1]=0;a[1]<2;a[1]++)
        for(a[2]=0;a[2]<2;a[2]++)
        {
            r=a[0]?(b[0]+b[1]):(b[0]-b[1]);
            r=a[1]?(r+b[2]):(r-b[2]);
            r=a[2]?(r+b[3]):(r-b[3]);
            if(r==7)
            {
                cout << b[0]<<(a[0]?'+':'-')<<b[1]<<(a[1]?'+':'-')<<b[2]<<(a[2]?'+':'-') <<b[3]<<"=7"<< endl;
                return 0;
            }
        }



    return 0;
}


Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int l, a, b, c, d; cin >> l >> a >> b >> c >> d;
	cout << l - max((a + c - 1) / c, (b + d - 1) / d) << endl;
	return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int A, B;
   cin >> A >> B;

   cout << max(A + B, max(A - B, A * B)) << endl;
   return 0;
}


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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
const int INF = 1e9 + 5;

signed main() {
    FAST_IO;

    int n, k;
    cin >> n >> k;
    vector<int> stone(n);
    for (int i = 0; i < n; i++) cin >> stone[i];
    vector<int> dp(n, INF); // dp[i] : stores the minimum cost to reach position i+1 (0 based indexing)
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= i + k; j++) {
            if (j < n) dp[j] = min(dp[j], dp[i] + abs(stone[i] - stone[j]));
        }
    }
    cout << dp[n - 1];
    return 0;
}

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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

void Main()
{
	Bint A, B, C, K;
	cin >> A >> B >> C >> K;

	Bint k = K;
	Bint a = min(A, k);
	k -= a;
	Bint b = min(B, k);
	k -= b;
	Bint c = min(C, k);

	Bint r = a - c;
	cout << r;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

 bool is_prime(long long x){
   if(x<=1) return false;
   for(long long i=2;i*i<=x;i++)
   if(x%i==0) return false;
   return true;
 }

int main() {
  int n;
  cin>>n;
  vector<int>sosuu(100005,-1);
  vector<int>hantei(100005,0);
  vector<int>rui(100005,0);
  sosuu[0]=0;
  sosuu[1]=0;
  for(int i=2;i<=100005;i++){
    if(sosuu[i]==-1)sosuu[i]=1;
    if(sosuu[i]==0)continue;
    int count=2;
    while(100005>i*count){
      sosuu[i*count]=0;
      count++;
    }
  }
  for(int i=2;i<100005;i++){
    if(i%2==1 && sosuu[i]==1 && sosuu[(i+1)/2]==1){
      hantei[i]=1;
    }
  }
  for(int i=2;i<100005;i++){
      rui[i]=hantei[i]+rui[i-1];
  }
  for(int i=0;i<n;i++){
    int l,r;
    cin>>l>>r;
    long long kotae=rui[r]-rui[l-1];
    cout<<kotae<<endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


int dp[10001];

void solve()
{
  
  int n;
  cin >> n ;

  for(int i=1;i<100;i++)
  {
    for(int j=1;j<100;j++)
    {
      for(int k=1;k<100;k++)
      {
        int vl = i*i+j*j+k*k+i*j+j*k+k*i;
        if(vl<=n) dp[vl]++;
      }
    }
  }

  forf(i,1,n+1)
  {
    cout<<dp[i]<<"\n";
  }

}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 3676
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, k;
    cin >> n >> k;
    vvll a(2, vll(n));
    for(ll i = 0; i < n; i++) cin >> a[0][i];
    ll last = 0;
    for(ll i = 0; i < k; i++) {
        last = i + 1;
        ll f = i % 2;
        fill(a[1-f].begin(), a[1-f].end(), 0);
        for(ll j = 0; j < n; j++) {
            ll l = max(j - a[f][j], 0ll);
            a[1-f][l]++;
            ll r = j + a[f][j];
            if(r + 1 < n) a[1-f][r+1]--;
        }
        for(ll i = 0; i < n - 1; i++) a[1-f][i+1] += a[1-f][i];
        bool alln = true;
        for(ll i = 0; i < n; i++) {
            if(a[1-f][i] < n) {
                alln = false;
                break;
            }
        }
        if(alln) break;
    }
    ll f = last % 2;
    for(ll i = 0; i < n; i++) {
        if(i < n - 1) cout << a[f][i] << ' ';
        else cout << a[f][i] << endl;
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		int arr[n];
		f(i,n) cin>>arr[i];
		ll ans =0 ;
		for(int i=1; i<n; i++) {
			if(arr[i] < arr[i-1]) {
				ans += arr[i-1] - arr[i];
				arr[i] = arr[i-1];
			}
		}
		cout<<ans<<"\n";
 	}
 	return 0;
}


Measured memory_bytes: 4432
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int a, b;
	cin >> a >> b;

	Int temp = a * b;
	Int flag = 0;
	for (Int i = 1; i < 4; i++) {
		if (temp*i%2) {
			flag = 1;
		}
	}
	if (flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";
}


Measured memory_bytes: 256
// Simple Calculator.c
// ２つの整数 a, b と１つの演算子 op を読み込んで、a op b を計算するプログラムを
// 作成して下さい。
// ただし、演算子 op は、"+"(和)、"-"(差)、"*"(積)、"/"(商)、のみとし、
// 割り算で割り切れない場合は、小数点以下を切り捨てたものを計算結果とします。
// 【入力】
// 入力は複数のデータセットから構成されています。各データセットの形式は以下のとおりです：
//   a op b
// op が '?' のとき 入力の終わりを示します。このケースの出力は行ってはいけません。
// 【出力】
// 各データセットについて、計算結果を１行に出力して下さい。
// 【制約】
// ・0 ≤ a, b ≤ 20000
// ・0 による割り算が与えられることはありません。
// 【例】
// 入力：
// 1 + 2
// 56 - 18
// 13 * 2
// 100 / 10
// 27 + 81
// 0 ? 0
// 出力：
// 3
// 38
// 26
// 10
// 108
#include<stdio.h>

int main( void) {
  int a, b;
  char op;

  while ( 1) {
    scanf( "%d %c %d", &a, &op, &b);

    if ( op == '?') break;

    if ( op == '+') printf( "%d\n", a+b);
    else if ( op == '-') printf( "%d\n", a-b);
    else if ( op == '*') printf( "%d\n", a*b);
    else printf( "%d\n", a/b);
  }

  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    int res = 0;
    int l, r, d; cin >> l >> r >> d;
    for (int i = l; i <= r; i++) {
        res += (i % d == 0);
    }
    cout << res << "\n";
}


Measured memory_bytes: 3648
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        int[] a = new int[n];
        var input = ReadLine().Split();
        int m = 0;
        foreach (int i in EnumerableCommon.Range(n))
        {
            a[i] = int.Parse(input[i]);
            m += a[i] - 1;
        }

        WriteLine(m);
    }


    public static partial class EnumerableCommon
    {
        public static IEnumerable<int> Range(int count)
        {
            return Enumerable.Range(0, count);
        }
    }
}

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

int main() {
	int n, a, q, m;
	cin >> n;

	bool dp[2001] = {1, 0};
	for (int i=0; i<n; ++i) {
		cin >> a;
		for (int j=2000; j>=0; --j) {
			dp[j+a] |= (dp[j] && j+a<2001);
		}
	}

	cin >> q;
	for (int i=0; i<q; ++i) {
		cin >> m;
		cout << (dp[m] ? "yes" : "no") << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
n = int(input())
w = list(map(int, input().split()))

res = sum(w)
sum1 = 0
sum2 = sum(w)
for i in range(n):
    sum1 += w[i]
    sum2 -= w[i]
    res = min(res, abs(sum2-sum1))

print(res)

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

int main() {
  int a,b,ans;
  cin >> a >> b;
  if (a%3==0 || b%3==0) {cout << 0 << endl;return 0;}
  ans=min(a,b);
  int t=0;
  for(int i=0;i<a+1;i++){
    if (t==0 && i*2>a-i){
      ans=min(ans,(i*b-(b/2)*(a-i)));
      ans=min(ans,((b/2+(b%2))*(a-i+1)-(i-1)*b));
      //　cout << ans << endl;
      t=1;
    }
  }
  t=0;
  for(int i=0;i<b+1;i++){
    if (t==0 && i*2>b-i){
      ans=min(ans,(i*a-(a/2)*(b-i)));
      ans=min(ans,((a/2+(a%2))*(b-i+1)-(i-1)*a));
      t=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> w(n);
    for(int i = 0; i < n; i++) cin >> w[i];
    vector<int> sum(n + 1, 0);
    for(int i = 0; i < n; i++) sum[i + 1] = sum[i] + w[i];
    int ans = INF;
    for(int i = 0; i < sum.size(); i++)
    {
        int a = sum[n] - sum[i];
        int b = sum[i];
        ans = min(ans, abs(a - b));
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  int m;
  cin >> m;
  vector<int> t(m);
  rep(i, m) cin >> t[i];

  map<int, int> mp;
  rep(i, n) ++mp[d[i]];
  bool ok = true;
  rep(i, m) {
    if (mp[t[i]] == 0) {
      ok = false;
      break;
    }
    --mp[t[i]];
  }
  if (ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

using namespace std;

int dp[3][100000];
int A[3][100000];

int f(int i, int j) {
  if(j < 0) return 0;
  if(dp[i][j]) return dp[i][j];
  int mx = 0;
  for(int k = 0; k < 3; ++k)
    if(k != i) mx = max(mx, f(k, j - 1) + A[k][j]);
  return dp[i][j] = mx;
}

int main() {
  int n; cin >> n;
  for(int i = 0; i < n; ++i)
    cin >> A[0][i] >> A[1][i] >> A[2][i];
  
  int mx = 0;
  for(int i = 0; i < 3; ++i)
    mx = max(mx, A[i][n - 1] + f(i, n - 2));
  
  cout << mx;
  return 0;
}

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

struct UnionFind{
  vector<int> parent;
  vector< ll > dist;
  UnionFind(int x=1){
    parent.clear();
    parent.resize(x,-1);
    dist.clear();
    dist.resize(x,0);
  }
  int find(int x){
    if(parent[x]<0)return x;
    int r=find(parent[x]);
    dist[x]+=dist[ parent[x] ];
    return parent[x]=r;    
  }
  ll depth(int x){
    find(x);
    return dist[x];
  }
  bool same(int x,int y){
    return (find(x)==find(y));
  }
  int size(int x){
    return -parent[find(x)];
  }
  void unite(int x,int y,ll k=0){
    k+=depth(y);
    k-=depth(x);
    k*=-1;
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(size(x)<size(y)){
      swap(x,y);
      k*=-1;
    }
    parent[x]+=parent[y];
    parent[y]=x;
    dist[y]=k;
  }
};




int main(){
  int n,q;
  scanf("%d %d",&n,&q);
  UnionFind T(n);
  for(int i=0;i<q;i++){
    int type,x,y;
    scanf("%d %d %d",&type,&x,&y);
    if(type==0){
      int a;
      scanf("%d",&a);
      T.unite(x,y,a);
    }else{
      
      if(!T.same(x,y)){
        printf("?\n");
      }else{
        printf("%lld\n",T.depth(x)-T.depth(y));
      }
    }
  }
  return 0;
}




Measured memory_bytes: 3868
#include<stdio.h>

int main(){

    int S,h,m,s;

    scanf("%d",&S);

    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = S % 3600 % 60;

    printf("%d:%d:%d\n",h,m,s);

    return 0;

}


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

const long long INF = 1LL<<60;
int N;
long long K;
vector<int> P;
vector<long long> C;

long long solve() {
    long long res = -INF;

    // 順列を各サイクルに分解する
    vector<bool> used(N, false);
    vector<vector<long long>> ss;
    for (int i = 0; i < N; ++i) {
        if (used[i]) continue;
        int cur = i;
        vector<long long> s;
        while (!used[cur]) {
            used[cur] = true;
            s.push_back(C[cur]);
            cur = P[cur];
        }
        ss.push_back(s);
    }

    // 各サイクルごとに考える
    for (auto vec : ss) {
        long long M = vec.size();

        // サイクルを二週したものの累積和
        vector<long long> sum(M*2+1, 0);
        for (int i = 0; i < M*2; ++i) sum[i+1] = sum[i] + vec[i%M];

        // amari[r] := 連続する r 個の総和の最大値
        vector<long long> amari(M, -INF);
        for (int i = 0; i < M; ++i) {
            for (int j = 0; j < M; ++j) {
                chmax(amari[j], sum[i+j] - sum[i]);
            }
        }

        // 余りの長さで場合分け
        for (int r = 0; r < M; ++r) {
            if (r > K) continue;
            long long q = (K - r) / M;
            if (r == 0 && q == 0) continue;

            if (sum[M] > 0) chmax(res, amari[r] + sum[M] * q);
            else if (r > 0) chmax(res, amari[r]);
        }
    }
    return res;
}

int main() {
    cin >> N >> K;
    P.resize(N); C.resize(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i];
    for (int i = 0; i < N; ++i) cin >> C[i];
    cout << solve() << endl;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
 
const int inf = 1e9 + 9;
 
int n;
int t[10101];
 
int dp[2][2][5050];
 
int main()
{
  cin >> n;
  for (int i = 1; i < n; i++){
    cin >> t[i];
  }
 
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 5050; k++)
        dp[i][j][k] = inf;
 
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++){
    for (int j = 0; j < n / 2; j++){
      dp[(i + 1) & 1][0][j + 1] = min(dp[i & 1][0][j], dp[i & 1][1][j] + t[i + 1]);
      dp[(i + 1) & 1][1][j] = min(dp[i & 1][0][j] + t[i + 1], dp[i & 1][1][j]);
 
      dp[i & 1][0][j] = dp[i & 1][1][j] = inf;
    }
  }
 
  cout << dp[n & 1][0][n / 2] << endl;
} 

Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    string ans="Possible";
    int count = 0;
    int a[10][10]={};
    for(int i=0;i<h;i++){
        string x;
        cin >> x;
        for(int j=0;j<w;j++){
            if(x[j]=='.'){
                a[i][j]=0;
            }else{
                a[i][j]=1;
                count++;
            }
        }
    }
    
    if(count != h+w-1){
        ans="Impossible";
    }
    int x=0,y=0;
    int cnt=0;
    int cnt2=0;
    bool flagx = false;
    bool flagy = false;
    while(x<h-1||y<w-1){
        if(x==0&&y==0){
            if(a[x+1][y]==1){
                flagx = true;
                cnt++;
            }
            if(a[x][y+1]==1){
                flagy = true;
                cnt++;
            }
        }else{
            if(x<h){
            if(a[x+1][y]==1){
                flagx = true;
                cnt++;
            }
            }
            if(y<w){
            if(a[x][y+1]==1){
                flagy = true;
                cnt++;
            }
            }
            if(x!=0){
                if(a[x-1][y]==1){
                    cnt2++;
                }
            }
            if(y!=0){
                if(a[x][y-1]==1){
                    cnt2++;
                }
            }
        }
        if(cnt>1||cnt2>1){
            ans="Impossible";
            break;
        }
        if(flagy==true&&flagx==true){
            ans="Impossible";
            break;
        }else if(flagx==true){
                x++;
        }else if(flagy==true){
                y++;
            }else{
                ans="Impossible";
                break;
            }
        cnt=0;
        cnt2=0;
        flagx = false;
        flagy = false;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
str = gets.chomp
numbers = Array.new(str.length, 0)
(0..str.length).each do |i|
	if str[i] == "L"
		if str[i - 1] == "L"
			numbers[i] = numbers[i - 1]+1
		end
	end
end
(0..str.length).each do |i|
	i=str.length-i
	if str[i] == "R"
		if str[i + 1] == "R"
			numbers[i] = numbers[i + 1]+1
		end
	end
end

result = Array.new(str.length, 0)
str.length.times do |i|
	if str[i] == "R"
		result[i + numbers[i] + numbers[i] % 2] += 1
	else
		result[i - numbers[i] - numbers[i] % 2] += 1
	end
end
puts result.join(" ")

Measured memory_bytes: 3964
//#include <bits/stdc++.h>
#include<iostream>
#include<numeric>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

int ctoi(char c) {
  if('0'<=c && c <= '9') return c-'0';
  return 0;
}

int main(){
  string s="";
  ull k=0;
  int ans=0;
  cin >> s >> k;
  for(int i=0;i<k;++i){
    if(s[i]!='1'){
      ans = i;
      break;
    }
  }
  cout << s[ans] << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long int ll;

int main(void){
  ll n,x;
  vector<ll> a;
  cin>>n;
  for(int i=0;i<3*n;i++){
    cin>>x;
    a.pb(x);
  }
  sort(all(a));
  ll res=0;
  for(int i=3*n-2;i>n-1;i-=2){
    res+=a[i];
  }
  cout<<res<<endl;
  return 0;
}


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

int main(void) {
  int n,m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i,n){
    cin >> h[i];
  }
  vector<int> a(m);
  vector<int> b(m);
  vector< vector<int> > hill(n);
  rep(i,m){
    cin >> a[i] >> b[i];
    hill[a[i]-1].emplace_back(b[i]);
    hill[b[i]-1].emplace_back(a[i]);
  }
  int counter=0;
  int good=0;
  rep(i,n){
    good=1;
    rep(k,hill[i].size()){
      if(h[hill[i][k]-1]>=h[i]){
        good=0;
        break;
      }
    }
    if(good) counter++;
  }
  cout << counter; //<< endl;
  /*rep(i,n){
    rep(k,hill[i].size()){
      cout << hill[i][k] << " ";

    }
    cout<<endl;
  }*/

  return 0;
}

Measured memory_bytes: 9544
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	bool ok = false;
	if (s.find("AC") != string::npos) {
		ok = true;
	}

	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


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

using namespace std;

int main(void) {
    string s;
    cin >> s;
    if (s[s.size()-1] == 's')
        s += "es";
    else
    {
        s += "s";
    }

    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
using i64 = long long;

std::vector<long long> fact, inv;

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

void init_factorial(const int n, const long long mod) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 998244353;
    i64 n, m, k;
    std::cin >> n >> m >> k;
    init_factorial(n, mod);

    i64 ret = 0;
    i64 r = pow(m - 1, n - k - 1, mod);
    for (int i = n - k - 1; i <= n - 1; i++) {
        ret = (ret + fact[n - 1] * inv[i] % mod * inv[n - 1 - i] % mod * m % mod * r % mod) % mod;
        r = r * (m - 1) % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 6336
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, x, ans = 0, count = 0;
  cin >> a >> b >> n;
  cout << a * min(n, b - 1) / b << endl;
}

Measured memory_bytes: 3612
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = list(map(int, "0"+input()))[::-1]
    l = len(n)
    dp = [n[0],10-n[0]]
    for i in range(1,l):
        ndp = [float("inf")]*2
        x = n[i]
        for j in range(2):
            x += j
            if x < 10:
                nd = dp[j]+x
                if nd < ndp[0]:
                    ndp[0] = nd
            if x > 0:
                nd = dp[j]+(10-x)
                if nd < ndp[1]:
                    ndp[1] = nd
        dp = [i for i in ndp]
    print(dp[0])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 119208
#include <stdio.h>

int main(void){
	int a, b, c = 0;
	scanf("%d%d%d", &a, &b, &c);

	if(a == b){
		printf("%d\n", c);
	} else if(a == c){
		printf("%d\n", b);
	} else {
		printf("%d\n", a);
	}

	return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    int g = 0;
    int ma = 0;
    for(int i = 0; i < N; ++i) {
        g = __gcd(g, A[i]);
        ma = max(ma, A[i]);
    }
    if(ma >= K && K % g == 0) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 640
N = int(input())

AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(N):
    S = str(input())
    if S=="AC":
        AC += 1
    elif S=="WA":
        WA += 1
    elif S=="TLE":
        TLE += 1
    elif S=="RE":
        RE += 1
    
print("AC x",AC)
print("WA x",WA)
print("TLE x",TLE)
print("RE x",RE)

Measured memory_bytes: 9204
#include "bits/stdc++.h"
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1155&lang=jp
using namespace std;
typedef long long ll;

int to_digit(int& at, string& S, int P, int Q, int R) {
	int ret;
	if (S[at] == 'P') ret = P;
	else if (S[at] == 'Q') ret = Q;
	else if (S[at] == 'R') ret = R;
	else ret = S[at] - '0';
	at++;
	return ret;
}
int dfs(int& at,string& S, int P, int Q, int R) {
	int ret;
	if (S[at] == '(') {
		at++;
		ret = dfs(at, S, P, Q, R);
		if (S[at] == '*') {
			at++;
			ret = min(ret, dfs(at, S, P, Q, R));
		}
		else if(S[at] == '+'){
			at++;
			ret = max(ret, dfs(at, S, P, Q, R));
		}

		//')'?????????
		at++;
		return ret;
	}
	else if (S[at] == '-') {
		at++;
		ret = dfs(at, S, P, Q, R);
		if (ret == 0) ret = 2;
		else if (ret == 1) ret = 1;
		else if (ret == 2) ret = 0;
		return ret;
	}
	else {
		return to_digit(at,S, P, Q, R);
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	string S;
	while (cin >> S) {
		if (S == ".")break;
		int ans = 0;
		for (int P = 0; P < 3; P++) {
			for (int Q = 0; Q < 3;Q++) {
				for (int R = 0; R < 3;R++) {
					int at = 0;
					if (dfs(at, S, P, Q, R) == 2) ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;

int f1[200005],f2[200005];
int ka[200005];
map<pair<int,int>,int> p;
int fin1(int x) {
    if(x!=f1[x])
    {
        f1[x]=fin1(f1[x]);
    }
    return f1[x];
}
int fin2(int x)
{
     if(x!=f2[x])
    {
        f2[x]=fin2(f2[x]);
    }
    return f2[x];
}

int main()
{
    int u,v,n,k,l;
    scanf("%d %d %d",&n,&k,&l);
    for(int i=0;i<=n;i++)
    {
        f1[i]=i;
        f2[i]=i;
        ka[i]=1;
    }
    while(k--)
    {
        scanf("%d %d",&u,&v);
        int x=fin1(u);
        int y=fin1(v);
            f1[x]=y;
    }
    while(l--)
    {
        scanf("%d %d",&u,&v);
        int x=fin2(u);
        int y=fin2(v);
            f2[x]=y;
    }
    for(int i=1;i<=n;i++)
    {
        ++p[{fin1(i),fin2(i)}];
    }
    for(int i=1;i<=n;i++)
        printf("%d%c",p[{fin1(i),fin2(i)}],i==n?'\n':' ');
}


Measured memory_bytes: 14336