akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>

using namespace std;

struct Node{
  int l, r, s;
  
  bool operator < (const Node &t) const{
      return r < t.r;
  }
  
  Node(int a, int b, int c){
      l = a;
      r = b;
      s = c;
  }
  
  Node():l(0),r(0),s(0){}
}d[1000005];

int n, m;
//Node d[500005];
int nex[2000000], C[2000000], f[2000000], s[2000000];

int lowbit(int i){
	return i & (-i);
}

void add(int a, int b){
	for(int i = a;i <= n;i += lowbit(i)) C[i] += b;
}

int query(int a){
	int ans = 0;
	for(int i = a;i > 0;i -= lowbit(i)) ans += C[i];
	return ans;
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1;i <= n;i++) scanf("%d", &f[i]);
    for(int i = 0;i < m;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        d[i] = Node(a, b, i);
    }
    sort(d, d + m);
    int key = 1;
    for(int i = 0;i < m;i++){
    	int r = d[i].r, l = d[i].l;
    	while(key <= r){
    		if(nex[f[key]] != 0) add(nex[f[key]], -1);
		    add(key, 1);
		    nex[f[key]] = key;
		    key++;
		}
		s[d[i].s] = query(r) - query(l - 1);
	}
	for(int i = 0;i < m;i++){
		if(i < m - 1){
			printf("%d\n", s[i]);
		}else{
			printf("%d", s[i]);
		}
	}
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    map<string, int> M;
    for (int i = 0; i < N; ++i)
    {
        string S;
        cin >> S;
        M[S]++;
    }

    // 最大の書かれた回数
    int writtenTimeMax = 0;
    for (auto e : M)
    {
        if (writtenTimeMax < e.second)
            writtenTimeMax = e.second;
    }

    for (auto e : M)
    {
        if (writtenTimeMax == e.second)
            cout << e.first << endl;
    }

    return 0;
}


Measured memory_bytes: 19160
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var H = input[0];
            var W = input[1];
            var c = new int[10, 10];
            var A = new int[10];
            var min = new int[10, 10];
            for (int i = 0; i < 10; i++)
            {
                input = ReadArrayInt();
                for (int j = 0; j < 10; j++)
                {
                    c[i, j] = input[j];
                    min[i, j] = input[j];
                }
            }
            for (int i = 0; i < H; i++)
            {
                input = ReadArrayInt();
                for (int j = 0; j < W; j++) if (input[j] != -1) A[input[j]]++;
            }

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        min[j, k] = Math.Min(min[j, k], min[j, i] + min[i, k]);
                    }
                }
            }

            var ans = 0;
            for (int i = 0; i < 10; i++) if (i != 1 && A[i] > 0) ans += min[i, 1] * A[i];

            Console.WriteLine(ans);
            Console.ReadLine();
        }        

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


Measured memory_bytes: 15444
package main

import (
  "bufio"
  "fmt"
  "math"
  "os"
  "sort"
  "strconv"
  "strings"
)

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n,_ = strconv.Atoi(NextLine())
  return n
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  var n int = NextInt()
  var a []int = NextIntArray()
  var idx int
  var mid,min float64
  sort.Sort(sort.Reverse(sort.IntSlice(a)))
  mid = 0.5*float64(a[0])
  min = float64(a[0])
  idx = 1
  for i:=1;i<n;i++ {
    t := math.Abs(float64(a[i])-mid)
    if min > t {
      min = t
      idx = i
    }
  }
  fmt.Println(a[0],a[idx])
}

Measured memory_bytes: 6016
#include<iostream>
#include<string>

using namespace std;

int main(){

	string exp;

	int ans;
	int ma,la;
	int mt;

	cin>>exp;
	cin>>ans;

	if(exp.size()==1){
		if(exp[0]-'0'==ans) cout<<"U"<<endl;
		else cout<<"I"<<endl;
		return 0;
	}

	la=(exp[1]=='+')?exp[0]-'0'+exp[2]-'0':(exp[0]-'0')*(exp[2]-'0');
	for(int i=3;i<exp.size();i+=2){
		if(exp[i]=='+') la+=exp[i+1]-'0';
		else la*=(exp[i+1]-'0');
	}

	if(exp[1]=='+'){
		ma=exp[0]-'0';
		mt=-1;
	}
	else{
		ma=0;
		mt=exp[0]-'0';
	}

	for(int i=2;i<exp.size()-1;i+=2){
		if(exp[i+1]=='*'){
			if(mt==-1) mt=exp[i]-'0';
			else mt*=(exp[i]-'0');
		}
		else{
			if(mt!=-1){
				ma+=(mt*(exp[i]-'0'));
				mt=-1;
			}
			else ma+=(exp[i]-'0');
		}
	}
	if(mt!=-1){
		ma+=(mt*(exp[exp.size()-1]-'0'));
		mt=-1;
	}
	else ma+=(exp[exp.size()-1]-'0');

	if(ans==ma&&ans==la) cout<<"U"<<endl;
	else if(ans==ma) cout<<"M"<<endl;
	else if(ans==la) cout<<"L"<<endl;
	else cout<<"I"<<endl;

	return 0;
}

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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;

