akhauriyash/Code-Regression huggingface dataset:
from collections import deque
import sys
input = sys.stdin.readline

def topological_sort(graph: list, n_v: int) -> list:
    # graph[node] = [(cost, to)]
    indegree = [0] * n_v # 各頂点の入次数
    for i in range(n_v):
        for c, v in graph[i]:
            indegree[v] += 1

    cand = deque([i for i in range(n_v) if indegree[i] == 0])
    res = []
    while cand:
        v1 = cand.popleft()
        res.append(v1)
        for c, v2 in graph[v1]:
            indegree[v2] -= 1
            if indegree[v2] == 0:
                cand.append(v2)

    return res


n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((d, r))

ts = topological_sort(edges, n)

if len(ts) != n:
    # Not DAG
    ans = "No"
else:
    # DAG
    dist = [-1] * n
    ans = "Yes"
    for i in range(n):
        v = ts[i]
        if dist[v] == -1:
            dist[v] = 0

        for c, u in edges[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + c
            elif dist[u] != dist[v] + c:
                ans = "No"
                break

print(ans)


Measured memory_bytes: 41736
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   1000000000
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}



//=============================================ASIFAZAD==============================================//

const int N = 200010;
vi inp(N);
int n, k;

bool ok(ll mid)
{
    ll an = 0;
    for(int i = 0;i < n;i++)
        an += (inp[i] - 1)/mid;
    return an <= k;
}



int32_t main()
{
    io;
    int n, k;
    cin>>n>>k;
    vi a(n);
    for(int i= 0;i < n;i++)
        cin >>a[i];

    ll l = 1, h = 1000000000, mid, ans;
    while(l <= h)
    {
        mid = (l + h)/2;
        ll s = 0;
        for(int i = 0; i< n;i++)
            s += (a[i] - 1)/mid;
        if(s <= k)
        {
            ans = mid;
            h = mid - 1;
        }
        else
            l = mid + 1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sca = new Scanner(System.in);
		int r = sca.nextInt();
		double ans = 2*(3.141)*r;

		System.out.println(ans);

		// 後始末
		sca.close();
	}
}

Measured memory_bytes: 35900
#include <bits/stdc++.h>
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
using namespace std;

struct Node{
    int p,l,r;
};

Node t[25];

void preorder(int v){
    if(v==-1)return;
    cout<<" "<<v;
    preorder(t[v].l);
    preorder(t[v].r);
}

void inorder(int v){
    if(v==-1)return;
    inorder(t[v].l);
    cout<<" "<<v;
    inorder(t[v].r);
}

void postorder(int v){
    if(v==-1)return;
    postorder(t[v].l);
    postorder(t[v].r);
    cout<<" "<<v;
}

