akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
    int n,i,par[100002],impar[100002],a;

    for (i=1; i<=100001; i++)
    {
        par[i]=0;
        impar[i]=0;
    }

    scanf ("%d",&n);

    for (i=1; i<=n; i++)
    {
        scanf ("%d",&a);
        if (i%2==1)
        {
            impar[a]++;
        }
        else
        {
            par[a]++;
        }
    }

    int maxpar=0,maxpar2=0,maximpar=0,maximpar2=0;
    int valpar,valimpar;

    for (i=1; i<=100001; i++)
    {
        if (impar[i]>maximpar)
        {
            maximpar2=maximpar;
            maximpar=impar[i];
            valimpar=i;
        }
        else if (impar[i]>maximpar2)
        {
            maximpar2=impar[i];
        }

        if (par[i]>maxpar)
        {
            maxpar2=maxpar;
            maxpar=par[i];
            valpar=i;
        }
        else if (par[i]>maxpar2)
        {
            maxpar2=par[i];
        }
    }

    if (valpar==valimpar)
    {
        if (maxpar2>maximpar2)
        {
            printf ("%d\n",n-maxpar2-maximpar);
        }
        else
        {
            printf ("%d\n",n-maxpar-maximpar2);
        }
    }
    else
    {
        printf ("%d\n",n-maxpar-maximpar);
    }

    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int n;

int main(){
  cin>>n;
  vector<int> a(n);
  rep(i,0,n) cin>>a[i];
  sort(a.begin(),a.end());

  //二部探索で半分を探す
  int left=0,right=n-1,p;
  int tmp=a[n-1]/2;
  rep(i,0,100){
    p=(left+right)/2;
    if(a[p]>tmp) right=p;
    else left=p;
  }

if(n==2){
  cout<<a[n-1]<<' '<<a[n-2];
}
else{
  cout<<a[n-1]<<' ';
  if((tmp-a[p])>(a[p+1]-(tmp+1))) cout<<a[p+1];
  else cout<<a[p];
}

}

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