llong fact(llong val) {
	llong res = 1;
	for (llong i = val; i > 0; i--) {
		res = (res * i) % mod;
	}
	return res;
}

void solve() {

	int a, b;
	cin >> a >> b;

	int diff = abs(a - b);
	if (diff > 1) {
		cout << 0;
	} else {

		llong a_ways = fact(a);
		llong b_ways = fact(b);

		llong ans = (a_ways * b_ways) % mod;
		if (diff == 0) {
			ans = (2LL * ans) % mod;
		}
		cout << ans;
	}
}

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

	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;


int main(void)
{
        unsigned int n;
        unsigned int org;


        cin >> n;

        org = (unsigned int)(n/1.08);

        if ( (unsigned int)(org*1.08) == n) {
                cout << org << endl;
                return 0;
        }


        while ((unsigned int)(org*1.08) <= n) {
                org += 1;
                if ( (unsigned int)(org*1.08) == n) {
                        cout << org << endl;
                        return 0;
                }
        }

        cout << ":(" << endl;
        return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>
#include<regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    long long int a[n+1];
    long long int b[n+1];
    long long int suma=0;
    for(int i=0;i<=n;i++){
        cin >> a[i];
        suma+=a[i];
    }
    long long int res=0;
    b[0]=1;
    res+=b[0];
    if(a[0]>=2 || (a[0]==1 && suma-1>0)){
        cout << -1 << endl;
            return 0;
    }
    for(int i=1;i<=n;i++){
        suma-=a[i-1];
        if(suma>=(b[i-1]-a[i-1])*2){
            b[i]=(b[i-1]-a[i-1])*2;
        }else{
            b[i]=suma;
        }
        res+=b[i];
        if(b[i]-a[i]<0){
            cout << -1 << endl;
            return 0;
        }else if(b[i]==a[i] && suma-a[i]>0){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << res << endl;
    
    return 0;
}

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

int n;
string s;
stack<int> st;

int main(){
	cin >> n >> s;
	for(int i=0; i<n; ++i){
		if(!st.empty() && st.top() == 0 && s[i] == ')') st.pop();
		else st.push(s[i] == '(' ? 0 : 1);
	}
	while(!st.empty()){
		if(st.top() == 0) s += ')';
		else s = '(' + s;
		st.pop();
	}
	cout << s << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long quotient = m / 2;
        long count = Math.min(quotient, n);
        n -= count;
        m -= (count * 2);
        if(n == 0) {
            count += m / 4;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23764
#!/usr/bin/env python3
import sys
import bisect


def solve(n: int, A: "List[int]"):
    A.sort()
    n = A[-1]
    r = n/2.0

    min_diff = float("inf")
    bi = 0
    for i in range(len(A)-1):
        if abs(A[i]-r) < min_diff:
            min_diff = abs(A[i]-r)
            bi = i

    print(n,A[bi])







# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15564
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int INF = 1 << 29;
const int N = 100;
int n;
int as[N+1][N+1];

void floyd() {
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                as[i][j] = min(as[i][j], as[i][k] + as[k][j]);
            }
        }
    }
}

int main() {
    while (cin >> n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                as[i][j] = INF;
            }
        }

        for (int i = 0; i < n; i++) {
            int r, k;
            cin >> r >> k;
            for (int j = 0; j < k; j++) {
                int t;
                cin >> t;
                as[r][t] = 1;
            }
        }
        floyd();
        int p;
        cin >> p;
        for (int i = 0; i < p; i++) {
            int s, d, v;
            cin >> s >> d >> v;
            int dist = as[s][d] + 1;
            if (dist <= v) {
                cout << dist << endl;
            } else {
                cout << "NA" << endl;
            }
        }
    }
}

Measured memory_bytes: 1204
import numpy as np
import itertools
from itertools import permutations

N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
Distance = []
for v in itertools.permutations(XY, N):
  distance_each = [np.sqrt((v[i][0] - v[i + 1][0])**2 + (v[i][1] - v[i + 1][1])**2) for i in range(N - 1)]
  distance = np.sum(distance_each)
  Distance.append(distance)
ans = np.average(Distance)
print(ans)

Measured memory_bytes: 15744
n,w=list(map(int, input().split()))
wv=[list(map(int, input().split())) for _ in range(n)]

dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(w+1):
        if j >= wv[i][0]:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[-1][-1])            