signed main(){
    int n;
    cin>>n;
    rep(i,n)t[i].p=-1;
    rep(i,n){
        int id,l,r;
        cin>>id>>l>>r;
        t[id].l=l;
        t[id].r=r;
        if(l!=-1)t[l].p=id;
        if(r!=-1)t[r].p=id;
    }
    
    int root;
    rep(i,n)if(t[i].p==-1)root=i;
    cout<<"Preorder"<<endl;
    preorder(root);
    cout<<endl<<"Inorder"<<endl;
    inorder(root);
    cout<<endl<<"Postorder"<<endl;
    postorder(root);
    cout<<endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(vec) vec.begin(), vec.end()

using namespace std;
using ll = long long;

int main() {
	ll N, K;
	cin >> N >> K;

	vector<ll> plus;
	vector<ll> minus;
	ll zero = 0;

	rep(i, N) {
		int a;
		cin >> a;
		if (a == 0) { zero++; }
		else if (a > 0) { plus.push_back(a); }
		else { minus.push_back(a); }
	}

	sort(all(plus));
	sort(all(minus));

	ll p = plus.size();
	ll m = minus.size();

	if (K <= p * m) {
		ll l = -1e18;
		ll r = -1;

		while (r - l > 1) {
			ll mid = (r + l) / 2;
			ll c = 0;

			rep(i, p) {
				ll d = (mid - plus[i] + 1) / plus[i];
				c += upper_bound(all(minus), d) - minus.begin();
			}
			if (c >= K) { r = mid; }
			else { l = mid; }
		}
		cout << r << endl;
	}

	else if (K <= ((zero * (zero - 1)) / 2 + zero * (p + m) + p * m)) { cout << 0 << endl; }
	else {
		ll l = 0;
		ll r = 1e18;
		K -= ((zero * (zero - 1)) / 2 + zero * (p + m) + p * m);

		rep(i, m) minus[i] = abs(minus[i]);
		sort(all(minus));

		while (r - l > 1) {
			ll mid = (r + l) / 2;
			ll c = 0;
			ll idx;

			rep(i, p) {
				idx = upper_bound(all(plus), mid / plus[i]) - plus.begin();
				if (i < idx) { idx--; }
				c += idx;
			}

			rep(i, m) {
				idx = upper_bound(all(minus), mid / minus[i]) - minus.begin();
				if (i < idx) { idx--; }
				c += idx;
			}

			c /= 2;

			if (c >= K) { r = mid; }
			else { l = mid; }
		}
		cout << r << endl;
	}


	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    priority_queue<int> a;
    priority_queue<int> b;
    priority_queue<int> c;
    for (int i = 0; i < A; i++){
        int z;
        cin >> z;
        a.push(z);
    }
    for (int i = 0; i < B; i++){
        int z;
        cin >> z;
        b.push(z);
    }
    for (int i = 0; i < C; i++){
        int z;
        cin >> z;
        c.push(z);
    }
    for (int i = 0; i < X; i++){
        int z;
        z = a.top();
        a.pop();
        c.push(z);
    }
    for (int i = 0; i < Y; i++){
        int z;
        z = b.top();
        b.pop();
        c.push(z);
    }
    int64_t ans = 0;
    for (int i = 0; i < X + Y; i++){
        int z;
        z = c.top();
        c.pop();
        ans += z;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int ans = 0;
	char s;
	for (int i = 0; i < 4; i++)
	{
		cin >> s;
		if (s == '+')
			ans++;
		else
			ans--;
	}
	cout << ans << endl;
} 

Measured memory_bytes: 3576
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  string s;
  cin >> s;
  lld l = s.length();
  for (lld i = 0; i < l; i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << "\n";
}

Measured memory_bytes: 3752
fun main() {
    val (A, B, C, K) = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    ans = if (A >= K) {
        K
    } else {
        if (A+B >= K) {
            A
        } else {
            A - (K - A -B)
        }
    }
    println(ans)
} 

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

using namespace std;

void A_Hitachi_String(void) {

	string S;
	cin >> S;

	bool re = true;

	if ((int)S.size() % 2 == 1) {
		re = false;
	}
	else {

		for (int loop = 0; loop < (int)S.size(); loop += 2) {

			if (!(S[loop] == 'h' && S[loop + 1] == 'i')) {

				re = false;
				break;
			}
		}
	}

	cout << (re ? "Yes" : "No") << flush;
	return;
}

int main(void) {

	A_Hitachi_String();
	return 0;
}


Measured memory_bytes: 256
#include<string>
//#include <vector>
//#include <stack>
#include <set>
#include<iostream>
#include <algorithm>
#include <limits.h>
#include <float.h>
#include <functional>
#include <math.h>
#include <hashtable.h>

using namespace std;
string s;

set<char> rmap;

bool isRight(char s){
	return rmap.find(s)!=rmap.end();
}

int main(){
	rmap.insert('q');
	rmap.insert('w');
	rmap.insert('e');
	rmap.insert('r');
	rmap.insert('t');
	rmap.insert('a');
	rmap.insert('s');
	rmap.insert('d');
	rmap.insert('f');
	rmap.insert('g');
	rmap.insert('z');
	rmap.insert('x');
	rmap.insert('c');
	rmap.insert('v');
	rmap.insert('b');

	while(true){
		cin >> s;
		if(s=="#"){
			break;
		}
		int c=0;
		bool nowRight=isRight(s[0]);
		for(int i=1,ln=s.length();i<ln;i++){
			bool r=isRight(s[i]);
			if((nowRight && !r) || (!nowRight && r)){
				c++;
				nowRight=r;
			}
		}
		cout<< c << endl;
	}
}

Measured memory_bytes: 1196
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
#define MAX 200000
#define INFTY 9000000000

int main(){
  int N,i;
  cin>>N>>i;
  cout<<N-i+1<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = [input()[0] for _ in range(N)]

from collections import Counter
cos = Counter(S)

num = [cos[i] for i in "MARCH"]

ans = 0
for i in range(5) :
    for j in range(i+1,5) :
        for k in range(j+1,5) :
            ans += num[i]*num[j]*num[k]

print(ans)


Measured memory_bytes: 4120
S = input()
 
N = len(S)

mod = 2019
d = [0 for i in range(2019)]
d[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    d[rem] += 1

print(int(sum([i * (i-1) / 2 for i in d])))


Measured memory_bytes: 9228
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

typedef long long ll;
typedef pair<int,int> P;

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    vector<int> water;
    vector<int> sugar;
    int check[3001];
    priority_queue<int,vector<int>,greater<int>> q;
    q.push(100*A);
    q.push(100*B);
    check[100*A] = check[100*B] = 1;
    while(!q.empty()){
        int m = q.top();
        q.pop();
        water.emplace_back(m);
        if(m + 100*A <= F && check[m + 100 * A] == 0){
            q.push(m+100*A);
            check[m + 100 * A] == 1;
        }
        if(m + 100*B <= F && check[m + 100 * B] == 0){
            q.push(m+100*B);
            check[m + 100 * B] == 1;
        }
    }
    memset(check,0,sizeof check);
    q.push(0);
    q.push(C);
    q.push(D);
    check[0] = check[C] = check[D] = 1;
    while(!q.empty()){
        int s = q.top();
        q.pop();
        sugar.emplace_back(s);
        if(s + C <= F && check[s + C] == 0) {
            q.push(s+C);
            check[s + C] = 1;
        }
        if(s + D <= F && check[s + D] == 0) {
            q.push(s+D);
            check[s + D] = 1;
        }
    }
    int n = sugar.size();
    double maxi = -1;
    int ans_water;
    int ans_sugar;
    for(int w : water){
        int left = 0;
        int right = n;
        while(right - left > 1){
            int mid = (left + right) / 2;
            if(w + sugar[mid] > F) right = mid;
            else if(w / 100 * E >= sugar[mid]) left = mid;
            else right = mid;
        }
        double temp = (double)100 * sugar[left] / (w + sugar[left]);
        if(maxi < temp){
            maxi = temp;
            ans_water = w;
            ans_sugar = sugar[left];
        } 
    }
    cout << ans_water+ans_sugar << " " << ans_sugar << endl;
    return 0;
}


Measured memory_bytes: 256
def bellman_ford(n, s, edges, init_val): 
    d = [init_val] * n
    d[0] = 0
    for _ in range(n):
        updated = False
        for vf, vt, w in edges:
            if d[vf] != init_val and d[vt] > d[vf] + w:
                d[vt] = d[vf] + w
                updated = True
        if not updated:
            break
    if updated: #閉路の存在
        for vf, vt, w in edges:
            if d[vf] != init_val and d[vt] > d[vf] + w:
                d[vt] = -float('inf')
    return d

n, m = map(int, input().split())

edges = []
for i in range(m):
    a, b, w = map(int, input().split())
    edges.append((a-1, b-1, -w))
d = bellman_ford(n, 0, edges, float('inf'))
print(-d[-1] if d[-1] != -float('inf') else 'inf')


Measured memory_bytes: 74740
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int lowest_a = 0,lowest_b = 0;
    for(int i = 0;i < n;i++)
    {
        int a,b;
        cin >> a >> b;
        if(a > lowest_a)
        {
            lowest_a = a;
            lowest_b = b;
        }
    }
    cout << lowest_a + lowest_b;

    return 0;
}

Measured memory_bytes: 764
using System;
class Program
{
	static int minNum = 1;
	static int maxNum = 10000;


	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		if (!chectNum(a) && !chectNum(b))
		{
			Console.WriteLine("入力値が不正です。");
		}

		if (a % 2 == 0 || b % 2 == 0)
			Console.WriteLine("Even");
		else
			Console.WriteLine("Odd");
	}
	private static bool chectNum(int target)
	{
		return minNum <= target && target <= maxNum;
	}
}

Measured memory_bytes: 13140
#include <stdio.h>
static const int MAX=100;
static const int INFTY=(1<<30);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[MAX][MAX];

void dijkstra(){
    int minv,i,o;
    int d[MAX],color[MAX];
    for(i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INFTY;
        int u=-1;
        for(i=0;i<n;i++){
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)
            break;
        color[u]=BLACK;
        for(o=0;o<n;o++){
            if(color[o]!= BLACK && M[u][o] != INFTY){
                if(d[o]>d[u]+M[u][o]){
                    d[o]=d[u]+M[u][o];
                    color[o]=GRAY;
                }
            }
        }
    }
    for(i=0;i<n;i++)
        printf("%d %d\n",i,(d[i]==INFTY)?-1:d[i]);
}

int main(void){
    int i,o,k,c,u,v;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        for(o=0;o<n;o++)
            M[i][o]=INFTY;
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(o=0;o<k;o++){
            scanf("%d %d",&v,&c);
            M[u][v]=c;
        }
    }
    dijkstra();
    return 0;
}

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