int main() {
	int n, t;
	cin >> n >> t;
	int no_use;
	cin >> no_use;
	int c;
	int h = t, cnt = t;
	for(int i = 1; i < n; ++i) {
		cin >> c;
		if(c < h) {
			cnt -= (h - c);
			h = c + t;
			cnt += t;
		} else {
			h = c + t;
			cnt += t;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
(defparameter *r* (read))
(defparameter *D* (read))
 
(defun next-x (x)
  (- (* *r* x) *D*))
 
(defparameter x (read))
 
(loop for i from 1 to 10
      do (progn (setq x (next-x x))
           		(print x)))

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

using namespace std;

bool cmp(pair<string, pair<int,int> > a, pair<string, pair<int,int> > b){
  if(a.first != b.first){
    return a.first < b.first;
  }
  else {
    return a.second.second > b.second.second;
  }
}

int main(){
  int n;
  pair<string, pair<int,int> > list[100];
  string s;
  int p;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s >> p;
    list[i] = make_pair(s, make_pair(i+1,p));
  }
  std::sort(list,list + n, cmp);
  for(int i = 0; i < n; i++){
    cout << list[i].second.first << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <map>

using namespace std;
int main()
{
	int w,a,b;
	scanf("%d%d%d",&w,&a,&b);
	if(a>b)
	{
		int tmp=a;
		a=b;
		b=tmp;
	}
    if(b-a-w>0)
    cout<<b-a-w<<endl;
    else
    cout<<"0"<<endl;
	return 0;
}

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

char solve(char x , int n) {
  int pos = x - 'A' ;
  pos += n ;
  if(pos >= 26) pos -= 26 ;
  return 'A' + pos ;
}
signed main() {
  ios :: sync_with_stdio(false) ;
  int n ;
  cin >> n ;
  string s ;
  cin >> s ;
  int len = s.length() ;
  for(int i = 0 ; i < len ; i ++)
    cout << solve(s[i] , n) ;
  return 0 ;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    let a: Vec<u32> = (0..n).map(|_| sc.read()).collect();
    for (&a, i) in a.iter().zip(0..n).rev() {
        print!("{}{}", a, if i == 0 { '\n' } else { ' ' });
    }
}



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

lis = [list(map(int,input().split())) for i in range(n)]
lis.sort(key = lambda x:x[1])

dp = {0:0}

for weight ,value in lis:
    gone = dp.copy()
    for key in dp:
        gone[key+value] = min(dp[key] + weight, dp.get(key+value, float("inf")))
    dp = gone
for key in sorted(dp.keys(), reverse = True):
    if dp[key] <= w:
        print(key)
        exit()

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

int main() {
	int a,b,c,sum;
	std::cin>>a>>b>>c;
	sum=a+b+c;
	if(sum%2==1)
		goto a;
	if(sum/2==std::max({a,b,c}))
		std::cout<<"Yes"<<std::endl;
	else{
		a:;
		std::cout<<"No"<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] a = new int[m];
		int count = 0;
		
		for(int i=0;i<m;i++) {
			a[i] = scan.nextInt();
			count += a[i];
		}
		
		if(count > n) {
			System.out.println(-1);
		}else {
			System.out.println(n - count);
		}

	}

}


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

int main() {
    int S;
    cin >> S;
    while (S--) {
        vector<long long> N(9);
        for (int i=0; i<9; ++i) {
            scanf("%x", &N[i]);
        }

        long long key = 0;
        int car = 0;
        for (int i=0; i<32; ++i) {
            int t = car % 2;
            for (int j=0; j<8; ++j) {
                t ^= (N[j] >> i) & 1;
            }

            if (t == ((N[8] >> i) & 1)) {
                for (int j=0; j<8; ++j) {
                    car += (N[j] >> i) & 1;
                }
            } else  {
                key |= (1LL << i);
                for (int j=0; j<8; ++j) {
                    car += ((N[j] >> i) & 1) ^ 1;
                }
            }
            car /= 2;
        }
        printf("%x\n", key);
    }
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>

#include <string>
#include <map>
#include <algorithm>
#include <cassert>
#include <cstdio>

using namespace std;
#define N 40
#define TEST 0


	string a[N];
	int b[N],c[N];
	string d[N][N];
	int edges[N][N];
	int n;

typedef long long i64;
int maxv;
i64 maxi;


void rec(i64 bits,int sum){
	if(sum<=maxv){
		return;
	}
	if((bits&1LL)==0LL)return;
	bool clique=true;
	int minind=100000;
	int mini=-1;
	for(int i=0;i<n;i++){
		if((bits&(1LL<<i))==0)continue;
		int ind=0;
		for(int j=0;j<n;j++){
			if((bits&(1LL<<j))==0)continue;
			if(i==j)continue;
			if(edges[i][j])
				ind+=1;
			else
				clique=false;
		}
		if(minind>ind){
			mini=i;
			minind=ind;
		}
	}
	if(mini==-1)assert(!"error mini==-1");
	int sub1=b[mini];
	i64 set1=1LL<<mini;
	for(int i=0;i<n;i++){
		if((bits&(1LL<<i))==0)continue;
		if(i==mini)continue;
		if(edges[mini][i]){
			sub1+=b[i];
			set1|=1LL<<i;
		}
	}
	if(!clique){
		rec(set1,sub1);
		rec(bits&~(1LL<<mini),sum-b[mini]);
		return;
	}
	//clique
	if(maxv<sub1){
		maxv=max(maxv,sub1);
		maxi=bits;
	}
}



int main(void){
	int di[N][N];
	while(1){
		cin>>n;
		if(TEST)cerr<<"n="<<n<<endl;
		if(n==0)break;
		map<string,int> m;
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i]>>c[i];
			for(int j=0;j<c[i];j++){
				cin>>d[i][j];
			}
		}
		int cnt=0;
		for(int i=0;i<n;i++){
			m.insert(pair<string,int>(a[i],i));
		}
		for(int i=0;i<n;i++){
			fill_n(edges[i],n,1);
			edges[i][i]=0;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<c[i];j++){
				di[i][j]=m[d[i][j]];
				edges[i][di[i][j]]=0;
			}
		}
		if(TEST){
			for(int i=0;i<n;i++){
				for(int  j=0;j<n;j++){
					cerr<<edges[i][j]<<" ";
				}
				cout<<":"<<b[i]<<endl;
			}
		}
		maxv=0;
		int sum=0;
		for(int i=0;i<n;i++){
			sum+=b[i];
		}
		rec((1LL<<n)-1,sum);
		cout<<maxv<<endl;
		if(TEST){
			fprintf(stderr,"set=%llx\n",maxi);
		}
	}
	return 0;
}

Measured memory_bytes: 1336
n=int(input())
alist=list(map(int,input().split()))
blist=[alist[0]]
for i in range(1,n):
	blist.append(blist[-1]+alist[i]) #累積和
alist.reverse()
clist=[alist[0]]
for i in range(1,n):
	clist.append(clist[-1]+alist[i])
clist.reverse()
dlist=[]
for i in range(1,n):
	dlist.append(abs(blist[i-1]-clist[i]))
ans=min(dlist)
print(int(ans))

# hanbun=blist[-1]/2
# shirushi=0
# l=0
# u=n-1
# while u>l+1:
	# aida=(l+u)//2
	# if blist[aida]==hanbun:
		# index=aida
		# shirushi=1
		# break
	# elif blist[aida]>hanbun:
		# l=aida
	# elif blist[aida]<hanbun:
		# u=aida

# if shirushi==1 and blist[-1]%2==0:
	# print(0)
# else:
	# if shirushi==0:
		# if blist[u]-hanbun>hanbun-blist[l]:
			# index=l
		# else:
			# index=u

	# ans=int(2*blist[index]-blist[-1])
	# if ans<0:
		# ans=int(ans*(-1))
	# print(ans)

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


int main(){
    int N,S1=0,S2=0,sum=0;
    cin >> N;
    vector<int> w(N);
    vector<int> s(N);
    for (int i=0;i<N;i++) cin >> w[i];
    for (int i=0;i<N;++i) sum += w[i];
    int tmp = sum;
    for (int i=0;i<N-1;++i){
        S1 = 0;
        for (int j=0;j<=i;++j){
            S1 += w[j];
        }
        S2 = sum - S1;
        if(abs(S2-S1)<=tmp){
            tmp = abs(S2-S1);
        }
    }

    cout << tmp << endl;

    }





Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;

int main(void) {
	int n;
	int a[101];
	long long int p;
	long long int mini=10000000000000;
	cin >> n;
	FOR(i, 1, n) {
		cin >> a[i];
	}
	FOR(i, -100, 100) {
		p = 0;
		FOR(t, 1, n) {
			p += abs(i - a[t])*abs(i - a[t]);
		}
		mini = min(mini, p);
	}
	cout << mini << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

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

BC = [tuple([int(_) for _ in input().split()]) for _ in range(M)]

X = Counter(A)
for a in X:
    BC.append((X[a], a))
BC.sort(key=lambda x: x[1], reverse=True)

ans = 0
k = N
for b, c in BC:
    v = min(k, b)
    ans += v * c
    k -= v

print(ans)


Measured memory_bytes: 42168
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

void solve() {
    int A, B;
    cin >> A >> B;
    int H, M;
    cin >> H >> M;

    dbg << M_PI << endl;
    double ht = (M_PI * H) / 6 + (M_PI * M) / 360;
    double mt = (M_PI * M) / 30;
    double hx = A * cos(ht);
    double hy = A * sin(ht);
    double mx = B * cos(mt);
    double my = B * sin(mt);
    dbg << ht << ", " << mt << endl;
    dbg << hx << ", " << hy << ", " << mx << ", " << my << endl;
    double dist = sqrt((hx - mx) * (hx - mx) + (hy - my) * (hy - my));
    cout << dist << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 4164
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int b[101];
long long ans=0;
int main()
{
	int n;
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>b[i];
	}
	for(int i=2;i<n;i++)
	{
		ans+=min(b[i],b[i+1]);
	}
	cout<<ans+b[2]+b[n];
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N, K, L, x;
  L =0;
  cin >> N >> K;
  for (int i=0;i<N;i++){
    cin >> x;
    if (K-x>x) L += 2*x;
    else if (K-x<=x) L += 2*(K-x);
  }
       cout << L << endl;
   
}
   

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	unordered_set<int> x,y;
	for(int i=0;i!=k;++i){
		int a,b;
		cin>>a>>b;
		if(a==1)
			x.insert(b);
		if(b==n)
			y.insert(a);
	}
	string ans("IMPOSSIBLE");
	for(auto i:x){
		if(y.find(i)!=y.end())
			ans="POSSIBLE";
	}
	cout<<ans;
}

Measured memory_bytes: 8520
def main():
    n, m = map(int, input().split())

    A = []
    B = []

    for _ in range(m):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)

         
    l = max(A)
    r = min(B)
    #print(l, r)

    if r >= l:
        return r - l + 1
    else:
        return 0