Measured memory_bytes: 173704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(string S)
{
    int zero = 0;
    int one = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '0')
        {
            zero++;
        }
        else
        {
            one++;
        }
    }

    cout << 2 * min(zero,one)<< endl;
}

int main()
{
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

constexpr int nlim = 1e2, klim = 1e5;
int dp[2][klim+1];

int main(){
  int n, k; cin >> n >> k;
  int a[n];
  REP(i, n) cin >> a[i];

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

  dp[0][0] = 0; dp[1][0] = 1;
  REP(rest, k+1)REP(turn, 2){
    if(turn == 0){
      dp[turn][rest] = 0;
      REP(i, n){
        if(rest - a[i] < 0) continue;
        dp[turn][rest] |= dp[1-turn][rest-a[i]];
      }
    } else {
      dp[turn][rest] = 1;
      REP(i, n){
        if(rest - a[i] < 0) continue;
        dp[turn][rest] &= dp[1-turn][rest-a[i]];
      }
    }
  }
  
  string ans = (dp[0][k])? "First": "Second";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=500001;
int n;
vi x,y,a;
map<char,int> mp={
	{'U',0},
	{'R',1},
	{'D',2},
	{'L',3},
};

int main(){
	cin>>n;
	int res=inf;
	x=y=a=vi(n);
	for(int i=0;i<n;i++){
		char c;
		cin>>x[i]>>y[i]>>c;
		a[i]=mp[c];
	}
	vvp b(M);
	for(int i=0;i<n;i++) if(a[i]%2==0) b[x[i]].push_back({y[i],a[i]});
	for(int i=0;i<M;i++) if(!b[i].empty()){
		sort(b[i].begin(),b[i].end());
		int tmp=-inf;
		for(auto p:b[i]){
			if(p.second==0) tmp=p.first;
			else res=min(res,p.first-tmp);
		}
	}
	b=vvp(M);
	for(int i=0;i<n;i++) if(a[i]%2==1) b[y[i]].push_back({x[i],a[i]});
	for(int i=0;i<M;i++) if(!b[i].empty()){
		sort(b[i].begin(),b[i].end());
		int tmp=-inf;
		for(auto p:b[i]){
			if(p.second==1) tmp=p.first;
			else res=min(res,p.first-tmp);
		}
	}
	b=vvp(M);
	for(int i=0;i<n;i++) b[x[i]+y[i]].push_back({x[i],a[i]});
	for(int i=0;i<M;i++) if(!b[i].empty()){
		sort(b[i].begin(),b[i].end());
		int tmp=-inf;
		for(auto p:b[i]){
			if(p.second==1) tmp=p.first;
			if(p.second==0) res=min(res,(p.first-tmp)*2);
		}
		tmp=-inf;
		for(auto p:b[i]){
			if(p.second==2) tmp=p.first;
			if(p.second==3) res=min(res,(p.first-tmp)*2);
		}
	}
	b=vvp(M);
	for(int i=0;i<n;i++) b[x[i]-y[i]+200005].push_back({x[i],a[i]});
	for(int i=0;i<M;i++) if(!b[i].empty()){
		sort(b[i].begin(),b[i].end());
		int tmp=-inf;
		for(auto p:b[i]){
			if(p.second==0) tmp=p.first;
			if(p.second==3) res=min(res,(p.first-tmp)*2);
		}
		tmp=-inf;
		for(auto p:b[i]){
			if(p.second==1) tmp=p.first;
			if(p.second==2) res=min(res,(p.first-tmp)*2);
		}
	}
	if(res==inf) cout<<"SAFE"<<endl;
	else cout<<res*5<<endl;
}

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

#define MAX 10*10*10*10*10*10*10*10*10

void gcd(int, int);

int main(){
  int x, y;

  scanf("%d%d",&x,&y);
  if(x < 1 || MAX < x) exit(1);
  if(y < 1 || MAX < y) exit(1);

  if(x == y) printf("%d\n", x);
  else gcd(x, y);

  return 0;
}

void gcd(int x, int y){
  int a, r;

  if(x < y){
    a=y;
    y=x;
    x=a;
  }
  while(y > 0){
    r=x%y;
    x=y;
    y=r;
  }
  
  printf("%d\n", x);
}
    



Measured memory_bytes: 2144
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;

    int sum = 0;
    int x = 0;
    while(sum < n){
        sum += ++x;
    }

    if(sum != n){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    if(n == 1){
        cout << 2 << endl;
        cout << 1 << " " << 1 << endl;
        cout << 1 << " " << 1 << endl;
        return 0;
    }

    vector<vector<int>> ans(x+1, vector<int>());
    ans[0].push_back(1);
    ans[0].push_back(2);
    ans[1].push_back(2);
    ans[1].push_back(3);
    ans[2].push_back(3);
    ans[2].push_back(1);

    if(n == 3){
        cout << x+1 << endl;
        rep(i, x+1){
            int m = ans[i].size();
            cout << m << " ";
            rep(j, m-1){
                cout << ans[i][j] << " ";
            }
            cout << ans[i][m-1] << endl;
        }
        return 0;
    }

    int y = 4;
    for(int s = 3; s <= x; s++){
        for(int t = 0; t < s; t++){
            ans[s].push_back(y);
            ans[t].push_back(y);
            y++;
        }
    }

    cout << x+1 << endl;
    rep(i, x+1){
        int m = ans[i].size();
        cout << m << " ";
        rep(j, m-1){
            cout << ans[i][j] << " ";
        }
        cout << ans[i][m-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); //夏休み日数
    int M = sc.nextInt(); //宿題個数
    int[] A = new int[M]; //宿題遂行必要日数
    for(int i=0; i<M; i++) {
      A[i] = sc.nextInt();
      N-=A[i];
      if(N>=0) {
        continue;
      } else {
        break;
      }
    }
     if(N>=0) {
       System.out.println(N);
     } else if(N<0) {
       System.out.println(-1);
     }
  }
}

Measured memory_bytes: 46196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(getDobt(n, 100000));
        }

        static int getDobt(int c, int value)
        {
            if (c-- == 0) return value;
            value += (value*5/100);
            if (value % 1000 != 0) { value /= 1000; value += 1; value *= 1000; }
            return getDobt(c, value);
        }
    }
}