using namespace std;
using ll = unsigned long long;

ll mod = 1e9 + 7;

bool nprime[10000001];

vector<ll> pr;

int cnt = 0;

int main()
{
    ll x; cin >> x;
    
    if (x == 1)
    {
        cout << 0;
        return 0;
    }

    nprime[0] = nprime[1] = true;
    
    for (ll i = 2; i < 10000001; ++i)
    {
        if (nprime[i])
            continue;
        
        pr.push_back(i);
        
        for (ll j = i * i; j < 10000001; j += i)
            nprime[j] = true;
    }
    
    for (int i = 0; i < pr.size(); ++i)
    {
        for (int j = pr[i]; j <= 1000000000000LL; j *= pr[i])
        {
            if (x >= j && x % j == 0)
            {
                ++cnt;
                x /= j;
            }
            else
            {
                for (; x%pr[i]==0;x/=pr[i]) {}
                break;
            }
        }
    }
    
    if (x > 1)
        ++cnt;
    
    cout << cnt;
}

Measured memory_bytes: 21404
//
// Created by yamunaku on 2020/01/10.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    vi x(n);
    iota(all(x), 1);
    int a, b, c = 0;
    do{
        c++;
        rep(i,n){
            if(x[i] != p[i]) goto next;
        }
        a=c;
        next:;
        rep(i,n){
            if(x[i] != q[i]) goto next2;
        }
        b=c;
        next2:;
    }while(next_permutation(all(x)));
    cout << abs(b - a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define max_t 100000

void Main() {
  //自動整形防止用
  int n;
  std::cin >> n;
  priority_queue<double, std::vector<double>, greater<double>> q;
  rep(i, n) {
    double tmp;
    std::cin >> tmp;
    q.push(tmp);
  }

  while (q.size() != 1) {
    double tmp = q.top();
    q.pop();
    double tmp2 = q.top();
    q.pop();
    double gnum = (tmp2 + tmp) / 2.0;
    q.push(gnum);
  }

  std::cout << q.top() << '\n';
  return;
}

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


Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 163 C - management
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/04/19
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#pragma GCC optimize("Ofast")
#include <cstdio>
using namespace std;

int n;
int a[200000];

void solve() {
    int bin[200000] = {};

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

int main() {

    scanf("%d",&n);
    for (int i=0;i<n-1;i++) {
        scanf("%d",&a[i]);
    }

    solve();

}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  // input
    int n;cin >> n;
    vector<int> a(n + 1);
    vector<int> c(n + 1,0);
    int counter = 0;
    for(int i = 1; i < n + 1; i++) cin >> a[i];

  // compute
    for(int i = 1; i < n + 1; i++) {
        if(a[i] > n){
            counter += 1;
        }else{
            c[a[i]] += 1;
        }
    }

    for(int i = 1; i < n + 1; i++){
        if(c[i] - i > 0){
            counter += c[i] - i;
        }else if(c[i] - i < 0){
            counter += c[i];
        }
    }
    
  // output 
    cout << counter << endl;

}


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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define inf 1e18+9
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    if(n<=0) return 1;
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

const ll MOD = 1e9+7;

inline ll mul(ll x, ll y) {
    x %= MOD;
    y %= MOD;
    ll ans = ((x*y)%MOD+MOD)%MOD;
    return ans;
}

int main() {
    fastio;
    ll N;
    cin>>N;

    ll pp = power(10,N,MOD);

    ll pp1 = power(8,N,MOD);
    ll pp2 = power(9,N,MOD);
    pp2 = mul(2,pp2);
    ll ans = (pp-pp2+pp1+MOD)%MOD;
    cout<<ans<<endl;
}






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

int main(){
    
    int H, W;

    while(true){
    cin >> H >> W;
    if((H==0)&&(W==0)) break;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if((i%2)==0){
            if((j%2)==0) cout << '#';
            else if((j%2)==1) cout << '.'; 
            }
            else{
            if((j%2)==1) cout << '#';
            else if((j%2)==0) cout << '.'; 
            }   
        }
        cout << endl;
    }
    cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define int long long
#define re(i,n) for(i=0;i<n;i++)
#define bre(i,n) for(i=n;i>0;i--)
#define rep(i,l,r) for(i=l;i<r;i++)
#define brep(i,l,r) for(i=r;i>l;i--)
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
template<int H,int W>int wa(int x1,int y1,int x2,int y2,int(&p)[H][W]){
	return p[y2][x2]-p[y2][x1]-p[y1][x2]+p[y1][x1];
}
struct Unif{
	vector<int> e;
	vector<int> rank;
	Unif(int n):e(n,-1),rank(n,1){}
	void uni(int a,int b){
		if(e[a]!=-1)
			uni(e[a],b);
		else if(e[b]!=-1)
			uni(a,e[b]);
		else{
			if(a==b)
				return;
			int ra=rank[a],rb=rank[b];
			if(ra>=rb){
				e[b]=a;
				if(ra==rb)
					rank[a]++;
			}
			else
				e[a]=b;
		}
	}
	bool find(int a,int b){
		if(e[a]!=-1)
			return find(e[a],b);
		else if(e[b]!=-1)
			return find(a,e[b]);
		else
			return a==b;
	}
	int num(int a){
		if(e[a]!=-1)
			return num(e[a]);
		else
			return a;
	}
};
int A,B,C,D,N,M,K,S,T,H,W;
int p[314514];
signed main(){
	int i,j,k;
	cin>>A>>B>>C;
	int ans=0;
	int x=(A&1)|((B&1)<<1)|((C&1)<<2);
	switch(x){
	case 0:
		break;
	case 1:
		B++;
		C++;
		ans++;
		break;
	case 2:
		A++;
		C++;
		ans++;
		break;
	case 3:
		A++;
		B++;
		ans++;
		break;
	case 4:
		A++;
		B++;
		ans++;
		break;
	case 5:
		A++;
		C++;
		ans++;
		break;
	case 6:
		B++;
		C++;
		ans++;
		break;
	case 7:
		break;
	}
	int t=max({A,B,C});
	int a=(t-A)/2,b=(t-B)/2,c=(t-C)/2;
	ans+=a+b+c;
	cout<<ans<<endl;
}

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

int main() {
	
	long n,d, x,y;
	cin >> n >> d;
	long counter = 0;
	while(n--){
		cin >> x >> y;
		if(sqrtl(powl(x,2) + powl(y,2)) <= d) counter++;
	}
	cout << counter << endl;
	
	
}


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

int main()
{
    long long int n,a=0,b=0,c=0,d=0;
    cin >> n;
    
    while(n--)
    {
        string s;
        cin >> s;
        
        if(s=="AC")
        {
            a++;
        }
        else if(s=="WA")
        {
            b++;
        }
         else if(s=="TLE")
        {
            c++;
        }
         else if(s=="RE")
        {
            d++;
        }
        
        
    }
    cout << "AC x" << " "<<a << "\n";
         cout << "WA x" <<" "<< b << "\n";
          cout << "TLE x" <<" "<< c << "\n";
           cout << "RE x" <<" "<< d << "\n";

    return 0;
}

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

typedef long long int ll;

int main(void){
	ll n;
  	ll a[200020];
  	ll sum;
  	ll i;
  
  	cin >> n;
  	for(i=0; i<n; i++)
    {
      	cin >> a[i];
    }
  	
  	sum = 0LL;
  	for(i=0; i<n-1; i++)
    {
      if(a[i] > a[i+1]){
        sum += a[i] - a[i+1];
      	a[i+1] = a[i];
      }
    }
  
  	cout << sum;
  
  return 0;
}


Measured memory_bytes: 5172
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

vector<bool> visited;
vector<vector<int>> G;
vector<pair<int, int>> E;
bool dfs(int n, int notuse) {
	if (visited[n]) return false;
	int a = E[notuse].first;
	int b = E[notuse].second;
	visited[n] = true;
	REP(i, G[n].size()) {
		if (G[n][i] == a && n == b || G[n][i] == b && n == a) continue;
		if (dfs(G[n][i], notuse)) return true;
	}
	return false;
}

int main(void) {
	int N, M;
	cin >> N >> M;
	G.resize(N);
	visited.resize(N, false);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
		E.push_back(make_pair(a - 1, b - 1));
	}
	int cnt = 0;
	REP(i, M) {
		visited.resize(0); visited.resize(N, false);
		dfs(0, i);
		bool bridge = false;
		REP(i, visited.size()) if (!visited[i]) bridge = true;
		if (bridge) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;

struct UnionFind{
  vector<int> par;
  
  UnionFind(int N) : par(N){
    for(int i = 0; i < N; i++) par[i] = i;
  }
  
  int root(int x){
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  bool unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return false;
    par[rx] = ry;
    return true;
  }
  
  bool same(int x, int y){
    return root(x) == root(y);
  }
};

struct corridor {
  int a, b;
  double len;
  corridor(int a, int b, double len) : a(a), b(b), len(len){}
  
  bool operator <(const corridor& rhs) const{
    if (len != rhs.len) { return len < rhs.len; }
    if (a != rhs.a) { return a < rhs.a; }
    return b < rhs.b;
  }
};

double dist(double x1, double y1, double z1, double x2, double y2, double z2){
  return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
}

int main(){
  while(1){
    int n;
    cin >> n;
    if (n == 0) break;
    UnionFind tree(n);
    vector<double> x(n), y(n), z(n), r(n);
    rep(i, n) cin >> x[i] >> y[i] >> z[i] >> r[i];

    vector<corridor> cor;
    rep(i, n)rep2(j, i+1, n){
      cor.push_back(corridor(i, j, max(0.0, dist(x[i], y[i], z[i], x[j], y[j], z[j]) - r[i] - r[j])));
    }
    sort(cor.begin(), cor.end());

    double ans = 0.0;
    int count = 0;
    for(auto itr = cor.begin(); count < n - 1; itr++){
      if (tree.unite(itr->a, itr->b)){
        ans += itr->len;
        count++;
      }
    }
    cout << fixed << setprecision(3) << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  vll A(3);
  rep(i, 3) cin >> A[i];
  SORT(A);

  if (A[0] == 5 && A[1] == 5 && A[2] == 7) {
    COUT("YES");
  } else {
    COUT("NO");
  }
  return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,k;
  int n;cin>>n;
  int a[n];
  for(i=0;i<n;i++) cin >> a[i];
  int ans = 1 << 30;
  for(i=-100;i<=100;i++){
    k=0;
    for(j=0;j<n;j++){
      k+=(i-a[j])*(i-a[j]);
    }
    ans=min(ans,k);
  }
  cout << ans << endl;  
  return 0;
}


Measured memory_bytes: 256
<?php
$max=100000;
$MAX=sqrt($max);
$ch=[0,0,1,1];
for($i=4;$i<$max;$i+=2){$ch[$i]=0;$ch[$i+1]=1;}
for($i=3;$i<$MAX;$i+=2) if($ch[$i]) for($j=$i<<1;$j<$max;$j+=$i) $ch[$j]=0;

$l=trim(fgets(STDIN));
$c=0;
for($i=0;$i<$l;$i++){
  $n=trim(fgets(STDIN));
  if($n<$max) $c+=$ch[$n];
  else $c+=isPn($n);
}

echo $c;

function isPn($n){
  if($n<2) return 0;
  if($n==2) return 1;
  if($n%2==0) return 0;
  $max=floor(sqrt($n));
  for($i=3;$i<=$max;$i+=2) if($n%$i==0) return 0;
  return 1;
}
?>

Measured memory_bytes: 29728
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n; cin >> n;
    vec<int> sorted(n), a(n);
    for (int i = 0; i < n; ++i) {
        int b; cin >> b;
        sorted[i] = a[i] = b;
    }
    sort(sorted.rbegin(), sorted.rend());

    for (int i = 0; i < n; ++i) {
        if (sorted[0] <= a[i]) cout << sorted[1] << endl;
        else cout << sorted[0] << endl;
    }
}



Measured memory_bytes: 4844
// http://kmjp.hatenablog.jp/entry/2018/03/20/0900

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted

int main(){

	ll N,ans=0;
	cin >> N;
	vector<ll> A(N),B(N);
	FOR(i,0,N)cin>>A[i];
	FOR(i,0,N)cin>>B[i];
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());

	FOR(i,0,29){
		vector<ll> C(N);
		FOR(x,0,N)C[x] = B[x]%(1<<(i+1));
		sort(C.begin(),C.end());
		ll tot = 0;
		FOR(x,0,N){
			ll y = A[x]%(1<<(i+1));
			tot += POSL(C,(1<<(i+1))-y)-POSL(C,(1<<(i))-y);
			tot += POSL(C,(1<<(i+2))-y)-POSL(C,3*(1<<(i))-y);
		}
		if(tot%2) ans += 1<<i;
	}
	cout << ans << endl;

}

Measured memory_bytes: 4992
N, M, Q = map(int, input().split())
wa = [[0]*(N+1) for _ in range(N+1)]
import numpy as np

for _ in range(M):
    l, r = map(int, input().split())
    wa[l][r] += 1

cwa = np.cumsum(np.cumsum(wa, axis=0), axis=1).tolist()
for i in range(Q):
    p, q = map(int, input().split())
    ans = cwa[N][q]-cwa[p-1][q]
    print(ans)


Measured memory_bytes: 26180
N, L = map(int, input().split())

T=[]
sum_t = 0

for n in range(N):
    taste = L + (n+1) -1
    sum_t += taste
    T.append(abs(taste))

m = T.index(min(T))

sum_t -= L + (m+1) -1
print(sum_t)




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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); cout.tie(NULL);
	
  int n;
  cin >> n;
  vector < int > u(n), v(n);
  vector < array < int, 3 > > a(n);

  for(int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    u[i] = x; 
    v[i] = y;
    a[i][0] = x + y;
    a[i][1] = x;
    a[i][2] = y;
  }

  sort(a.rbegin(), a.rend());

  long long ans = 0;

  for(int i = 0; i < n; ++i) {
    if(i % 2) ans -= a[i][2];
    else ans += a[i][1]; 
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int main(void)
{
	int a,b,c,d,x,y,z;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	x=a+b+c+d;
	y=x/60;
	z=x%60;
	printf("%d\n",y);
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 2752
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

ll ans;
int n, m, a[100000];
priority_queue<pair<int, int>> pq;
int main(void) {
    cin >> n >> m;
    rep(i,n) cin >> a[i];
    sort(a, a+n);
    rep(i,m) {
        int b, c;
        cin >>b >> c;
        pq.push(make_pair(c, b));
    }
    int i = 0;
    while (pq.size() != 0) {
        auto p = pq.top();
        pq.pop();
        int j = 0;
        while (j < p.second) {
            if (a[i] < p.first) {
                a[i] = p.first;
                i++; j++;
                if (i == n) goto end;
                continue;
            }
            goto end;
        }
    }
 end:
    rep(i,n) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1784
#include<stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right) / 2;
        if(key == A[mid]) return 1;  /* keyを発見 */
        if(key > A[mid]) left = mid + 1;  /* 後半を探索 */
        else if(key < A[mid]) right = mid;  /* 前半を探索 */
    }
    return 0;
}

int main(){
    int i, q, k, sum = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &k);
        if(binarySearch(k)) sum++;
    }
    printf("%d\n", sum);
    
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

