akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7,mod=1e9+7;
int n,m,ans,a[25],fac[N],inv[N],f[22][N];
int C(int a,int b){return 1ll*fac[a]*inv[b]%mod*inv[a-b]%mod;}
void add(int&x,long long y){x=(x+y)%mod;}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)cin>>a[i];
	sort(a+1,a+m+1);
	fac[0]=1;for(int i=1;i<N;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;for(int i=2;i<N;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<N;i++)inv[i]=1ll*inv[i-1]*inv[i]%mod;
	f[m][0]=1;
	for(int i=m;i;i--)
	for(int S=0;S<(1<<n);S++)
	if(f[i][S])
	{
		add(f[i-1][S],f[i][S]);
		for(int j=0;j<n;j++)
		if(!(S&(1<<j)))add(f[i-1][S|(1<<j)],(mod-1ll*f[i][S]*C((1<<n)-a[i]-S,(1<<j)-1)%mod)*fac[1<<j]);
	}
	for(int S=0;S<(1<<n);S++)add(ans,1ll*f[0][S]*fac[(1<<n)-1-S]);
	ans=1ll*ans*(1<<n)%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 8576
#include <stdio.h>
#include <algorithm>
#include <deque>
#include <math.h>

using namespace std;

typedef long long ll;

#define N 110000

ll a[N];

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
        sort(a, a + n);
        if (n == 1 || n == 0) puts("0");
        if (n == 2) printf("%lld\n", a[1] - a[0]);
        else {
            int i = 0, j = n - 1;
            deque<ll> q;
            q.push_back(a[j--]);
            q.push_back(a[i++]);
            while (i <= j) {
                ll f = q.front(); ll b = q.back();
                if (i == j) {
                    if (abs(f - a[i]) > abs(b - a[i])) {
                        q.push_front(a[i++]); break;
                    } else {
                        q.push_back(a[j--]); break;
                    }
                }
                if (abs(f - a[i]) + abs(b - a[j]) > abs(f - a[j]) + abs(b - a[i])) {
                    //printf("1  %lld %lld\n", a[i], a[j]);
                    q.push_front(a[i++]); q.push_back(a[j--]);
                } else {
                    //printf("2  %lld %lld\n", a[i], a[j]);
                    q.push_front(a[j--]); q.push_back(a[i++]);
                }
            }
            ll res = 0;
            ll x = q.front(); q.pop_front(); //printf("%lld\n", x);
            while (!q.empty()) {
                ll y = q.front(); q.pop_front();
                //printf("%lld\n", y);
                res += abs(x - y);
                x = y;
            }
            printf("%lld\n", res);
        }
    }
    return 0;
}

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

int main()
{
    int n;
    scanf("%d",&n);
    if(n%10==3) printf("bon");
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8) printf("pon");
    else printf("hon");
    return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    vector<lint> v(3);
    bool flag = false;
    rep(i, 3){
        cin >> v[i];
        flag |= (v[i] % 2LL == 0LL);
    }

    if(flag){
        cout << 0 << endl;
    }else{
        SORT(v);
        cout << v[0] * v[1] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int a[10009], b[10009];

int main() {
    int n;
    scanf("%d", &n);

    long long suma = 0, sumb = 0, sum1 = 0, cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        suma += a[i];
    }

    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]);
        sumb += b[i];
        if (a[i] > b[i])
            cnt1 += a[i] - b[i];
        else if ((b[i] - a[i]) % 2 == 0)
            cnt2 += (b[i] - a[i]) / 2;
        else
            cnt2 += (b[i] - a[i] + 1) / 2, cnt1++;
    }

    if (cnt1 <= sumb - suma && cnt2 <= sumb - suma && 2 * (sumb - suma - cnt2) == sumb - suma - cnt1)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){

	char w[11]={},t[1001]={};
	int cnt=0,i,wlen,tlen;
	scanf("%s",w);
	wlen=strlen(w);
	for(i=0;i<wlen;i++){
		w[i]=tolower(w[i]);
	}	
	while(1){
		scanf("%s",t);
		tlen=strlen(t);
		if(strcmp(t,"END_OF_TEXT")==0)	break;
		for(i=0;i<tlen;i++){
			t[i]=tolower(t[i]);
		}
		if(strcmp(w,t)==0)	cnt++;
	}	
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int x;
    cin >> x;
    cout << !x << endl;

    return 0;
}

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