Measured memory_bytes: 5592
import java.util.*;
import java.io.*;

class Card{
 char mark;
 int num;
 boolean have = false;
 static List<Card> allCards = new ArrayList<Card>();

 Card(char mark, int num){
	this.mark = mark;
	this.num = num;
	
}
}

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

 char[] marks ={'S','H','C','D'};
 
	for(char mark: marks){
		for(int i = 0; i < 13; i++){
		 Card.allCards.add(new Card(mark, i+1));
		}
	}

	try{
	 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	 int n = Integer.parseInt(br.readLine());
	 	for(int a = 0; a < n; a++ ){
	  	 String[] str = br.readLine().split(" ");
		 	for(Card c : Card.allCards){
				if(c.mark != str[0].charAt(0)){
					continue;
				}
				if(c.num == Integer.parseInt(str[1])){
					c.have = true;
				}
			}
		}
	}catch(IOException e){
	 System.out.println(e);
	}

	for(Card c : Card.allCards){
		if(c.have == false){
		 System.out.println(c.mark + " " + c.num);
		}
	}
}
}

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

typedef long long LL;
const int N = 1e5 + 5;

int a[N];
LL dif[N << 1], ddif[N << 1], ans = 0;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
  for (int i = 2, s; i <= n; i ++) {
    s = (a[i] + m - a[i - 1]) % m;
    dif[a[i] + m + 1] --;
    dif[a[i] + m - s + 2] ++;
    ddif[a[i] + m + 1] -= s - 1;
    ans += s;
  }
  for (int i = 1; i <= (m << 1); i ++) dif[i] += dif[i - 1];
  for (int i = 1; i <= (m << 1); i ++) dif[i] += dif[i - 1] + ddif[i];
  LL sub = 0;
  for (int i = 1; i <= m; i ++) sub = max(sub, dif[i] + dif[i + m]);
  printf("%lld\n", ans - sub);
  return 0;
}


Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#define N 394
using namespace std;

int main(){
  int n,s[N],l[N],p[N],dp[N][N],m,w,ans[N],flag=0;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>s[i]>>l[i]>>p[i];
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++) dp[i][j]=-1;
  dp[0][0]=0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<N;j++){
      dp[i][j]=max(dp[i][j],dp[i-1][j]);
      for(int k=s[i];k<=l[i];k++){
	if(j-k>=0&&dp[i-1][j-k]!=-1) dp[i][j]=max(dp[i][j],dp[i-1][j-k]+p[i]);
      }
      dp[i-1][j]=max(dp[i-1][j],dp[i][j]);
    }
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>w;
    if(dp[n][w]==-1){
      flag=1;
      break;
    }else ans[i]=dp[n][w];
  }
  if(!flag)
    for(int i=0;i<m;i++) cout<<ans[i]<<endl;
  else cout<<-1<<endl;
  return 0;
}

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

using namespace std;

const int MX = 100 * 1000 + 7;