struct UnionFind {
   vector<int> d;
   UnionFind(int n = 0) : d(n, -1) {}
   int find(int x) {
      if (d[x] < 0)
         return x;
      return d[x] = find(d[x]);
   }
   bool unite(int x, int y) {
      x = find(x);
      y = find(y);
      if (x == y)
         return false;
      if (d[x] > d[y])
         swap(x, y);
      d[x] += d[y];
      d[y] = x;
      return true;
   }
   bool same(int x, int y) { return find(x) == find(y); }
   int size(int x) { return -d[find(x)]; }
};

int deg[100005];
vector<int> to[100005];

int main() {
   int n, m, k;
   cin >> n >> m >> k;
   UnionFind uf(n);
   rep(i, m) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      deg[a]++;
      deg[b]++;
      uf.unite(a, b);
   }
   rep(i, k) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      to[a].push_back(b);
      to[b].push_back(a);
   }
   rep(i, n) {
      int ans = uf.size(i) - 1 - deg[i];
      for (int u : to[i]) {
         if (uf.same(i, u))
            ans--;
      }
      printf("%d%c", ans, i == n - 1 ? '\n' : ' ');
   }
   return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N; cin >> N;
    long long a[300010];
    for (int i = 0; i < 3*N; i++){
        cin >> a[i];
    }
    sort(a,a+3*N);
    reverse(a,a+3*N);
    long long ans = 0;
    for (int i = 0; i < N; i++){
        ans += a[2*i+1];
    }
    cout << ans << endl;
}