a = sorted(a)
zero_monster_indexes = []

while True:
    for monster_i in range(1, len(a)):
        if a[monster_i] == 0:
            zero_monster_indexes.append(monster_i)
        else:
            a[monster_i] %= a[0]

            if a[monster_i] == 0:
                zero_monster_indexes.append(monster_i)

    for zero_monster_index in reversed(zero_monster_indexes):
        a.pop(zero_monster_index)
    zero_monster_indexes.clear()

    a = sorted(a)
    if len(a) == 1:
        break

print(a[0])


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

int main()
{
    
    int N, M, tmp, b, c,j;
    ll total=0;
    cin >> N >> M;
    vector<P> data(N+M);
    for (int i = 0; i < N; i++)
    {
        cin >>data[i].first;
        data[i].second = 1;
    }
    for (int i = 0; i < M; i++)
    {
        cin >> data[i+N].second >> data[i+N].first;
    }
    sort(data.begin(),data.end(),greater<P>());
    j=N;
    for(int i=0;i<j;i++){
        if(N>data[i].second){
            total+=data[i].second * data[i].first;
            N-=data[i].second;
        }
        else{
            total+= N * data[i].first;
            break;
        }
    }
    cout << total;
    return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

int main()
{
  const int pow2[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
  
  char buf[64];
  buf[63]=0;
  buf[62]='\n';
  int i, j, k, m, n, o, v;
  fgets(buf, 64, stdin);
  n = buf[2]=='\n' ? (buf[0]-'0')*10+buf[1]-'0' : buf[0]-'0';
  fgets(buf, 64, stdin);
  if (buf[0]=='0') {
    fputs("0:\n",stdout);
    return 0;
  }

  char *p;
  if (buf[2]==' ') {
    k = (buf[0]-'0')*10+buf[1]-'0';
    p = buf+3;
  } else {
    k = buf[0]-'0';
    p = buf+2;
  }
  int b[28], d[28];
  b[0] = 0;  
  for (i=0; *p!='\n'; p++) {
    if (*p == ' ')
      b[++i] = *(++p)-'0';
    else
      b[i] = b[i] * 10 + *p - '0';
  }

  for (i=0;i<k;i++)    d[i]=pow2[b[i]];
  m = pow2[k];
  for (i=0; i<m; i++) {
    v = 0;
    o = 61;
    for (j=k; j>=0; j--) {
      if (i & pow2[j]) {
	v += d[j];
	int ov=b[j];
	if (ov==0) {
	  buf[o--]='0';
	}
	for (; ov>0; o--, ov/=10)   buf[o] = '0' + (ov%10);
	buf[o--]=' ';
      }
    }
    buf[o--] = ':';
    if (v==0)     buf[o--]='0';
    else {
      for (; v>0; o--, v/=10)
	buf[o] = '0' + (v%10);
    }
    fputs(buf+o+1, stdout);
  }

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

bool solve() {
    ll a, b, c;
    std::cin >> a >> b >> c;
    ll l = a + b;
    ll r = c;
    if (r < l) return false;
    ll ok = 0, ng = 1e9 + 10;
    while (std::abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        (mid * mid <= 4 * a * b ? ok : ng) = mid;
    }
    return a + b + ok < c;
}

int main() {
    std::cout << (solve() ? "Yes" : "No") << '\n';
    return 0;
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    string ans = "Yes";
    for (int i = N - 2; i >= 0; i--) {
        if (H[i] > H[i + 1]) H[i]--;
        if (H[i] > H[i + 1]) ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import math
X = int(input())

#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

while 1:
    if is_prime(X):
        print(X)
        break
    else:
        X += 1


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

int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>> roads(M,vector<int>(2));
    for (int i=0; i<M; i++) {
        for (int j=0; j<2; j++) {
            cin >> roads.at(i).at(j);
        }
    }

    vector<int> answer(N);

    for (int i=0; i<N; i++) {
        for (int j=0; j<M; j++) {
        for (int k=0; k<2; k++) {
            if (roads.at(j).at(k)-1==i) {
                answer.at(i)++;
            }
        }
    }
    }

    for (int i=0; i<N; i++) {
        cout << answer.at(i) << endl;
    }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 200 + 50;
int n;
ll p[maxn];
ll x[maxn], y[maxn];
map<pair<ll, ll>, ll> mp;
void pre(){
    p[0] = 1;
    for(int i = 1; i < maxn; i++){
        p[i] = (p[i-1] * 2) % mod;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    pre();
    while(cin >> n){
        for(int i = 0; i < n; i++)
            cin >> x[i] >> y[i];
        ll ans = p[n] - n - 1;//减去空集和单点集
        ll deltay, deltax, k;
        for(int i = 0; i < n; i++){
            mp.clear();
            for(int j = i+1; j < n; j++){
                deltay = y[j] - y[i];
                deltax = x[j] - x[i];
                k = __gcd(deltay, deltax);
                deltay/=k;
                deltax/=k;
                ++mp[{deltay,deltax}];
                //mp记录共线的点，用pair是防止斜率为0，或者为小数
            }
            for(map<pair<ll, ll>, ll>::iterator iter = mp.begin(); iter != mp.end(); iter++){
                ll tmp = p[iter->second] - 1;//除i点以外共线集的个数，减去只有一个i点的情况
                ans = (ans - tmp + mod) % mod;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    int a, b;
    cin >> a >> b;
    if(a>b)
    {
        for(int i=0; i<a; i++)
        {
            cout << b;
        }
        cout << endl;
    }
    else
    {
        for(int i=0; i<b; i++)
        {
            cout << a;
        }
        cout << endl;
    }
    return 0;
}


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

signed main() {
    int n, k, c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    vi l(k), r(k);

    int d = 0;
    rep(i, k) {
        while(true) {
            if(s[d] == 'x') d++;
            else {
                l[i] = d;
                d += c+1;
                break;
            }
        }
    }
    d = n - 1;
    for(int i=k-1; i>=0; i--) {
        while(true) {
            if(s[d] == 'x') d--;
            else {
                r[i] = d;
                d -= c+1;
                break;
            }
        }
    }
    rep(i,k) {
        if(l[i]==r[i]) {
            cout << l[i]+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3332
#include <stdio.h>
 
int search(int k, int *a, int n){
  int l=0,r=n,m;
  while(l<r){
    m=(l+r)/2;
    if(a[m]<k) r=m;
    else l=m+1; 
  }
  return l;
}
 
int main(){
  int n;scanf("%d",&n);
  int g[n],c=0,a,j;
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    j = search(a,g,c);
    g[ j<c? j: c++ ] = a;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

int main() {
    long long N;
    cin >> N;
    vector<long long> t(5);
    for(int i = 0; i < 5; i++){
        cin >> t[i];
    }
    sort(t.begin(),t.end());
    long long count = N / t[0];
    if(N % t[0] != 0){
        count++;
    }
    cout << count + 4 << endl;

}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int f[(int) 1e6];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k, cnt = 1, mod;
  cin >> k;
  mod = 7 % k;
  while (mod > 0) {
    cnt++;
    f[mod] = 1;
    mod = (mod * 10 + 7) % k;
    if (f[mod]) {
      cout << "-1\n";
      return 0;
    }
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 7504
#include<bits/stdc++.h>
using namespace std;
int n;
int x[10],y[10];
double dis(int i,int j){
    double xx=x[i]-x[j];
    double yy=y[i]-y[j];
  return sqrt(xx*xx+yy*yy);
}
void solve(){
  int n1=1;
  cin >> n;
  for(int i=1;i<=n;i++)cin >> x[i] >> y[i];
  long double sum=0.0;
  vector<int> v(n);
  for(int i=0;i<n;i++)v[i]=i+1;
  for(int i=1;i<=n;i++)n1*=i;
  do{
    for(int i=0;i<n-1;i++)sum+=dis(v[i],v[i+1]);
  }while(next_permutation(v.begin(),v.end()));
  cout << fixed << setprecision(10) << (double)sum/n1 << endl;
  return;
}
int main(){
  solve();
}
  

Measured memory_bytes: 3788
'use strict';
function main(input) {
  const a = input.trim().split('\n')[0].split(' ')[0];
  const b = input.trim().split('\n')[1].split(' ').map(x => Number(x));
  let sum = 0;
  
  for (let i = 0; i < b.length; i ++) {
    sum += b[i];
  }

  if (a < sum) {
    console.log(-1);
  } else {
    console.log(a - sum);
  }

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30604
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,k;
vi a;

int loss(int p, int n){
    return p < -n ? p : -n;
}
signed main(){
    I(n); I(k);
    a.resize(n+1);
    REP(i,n) I(a[i]);

    int mask = 1e+15;
    int maskl = -1;
    int maskblack = 0;
    int shakup = 0;
    int shakun = 0;
    
    REP(i,k) (a[i] > 0 ? shakup : shakun) += a[i];
    REP(i,n-k){
        if(mask > loss(shakup, shakun)){
            mask = loss(shakup, shakun);
            maskl = i;
            maskblack = (shakup + shakun >= 0);
        }
        (a[i] > 0 ? shakup : shakun) -= a[i];
        (a[i+k] > 0 ? shakup : shakun) += a[i+k];
        
    // cerr << loss(shakup, shakun) << endl;
    }
        if(mask > loss(shakup, shakun)){
            mask = loss(shakup, shakun);
            maskl = n-k;
            maskblack = (shakup + shakun >= 0);
            
        }
    int ret = 0;
    REP(i,n){
        if (maskl <= i && i < maskl + k){
            ret += a[i] * maskblack;
        } else {
            ret += max(0LL,a[i]);
        }
    }
    cout << ret << endl;
    

    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
long long gcd(long x,long y){
    if(y==0)return x;

    return gcd(y,x%y);
}
long long lcm(long x,long y){
    return x*y/gcd(x,y);
}

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

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

    for(int i=0;i<S.length()-1;i++){
        if(S[i]=='A'&&S[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}

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

#define FOR(i,s,t) for(int i = s; i < t; i++)
using VI = vector<int>;


int main(void) {
	int N;
	cin >> N;
	vector<int>a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	VI m(N + 1, 1e9);
	queue<int>q;
	q.push(0);
	m[0] = 0;
	while (!q.empty()) {
		int pos = q.front(); q.pop();
		if (a[pos] == 0) {
			FOR(k, 1, 6 + 1) {
				int nx = min(N - 1, pos + k);
				if (m[nx] > m[pos] + 1) {
					m[nx] = m[pos] + 1;
					q.push(nx);
				}
			}
		}
		else {
			int nx = pos + a[pos];
			if (m[nx] > m[pos]) {
				m[nx] = m[pos];
				q.push(nx);
			}
		}
	}



	cout << m[N - 1] << endl;


	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int a, b, q;
    cin >> a >> b >> q;
    vector<LL> s(a), t(b), x(q);
    REP(i, a) cin >> s[i];
    REP(i, b) cin >> t[i];
    REP(i, q) cin >> x[i];

    REP(i, q){
        int sindex1 = lower_bound(all(s), x[i]) - s.begin();
        int sindex2 = sindex1 - 1;
        int tindex1 = lower_bound(all(t), x[i]) - t.begin();
        int tindex2 = tindex1 - 1;

        LL ans = INFL;
        if(sindex1 < s.size() && tindex1 < t.size()){
            ans = min(ans, max(s[sindex1], t[tindex1]) - x[i]);
        }
        if(sindex2 >= 0 && tindex2 >= 0){
            ans = min(ans, x[i] - min(s[sindex2], t[tindex2]));
        }
        if(sindex1 < s.size() && tindex2 >= 0){
            LL dis1 = abs(x[i] - s[sindex1]);
            LL dis2 = abs(x[i] - t[tindex2]);
            ans = min(ans, max(dis1, dis2) + min(dis1, dis2) * 2);
        }
        if(sindex2 >= 0 && tindex1 < t.size()){
            LL dis1 = abs(x[i] - s[sindex2]);
            LL dis2 = abs(x[i] - t[tindex1]);
            ans = min(ans, max(dis1, dis2) + min(dis1, dis2) * 2);
        }

        cout << ans << endl;
    }
}

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


int  main()
{
    long long  n,i,a=0,j;
    string str,s="ABC";
    cin>>n>>str;
    for(i=0;i<str.size();)
    {
       for(j=0;j<s.size();j++)
       {
          if(s[j]!=str[i])
            break;
         else
            i++;
       }
       if(j==s.size())
         a++;
      if(str[i]!='A')
         i++;
    }

    cout<<a<<endl;

    return 0;
}


Measured memory_bytes: 256
N, Q = (int(i) for i in input().split())
S = input()

counts = 0
totals = [0]
for i in range(1, N):
  if S[i-1] == 'A' and S[i] == 'C':
    counts += 1
  totals.append(counts)

L = []
R = []
for i in range(Q):
    L, R = (int(i) for i in input().split())
    print(totals[R-1] - totals[L-1])

Measured memory_bytes: 6100
class Array
  def cumsum; s = 0; map{|k| s += k } end
end

n, m = gets.to_s.split.map{|t|t.to_i}
a = Array.new(n){ gets.to_s.to_i }

if n == 1
  puts 1
  exit
end

broken = Array.new(n+1){false}
stairs = Array.new(n+1){ 0 }
stairs[0] = stairs[1] = 1

a.each do |k|
  broken[k] = true
end

stairs[1] = 0 if broken[1]

2.upto(n) do |i|
  next if broken[i]
  stairs[i] = stairs[i-1] + stairs[i-2]
end

puts stairs[-1] % (10**9+7)

Measured memory_bytes: 434556
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn eat(level: usize, x: usize, data: &Vec<(usize, usize)>) -> (usize, usize) {
    if data[level].0 <= x {
        return data[level];
    }
    let mut t = 0;
    let mut p = 0;
    if x == t {
        return (t, p);
    }
    t += 1;
    let r1 = eat(level - 1, x - t, data);
    t += r1.0;
    p += r1.1;
    if x == t {
        return (t, p);
    }
    t += 1;
    p += 1;
    if x == t {
        return (t, p);
    }
    let r2 = eat(level - 1, x - t, data);
    t += r2.0;
    p += r2.1;
    if x == t {
        return (t, p);
    }
    t += 1;
    (t, p)
}

fn main() {
    input! {
        n: usize,
        x: usize,
    }

    let mut data = vec![];

    data.push((1, 1));
    for i in 1..n + 1 {
        let next = (data[i - 1].0 * 2 + 3, data[i - 1].1 * 2 + 1);
        data.push(next);
    }
    println!("{}", eat(n, x, &data).1);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int n,r;
vector<long long> v;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        long long x;
        cin>>x,v.push_back(x);
    }
    sort(v.begin(),v.end());
    for(int i=n-1;i>=0;i--)
        for(int j=i-1;j>=0;j--)
    {
        auto k=lower_bound(v.begin(),v.end(),v[i]+v[j]);
        long long l=distance(k,v.end());
        r+=n-1-i-l;
    }
    cout<<r;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,x;
  cin>>n>>x;
  vector<Int> ls(n);
  for(Int i=0;i<n;i++) cin>>ls[i];
  Int ans=1,pos=0;
  for(Int i=0;i<n;i++){
    pos+=ls[i];
    if(pos<=x) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

class UnionFind {
public:
  vector<int> par, rank;
  // if par is negative, it is a root, of which tree size is the abs-value.
  // rank represents depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;
    if(rank[x] < rank[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    if(rank[x]==rank[y]) rank[x]++;
  }
  inline bool same(int x, int y){ return find(x) == find(y); }
  inline int size(int x){ return -par[find(x)]; }
};

vector<long> val;
vector<int> tree[200005];

long ans[100005];

void dfs(int v, long p_val){
  p_val += val[v];
  if(tree[v].size()==0) ans[v] = p_val;
  for(auto to : tree[v]) dfs(to, p_val);
}

int main(){
  int n;
  cin>>n;
  vector<pair<int,pair<int,int>>> g;
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    g.pb(mp(c,mp(a,b)));
  }

  sort(all(g));
  reverse(all(g));

  UnionFind uf(n);

  vector<int> pnode(n,0);
  rep(i,n) pnode[i] = i;
  int nodes = n;

  val.resize(n,0);

  for(auto &pp : g){
    int a = pp.se.fi;
    int b = pp.se.se;
    long c = pp.fi;
    if(uf.same(a,b)) continue;
    int pa = pnode[uf.find(a)];
    int pb = pnode[uf.find(b)];
    tree[nodes].pb(pa);
    tree[nodes].pb(pb);
    val[pa] += uf.size(b) * c;
    val[pb] += uf.size(a) * c;

    uf.unite(a,b);
    pnode[uf.find(a)] = nodes;
    nodes++;
    val.pb(0);
  }

  dfs(nodes-1, 0);

  rep(i,n) cout << ans[i] << "\n";

  return 0;
}


Measured memory_bytes: 17380
import math

cou = 0
n = int(input())
A = [int(input()) for i in range(n)]

for i in range(n):
    a_sq = int(math.sqrt(A[i]))
    for j in range(2,a_sq+2):
        if(A[i]%j==0 and not(A[i]==j)):
            break
        if(j==a_sq+1):
            cou += 1

print(cou)



Measured memory_bytes: 6016
def solve(n,left,right):
    if n==10:
        return 1
    if a[n]>left:
        return solve(n+1,a[n],right)
    if a[n]>right:
        return solve(n+1,left,a[n])
    return 0

n=int(input())
for _ in range(n):
    a=[int(i) for i in input().split()]
    print("YES" if solve(0,0,0) else "NO")

Measured memory_bytes: 7660
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;


main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,ans=0;
	cin>>n;
	vector<ll> a(n),f(1e6+1),dp(1e6+1);
	for(ll i=0;i<n;i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	for(ll i=0;i<n;i++)
	{
		f[a[i]]++;
		dp[a[i]]=1;
		if(f[a[i]]>=2)
			dp[a[i]]=0;
		for(ll j=1;j*j<=a[i];j++)
		{
			if(j==1)
			{
				if(f[1] && a[i]!=1)
					dp[a[i]]=0;
			}
			else if(a[i]%j==0)
			{
				if(f[a[i]/j]||f[j])
					dp[a[i]]=0;
			}
		}
		
	}
	ll cnt=0;
	for(ll i=1;i<=1e6;i++)
	{
		if(dp[i])
			cnt++;
	}
	cout<<cnt;


	


		

	
	
	

	
	
	
	
	
	

	
	
	

}

Measured memory_bytes: 20360
number_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
out = number_list[k-1]
print(out)

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

class Program
{
    static void Main(string[] args)
    {
        var S = sc.ReadStr();
        S = new string(S.Reverse().ToArray());
        var dream = new string("dream".Reverse().ToArray());
        var dreamer = new string("dreamer".Reverse().ToArray());
        var erase = new string("erase".Reverse().ToArray());
        var eraser = new string("eraser".Reverse().ToArray());

        var ok = true;
        for (int i = 0; i < S.Length; i++)
        {
            if (i + 5 - 1 < S.Length && S.Substring(i, 5) == dream) i += 4;
            else if (i + 7 - 1 < S.Length && S.Substring(i, 7) == dreamer) i += 6;
            else if (i + 5 - 1 < S.Length && S.Substring(i, 5) == erase) i += 4;
            else if (i + 6 - 1 < S.Length && S.Substring(i, 6) == eraser) i += 5;
            else
            {
                ok = false;
                break;
            }
        }
        Console.WriteLine(ok ? "YES" : "NO");
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 15328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define int long long
#define N 400002
using namespace std;
struct edge{
	int u,v,w;
}e[N];
int n,q,i,f[N],num,fa[N];
int read()
{
	char c=getchar();
	int w=0;
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0'){
		w=w*10+c-'0';
		c=getchar();
	}
	return w;
}
int my_comp(const edge &x,const edge &y)
{
	return x.w<y.w;
}
int find(int x)
{
	if(x!=fa[x]) fa[x]=find(fa[x]);
	return fa[x];
}
int Kruscal()
{
	for(int i=1;i<=n;i++) fa[i]=i;
	sort(e+1,e+num+1,my_comp);
	int cnt=n,ans=0;
	for(int i=1;i<=num;i++){
		int f1=find(e[i].u),f2=find(e[i].v);
		if(f1!=f2){
			fa[f1]=f2;
			cnt--;
			ans+=e[i].w;
		}
	}
	return ans;
}
signed main()
{
	memset(f,0x3f,sizeof(f));
	n=read();q=read();
	for(i=1;i<=q;i++){
		int a,b,c;
		a=read()+1;b=read()+1;c=read();
		e[++num]=(edge){a,b,c};
		f[a]=min(f[a],c+1);
		f[b]=min(f[b],c+2);
	}
	bool flag=0;
	for(i=1;i<=n;i++){
		f[i%n+1]=min(f[i]+2,f[i%n+1]);
		if(i==n&&!flag) i=0,flag=1;
	}
	for(i=1;i<=n;i++) e[++num]=(edge){i,i%n+1,f[i]};
	cout<<Kruscal()<<endl;
	return 0;
}


Measured memory_bytes: 18560
#include <iostream>

using namespace std;


int main(void)
{
  int A,B;
  cin >> A >> B;
  
  if(A>B){
    int tmp = B;
    B = A;
    A = tmp;
  }

  for(int i = 0; i<B; i++)
  {
    cout << A;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std;

double h[1100];
double b[1100];

double _minus(double x, double y)
{
	if (x > y)
		return x - y;
	else if (y > x)
		return y - x;
	else if (x == y)
		return x - y;
}

int main()
{
	double n, t, a;
	cin >> n >> t >> a;
	
	for (int i = 1; i <= n; i++)
	{
		cin >> h[i];
		b[i] = t - (h[i] * 0.006);
	}
	double ch = _minus(a, b[1]);
	int fin = 1;
	for (int i = 2; i <= n; i++)
	{
		if (_minus(a, b[i]) < ch)
		{
			ch = _minus(a, b[i]);
			fin = i;
		}
	}

	printf("%d", fin);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,r;
	cin >> n >> r;
	if(n>=10) cout << r << endl;
	else{
		n=100*(10-n);
		cout << r+n << endl;
	}
	return 0;
}


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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define ii pair<int, int>

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

int n, m;
int a[N], b[N], bit[N];
vector<ii> tmp;
vector<int> com;

void add(int &x, int y) { x = (x + y + 1ll * MOD * MOD) % MOD; } // :D
void upd(int pos, int val){
    for(int i = pos; i <= N - 1; i += (i & -i))
        add(bit[i], val);
}
int getm(int pos) { int res = 0; for(int i = pos; i >= 1; i -= (i & -i)) add(res, bit[i]); return res; }
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, m) cin >> b[i];
    sort(a + 1, a + n + 1);
    sort(b + 1, b + m + 1);
    FOR(i, 1, n)    {
        int x = 0, y = 0;
        if(a[i] <= b[1] || a[i] >= b[m]) continue;
        x = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
        y = lower_bound(b + 1, b + m + 1, a[i]) - b;
        x = a[i] - b[x];
        y = b[y] - a[i];
        //cout << x << ' ' << y << '\n';
        tmp.pb(ii(x, y));
        com.pb(y);
    }
    com.pb(0);
    unique(com.begin(), com.end());
    sort(com.begin(), com.end());
    sort(tmp.begin(), tmp.end());
    //for(int v: com) cout << v << ' '; cout << '\n';
    upd(1, 1);
    for(int i = 0; i < tmp.size(); ++i) {
        if(i > 0 && tmp[i] == tmp[i - 1]) continue;
        ii v = tmp[i];
        int y = lower_bound(com.begin(), com.end(), v.se) - com.begin() + 1;
        int cur = getm(y - 1);
        //cout << i << ' ' << y << ' ' << cur << '\n';
        if(i > 0 && tmp[i].fi == tmp[i - 1].fi) {
            int ny = lower_bound(com.begin(), com.end(), tmp[i - 1].se) - com.begin() + 1;
            add(cur, -getm(ny - 1));
        }
        //cout <<  cur << ' ' << y << '\n';
        upd(y, cur);
    }
    cout << getm(N - 1);
}


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

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

  int N; cin >> N;
  vector<long long> c(5);
  for (int i = 0; i < N; i++) {
    string S; cin >> S;
    if (S.front() == 'M') c[0]++;
    else if (S.front() == 'A') c[1]++;
    else if (S.front() == 'R') c[2]++;
    else if (S.front() == 'C') c[3]++;
    else if (S.front() == 'H') c[4]++;
  }

  long long ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i+1; j < 4; j++) {
      for (int k = j+1; k < 5; k++) {
        ans += c[i] * c[j] * c[k];
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
n, x = map(int,input().split())
ans = [-1]*(2*n - 1)
if x == 1 or x == 2*n - 1:
    print('No')
else:
    if n == 2:
        if x == 3:
            print('No')
        else:
            print('Yes')
            print('1\n2\n3')
    else:
        print('Yes')
        t = 0
        if x == 2:
            ans[n - 3] = 4
            ans[n - 2] = 1
            ans[n - 1] = 2
            ans[n] = 3
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t > 4:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1
        else:
            ans[n - 3] = x - 2
            ans[n - 2] = x + 1
            ans[n - 1] = x
            ans[n] = x - 1
            t, i = 1, 0
            for rep in range(10**6):
                if i >= 2*n - 1:
                    break
                if ans[i] == -1:
                    if t < x - 2 or t > x + 1:
                        ans[i] = t
                        i += 1
                    t += 1 
                else:
                    i += 1

        for i in ans:
            print(i)

Measured memory_bytes: 12480
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
int n;
int A[300010];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  for(int i=1;i<=n*3;++i) read(A[i]);
  sort(A+1,A+3*n+1);
  LL res=0;
  for(int i=n*3-1;i>n;i-=2) res+=A[i];
  printf("%lld\n",res);
  return 0;
}


Measured memory_bytes: 1408
import scala.io.StdIn.readInt

object Main {
  val angle = Math.PI/3
  def main(args:Array[String]) = {
    val n = readInt
    var list = IndexedSeq(((0D,0D),(100D,0D)))
    (1 to n).foreach { _=>
      list = for{
        i<-list;
        p1 = (i._1._1*2/3+i._2._1/3,i._1._2*2/3+i._2._2/3)
        p2 = (i._1._1/3+i._2._1*2/3,i._1._2/3+i._2._2*2/3)
        x = (p2._1-p1._1)*Math.cos(angle)-(p2._2-p1._2)*Math.sin(angle)+p1._1
        y = (p2._1-p1._1)*Math.sin(angle)+(p2._2-p1._2)*Math.cos(angle)+p1._2
        p3 = (x,y)
        j<-List((i._1,p1),(p1,p3),(p3,p2),(p2,i._2))
      } yield j
    }

    for(i<-list)
      printf("%.8f %.8f\n",i._1._1,i._1._2)
    printf("%.8f %.8f\n",list.last._2._1,list.last._2._2)
  }
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = ReadInt();
            WriteLine(r * r);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define INF 1e18
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    ll L, R;
    cin >> L >> R;
    ll minMod = 2018;
    bool finish = false;
    for (ll i=L; i<R; i++) {
        for (ll j=i+1; j<=R; j++) {
            ll tmp = (i*j) % 2019;
            if (minMod > tmp) {
                minMod = tmp;
            }
            if (minMod == 0) {
                finish = true;
                break;
            }
        }
        if (finish) break;
    }
    print(minMod);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    _LL d, t, s;
    cin >> d >> t >> s;
    if( s * t >= d )
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;    
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int k = 0;
  string s;
  cin >> k >> s;
  int size = 0;
  size = s.size();
  if(size <= k)cout << s << endl;
  else{
    cout << s.substr(0,k) << "..." << endl;
  }
}

Measured memory_bytes: 3624
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, k =f()
    l = f()

    l = sorted(l, reverse = True)

    print(sum(l[0:k]))


solve()


Measured memory_bytes: 2940
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,=pin()
    H=lispin()
    for i in range(1,N):
        if H[i]-H[i-1]>0:
            H[i]-=1
    cond=1
    for j in range(1,N):
        if H[j]-H[j-1]<0:cond=0;break
    print(["No","Yes"][cond])
    #print(B)
#%%submit!
resolve()

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll = pair<ll,ll>;
using Graph = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) // x/yの除算の切り上げ
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007; //1000000007;
const ld pi = acos(-1);

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

    ll k;
    cin >> k;
    if(k%2==0){
        cout << -1 << endl;
        return 0;
    }
    ll x=0;
    rep(i,k+10){
        x=x*10+7;
        x%=k;
        if(x<0) x+=k;
        if(x==0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3580
import collections
n = int(input())
s = [str(input()) for _ in range(n)]
m = int(input())
t = [str(input()) for _ in range(m)]
s = collections.Counter(s)
t = collections.Counter(t)

for k, j in t.items():
    if k in s:
        s[k] -= j

values, counts = zip(*s.most_common())
print(max(0,counts[0]))


Measured memory_bytes: 9468
#include <stdio.h>
#include <limits.h>

int main(void)
{
  char n[5];
  int number;
  int max = 0;
  int min = INT_MAX;

  fgets(n, sizeof(n), stdin);
  sscanf(n, "%d", &number);

  for (int i=0; i < number; i++) {

    int num;

    scanf("%d", &num);

    if (num < min) {
      min = num;
    }

    if (num > max) {
      max = num;
    }

  }

  printf("%d\n", max-min);
  
  return 0;
}


Measured memory_bytes: 128