int c[MX], s[MX], f[MX];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) cin >> c[i] >> s[i] >> f[i];
    int t = 0;
    for (int j = 0; j < n; j++) {
        t = 0;
        for (int i = j; i < n - 1; i++) {
            t = max(t, s[i]);
            while (t % f[i]) t++;
            t += c[i];
        }
        cout << t << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define mod 100000007
#define INF 1e9
/****************************/
int n;
int a[200010];
int b[200010];
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	int l=b[n/2-1];
	int r=b[n/2];
	rep(i,n)
	{
		if(a[i]>l)
		{
			cout<<l<<endl;
		}
		else
		{
			cout<<r<<endl;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N, M;
    cin >> N >> M;

    if (N == M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


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

using ll = long long;
const int nax = 1e5+5;
vector<int> edges[nax];

const int mod = 1e9+7;
int mul(int a, int b){
    return (ll) a*b%mod;
}

// returns pair of number of ways to paint black, white
pair<int,int> dfs(int a, int parent){
    int all_white = 1; //means vertex can be painted black
    int smthg_is_black = 0;
    for(int b: edges[a]){
        if(b!=parent){
            pair<int,int> p = dfs(b,a);
            int memo_all_white = all_white;
            all_white = mul(all_white, p.second);
            smthg_is_black = (mul(memo_all_white, p.first) 
              + mul(smthg_is_black, p.first+p.second))%mod;
        }
    }
    return make_pair(all_white,(smthg_is_black+all_white)%mod);
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    pair<int,int> p = dfs(1,-1);
    int answer = (p.first+p.second)%mod;
    printf("%d\n", answer);
}


Measured memory_bytes: 12672
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int modu = 1e9 + 7;

long long rev[2005];

long long C(int n, int m) {
	long long res = 1;
	for (int i = n; i >= n-m+1; --i)
		res = res * i % modu;
	for (int i = 1; i <= m; ++i)
		res = res * rev[i] % modu;
	return res;
}

int main() {
	rev[1] = 1;
	int S;
	cin >> S;
	for (int i = 2; i <= S; ++i)
		rev[i] = (modu-(modu/i))*rev[modu%i]%modu;
	long long ans = 0;
	for (int i = 1; i <= S; ++i) {
		if (i*3 > S) break;
		ans = (ans + C(S-i*2-1, i-1)) % modu;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3188
n,k=map(int,input().split())
a=list(map(int,input().split()))

l=[]
l2=[]
for i in range(n):
    temp=0
    temp2=0
    for j in range(n):
        if a[i]>a[j]:
            if i<j:
                temp2+=1
            temp+=1
    l.append(temp)
    l2.append(temp2)
ans=0
for i in range(n):
    ans=(ans+k*l2[i]+(((k-1)*k*l[i]))//2)%(10**9+7)
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>


struct STACK
{
	int num[ 10 ] ;
	int p ;
	
	int		Top( void )	;
	void	Push( int )	;
	void	Pop( void )	;
	void	Init( void ) ;
} stack ;


int main( void )
{
	stack.Init() ;

	int kale ;
	while( scanf( "%d" ,&kale ) != EOF )
	{
		if( kale == 0 )
		{
			printf( "%d\n" ,stack.Top() ) ;

			stack.Pop() ;
		}

		else
		{
			stack.Push( kale ) ;
		}
	}

	return 0 ;
}


void STACK::Init( void )
{
	p = 0 ;
}

void STACK::Push( int kale )
{
	num[ p++ ] = kale ;
}

void STACK::Pop( void )
{
	--p ;
}

int STACK::Top( void )
{
	return num[ p - 1 ] ;
}


Measured memory_bytes: 2692
import math
MOD = 1000000007
N = int(input())
A = []
d = {}
for i in range(N):
	a,b = map(int,input().split())
	g = math.gcd(a,b)
	if a < 0:
		a *= -1
		b *= -1
	if a == 0 and b < 0:
		b *= -1
	if g != 0:
		a = a // g
		b = b // g
	if (a,b) in d:
		d[(a,b)] += 1
	else:
		d[(a,b)] = 1

ans_sp = 0
if (0,0) in d:
	ans_sp += d[(0,0)]

def pow(n, k):
	ret = 1
	while k > 0:
		if k % 2 == 1:
			ret = ret * n % MOD
		n = n * n % MOD
		k = k // 2
	return ret

ans = 1
for k in d:
	a,b = k[0], k[1]
	if a == 0 and b == 0:
		continue
	v = d[k]
	x,y = b,-a
	if x < 0:
		x *= -1
		y *= -1
	if x == 0 and y < 0:
		y *= -1
	if y == 0 and x < 0:
		x *= -1
	if (x,y) in d:
		if  b > y:
			continue
		tmp = (pow(2,v) + pow(2,d[(x,y)]) - 1) % MOD
		ans = (ans * tmp) % MOD
	else:
		ans = (ans * pow(2,v)) % MOD
print((ans_sp + ans - 1) % MOD)

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

int main() {
  int N;
  cin >> N;
  
  vector<string> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  map<string, int> data;
  for (int i = 0; i < N; i++) {
    if (data.count(A.at(i))) data.at(A.at(i)) ++;
    else data [A.at(i)] = 1;
  }
  
  int max = 0;
  for (auto p : data) {
    if (p.second > max) max = p.second;
  }
  
  vector<string> name; // 出力する人物の名前を集める
  for (auto p : data) {
    if (p.second == max) name.push_back(p.first);
  }
  
  sort(name.begin(), name.end());
  
  for (auto p : name) cout << p << endl;
}

Measured memory_bytes: 28404
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N=0;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  int ans=0;
  int maxheight=-1;
  for(int i=0;i<N;i++){
    if(maxheight<=A.at(i)){
      ans++;
      maxheight=A.at(i);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
/**
 *  author: mahfuzz
 *  created: 17.04.2020
**/
 
#include <iostream>
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int n; cin >> n;
    
    if(n % 2 == 0)
        cout << n << "\n";
    else
        cout << n * 2 << "\n";
    
        
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n=int(input())

rest=defaultdict(list)
for i in range(n):
	s,h=input().split()
	rest[s].append([int(h),i+1])
for k in sorted(list(rest.keys())):
	for p,i in sorted(list(rest[k]),key=lambda x:x[0])[::-1]:
		print(i)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll> b(n-1),a(n);
    rep(i,n-1)cin >> b[i];
    a[0]=b[0];
    rep2(i,1,n-1)a[i]=min(b[i-1],b[i]);
    a[n-1]=b[n-2];
    cout << accumulate(a.begin(),a.end(),0LL) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


int main(void){
  string n; cin >> n;
  ll k; cin >> k;
  ll nlen = n.length();
  ll ans = 0;

  FOR(i,1,nlen-1){
    if(i<k) continue;

    if(k==1) ans += 9;
    else if(k==2){
      ans += (i-1) * 81;
    }
    else {
      ans += (i-1) * (i-2) * 729 / 2;
    }
  }

  if(k==1){
    ans += (n[0]-'0');
  }
  else if(k==2){
    int ret = 1;
    while(n[ret]=='0' && ret<nlen){
      ++ret;
    }
    if(ret!=nlen){
      ans += (n[ret] - '0');
      // ans += ((n[0] - '0') - 1) * 9;
      // ans += (n[0] - '0') * (nlen-ret-1) * 9;
      ans += (nlen-ret-1) * 9;
    }
    ans += ((n[0] - '0') - 1) * 9 * (nlen-1);
  }
  else{
    int reta,retb; 
    reta = 1; 
    retb = -1;
    while(n[reta]=='0' && reta<nlen){
      ++reta;
    }
    if(reta!=nlen){
      retb = reta + 1;
      while(n[retb]=='0' && retb<nlen){
        ++retb;
      }
    }

    if(reta!=nlen){
      if(retb!=nlen){
        ans += (n[retb] - '0');
        ans += 9 * (nlen-retb-1);
        ans += ((n[reta] - '0') - 1) * 9 * (nlen-reta-1);
        ans += (nlen-reta-1) * (nlen-reta-2) * 81 / 2;
      } else {
        ans += ((n[reta] - '0') - 1) * 9 * (nlen-reta-1);
        ans += (nlen-reta-1) * (nlen-reta-2) * 81 / 2;
      }
      ans += (nlen-1) * (nlen-2) * (n[0] - '0' - 1) * 81 / 2;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void bubble(string c[],int n){
    for(int i = 0; i <= n -1; i++){
        string kari;
        for(int j = n - 1; j >= i + 1; j--){
            if(c[j][1] < c[j-1][1]){
                kari = c[j];
                c[j] = c[j-1];
                c[j-1] = kari;
            }
        }
    }
    /*
    for(int k = 0; k < n-1; k++){
        cout << c[k] << " ";
    }
    cout << c[n-1] << "1" << endl;
    */
}

void select(string c[], int n){
    int minj;
    string kari;
    for(int i = 0; i <= n - 1 ; i++){
        minj  = i;
        for(int j = i; j <= n - 1; j++){
            if(c[j][1] < c[minj][1]){
                minj = j;
            }
        }
        kari = c[i];
        c[i] = c[minj];
        c[minj] = kari;
        
    }
    /*
    for(int k = 0; k < n-1; k++){
        cout << c[k] << " ";
    }
    cout << c[n-1] << "2" << endl;
    */
}
int main(void){
    int n;
    cin >> n;
    string l[n],u[n],a;
    for(int i = 0; i < n; i++){
        cin >> a;
        l[i] = a;
        u[i] = a;
    }

    bubble(l,n);
    select(u,n);
    bool ans = true;
    for(int i = 0; i < n; i++){
        if(u[i] != l[i]){
            ans = false;
        }
    }
    for(int k = 0; k < n-1; k++){
        cout << l[k] << " ";
    }
    cout << l[n-1] << endl << "Stable" << endl;
    for(int k = 0; k < n-1; k++){
        cout << u[k] << " ";
    }
    cout << u[n-1] << endl;
    if(ans){
        cout << "Stable";
    } else {
        cout << "Not stable";
    }
    cout << endl;


}



Measured memory_bytes: 3224
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    public void solve() {
    	int H = Integer.parseInt(sc.next());
    	int W = Integer.parseInt(sc.next());
    	int[][] A = new int[H][W];
    	for (int i = 0; i < H; i++) {
    		for (int j = 0; j < W; j++) {
    			A[i][j] = Integer.parseInt(sc.next());
    		}
		}
    	int N = 0;
    	boolean f = true;
    	List<PP> hist = new ArrayList<>();
    	for (int i = 0; i < H; i++) {
			if(f) {
				for (int j = 0; j < W; j++) {
					if(A[i][j] % 2 == 1) {
						if(j != W-1) {
							N++;
							A[i][j+1]++;
							hist.add(new PP(i,j,i,j+1));
						} else if(i != H-1) {
							N++;
							A[i+1][j]++;
							hist.add(new PP(i,j,i+1,j));
						}
					}
				}
			} else {
				for( int j = W-1; j >= 0; j--) {
					if(A[i][j] % 2 == 1) {
						if(j != 0) {
							N++;
							A[i][j-1]++;
							hist.add(new PP(i,j,i,j-1));
						} else if(i != H-1) {
							N++;
							A[i+1][j]++;
							hist.add(new PP(i,j,i+1,j));
						}
					}
				}
			}
			f = !f;
		}
    	out.println(N);
    	for (PP p : hist) {
			out.println((p.y1+1) + " " + (p.x1+1) + " " + (p.y2+1) + " " + (p.x2+1));
		}
    }
    class PP {
    	int y1, x1, y2, x2;
    	public PP(int y1, int x1, int y2, int x2) {
    		this.y1 = y1;
    		this.x1 = x1;
    		this.y2 = y2;
    		this.x2 = x2;
    	}
    }
}


Measured memory_bytes: 69324
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
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 nx[4]={0,1,-1,0};
int ny[4]={1,0,0,-1};
int main(){
  ll n,m;
  cin>>n>>m;
  ll cu=m/n;
  for(int i=cu;i>0;i--){
    ll k=m-n*i;
    if(k%i==0){
      COUT(i);
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
void chmin(int &a, int b) { if (a > b) a = b; }

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
char da[4] = { 'R', 'L', 'D', 'U' };
char dax[4] = { -1, 1, -1, 1 };
char dax2[4] = { 1, -1, 1, -1 };
ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }





vector<ll> l;
ll N, A, B, C;
ll dfs(int num, int curA, int curB, int curC, ll point) {
	
	if(num == N){
		if (curA == 0 || curB == 0 || curC == 0)
			return inf;
		else
			return point + abs(curA - A) + abs(curB - B) + abs(curC - C);
	}

	
	ll retval = dfs(num + 1, curA + l[num], curB, curC, point + 10 * (curA > 0));
	retval = min(dfs(num + 1, curA, curB + l[num], curC, point + 10 * (curB > 0)), retval);
	retval = min(dfs(num + 1, curA, curB, curC + l[num], point + 10 * (curC > 0)), retval);
	retval = min(dfs(num + 1, curA, curB, curC, point), retval);
	return retval;
}


int main() {
	

	cin >> N >> A >> B >> C;
	l.resize(N);
	rep(i, N)
		cin >> l[i];


	cout << dfs(0, 0, 0, 0, 0) << endl;
	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n, x[120], y[120], h[120], px, py, ph=-1;

int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d %d %d", &x[i], &y[i], &h[i]);
        if(h[i] != 0) {
            px = x[i];  py = y[i]; ph=h[i];
        }
    }
    for(int i=0; i<=100; i++){  // x
        for(int j=0; j<=100; j++){  // y
            int aux=0, c;
            bool flag = true;
            if( ph != -1){
                aux = abs(px-i)+abs(py-j)+ph;
            } else {
                aux = abs(x[0]-i)+abs(y[0]-j)+h[0];
            }
            for(int k=0; k<n; k++){
                c = max(aux-abs(x[k]-i)-abs(y[k]-j), 0);
                if(c != h[k] ){
                    flag = false;
                    break;
                }
                //printf("%d %d %d %d\n", i, j, c, aux);
            }
            if(flag){
                printf("%d %d %d\n", i, j, aux);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n;cin>>n;
    int a[3*n];rep(i,3*n)cin>>a[i];
    sort(a,a+(3*n),greater<int>());
    ll ans = 0;
    for(int i=0;i<2*n;i++){
        if(i%2==1){ans += a[i];}
    }
    co(ans);
}

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

int main()
{
	int N, T, A;
	cin >> N >> T >> A;
	int h = (T - A) * 500;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i]; H[i] *= 3;
	}
	int id = 0;
	for (int i = 1; i < N; i++) {
		if (abs(H[i] - h) < abs(H[id] - h)) {
			id = i;
		}
	}
	cout << id + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k, l;
  
  ll A, B;
  cin >> A >> B;
  string s[111];
  
  for(i=0; i<50; i++) {
    s[i]=string(100, '.');
    s[i+50]=string(100, '#');
  }
  A--; B--; //初期配置の段階で白黒一つずつ連結成分が出来ているため
  
  ll h=0, w=0;
  for(i=0; i<B; i++, w+=2) {
    if(w==100) {
      h+=2;
      w=0;
    }
    
    s[h][w]='#';
  }
  
  h=99; w=0;
  for(i=0; i<A; i++, w+=2) {
    if(w==100) {
      h-=2;
      w=0;
    }
    
    s[h][w]='.';
  }
  
  pt(100<<" "<<100);
  for(i=0; i<100; i++) pt(s[i]);
  
}




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

#define MAX_SIZE 200

int Stack[MAX_SIZE];
int Stack_size;

void push(int x){
  Stack_size++;
  Stack[Stack_size]=x;
}

int pop(){
  Stack_size--;

  return Stack[Stack_size+1];
}

int main(void){
  int  num, a, b;
  char com[100];

  while(scanf("%s", com) != EOF){
    if(com[0] == '+'){
      push(pop()+pop());
    }
    else if(com[0] == '-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(com[0] == '*'){
      push(pop()*pop());
    }
    else{
      num=atoi(com);
      push(num);
    }
  }

  printf("%d\n", Stack[Stack_size]);

  return 0;
}



Measured memory_bytes: 2712
#include <stdio.h>
int main(void)
{
	int h, w;
	int i, j;

	while (1){
		scanf("%d %d", &h, &w);

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

		for (i = 1; i <= h; i++){
			if (i % 2 != 0){
				for (j = 1; j <= w; j++){
					if (j % 2 != 0){
						printf("#");
					}
					else {
						printf(".");
					}
				}
			}
			else if (i % 2 == 0){
				for (j = 1; j <= w; j++){
					if (j % 2 != 0){
						printf(".");
					}
					else {
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return (0);

}

Measured memory_bytes: 572
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
	class Program
	{
/*		public class Temp
		{
			public int a { get; set; }
			public int b { get; set; }
			public int c { get; set; }
			public int d { get; set; }
		}

		// Aは長さNの整数列
		var N = valueList[0];
		// 1 と Mの間の数字で構成
		var M = valueList[1];
		var Q = valueList[2];

		var tempList = new List<Temp>();

			for (int i = 0; i<Q; i++)
			{
				var inputValueList = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		tempList.Add(new Temp() { a = inputValueList[0], b = inputValueList[1],c = inputValueList[2],d = inputValueList[3]});
			}

*/

	static void Main(string[] args)
		{
			var valueList = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			var A = valueList[0];
			var B = valueList[1];
			var N = valueList[2];

			long answer = 0;

			if(B > N)
			{
				var first = (A * N / B);
				var last = 5 * (N / B);
				answer = first - last;
			}
			else
			{
				var first = (A * (B - 1) / B);
				var last = 5 * ((B - 1) / B);
				answer = first - last;

			}

/*			for (long i = 1; i <= N; i++)
			{
				var first =  (A * i / B);
				var last = 5 * (i / B);

				var answer = first - last;

				if(max < answer)
				{
					max = answer;
				}
			}
*/
			Console.WriteLine(answer);
		}
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
}
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }

}

Node treeSuccessor(Node x){
   Node y;
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL){
    y=z;
  }
  else{
    y=treeSuccessor(z);
  }
  if(y->left!=NIL){
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else if(y==y->parent->left){
    y->parent->left=x;
  }
  else{
    y->parent->right=x;
  }
  if(y!=z){
    z->key=y->key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if(z->key<y->key){
    y->left=z;
  }
  else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u == NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
  if(u == NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20484
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#define rep(i,n) for (int i = 0; i < n; ++i)
const int INF = 1001001001;

using namespace std;

int main() {
    string n;
    cin >> n;
    int l = n.size();
    int x = n[l-1] - '0';
    if (x == 3) cout << "bon" << endl;
    else if (x == 0 || x == 1 || x == 6 || x == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        String[] words = {
            "dream",
            "dreamer",
            "erase",
            "eraser"
        };
        boolean[] dp = new boolean[N+1];
        dp[0] = true;
        for (int i = 0; i < N; i++) {
            if (dp[i]) {
                for (String w : words) {
                    if (S.startsWith(w, i)) {
                        dp[i + w.length()] = true;
                    }
                }
            }
        }
        System.out.println(dp[N] ? "YES" : "NO");
        
    }
}

Measured memory_bytes: 25676