Measured memory_bytes: 2560
#include <iostream>
      #include <string>
      #include <vector>
      #include <algorithm>
      #include <set>
      using namespace std;
      typedef long long ll;
      #define rep(i,n) for (int i=0;i < (int)(n);i++)
      
      int v[100001];
      int main(){
        set <int> st;
        int n;
        cin >> n;
        rep(i,n){
          int tmp;
          cin >> tmp;
          if (st.count(tmp)) st.erase(tmp);
          else st.insert(tmp);
        }
        cout << st.size() << endl;
        
        
        return 0;

        
      }
        
        

Measured memory_bytes: 4864
#include<stdio.h>
int main(){
  int a,i,n,k,ans=0;
  scanf("%d %d\n",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a>=k){
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a<b){
	 printf("a < b\n");
	}else if(a>b){
	 printf("a > b\n");
    } else {
	 printf("a == b\n");
    }
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <deque>

using namespace std;

int main(){
  int a[200000],n;
  deque<int> b;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }

  if(n%2==0){
    for(int i=0;i<n;i++){
      (i%2==1)?b.push_front(a[i]):b.push_back(a[i]);
    }
  }else{
    for(int i=0;i<n;i++){
      (i%2==0)?b.push_front(a[i]):b.push_back(a[i]);
    }
  }

  for(int i=0;i<n;i++){
    cout << b.at(i) <<" ";
  }
  cout << endl;
}