if __name__ == "__main__":
    print(main())



"""
for i in range(1, n + 1):
        for j in range(m):
            if gate[j][0] <= i and i <= gate[j][1]:
                if j == len(gate) - 1:
                    result += 1
                continue
            else:
                break
"""

Measured memory_bytes: 11048
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int degree = scan.nextInt();

        System.out.println(0.5 * a * b * Math.sin(Math.toRadians(degree))); // 面積
        System.out.println(a + b + Math.sqrt(((Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(degree))))));
        System.out.println(b * Math.sin(Math.toRadians(degree)));
    }
}

Measured memory_bytes: 17328
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using pint = pair<int,int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

int main() {
    int n,m;cin>>n>>m;
    priority_queue<pint> q;
    rep(i,n) {int a; cin>>a; q.push(make_pair(a, 1));}
    rep(i,m) {
        int b,c; cin>>b>>c;
        q.push(make_pair(c,b));
    }

    ll ans=0;
    rep(i,n){
        auto p=q.top();
        ans+=p.first;
        q.pop();
        if(p.second>1){
            p.second--;
            q.push(p);
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include <cstdio>

using namespace std;

int main(){
    int n;
    int a[21];
    int b[21];
    int c[21];
    int res = 0;

    scanf("%d", &n);
    for(int i=0; i < n; i++){
        scanf("%d", a + i);
    }
    for(int i=0; i < n; i++){
        scanf("%d", b + i);
    }
    for(int i=0; i < n - 1; i++){
        scanf("%d", c + i);
    }
    int ind_prev = -2;
    for(int i=0; i < n; i++){
        int ind = a[i] - 1;
        res += b[ind];
        if(ind_prev + 1 == ind){
            res += c[ind-1];
        }
        ind_prev = ind;
    }
    printf("%d\n", res);
}

Measured memory_bytes: 128
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n,k;
  int res=1;
  cin >> n >> k;

  res *= k;
  res *= pow(k-1, n-1);

  cout << res << endl;

  return 0;
}


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

int judge_2017(int x){
	int f1 = 1, f2 = 1;
	for(int i=3; i<=sqrt(x) && f1 == 1; i=i+2){
		if(x % i == 0) f1 = 0;
	}
	for(int i=2; i<=sqrt((x+1)/2) && f2 == 1; i++){
		if(((x+1)/2) % i == 0) f2 = 0;
	}
	if(f1 && f2){
		return 1;
	}else{
		return 0;
	}
}

int main(){
	int Q, r[100001];
	cin >> Q;
	int L[Q], R[Q];
	r[0] = 0;
	r[1] = 0;
	for(int i=2; i<100001; i++){
		if(i % 2 == 0){
			r[i] = r[i-1];
		}else{
			if(judge_2017(i)){
				r[i] = r[i-1] + 1;
			}else{
				r[i] = r[i-1];
			}
		}
	}
	for(int i=0; i<Q; i++){
		cin >> L[i] >> R[i];
	}
	for(int i=0; i<Q; i++){
        cout << r[R[i]] - r[L[i] - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll N,K;
    cin >> N >> K;
    vector<ll> count(N,0);

    rep(i,K){
        ll di;
        cin >> di;
        rep(j,di){
            ll Aij;
            cin >> Aij;
            count[Aij-1]++;
        }
    }

    ll cnt=0;
    rep(i,N){
        if(count[i]==0){
            cnt++;
        }
    }

    cout << cnt;


}

Measured memory_bytes: 3652
import           Control.Monad
import           Data.Array
import qualified Data.ByteString.Char8         as BS
import           Data.List
import           Data.Maybe
import           Data.Ord

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main = do
  s <- getLine
  putStrLn $ solve s

solve :: String -> String
solve (s : []) = "Good"
solve (s : ss) | s == head ss = "Bad"
               | otherwise    = solve ss


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

using namespace std;
int main(){
	int n,K;
	cin>>n>>K;
	if(K>(n-1)*(n-2)/2){
		cout<<-1<<endl;
		return 0;
	}
	vector<pair<int,int> > ans;
	for(int i=1;i<=n-1;i++) ans.push_back({i,n});
	int num=0;
	for(int i=1;i<=n-1;i++){
		for(int j=i+1;j<=n-1;j++){
			if((n-1)*(n-2)/2-num>K){
				num++;
				ans.push_back({i,j});
			}
			else break;
		}
	}
	cout<<(int)ans.size()<<endl;
	for(auto v:ans){
		cout<<v.first<<' '<<v.second<<endl;
	}
	return 0;
}

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

int main()
{
    while (true)
    {
        ll h, w;
        cin >> h >> w;
        if (h == 0 && w == 0)
        {
            break;
        }

        for (size_t i = 0; i < h; i++)
        {
            for (size_t j = 0; j < w; j++)
            {
                if ((i + j) % 2 == 0)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3068
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int mod=1e9+7;
int dp[3000][3000];
//dp[i][j] is answer if we use first i of a and j of b
int a[3000],b[3000];
int32_t main()
{	
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];

	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod;
		dp[i][j]+=mod;dp[i][j]%=mod;
		if(a[i]==b[j])
		{
			dp[i][j]=(1+dp[i-1][j-1]+dp[i][j])%mod;
		}
	}
	cout<<(dp[n][m]+1)%mod;

	
}


Measured memory_bytes: 42684
import java.util.*;
public class Main{
	public static void main(String[] args){
		//abc
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();//制限
		//c-a<dこの時点でtrue
		//b-a<d&&c-a<dならtrue
		if((double)Math.abs(b - a) <= d && (double)Math.abs(c - b) <= d){
		System.out.println("Yes");
		}else if((double)Math.abs(c - a) <= d){
		System.out.println("Yes");
		}else{
		System.out.println("No");		
		}	
	}
}


Measured memory_bytes: 21972
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int w, a, b; cin >> w >> a >> b;
    if(abs(a-b) <= w) cout << 0 << "\n";
    else cout << abs(a-b) - w << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, b=0;
  cin >>N;
  vector<long long> A(N,0), B(N,0);
  for(int i=0; i<N; i++){
    long long a;
    cin >>a;
    b+=a;
    A[i]=a;
    B[i]=b;
  }
  long long ans=1e15;
  for(int i=0; i<N-1; i++){
    ans=min(abs(B[N-1]-2*B[i]), ans);
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
const int N=1e5+6;
int n,m,deg[N],u,v,head[N],cnt=1;
bool vis[N];
struct edge{
    int to,nxt;
}e[N<<1];
void dfs(int u,int pre){
    vis[u]=1;
    for(int i=head[u];i;i=e[i].nxt)
    if(i!=pre&&e[i].to!=v){
        if(!vis[e[i].to])dfs(e[i].to,i^1);else{puts("Yes");exit(0);}
    }
    vis[u]=0;
}
int main(){
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&u,&v);
        e[++cnt]=(edge){v,head[u]},head[u]=cnt;
        e[++cnt]=(edge){u,head[v]},head[v]=cnt;
        ++deg[u],++deg[v];
    }
    for(int i=1;i<=n;++i)if(deg[i]&1)return puts("No"),0;
    if(*std::max_element(deg+1,deg+n+1)>4)return puts("Yes"),0;
    u=v=0;
    for(int i=1;i<=n;++i)
    if(deg[i]==4){if(!u)u=i;else if(!v)v=i;else return puts("Yes"),0;}
    if(v)dfs(u,0);
    return puts("No"),0;
}

Measured memory_bytes: 3328
#include <bitset>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#include <vector>

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> sz;

  UnionFind(int N) : par(N), sz(N) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      par[i] = i;
      sz[i] = 1;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if(rx == ry)
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    sz[ry] += sz[rx]; // サイズを更新
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return sz[root(x)]; }
};

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  auto uf = UnionFind(N);
  vector<vector<int>> fs(N);
  vector<vector<int>> bs(N);
  int a, b;
  for(int i = 0; i < M; ++i) {
    cin >> a >> b;
    uf.unite(a - 1, b - 1);
    fs[a - 1].push_back(b - 1);
    fs[b - 1].push_back(a - 1);
  }
  for(int i = 0; i < K; ++i) {
    cin >> a >> b;
    bs[a - 1].push_back(b - 1);
    bs[b - 1].push_back(a - 1);
  }
  for(int i = 0; i < N; ++i) {
    int ans = uf.size(i) - fs[i].size() - 1;
    for(auto b : bs[i]) {
      if(uf.same(i, b)) {
        ans--;
      }
    }
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 12920
#include <iostream>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  string ans = "";
  if (0 < a && 0 < b)
    ans = "Positive";
  if (a == 0 || b == 0)
    ans = "Zero";
  if (a < 0 && 0 < b)
    ans = "Zero";
  if (a < 0 && b < 0)
  {
    if ((-1 * a + (-1) * b) % 2 == 0)
      ans = "Negative";
    else
      ans = "Positive";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int* arr;
	arr = new int[n];
	int rep[1000001] = { 0 };
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		rep[arr[i]]++;
	}
	int ans = 0;
	sort(arr, arr + n);
	int occ[1000001] = { 0 };
	for (int i = 0; i < n; i++)
	{
		if (occ[arr[i]] == 0 )
		{
			for (int j = arr[i] ; j < 1000001; j += arr[i])
				occ[j]++;
			if (rep[arr[i]] == 1)
			{
				ans++;

			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 12196
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX = 1001;
int cnt[MAX];

struct team {
	int id, univ, AC, time;
	team(int id_, int univ_, int AC_, int time_):id(id_), univ(univ_), AC(AC_), time(time_) {}
	bool operator>(const team &t) const {
		if(AC != t.AC) return AC > t.AC;
		if(time != t.time) return time < t.time;
		return id < t.id;
	}
};

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

	for(int n; cin >> n && n;) {
		vector<team> teams;
		teams.reserve(n);

		for(int i = 0; i < n; ++i) {
			int id, u, a, p;
			cin >> id >> u >> a >> p;
			teams.emplace_back(id, u, a, p);
		}

		sort(teams.begin(), teams.end(), greater<team>());
		
		int sum = 0;
		memset(cnt, 0, sizeof(cnt));
		int limit = 3;
		for(const auto &t : teams) {
			if(cnt[t.univ] < limit) {
				cout << t.id << endl;
				++cnt[t.univ];
				++sum;
				if(sum == 10 || sum == 20 || sum == 26) --limit;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
c = a[-1]
for i in range(n):
    p = abs(a[-1]-a[i]*2)
    if c > p:
        c = p   
print(c)

Measured memory_bytes: 26024
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var dwh = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).OrderBy(i => i).ToArray();
                if (dwh.SequenceEqual(new int[] { 0, 0, 0 }))
                    break;
                var size = Math.Sqrt(dwh[0] * dwh[0] + dwh[1] * dwh[1]);

                var n = int.Parse(Console.ReadLine());
                while (n-- != 0)
                {
                    var r = int.Parse(Console.ReadLine());
                    Console.WriteLine(r * 2 > size ? "OK" : "NA");
                }
            }
        }
    }
}

Measured memory_bytes: 6224
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n;
  cin>>n;
  if(n%10== 2 || n%10== 4 || n%10== 5 || n%10== 7 || n%10== 9){
    cout<<"hon";
  }else if(n%10== 0 || n%10== 1 || n%10== 6 || n%10== 8){
    cout<<"pon";
  }else if(n%10== 3){
    cout<<"bon";
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    
    
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int i;
    long long sum = 0;
    
    for(i = 0; i < h-a; i++){
        sum += COM(b-1+i, i) * COM(w-b-1+h-1-i, w-b-1);
        sum %= MOD;
    }
    
    
    
    
    cout << sum << endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#include<iterator>
#include<vector>
#include<algorithm>


#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned

#define mod 1000000007
#define MAXN 100000
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main() 
{  
    string s;
    cin>>s;
    int q;
    cin>>q;
    int t,f;
    string p;
    int state = 0;
    while(q--)
    {

        cin>>t;
        if(t == 1)
        {
            state++;
            state %= 2;
        }
        else
        {
            cin>>f>>p;
            char temp = p[0];
            if(state == 0)
            {
                if(f == 1)
                s.insert(0,p);
                else
                s.pb(temp);
            }
            else
            {
                if(f == 1)
                s.pb(temp);
                else
                s.insert(0,p);    
            }
        }
        // cout<<s<<endl;
    
    }
    if(state)
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 900
#include<cstdio>
#include<vector>
#include<cstring>
#define maxn 105
using namespace std;
int n,a[maxn],b[maxn],c[maxn],d[maxn],mx[maxn],my[maxn],ans;
vector<int> G[maxn];
bool vis[maxn];
int dfs(int u)
{
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(vis[v]) continue;
		vis[v]=true;
		if(!my[v]||dfs(my[v]))
		{
			my[v]=u;mx[u]=v;
			return 1;
		}
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&c[i],&d[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i]<c[j]&&b[i]<d[j])
				G[i].push_back(j);
	for(int i=1;i<=n;i++)
		if(!mx[i]) 
		{
			memset(vis,0,sizeof(vis));
			ans+=dfs(i);
		}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

LLI A[200005];
int B[200005];
LLI pre0[200005],pre1[200005],pre2[200005];
LLI dp[200005];
LLI query(int j,int i) {
    return (i-j)*(A[i]+A[j])-2*(-(LLI) i*j*(pre0[i+1]-pre0[j])+(i+j)*(pre1[i+1]-pre1[j])-(pre2[i+1]-pre2[j]));
}
vi S;
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%lld",&A[i]);
    for (i = 0; i < N; i++) scanf("%d",&B[i]);

    int m = 0;
    for (i = 0; i < N; i++) {
        if (A[i] > A[m]) m = i;
    }
    rotate(A,A+m,A+N),rotate(B,B+m,B+N);
    A[N] = A[0],B[N] = B[0];
    for (i = 0; i <= N; i++) {
        pre0[i+1] = pre0[i]+B[i];
        pre1[i+1] = pre1[i]+(LLI) i*B[i];
        pre2[i+1] = pre2[i]+(LLI) i*i*B[i];
    }
    dp[0] = 0,S.pb(0);
    for (i = 1; i <= N; i++) {
        while ((S.size() >= 2) && (dp[S.back()]+query(S.back(),i) < dp[S[S.size()-2]]+query(S[S.size()-2],i))) S.pop_back();
        dp[i] = dp[S.back()]+query(S.back(),i);
        S.pb(i);
    }
    printf("%.12lf\n",(double) dp[N]/(2*N));

    return 0;
}



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

int main(){
    int N,K;cin>>N>>K;
    string s;cin>>s;
    int ans=0;
    REP(i,N-1){
        if(s[i]==s[i+1]) ans++;
    }
    ans=min(N-1,ans+2*K);
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.*;

class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int total = 3;
if(a == b || a == c || b == c){
total = 2;
}
if(a == b && a == c && b == c){
total = 1;
}
System.out.println(total);

}
}



Measured memory_bytes: 21716
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int main(){
  ll N; cin >> N;
  ll ans = 0;
  for (ll i = 0; i <= N; i++){
    if (i % 3 == 0 || i % 5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3636
s = gets.chomp

if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]
  puts "Yes"
elsif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]
  puts "Yes"
elsif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
N = int(input())
A = tuple(map(int, input().split()))

M, m = max(A), min(A)

print(2 * N - 2)
if abs(M) >= abs(m):
    ind = A.index(M)
    for x in set(range(N)) - {ind}:
        print(ind + 1, x + 1)
    for x in range(1, N):
        print(x, x + 1)
else:
    ind = A.index(m)
    for x in set(range(N)) - {ind}:
        print(ind + 1, x + 1)
    for x in range(N - 1, 0, -1):
        print(x + 1, x)


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

int main()
{
    int n,k,i,a,tot=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        tot+=2*(min(a,abs(k-a)));
    }
    printf("%d\n",tot);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
  
int main()
{
  	ll n, d, ans=0;
  	long double stc=0.0;
  	cin >> n >> d;
	vector<vector<ll>> c(n, vector<ll>(d));
  	rep(i, n){
    	rep(j, d) cin >> c.at(i).at(j);
    }
  	rep(i, n){
    	REP(j, i+1, n){
        rep(k, d) stc += pow(abs(c.at(i).at(k)-c.at(j).at(k)), 2);
        stc = sqrt(stc);
      	if(stc-floorl(stc) == 0) ++ans;
      	stc=0.0;
      }
    }
  	cout << ans << "\n";
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int N;
    cin >> N;
    unordered_map<ll, ll> mp;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        ++mp[a];
    }

    bool ok = true;
    for (const auto& p : mp) {
        if (p.second > 1) {
            ok = false;
        }
        if (!ok) {
            break;
        }
    }

    cout << (ok ? "YES\n" : "NO\n");

    return 0;
}

Measured memory_bytes: 8520
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, mod - 2);
}

void precalc() {
}

const int maxn = 1e6;

int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < 3 * n; i++) {
    scanf("%d", a + i);
  }
  return true;
}

void solve() {
  sort(a, a + 3 * n);
  reverse(a, a + 3 * n);
  ll res = 0;
  for (int i = 1, it = 0; it < n; i += 2, it++) {
    res += a[i];
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



Measured memory_bytes: 1408
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import Data.Tuple (swap)
import Data.Maybe (catMaybes)
import Data.List (mapAccumL)

main :: IO ()
main = do
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    parents :: [(Int, Int)] -> VU.Vector Int
    parents = VU.accum (flip const) (VU.replicate n n)
  abs <- sequence . replicate m $ unsafeListToPair . map (pred . unsafeTextToInt) . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    edges = (++) <$> id <*> map swap $ abs :: [(Int, Int)]
    adjacency = fromEdgesToAdjacencyVectorN n edges :: V.Vector IntSet
    tree = fromAdjacencyVectorToSimpleGraph adjacency 0 :: Tree Int
    queue = (tree, n) : walk (pred n) (IS.singleton 0) queue :: [(Tree Int, Int)]
      where
        walk :: Int -> IntSet -> [(Tree Int, Int)] -> [(Tree Int, Int)]
        walk 0 _ _ = []
        walk l s (((Node i ts), _) : tps) = tps' ++ walk l' s' tps
          where
            {-
            ts' = filter (flip IS.notMember s . extract) ts :: [Tree Int]
            tps' = map (flip (,) i) ts' :: [(Tree Int, Int)]
            l' = length ts' :: Int
            s' = IS.union s (IS.fromList . map extract $ ts') :: IntSet
            -}
            {--}
            ((l', s'), tps') = fmap catMaybes . mapAccumL step (l, s) $ ts :: ((Int, IntSet), [(Tree Int, Int)])
              where
                step :: (Int, IntSet) -> Tree Int -> ((Int, IntSet), Maybe (Tree Int, Int))
                step ls@(l, s) t@(Node x _) | IS.member x s = (ls, Nothing)
                                            | otherwise     = ((pred l, IS.insert x s), Just (t, i))
            {--}
  T.putStrLn . T.pack $ "Yes"
  VU.mapM_ print . VU.map succ . VU.tail . parents . map ((,) <$> extract . fst <*> snd) $ queue

fromEdgesToAdjacencyVectorN :: Int -> [(Int, Int)] -> V.Vector IntSet
fromEdgesToAdjacencyVectorN n = V.accum (flip IS.insert) (V.replicate n IS.empty)
{-# INLINE fromEdgesToAdjacencyVectorN #-}

fromAdjacencyVectorToSimpleGraph :: V.Vector IntSet -> Int -> Tree Int
fromAdjacencyVectorToSimpleGraph adjacency root = Node root (map (f root) . IS.toList $ adjacency V.! root)
  where
    f :: Int -> Int -> Tree Int
    f p i = Node i (map (f i) . filter (/= p) . IS.toList $ adjacency V.! i)
{-# INLINE fromAdjacencyVectorToSimpleGraph #-}

data Tree a = Node a [Tree a]

extract :: Tree a -> a
extract (Node x _) = x

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

int main() {
  string S;
  cin >> S;
  int ans=0;
  int num=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
      num++;
    }
    else{
      num=0;      
    }
    ans=max(ans,num);
  }
  cout << ans << endl;
}
    
      


Measured memory_bytes: 256
n=int(input())
dp=[[0 for i in range(n+1)] for j in range(3)]
for i in range(1,n+1):
  a,b,c=map(int,input().split())
  dp[0][i]=max(dp[1][i-1]+a,dp[2][i-1]+a)
  dp[1][i]=max(dp[0][i-1]+b,dp[2][i-1]+b)
  dp[2][i]=max(dp[0][i-1]+c,dp[1][i-1]+c)
print(max(dp[0][n],dp[1][n],dp[2][n]))

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

class UnionFind {
public:
  int n;
  vi par; //親
  vi ran; //木の深さ
  vi num; //要素数
  int g; // group数
 
  UnionFind(int _n) {
    n = _n;
    g = n;
    par.resize(n); ran.resize(n); num.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i; ran[i] = 0; num[i] = 1;
    }
  }
 
  //木の根を求める
  int find(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      return par[x] = find(par[x]);
    }
  }
 
  //xとyの属する集合を併合
  void unite(int x, int y) {
    x = find(x); y = find(y);
    int numsum = num[x] + num[y];
    if (x == y) {
      return;
    }
    if (ran[x]<ran[y]) {
      par[x] = y;
    }
    else {
      par[y] = x;
      if (ran[x] == ran[y]) {
        ran[x]++;
      }
    }
    num[x] = num[y] = numsum;
    g--;
  }
 
  //xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }
 
};
 
 
int main() {
  int n, m;
  cin >> n >> m;
 
  UnionFind uf(n);
  rep (i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    uf.unite(x, y);
  }
  cout << uf.g << endl;
  
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N, K;
	cin >> N >> K;

	vector<int>p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

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

	int sum = 0;

	for (int i = 0; i < K; i++) {
		sum += p[i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int k; cin>>k;
    string s; cin>>s;
    if(s.length()<=k) cout<<s<<endl;
    else{
        s=s.substr(0,k);
        cout<<s<<"..."<<endl;
    }
}

Measured memory_bytes: 3632