akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll A, B;
  cin>>A>>B;
  ll ans;
  ll num;
  if(A%2==0) {
    if(B%2==0) {
      num = (B-A)/2;
      num %= 2;
      ans = B^num;
    }
    else {
      num = (B-A+1)/2;
      num %= 2;
      ans = num;
    }
  }
  else {
    if(B%2==0) {
      num = (B-A)/2;
      num %= 2;
      ans = A^B^num;
    }
    else {
      num = (B-A)/2;
      num %= 2;
      ans = A^num;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>

using namespace std;
int n,a[201001],b[202020],st,ed;
int main() {
	scanf("%d",&n);
	for (int i = 1;i <= n; i++)
		scanf("%d",&a[i]);
	st = 1,ed = n;
	for (int i = n;i >= 1; i--)
		if ((n-i+1)&1)
			b[st++] = a[i];
		else
			b[ed--] = a[i];
	for (int i = 1;i <= n; i++)
		printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int n;
int a[55];
int main(){
	//freopen("B.in","r",stdin);
	//freopen("B.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]!=i)cnt++;
	}
	if(cnt>2){
		cout<<"NO";
	}else {
		cout<<"YES";
	}
	return 0;
}



Measured memory_bytes: 256
def solve():
    N = int(input())
    Ss = input()
    Q = int(input())
    ks = list(map(int, input().split()))

    anss = []
    for k in ks:
        numD = numM = numDM = numDMC = 0
        for i in range(N):
            S = Ss[i]
            if S == 'D':
                numD += 1
            elif S == 'M':
                numM += 1
                numDM += numD
            elif S == 'C':
                numDMC += numDM

            if i >= k-1:
                S = Ss[i-k+1]
                if S == 'D':
                    numD -= 1
                    numDM -= numM
                elif S == 'M':
                    numM -= 1

        anss.append(numDMC)

    print('\n'.join(map(str, anss)))


solve()


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

map<char, int> m;

int dec (string str) {
	int sum = 0;
	int coef = 1;
	for (char c : str) {
		if (c >= '2' && c <= '9') coef = c - '0';
		else {
			sum += m[c] * coef;
			coef = 1;
		}
	}
	return sum;
}

string enc (int x) {
	string s[] = {"i", "x", "c", "m"};
	string ret = "";
	for (int i = 0; i < 4; i++) {
		int coef = x % 10;
		x /= 10;
		string tmp = "";
		if (coef >= 2) tmp += coef + '0';
		if (coef) tmp += s[i];
		ret = tmp + ret;
	}
	return ret;
}

int main()
{
	int n;
	string a, b;

	m['m'] = 1000;
	m['c'] = 100;
	m['x'] = 10;
	m['i'] = 1;

	cin >> n;
	while (n--) {
		cin >> a >> b;
		cout << enc(dec(a) + dec(b)) << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
s = input()
alpha = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    for ss in s:
        alpha.remove(ss)
    print(s + alpha[0])
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        tmp_pos = [[alpha.index(s[-1]), s[-1]]]
        for i, ss in enumerate(s[::-1], start = 1):
            for pos, tmp in tmp_pos:
                if alpha.index(ss) < pos:
                    print(s[:-i] + tmp)
                    exit()
            tmp = ss
            pos = alpha.index(ss)
            tmp_pos.append([pos, tmp])

Measured memory_bytes: 3064
x = 0

while x == 0:
    a = list(map(int, input().split()))
    if a[0] == 0 and a[1] == 0:
        break
    else:
        if a[0] >= a[1]:
            print(a[1], a[0])
        else:
            print(a[0], a[1])
    
    


Measured memory_bytes: 5608
#include <cstdio>

int main()
{
    int n, i;
    int arr[100];
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf(" %d", &arr[i]);
    }
    for (i = 0; i < n; i++)
    {
        if (i)
            printf(" ");
        printf("%d", arr[n - i - 1]);
    }
    printf("\n");
}


Measured memory_bytes: 2684
n = gets.to_i
a = Array.new(n)
n.times do |i|
  t = gets.to_i - 1
  a[i] = t
end
p = 0
i = 0
while i < n
  i = i + 1
  p = a[p]
  if p == 1
    break
  end
end
if i == n
  puts -1
else
  puts i
end


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

int main() {
    string S;
    cin >> S;
    bool ans = true;

    if (S.size() % 2 == 1) ans = false;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0 && S[i] != 'h')
            ans = false;
        else if (i % 2 == 1 && S[i] != 'i')
            ans = false;
    }
    puts(ans ? "Yes" : "No");
}

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

int main(){
    int m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2-d1 == 1) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main()
{
    KAKA
    vector<ll> v(5);
    ll idx;
    pragi(0,5)
    {
        cin>>v[i];
        if(v[i] == 0)
        {
            idx = i + 1;
            break;
        }
    }
    cout<<idx<<"\n";
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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 factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    int n,m;
    cin >> n >> m;
    pf((1900 * m + 100 * n - 100 * m) * pow(2, m))
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lld long long
#define nmax 20005
#define pii pair<int,int>
#define pb push_back
using namespace std;
int n, t, a[nmax];
priority_queue<pii>pq;
int ans;
int main() {
    cin>>n>>t;
    for (int i=1;i<=t;++i){
        cin>>a[i];
        pq.push(make_pair(a[i],i));
    }
    int lst = -1, ans = 0;
    for (int i=1;i<=n;++i){
        auto act = pq.top();
        pq.pop();
        if (act.second == lst){
            if (pq.empty()){
                ++ans;
                --act.first;
                if (act.first){
                    pq.push(act);
                }
                lst = act.second;
            } else {
                auto act2 = pq.top();
                pq.pop();
                --act2.first;
                if (act2.first){
                    pq.push(act2);
                }
                if (act.first){
                    pq.push(act);
                }
                lst = act2.second;
            }
        } else {
            lst = act.second;
            --act.first;
            if (act.first){
                pq.push(act);
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	vi in(3);
	rep(i,3)cin>>in[i];
	sort(all(in));
	int n;
	cin>>n;
	rep(i,n)in[2]*=2;
	cout<<in[0]+in[1]+in[2]<<endl;
}









Measured memory_bytes: 256
n, *h = $stdin.read.split.map(&:to_i)
dp = Array.new(n, 0)
dp[0] = 0
dp[1] = (h[1] - h[0]).abs
(2..n-1).each { |i| dp[i] = [dp[i-1] + (h[i] - h[i-1]).abs, dp[i-2] + (h[i] - h[i-2]).abs].min } 
puts dp[n-1]


Measured memory_bytes: 12668
import sys
import numpy as np
import itertools
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

# input
K, N = [int(i) for i in readline().split()]
A = list(map(int, readline().split()))

A.append(A[0] + K)
tmp = np.diff(np.array(A))
distance = np.append(tmp, tmp[0:N-2])

#print(distance)

base = np.sum(distance[0:N-1])
ans = min(base, 1000000)
for i in range(N-1):
    #print(base)
    base -= distance[i]
    base += distance[N-1+i]
    ans = min(base, ans)
   
print(ans)


Measured memory_bytes: 42480
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    stack<char> s;
    string str;
    cin >> str;
    int ans = 0;
    REP(i, str.size()) {
    	char c = str[i];
    	if(s.size() && s.top() != c) {
    		s.pop();
    		ans += 2;
    	} else {
    		s.push(c);
    	}
    }
    cout << ans << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)



Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<ll> l(n);
    REP(i, n){
        cin >> l[i];
    }
    ll m = round(pow(2, n * 3));
    ll ans = INF;
    REP(i, m){
        bool use[3][8] = {}, ok = true, flag[8] = {};
        for(ll j = n * 3 - 1; j >= 0; j--){
            if(i & (1 << j)){
                if(flag[j % n]){
                    ok = false;
                    break;
                }
                use[j / n][j % n] = true;
                flag[j % n] = true;
            }
        }
        if(!ok) continue;
        REP(j, 3){
            bool f = false;
            REP(k, n){
                if(use[j][k]) f = true;
            }
            if(!f) ok = false;
        }
        if(!ok) continue;
        ll sum = 0;
        REP(j, 3){
            ll d = 0, cnt = 0;
            REP(k, n){
                if(use[j][k]){
                    d += l[k];
                    cnt++;
                }
            }
            sum += 10 * (cnt - 1);
            if(j == 0) sum += abs(a - d);
            else if(j == 1) sum += abs(b - d);
            else sum += abs(c - d);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


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

Measured memory_bytes: 1776
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>v1,v2;
    int k=9;
    while(k<=100000){
        v1.push_back(k);
        k=k*9;
    }
    k=6;
    while(k<=100000){
        v2.push_back(k);
        k=k*6;
    }
    int res=1e9;
    v1.push_back(1);
    v2.push_back(1);
    sort(v1.rbegin(),v1.rend());

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

    for(int i=0;i<=n;i++){
        int ans=0;
        int a1=i;
        int a2=n-i;
        while(a1>0){
            for(int l=0;l<v2.size();l++){
                if(a1-v2[l]>=0){
                    ans++;
                    a1-=v2[l];
                    break;
                }
            }
        }
        while(a2>0){
            for(int l=0;l<v1.size();l++){
                if(a2-v1[l]>=0){
                    ans++;
                    a2-=v1[l];
                    break;
                }
            }
        }
        res=min(res,ans);
    }
    cout<<res<<endl;
    return 0;
    }

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



int main()
{
     
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    cin>>s;
    int i;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int ans = 1;
		for (int i = 2; i <= x; i++) {
			int temp = i*i;
			for (int j = 2; j <= x; j++) {
			
				if (temp > x) {
					break;
				}
				ans = Math.max(temp, ans);
				temp *= i;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25044
from itertools import combinations 

N = int(input())
L_list = list(map(int, input().split()))
ans = 0

for x, y, z in combinations(L_list, 3):
  #print(x, y, z)
  if x == y or y == z or z == x:
    continue
  if x + y > z and y + z > x and z + x > y:
    ans += 1

print(ans)

Measured memory_bytes: 9176
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 998244353

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int vs;
    cin >> vs;
    vector<int> map(vs+1);
    bool flag = 1;
    for(int i = 0; i < vs; i++) {
        int dist;
        cin >> dist;
        // impossible!
        if(i == 0 && dist != 0) flag = 0;
        if(i != 0 && dist == 0) flag = 0;
        map[dist]++;
    }

    ps(map);
    vector<int> powers(vs+1);
    int cnt = map[0];
    for(int i = 1; i <= vs; i++) {
        int base = map[i-1];
        int power = map[i];
        cnt += power;
        if(power == 0) break;
        powers[base] += power;
    }
    debug("%d\n", cnt);
    // This is not connected
    if(cnt != vs) flag = 0;

    int64_t ans = 1;
    for(int base = 1; base <= vs; base++) {
        debug("%d -> %d -> %ld\n", base, powers[base], ans);
        while(powers[base]--) {
            ans = (ans * base)%DIVISOR;
        }
    }
    cout << (flag ? ans : 0) << endl;
    return 0;
}

Measured memory_bytes: 4052
N, K = map(int, input().split())
d = (N-1)*(N-2)//2 - K
if d < 0:
    print(-1)
    exit()

print(N-1 + d)
for i in range(2, N+1):
    print(1, i)
j = 2
while True:
    for k in range(j+1, N+1):
        if d > 0:
            print(j, k)
            d -= 1
        else:
            break
    if d == 0:
        break
    else:
        j += 1

Measured memory_bytes: 44016
import sys

n, *lst = map(int, sys.stdin.read().split())
lst.sort()
mod = 10 ** 9 + 7
if n % 2:
  for i in range(1, n):
    if lst[i] != (i + 1) // 2 * 2:
      print(0)
      quit()
else:
  for i in range(n):
    if lst[i] != i // 2 * 2 + 1:
      print(0)
      quit()
print((1 << (n >> 1)) % mod)

Measured memory_bytes: 13940
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main(void) {
  long N, M;
  long ans = 0;
  cin >> N >> M;
  vector<long> A;
  for (long i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  unordered_map<long, long> minus;
  minus[0] = 1;
  long sum = 0;
  for (auto current: A) {
    sum = (sum + current) % M;
    if (minus[sum]) ans += minus[sum];
    minus[sum]++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, w;
    cin >> n >> w;
    vector <long long> dp(w + 1, -1e18);
    dp[0] = 0;
    forn (i, 0, n) {
        int weight, cost;
        cin >> weight >> cost;
        for (int j = w; j - weight >= 0; --j)
            chkmax(dp[j], dp[j - weight] + cost);
    }
    cout << *max_element(all(dp));
    return 0;
}

Measured memory_bytes: 1152
import Control.Monad
import Data.List

f rate (flags, free)
  | rate < 3200 = let idx = div rate 400 in (take idx flags ++ [True] ++ drop (idx+1) flags, free)
  | otherwise = (flags, free+1)

calc rs = show minc ++ " " ++ show maxc
  where
    (flags, free) = foldr f (replicate 8 False, 0) rs
    colors = length $ filter id flags
    minc = max colors 1
    maxc = colors + free


main = getLine >> getLine >>= putStrLn . calc . map read . words

Measured memory_bytes: 1020
N = int(input())
XL = [list(map(int, input().split())) for x in range(N)]

XL = sorted(XL, key=lambda x: x[0]+x[1])

cnt = 0
prev_right = -10**9+10
for x, l in XL:
    left = x - l
    right = x + l
    if left >= prev_right:
        cnt += 1
        prev_right = right

print(cnt)


Measured memory_bytes: 32672
N, Q = map(int,input().split())
S = input()
memo = [0 for _ in [0]*(N+1)]
for i in range(2,N+1):
    memo[i] = memo[i-1] + int(S[i-2:i]=="AC")
for _ in range(Q):
    l, r = map(int,input().split())
    print(memo[r]-memo[l])

Measured memory_bytes: 7788
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e9)
using namespace std;
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B;
    ll X[100010];
    cin >> N >> A >> B;
    rep(i,0,N){
        cin >> X[i];
    }
    ll ans = 0;
    rep(i,1,N){
        if((X[i] - X[i-1]) * A >= B){
            ans += B;
        }else{
            ans += A*(X[i] - X[i-1]);
        }
    }
    print(ans);
}


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

int main()
{
    string a;
    cin >> a;
    for(int i =0; i < a.size()-1; i++)
    {
        if(a[i]==a[i+1])
        {
            cout << "Bad" << endl; return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> x(n), y(n), h(n);
    inc(i, 0, n) cin >> x[i] >> y[i] >> h[i];
    inc(cx, 0, 101){
        inc(cy, 0, 101){
            set<int> st;
            int H;
            inc(i, 0, n){
                if(h[i] > 0){
                    H = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
                    st.insert(H);
                }
            }
            if(st.size() == 1){
                bool f = true;
                inc(i, 0, n){
                    if(h[i] != max(H-abs(x[i]-cx)-abs(y[i]-cy), 0)){
                        f = false;
                    }
                }
                if(f){
                    cout << cx << " " << cy << " " << H << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    while True:
        n = int(input())
        player1 = 0
        player2 = 0
        if n == 0:
            break

        for i in range(n):
            str = input().split()
            right = int(str[0])
            left = int(str[1])

            if right > left:
                player1 += right + left
            elif right < left:
                player2 += right + left
            else:
                player1 += right
                player2 += left

        print("{0} {1}".format(player1, player2) )


if __name__=="__main__":
    main()

Measured memory_bytes: 6720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);
#define int long long
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds_;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds;


int binomialCoeff(int n,int r){
    int res=1;
    if(r>n-r)r=n-r;
    for(int i=0;i<r;i++){
        res*=(n-i);
        res/=(i+1);
    }
    return res;
}



int power(int x,int n,int mod){
//(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){

return power(x,mod-2,mod);
}

const int N=2e5+5;
int arr[N];
int32_t main() {

    simplify
    int n;
    cin>>n;
    map<int,int>mp;
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    }
    int b,c,q;
    cin>>q;

    while(q--){
        cin>>b>>c;
        int bb=mp[b];
        int cc=mp[c];
        sum+=(bb)*(c-b);
        cout<<sum<<endl;
        mp[c]+=mp[b];
        mp[b]=0;
    }



    return 0;
}


Measured memory_bytes: 10312
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
#define ll long long

int main(){
    std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
    int n;
    double ans;
    cin>>n;
    ans=n*2*3.14159265359;
    cout<<ans<<endl;
}

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

#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vt vector<string>
#define si set<int>
#define sc set<char>
#define st set<string>
#define pii pair<int,int>
#define fi first
#define se second

using namespace std;
int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    int a[11];
    a[0]=x;
    for(int i=0;i<10;i++)
    a[i+1]=a[i]*r-d;
    for(int i=1;i<=10;i++)
        cout<<a[i]<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
  cin>>n>>k;
  int ans=1;
  for(int i=0;i<n;i++){
   if(ans+k<ans*2)
     ans=ans+k;
    else
      ans=ans*2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc157/tasks/abc157_e
//E - Simple String Queries
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

// fenwick_tree<T> t(n)
// サイズ n，型 T の木を作る
// t.sum(l,r)
// [l, r) の和を求める
// t.sum(r) [0, r) の和
// t.add(i,a)
// 0-indexed で i 番目の要素に a を足す
//
// vector<ll> an={1,2,3,4,5};
// fenwick_tree<ll> tmp(an.size());
// FOR(i,0,an.size()){
//     tmp.add(i,an[i]); //add(0,1),add(1,2),add(2,3)...
// }
// FOR(i,0,an.size()+1){
//     dump(i,tmp.sum(i)); //i=0,sum(i)=0, i=1,sum(i)=1, i=2,sum(i)=3,...,i=5,sum(i)=15
// }
template <class T>
struct fenwick_tree {
    int n;
    std::vector<T> x;
    fenwick_tree(int n_ = 0) : n(n_), x(n + 1, 0) {}
    int size() const { return n; }
    T sum(int r) const {
        T S = 0;
        for (r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
        return S;
    }
    T sum(int l, int r) const { return sum(r) - sum(l); }
    void add(int k, const T &a) {
        for (; k < n; k |= k + 1) x[k] += a;
    }
    void set(int k, const T &a) { add(k, a - sum(k, k + 1)); }
};

int main() {
    ll N; cin>>N;
    string S; cin>>S;
    unordered_map<char,fenwick_tree<ll>> tbl;
    for(char c='a';c<='z';++c){
        tbl[c]=fenwick_tree<ll>(N);        
    }
    FOR(i,0,S.size()){
        tbl[S.at(i)].add(i,1);
    }

    auto irekae = [&](ll p,char c){
        --p;
        auto prev=S.at(p);
        tbl[prev].add(p,-1);
        S.at(p)=c;
        tbl[c].add(p,1);
    };
    auto count = [&](ll s,ll e)->ll{
        ll ret=0;
        --s;
        for(const auto& t:tbl){
            if (t.second.sum(s,N) - t.second.sum(e,N)>0) ++ret;
        }
        return ret;
    };

    ll Q; cin>>Q;
    vector<ll> ans;
    REP(i,Q){
        ll t; cin>>t;
        if(t==1){
            ll p; cin>>p;
            char c; cin>>c;
            irekae(p,c);
        }else if(t==2){
            ll l,r;; cin>>l>>r;
            ans.push_back(count(l,r));
        }else{
            assert(0);
        }
    }
    for(const auto& a:ans){
        cout<<a<<endl;
    }


    return 0;
}

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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
vector<int> G[N], vec[N];
int f[N], g[N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        G[u - 1].emplace_back(v - 1);
        G[v - 1].emplace_back(u - 1);
    }

    return true;
}

void solve() {
    for (int i = 0; i < n; ++i)
        if (G[i].size() % 2 != 0) {
            cout << "No\n";
            return ;
        }

    vector<int> S, path;
    S.emplace_back(0);
    set< pair<int, int> > used;

    for (; !S.empty(); ) {
        auto v = S.back();

        for (const auto& to : G[v])
            if (!used.count(make_pair(min(v, to), max(v, to)))) {
                S.emplace_back(to);
                used.insert(make_pair(min(v, to), max(v, to)));
                break;
            }

        if (v == S.back()) {
            S.pop_back();
            path.emplace_back(v);
        }
    }

    auto len = path.size();
    path.insert(path.end(), path.begin() + 1, path.end());

    for (int i = 0; i < path.size(); ++i)
        vec[path[i]].emplace_back(i);

#ifdef LOCAL
    for (auto i : path) cout << i + 1 << ' ';
    cout << endl;
#endif

    int minr = MOD;
    f[path.size()] = MOD;

    for (int i = path.size() - 1; i >= 0; --i) {
        int v = path[i];

        if (i == vec[v].back()) {
            f[i] = f[i + 1];
            continue;
        }

        auto it = lower_bound(vec[v].begin(), vec[v].end(), minr);

        if (it != vec[v].end())
            f[i] = min(*it, f[i + 1]);
        else
            f[i] = f[i + 1];

        minr = min(minr, *upper_bound(vec[v].begin(), vec[v].end(), i));

        if (i < len && f[i + 1] < i + len) {
            cout << "Yes\n";
            return ;
        }
    }

    g[path.size()] = MOD;

    for (int i = path.size() - 1; i >= 0; --i) {
        int v = path[i];

        if (i == vec[v].back()) {
            f[i] = f[i + 1];
            g[i] = g[i + 1];
            continue;
        }

        int j = *upper_bound(vec[v].begin(), vec[v].end(), i);
        f[i] = min(f[i + 1], g[j]);
        g[i] = min(g[i + 1], j);

        if (i < len && f[i + 1] < i + len) {
            cout << "Yes\n";
            return ;
        }
    }

    cout << "No\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 23280
n = int(input())
a = sorted(set(map(int, input().split())))
while len(a) != 1:
    for i in range(1, len(a)):
        a[i] %= a[0]
    a = sorted(set(a))
    if 0 in a:
        a = a[1:]
print(a[0])


Measured memory_bytes: 20012
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d[] = new int[n];
    int heal = 0;
    for(int i = 0; i < n; i++){
      d[i] = sc.nextInt();
    }
    for(int i = 0; i < n - 1; i++){
      for(int j = i + 1; j < n; j++){
        heal += d[i] * d[j];
      }
    }
    System.out.println(heal);
  }
}

Measured memory_bytes: 23764
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()
r,s,p=n1()
t=s0()

def win(h):
    if h=="r":return p
    elif h=="s": return r
    else: return s

ans=0
t2=[False]*n
for i in range(k):
#     print(t[i],ans)
    ans+=win(t[i])
    t2[i]=True
for i in range(k,n):
#     print(t[i],t2[i-k],ans)
    if t[i-k]!=t[i] or t2[i-k]==False:
        ans+=win(t[i])
        t2[i]=True
        
print(ans)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int x, y;
  cin >> x >> y;
  cout << x + (y/2) << endl;
  return 0;
}

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

template<int MOD_> struct modnum {
    static constexpr int MOD = MOD_;
    static_assert(MOD_ > 0, "MOD must be positive");

private:
    using ll = long long;
    int v;
    static int minv(int a, int m) {
        a %= m;
        assert(a);
        return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
    }

public:
    modnum() : v(0) {}
    modnum(ll v_) : v(int(v_ % MOD)) {
        if (v < 0)
            v += MOD;
    }
    explicit operator int() const { return v; }
    friend ostream& operator<<(ostream& out, const modnum& n) {
        return out << int(n);
    }
    friend istream& operator>>(istream& in, modnum& n) {
        ll v_;
        in >> v_;
        n = modnum(v_);
        return in;
    }

    friend bool operator==(const modnum& a, const modnum& b) { return a.v == b.v; }
    friend bool operator!=(const modnum& a, const modnum& b) { return a.v != b.v; }

    modnum inv() const {
        modnum res;
        res.v = minv(v, MOD);
        return res;
    }
    friend modnum inv(const modnum& m) { return m.inv(); }
    modnum neg() const {
        modnum res;
        res.v = v ? MOD - v : 0;
        return res;
    }
    friend modnum neg(const modnum& m) { return m.neg(); }

    modnum operator-() const { return neg(); }
    modnum operator+() const { return modnum(*this); }
    modnum& operator++() {
        v++;
        if (v == MOD) v = 0;
        return *this;
    }
    modnum& operator--() {
        if (v == 0) v = MOD;
        v--;
        return *this;
    }
    modnum& operator+=(const modnum& o) {
        v += o.v;
        if (v >= MOD) v -= MOD;
        return *this;
    }
    modnum& operator-=(const modnum& o) {
        v -= o.v;
        if (v < 0) v += MOD;
        return *this;
    }
    modnum& operator*=(const modnum& o) { v = int(ll(v) * ll(o.v) % MOD); return *this; }
    modnum& operator/=(const modnum& o) { return *this *= o.inv(); }

    friend modnum operator++(modnum& a, int) { modnum r = a; ++a; return r; }
    friend modnum operator--(modnum& a, int) { modnum r = a; --a; return r; }
    friend modnum operator+(const modnum& a, const modnum& b) { return modnum(a) += b; }
    friend modnum operator-(const modnum& a, const modnum& b) { return modnum(a) -= b; }
    friend modnum operator*(const modnum& a, const modnum& b) { return modnum(a) *= b; }
    friend modnum operator/(const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using mint = modnum<int(1e9) + 7>;
vector<vector<int>> adj;
array<mint, 2> dfs(int u, int p) {
    array<mint, 2> res{1, 1}; // {black, white}
    for (int v : adj[u]) {
        if (v != p) {
            auto arr = dfs(v, u);
            res[0] *= arr[1]; // w -> b
            res[1] *= arr[0] + arr[1]; // b -> w + w -> w
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    adj.resize(n + 1);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    auto ans = dfs(1, -1);
    cout << ans[0] + ans[1] << '\n';
    return 0;
}

Measured memory_bytes: 15468
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,K ,B;
  cin >> K >> A >>B;
  for(int i=A;i<=B;i++){
    if(i%K==0){
      cout << "OK" << endl;
      return 0;
    }else if(i==B) {
      cout << "NG" << endl;
      return 0;
    }
  }
}

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

int main(){
  int N;cin>>N;
  vector<int> a(N);
  int sum=0;

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

  int mini=sum;
  int prefix_sum=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    prefix_sum+=a[i];
    mini=min(mini,abs(prefix_sum-(sum-prefix_sum)));
  }

  cout<<mini<<endl;
  return 0;
}


Measured memory_bytes: 3648
n = int(input())
H = list(map(int, input().split()))
inf = float('inf')
dp = [inf] * n
dp[0] = 0
for i in range(n - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
    if i + 2 < n:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))
print(dp[-1])

Measured memory_bytes: 13980
#include <unistd.h>
#include <cstdio>
#include <x86intrin.h>

typedef long long ll;
int mat[3000][3000]; 
ll dp0[3000] __attribute((aligned(32)));

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx512vl"))), apply_to=function)
int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    __m256i mask0 = _mm256_set_epi64x(0, 0, 0, -1); 
    __m256i mask1 = _mm256_set_epi64x(-1, -1, -1, 0); 
    for (int y = 0; y < rr; y++) {
        __m256i work = _mm256_setzero_si256();
        //ymm[0] = ymm[1] = ymm[2] = ymm[3] = 0;
        for (int x = 0; x < cc; x++) {
            __m256i tmp = _mm256_maskz_set1_epi64(1, dp0[x]);
            work = _mm256_max_epi64(work, tmp);
            //ymm[0] = std::max(ymm[0], dp0[x]);
            //int v = mat[y][x];
            __m256i v = _mm256_maskz_set1_epi64(14, mat[y][x]);
//            v = _mm256_andnot_si256(mask0, v);
            __m256i s = _mm256_permutex_epi64(work, (2 << 6) + (1 << 4));
            s = _mm256_add_epi64(s, v);
            work  = _mm256_max_epi64(work, s);
            __m256i s2 = _mm256_permutex_epi64(work, (1 << 6) + (0 << 4) + (3 << 2) + (2 << 0));
            __m256i s3 = _mm256_max_epi64(work, s2);
            __m256i s4 = _mm256_permutex_epi64(s3, 5);
            __m256i s5 = _mm256_max_epi64(s3, s4);

//            for (int c = 3; c > 0; c--) {
//                ymm[c] = std::max(ymm[c], ymm[c - 1] + v);
//            }
//            dp0[x] = std::max(std::max(ymm[0], ymm[1]), std::max(ymm[2], ymm[3]));
            _mm256_mask_store_epi64(&dp0[x], 1, s5);
        }
    }
    std::printf("%lld\n", dp0[cc - 1]);
    return 0;
}
#pragma clang attribute pop

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

int main(){
  int n;
  vector<int> v;

  cin >> n;

  for (int i = 0; i < 3*n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }

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

  long long ans = 0;
  int cnt = 0;
  int i = 0;
  while (cnt < n) {
    if (i % 2 != 0) {
      ans += v[i];
      cnt++;
    }
    i++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h> 
using namespace std; 
int mod = 1000000007;
class unionfind{
    public:
    vector <int> p,rank;
    void initialize(int n){
        p.assign(n,0);
        rank.assign(n,1);
        for(int i=0;i<n;i++)p[i]=i;
    }
    int find(int u){
        if(p[u]==u)return u;
        return p[u]=find(p[u]);
    }
    void merge(int u,int v){
        u=find(u);
        v=find(v);
        if(u==v)return;
        if(rank[u]<rank[v])swap(u,v);
        rank[u]+=rank[v];
        p[v]=u;
    }
};

int main() 
{ 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        int n,m;cin>>n>>m;
        unionfind dsu;
        dsu.initialize(n+1);
        for(int i=0;i<m;i++){
            int u,v;cin>>u>>v;
            dsu.merge(u,v);
        }
        int cnt[n+1];memset(cnt,0,sizeof cnt);
        for(int i=1;i<=n;i++)cnt[dsu.find(i)]++;
        cout<<*max_element(cnt,cnt+n+1)<<"\n";
    }
    return 0; 
} 

Measured memory_bytes: 5460
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

double dp[3010][3010];

int main()
{
    int n; cin >> n;
    double p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= i; j++){
            dp[i+1][j+1] += (dp[i][j] * p[i]);
            dp[i+1][j]   += (dp[i][j] * (1-p[i]));
        }
    }
    double ans = 0;
    for(int i = (n+1)/2; i <= n; i++){
        ans += dp[n][i];
    }
    printf("%.10lf",ans);
}


Measured memory_bytes: 69120
#include<iostream>
using namespace std;
int main(void){
    int n;
    long long a;
    long long minValue = 1000000;
    long long maxValue = -1000000;
    long long sum = 0;
     cin >> n;
     
     for(int i=0; i<n; i++){
         cin >> a;
         if( a < minValue) minValue = a;
         if( a > maxValue) maxValue = a;
         sum += a;
     }
     
     cout << minValue << " " << maxValue << " " << sum << endl;
     return 0;
}



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

int main(){
    int n;
    cin >>n;
    n %= 10;
    if(n==3){
        cout << "bon" <<endl;
    }else if(n==0 || n==1 || n==6 || n==8){
        cout << "pon" <<endl;
    }else
    {
        cout << "hon" <<endl;
    }
    
    
    return 0;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int Sx = scan.nextInt();
        int Sy = scan.nextInt();
        int Tx = scan.nextInt();
        int Ty = scan.nextInt();
        int a = Tx-Sx;
        int b = Ty-Sy;
       R(a);
       U(b);
       L(a);
       D(b+1);
       R(a+1);
       U(b+1);
       L(1);
       U(1);
       L(a+1);
       D(b+1);
       R(1);
	}
	public static void R(int i){
		for(int n=0;n<i;n++){
		System.out.print('R');
		}
	}
	public static void L(int i){
			for(int n=0;n<i;n++){
			System.out.print('L');
			}
	}
	public static void D(int i){
		for(int n=0;n<i;n++){
		System.out.print('D');
		}
}
	public static void U(int i){
		for(int n=0;n<i;n++){
		System.out.print('U');
		}
}
	
}

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

int main(){
char a;
  cin >>a;
if(a=='S') cout <<"Cloudy";
  else if(a=='C') cout <<"Rainy";
    else cout <<"Sunny";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  double r;
  cin >> r;
  pd(2*r*3.14159265358979);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3808