Measured memory_bytes: 3840
x=int(input())
s={0}
n=1
stop=0
while(1):
    N=n**5
    for i in s:
        if N-i==x:
            if i>0:
                sig=1
            elif i<0:
                sig=-1
            else:
                sig=0
            print(n,int(sig*pow(abs(i),1/5)))
            stop=1
        elif i-N==x:
            if i>0:
                sig=1
            elif i<0:
                sig=-1
            else:
                sig=0
            print(int(sig*pow(abs(i),1/5)),n)
            stop=1
    if stop==1:
        break
    s|={N,-N}
    n+=1

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

namespace AthleteProgramming2
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0)
                {
                    break;
                }
                int[] array = new int[n];
                for(int i = 0; i < n; i++)
                {
                    array[i] = int.Parse(Console.ReadLine());
                }
                int[] dp = new int[n];
                dp[0] = array[0];
                for(int i = 1; i < n; i++)
                {
                    dp[i] = Max(dp[i - 1] + array[i], array[i]);
                }

                Console.WriteLine(dp.Max());
                
            }
        }

        static int Max(int a,int b)
        {
            if (a >= b)
            {
                return a;
            }else
            {
                return b;
            }
        }

    }

}

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

int main() {
    ll n, x, m;
    cin >> n >> x >> m;

    ll ans = 0;

    ll now = x;
    vector<ll> sum;

    map<ll, int> mp;

    if (x == 1) {
        cout << x * n << endl;
        return 0;
    }

    sum.push_back(0);

    rep(i, n) {
        sum.push_back(now);
        if (mp.count(x) == 0)
            mp[x] = i + 1;
        else {
            ll sa = n - i;
            ll phase = i - mp[x] + 1;
            ll plus = sum[sum.size() - 1] - sum[mp[x]];

            //cout << plus << endl;

            ans += sa / phase * plus;
            sa -= sa / phase * phase;

            ans += sum[mp[x] + sa - 1] - sum[mp[x] - 1];
            break;
        }

        ans += x;

        x *= x;
        x %= m;

        now += x;

        if (x == 0)
            break;
    }

    cout << ans << endl;

    return 0;
}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            List<int> A = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToList();
            long ans = A.Select(i => i - 1).Sum();
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13408
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ");
        var N = int.Parse(input[0]);
        var K = int.Parse(input[1]);
        var p = new List<int>();
        var line = Console.ReadLine().Split(" ");

        p.Add(0);
        for (int i = 0; i < N; i++)
        {
            p.Add(int.Parse(line[i]));
        }

        var dp = new int[N + 1, K + 1];
        for (int i = 0; i < N; i++)
        {
            dp[i, 0] = 0;
        }

        for(int i = 0; i < N; i++)
        {
            for(int k = 0; k < K; k++)
            {
                if (i == k)
                {
                    dp[i + 1, k + 1] = dp[i, k] + p[i + 1];
                    break;
                }
                else 
                {
                    dp[i + 1, k + 1] = Math.Min(dp[i, k] + p[i + 1], dp[i, k + 1]);
                }
            }
        }

        Console.WriteLine(dp[N, K]);
    }
}


Measured memory_bytes: 32020
S = input()
N = len(S)
X = 0
for i in range (N):
  if i%2 == 0:
    if S[i] == "L" :
      X += 1
    else:
      X += 0
  else :
    if S[i] == "R" :
      X += 1
    else :
      X += 0
if X >= 1:
  print("No")
else :
  print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using vi = vector<int>;
using vll = vector<ll>;
ll fast_exp(ll base,ll e){
    ll r=1;
    while(e>0){
        if(e%2)r=(r*base);
        base=base*base;
        e/=2;
    }
    return r;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,W;
    cin>>n>>W;
    vector<ll> dp(W+1,0);
    for(int i=0;i<n;i++){
        ll w,v;cin>>w>>v;
        for(int j=W;j>=0;j--){
            if(j>=w)
            dp[j]=max(dp[j],v+dp[j-w]);
            else
            dp[j]=dp[j];
        }
    }
    // for(int i=0;i<=W;i++)cout<<dp[i]<<" ";cout<<endl;
    cout<<dp[W];
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
double f(double x,double q){
  return (x-(x*x*x-q)/(3*x*x));
}
double newton(double x,double q){
  double nx = f(x,q);
  if(abs(nx*nx*nx-q)<0.00001*q) return nx;
  else return (newton(nx,q));
}
int main(void){
  int q;
  while(cin>>q){
    if(q==-1) break;
    printf("%lf\n",newton(q/2,q));
  }
  return 0;
}

Measured memory_bytes: 0