akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
  
int main(){
	int n,m,a,t,i;
	int h[1001],p[1001],q[1001];
	while(1){
		for(i=0;i<1001;i++){
			h[i]=0;p[i]=0;q[i]=0;
		}
		cin>>n>>m>>a;
		if(n==0)break;
		for(i=0;i<m;i++){
			cin>>h[i]>>p[i]>>q[i];
		}
		for(t=1000;t>0;t--){
			for(i=0;i<m;i++){
				if(t==h[i]&&a==p[i]){
					a=q[i];
				}else if(t==h[i]&&a==q[i]){
					a=p[i];
				}
			}
		}
		cout<<a<<endl;
	}
    return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>

int main() {
  long long n,sum=0,T,max,min;
  scanf("%lld", &T);

  for (int i = 1; i <= T;i++) {
    scanf("%lld", &n);
    if( i== 1) {
      max = min = n;
    }
    if(max < n) {
      max = n;
    } else if(min > n) {
      min = n;
    }
    sum = sum + n;
  }
  printf("%d %d %lld\n",min,max,sum);
  return 0;
}


Measured memory_bytes: 2120
N, A, B, C, D = map(int, input().split())
ans = False
for i in range(N):
  inc = i
  dec = N-1-i
  # print(i, A + inc * C - dec * D, A + inc * D - dec * C)
  if A + inc * C - dec * D <= B <= A + inc * D - dec * C:
    ans = True
print('YES' if ans else 'NO')
    

Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>
int main(){
  int i,j,k;
  int n,r,s[5134];
  s[0]=2;
  for(i=3,j=1;i<50022;i+=2){
    r=(int)sqrt(i)+1;
    for(k=3;k<r;k+=2){
      if(i%k==0)
	r=0;
    }
    if(r){
      s[j]=i;
      j++;
    }
  }
  while(scanf("%d",&n)!=-1){
    for(i=0;i<j-1;i++){
      if(s[i]==n){
	printf("%d %d\n",s[i-1],s[i+1]);
	break;
      }else if(s[i+1]==n){
	printf("%d %d\n",s[i],s[i+2]);
	break;
      }else if(s[i]<n&&n<s[i+1]){
	printf("%d %d\n",s[i],s[i+1]);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#define retrun return
#define cpnst const
#include<string>
#include<iostream>
using std::cout;
using std::endl;
using std::string;
int ask(string x)
{
	cout<<"? "+x<<endl;
	int _tp;
	scanf("%d",&_tp);
	return _tp;
}
int t=0;
bool good(string x)
{return(ask(x)+(int)x.length())==t;}
int match(string x)
{return x.length()-ask(x);}
string merge(string x,string y)
{
	string ret="";
	for(;x.length()&&y.length();)
	{
		if(good(y+x.back()+ret))ret=x.back()+ret,x.pop_back();
		else ret=y.back()+ret,y.pop_back();
	}for(;x.length();)ret=x.back()+ret,x.pop_back();
	for(;y.length();)ret=y.back()+ret,y.pop_back();
	return ret;
}
string str[1111];
string pw(char c,int k)
{
	register int i;
	string ret="";
	for(i=1;i<=k;i++)ret=ret+c;
	return ret;
}
#include<queue>
struct comp{
	bool operator()(cpnst string&x,cpnst string&y){return x.length()>y.length();}
};
std::priority_queue<string,std::vector<string>,comp>Q;
char mp[]="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
int main()
{
	register int i;
	for(i=0;i<62;i++)
	{
		int len=match(pw(mp[i],128));
		if(len)Q.push(pw(mp[i],len)),t+=len;
	}for(;Q.size()>1;)
	{
		string A=Q.top();Q.pop();
		string B=Q.top();Q.pop();
		Q.push(merge(A,B));
	}if(!Q.size())cout<<"! "<<endl;
	else cout<<"! "+Q.top()<<endl;
}
/*
Just go for it.
*/

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,q;cin>>n>>q;
  string s;
  cin>>s;
  vector<int >nos(n,0);
  for(int i=1;i<n;i++){
  	if(s[i]=='C' && s[i-1]=='A')nos[i]=nos[i-1]+1;
    else nos[i]=nos[i-1];
  }
  for(int i=0,a,b;i<q;i++){
    cin>>a>>b;
  	cout<<nos[b-1]-nos[a-1]<<'\n';
  }
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = 1005;
const int MAX_V = MAX_N * MAX_N / 2;
int id[MAX_N][MAX_N] = {0};
vector<int> to[MAX_V];
int toId(int i, int j){
    if (i > j) swap(i, j);
    return id[i][j];
}

bool visited[MAX_V];
bool calculated[MAX_V];
int dp[MAX_V]; // max length

int dfs(int v) {
    if (visited[v]) {
        if (calculated[v]) return dp[v];
        else return -1;
    }
    visited[v] = true;
    dp[v] = 1;
    for (int u: to[v]){
        int res = dfs(u);
        if (res == -1) return -1;
        dp[v] = max(dp[v], res + 1);
    }
    calculated[v] = true;
    return dp[v];
}


int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>()); 
    rep(i, n){
        rep(j, n-1){
            int tmp; cin >> tmp;
            tmp--;
            a[i].push_back(tmp);
        }
    }
    int V = 0;
    rep(i, n)rep(j, n){
        if (i < j) id[i][j] = V++;
    }
    rep(i, n){
        rep(j, n-1){
            a[i][j] = toId(i, a[i][j]);
        }
        rep(j, n-2){
            to[a[i][j+1]].push_back(a[i][j]);
        }
    }
    int ans = 0;
    rep(i, V){
        int res = dfs(i);
        if (res == -1){
            puts("-1");
            return 0;
        }
        ans = max(ans, dfs(i));
    }

    cout << ans << endl;
}



Measured memory_bytes: 38656
#include <iostream>

using namespace std;

long long n;

int main()
{
    cin>>n;
    cout<<n*(n+1)/2-3*((n/3)*((n/3)+1)/2)-5*((n/5)*((n/5)+1)/2)+15*((n/15)*((n/15)+1)/2);
    return 0;
}


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

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  
  int ans = 1e9 + 10;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      int tmp = 0;
      int xx = x;
      if (i == 1) {
        xx *= -1;
        tmp++;
      }
      int yy = y;
      if (j == 1) {
        yy *= -1;
        tmp++;
      }
      if (xx <= yy) {
         tmp += yy - xx;
         ans = min(ans, tmp);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	while(cin>>N) {
		VI a;
		a.PB(0);
		REP(i, N) {cin>>K;a.PB(K);}
		a.PB(0);
		ll sum=0;
		RANGE(i, 1, N+2) sum+=abs(a[i]-a[i-1]);
//		DD(sum);
		RANGE(i, 1, N+1) {
			cout<<sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 2292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

#define __ { \
	freopen("input.txt","r",stdin); \
	freopen("output.txt","w",stdout); \
}
#define _ { \
	ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
}

int main(){
   _;
  // __;
  int n,m;cin>>n>>m;
 vector<pair<ll,int> > v(n+m);
 for(int i=0;i<n;i++)cin>>v[i].first,v[i].second=1;
 for(int i=n;i<m+n;i++)cin>>v[i].second>>v[i].first;
 sort(v.rbegin(),v.rend());
 ll ans=0;
 int yay=n;
 for(int i=0;i<n;i++){
     if(v[i].second<=yay){ans+=v[i].second*v[i].first;yay-=v[i].second;}
     else {ans+=v[i].first*yay;break;}
 }
 cout<<ans;
}

Measured memory_bytes: 3328
package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}



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

signed main(){
#ifdef _DEBUG
	//freopen("_in" , "r", stdin );
	//freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= 9; i++) {
		if (n % i == 0 && n / i >= 1 && n / i <= 9) {
			cout << "Yes\n";\
			return 0;
		}
	}
	cout << "No\n";
}


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

using namespace std;

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

  int x, t;
  cin >> x >> t;
  if (x < t) {
    cout << "0\n";
  } else {
    cout << x - t << "\n";
  }
}


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

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (i % 2 == 0)
        {
            cout << s[i];
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n) {
        int input;
        cin >> input;
        p.push_back(input);
    }

    SORT(p);
    int max_p = p.back();
    int sum = accumulate(p.begin(), p.end()-1, 0);
    P(max_p/2 + sum);

    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
#INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
S = [int(s) for s in input()] + [1]

r = -1
ans = 0
cnt = 0
used = [0]*(N+1)

for l in range(N):
	if S[l] + S[l-1] == 0:
		continue
	while r < N and used[r] - used[l-1] <= K:
		r += 1
		if S[r-1] == 1 and S[r] == 0:
			used[r] = used[r-1] + 1
		else:
			used[r] = used[r-1]
	ans = max(ans, r-l)

print(ans)

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

int main(){
	string s;
	cin>>s;
	int flag=0;
	for (int i = 0; i < s.length(); i++) {
		if (i%2==0) {
			if (s[i]=='L') {
				flag=1;
			}
		}else {
			if (s[i]=='R') {
				flag=1;
			}
		}
	}
	if (flag==1) {
		cout<<"No"<<endl;
	}else {
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 256
MOD = 1000000007
NCK_MAX = 510000

fac = [0 for _ in range(NCK_MAX)]; finv = [0 for _ in range(NCK_MAX)]
inv = [0 for _ in range(NCK_MAX)]; facn = [0 for _ in range(NCK_MAX)]

def myPow(x,n,MOD=MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return myPow(x*x%MOD,n//2)
    else:
        return x*myPow(x,n-1)%MOD

def COMinit(n):
    fac[0] = 1; fac[1] = 1
    facn[1] = n
    finv[0] = 1; finv[1]=1
    inv[1]=1
    for i in range(2,NCK_MAX):
        fac[i] = fac[i-1]*i%MOD
        facn[i] = facn[i-1]*(n-i+1)%MOD
        inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i] = finv[i-1]*inv[i]%MOD

def modinv(a,MOD=MOD):
    return myPow(a,MOD-2)

def COM(n,k):
    if n<k:
         return 0
    elif n<0 and k<0:
         return 0
    return facn[k] * finv[k]%MOD

n,a,b = map(int,input().split())
COMinit(n)
ans = (myPow(2,n)-1+MOD)%MOD
ans = (ans-COM(n,a)+MOD)%MOD
ans = (ans-COM(n,b)+MOD)%MOD
print(ans)


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

template<typename T>
T gcd(T a, T b)
{
	return b ? gcd(b, a%b) : a;
}

template<typename T>
T lcm(T a, T b)
{
	return a / gcd(a, b) * b;
}

//(a^e)%mod
template<typename T>
T power(T a, T e, T mod)
{
	if(e == 0)
	{
		return 1;
	}
	if(e % 2 != 0)
	{
		//a^e=a^(e-1)*a
		return (power(a, e - 1, mod) * a) % mod;
	}
	T res = power(a, e / 2, mod);
	//a^e=a^(e/2)*a^(e/2)
	return (res * res) % mod;
}

template<typename T>
class Tree
{
private:
public:
	T data;
	Tree* parent = NULL;
	std::vector<Tree*> children;
	void setData(T x)
	{
		data = x;
	}
	void setParent(Tree* t)
	{
		parent = t;
	}
	void addChild(Tree* t)
	{
		children.push_back(t);
	}
	Tree(){}
	~Tree(){}
};

template<typename T>
class Graph
{
public:
	T index;
	vector<T> edge;
	void setEdge(T t)
	{
		edge.push_back(t);
	}
	Graph(){}
	~Graph(){}
};

Graph<int> G[100001];
int visited[100001];
void rec(int a, int b)
{
	if(visited[a] != 0)
	{
		return;
	}
	visited[a] = b;
	for (auto it : G[a].edge)
	{
		rec(it, b);
	}
	return;
}

int main()
{
	using namespace std;
	int n, m;
	cin >> n >> m;
	int a, b;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		G[a].setEdge(b);
		G[b].setEdge(a);
	}
	for (int i = 1; i <= n; ++i)
	{
		rec(i, i);
	}
	int q;
	cin >> q;
	for (int i = 1; i <= q; ++i)
	{
		cin >> a >> b;
		cout << (visited[a] == visited[b] ? "yes" : "no") << endl;
	}

	return 0;
}



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


int A[1000];

int main(){
	int n,m,a,b;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		A[a]++;
		A[b]++;
	}
	
	for(int i=1;i<=n;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;
  vector<int> a(n);
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int sum = 0;
  for (int i = 0; i < k; i ++) {
    sum += a.at(i);
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
num = list(map(int,list(input())))
plusminus= [0 for i in range(3)]

for i in range(1 << 3):
    p = num[0]
    for j in range(3):
        if ((i >> j) & 1):
            p += num[j+1]
            plusminus[j] = '+'
            # print(p)
        else:
            p -= num[j+1]
            plusminus[j] = '-'
            # print(p)
    if p == 7:
        print(num[0],plusminus[0],num[1],plusminus[1],num[2],plusminus[2],num[3],'=7',sep='')
        break

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll m,k,v=1;
  cin >> m >> k;
  for(int i=0;i<m;i++){
    v*=2;
  }
  if(k>=v){
    cout << "-1\n";
    return 0;
  }
  if(m==0){
    if(k==0){
      cout <<"0 0\n";
    }else{
      cout <<"-1\n";
    }
  }else if(m==1){
    if(k==0){
      cout <<"0 1 1 0\n";
    }else{
      cout << "-1\n";
    }
  }else{
    vector<ll> a,b,c;
    for(int i=0;i<v;i++){
      if(i!=k){
        b.push_back(i);
        c.push_back(i);
      }
    }
    sort(b.begin(),b.end());
    sort(c.begin(),c.end(),greater<ll>());
    for(auto i:b){
      cout << i<<" ";
    }
    cout << k<<" ";
    for(auto i:c){
      cout << i<<" ";
    }
    cout << k<<"\n";
  }
}


Measured memory_bytes: 4076
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()
    Alice, Bob = 0, 0
    for i in range(N):
        if i % 2 == 0: Alice += A[N-i-1]
        else: Bob += A[N-i-1]
    print(Alice - Bob)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
n = int(input())

count = 0

if(n >= 105):
    for i in range(105, n+1, 2):
        l = []
        for j in range(1, i+1):
            if (i % j == 0):
                l += [j]
        if(len(set(l)) == 8):
            count += 1

print(count)

Measured memory_bytes: 38512
n=int(input())
a=list(map(int,input().split()))
f=1
for i in range(n):
    if a[i]%2:
        continue
    else:
        if a[i]%3==0 or a[i]%5==0:
            continue
        else:
            f=0
if f:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 38256
/**
*    created: 12.05.2020 00:57:08
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    string s; cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
def layers(n):
    result = 1
    for _ in range(0, n):
        result = result * 2 + 3
    return result


def meat(n):
    result = 1
    for _ in range(0, n):
        result = result * 2 + 1
    return result


def calc(n, x):
    before_layer = layers(n - 1)
    before_meat = meat(n - 1)
    if x == 1:
        return 1 if n == 0 else 0
    elif x <= 1 + before_layer:
        return calc(n - 1, x - 1)
    elif x == 2 + before_layer:
        return 1 + before_meat
    elif x <= 2 + 2 * before_layer:
        return 1 + before_meat + calc(n - 1, x - 2 - before_layer)
    elif x == 3 + 2 * before_layer:
        return 2 * before_meat + 1


def main():
    n, x = map(int, input().split())
    print(calc(n, x))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include<iostream>
#include<vector>

using namespace std;

int N;

int main() {
	cin >> N;
	vector<int> A(N);
	double sum = 0;
	for (int i = 0; i < N; i++) { 
		cin >> A[i];
		sum += 1.0 / A[i];
	}
	printf("%.7lf\n", 1.0 / sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,a;
  cin >> n >> a;
  if(n%500<=a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

ll solve() {
	ll N;
	cin >> N;
	const ll MOD = 1e9 + 7;
	auto Add = [&](ll& x, ll y) { x = (x + y % MOD) % MOD; };
	auto Mul = [&](ll& x, ll y) { x = (x * y % MOD) % MOD; };
	vector<ll> dp(N + 1), c(N + 1);
	dp[0] = 1, c[0] = 1;
	for (int i = 1; i <= N; i++) {
		Add(dp[i], dp[i - 1]);
		if (i >= 3) Add(dp[i], c[i - 3]);
		Add(c[i], c[i - 1]);
		Add(c[i], dp[i]);
	}
	ll ans = 0;
	for (int i = 0; i <= N - 2; i++) {
		ll x = dp[i];
		Mul(x, N - 1);
		Mul(x, N - 1);
		Add(ans, x);
	}
	{
		ll x = dp[N];
		Add(ans, x);
	}
	{
		ll x = dp[N - 1];
		Mul(x, N - 1);
		Add(ans, x);
	}
	for (int i = 0; i <= N - 2; i++) {
		ll x = dp[i];
		Mul(x, i + 1);
		Add(ans, x);
	}
	return ans;
}

int main() {
	auto ans = solve();
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 15872
from collections import Counter
N, M = map(int, input().split())
H=[int(x) for x in input().split()]
list=[]
for i in range (1,M+1):
  a, b = map(int, input().split())
  if H[a-1] > H[b-1]:
    list.append(b)
  elif  H[a-1] < H[b-1]:
    list.append(a)
  elif  H[a-1] == H[b-1]:
    list.append(a)
    list.append(b)
c = Counter(list)
print(N-len(c))


Measured memory_bytes: 22068
let sum_of_digits s =
  let rec loop sum = function
    i when i = (String.length s) -> string_of_int sum
    | i -> loop (sum + (int_of_char s.[i]) - 48) (i+1)
  in loop 0 0;;

let rec read u =
  let str = read_line () in
  if str.[0] != '0' then begin
      sum_of_digits str |> print_endline;read u
    end

let () = read ();;

Measured memory_bytes: 2140
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class BTag {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        ll a,b,v,w,t;
        cin>>a>>w>>b>>v>>t;
        if (a<b){
            if (w*t+a>=v*t+b)
                cout<<"YES";
            else cout<<"NO";
        }
        else{
            if (a-w*t<=b-v*t)
                cout<<"YES";
            else
                cout<<"NO";
        }
	}
};


int main() {
	BTag solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
const int N = 305;
double p[N][N][N];
double e[N][N][N];

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	cout<<fixed<<setprecision(15);
	int n; cin>>n;
	map <int,int> m;
	forn(i,n){ int p; cin>>p; m[p]++; }
	p[m[1]][m[2]][m[3]] = 1.0;
	for(int c=m[3];c>=0;c--)
	{
	    for(int b=m[2]+m[3];b>=0;b--)
	    {
	        for(int a=m[1]+m[2]+m[3];a>=0;a--)
	        {
	            if(a+b+c>n) continue;
	            if( a==0 && b==0 && c==0 ) continue;
	            double ww = (double)( n - (a+b+c) )/(double)n;
	            double ee = 1.0 + ww/(1.0-ww);
	            e[a][b][c] += ee*p[a][b][c];
	            if(a>0)
	            {
	                double gg = (double)a/(a+b+c);
	                p[a-1][b][c] += p[a][b][c]*gg;
	                e[a-1][b][c] += e[a][b][c]*gg;
	            }
	            if(b>0)
	            {
	                double gg = (double)b/(a+b+c);
	                p[a+1][b-1][c] += p[a][b][c]*gg;
	                e[a+1][b-1][c] += e[a][b][c]*gg;
	            }
	            if(c>0)
	            {
	                double gg = (double)c/(a+b+c);
	                p[a][b+1][c-1] += p[a][b][c]*gg;
	                e[a][b+1][c-1] += e[a][b][c]*gg;
	            }
	        }
	    }
	}
	cout<<e[0][0][0];
	
	return 0;
}


Measured memory_bytes: 438528
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    vi p(n);
    rep(i, n) cin >> p[i];

    vi a(3);
    int ans = 0;
    for(int i = 1; i < n - 1; i++) {
        rep(j, 3) {
            a[j] = p[i-1+j];
        }
        sort(all(a));
        if(a[1] == p[i]) ans++;
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int i,a,b,sum,j;
    while (scanf ("%d%d",&a,&b) != EOF)
    {
    j=0;
        sum=0;
        if(((a<0 || a>1000000)||(b<0 || b>1000000))||(i>200))
            break;
        sum=a+b;
        while(sum!=0)
        {
            sum=sum/10;
            j++;
        }
        printf("%d\n",j);
        i++;
    }
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int T[5];
  while(cin >> T[0] >> T[1] >> T[2] >> T[3] >> T[4]){
    if(T[0] == 0) break;
    bool f[3];
    memset(f, false, sizeof(f));
    for(int i = 0 ; i < 5 ; i++) f[T[i]-1] = true;
    if(f[0] && f[1] && f[2]){
      for(int i = 0 ; i < 5 ; i++) T[i] = 3;
    }
    else if(f[0] && f[1] && !f[2]){
      for(int i = 0 ; i < 5 ; i++){
	if(T[i] == 1) T[i] = 1;
	else if(T[i] == 2) T[i] = 2;
      }
    }
    else if(f[1] && f[2] && !f[0]){
      for(int i = 0 ; i < 5 ; i++){
	if(T[i] == 2) T[i] = 1;
	else if(T[i] == 3) T[i] = 2;
      }
    }
    else if(f[0] && f[2] && !f[1]){
      for(int i = 0 ; i < 5 ; i++){
	if(T[i] == 3) T[i] = 1;
	else if(T[i] == 1) T[i] = 2;
      }
    }
    else{
      for(int i = 0 ; i < 5 ; i++){
	T[i] = 3;
      }
    }
    for(int i = 0 ; i < 5 ; i++){
      cout << T[i] << endl;
    }
  }
  return 0;
}

    

Measured memory_bytes: 1160
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int x;
    cin >> x;
    int maxx = 1;
    for(int i=2;i<=40;i++){
        int a = i;
        while (a * i <= x)
            a *= i;
        if (a == i)
            continue;
        maxx = max(maxx, a);
    }
    cout << maxx << endl;
    return 0;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	long long t, a;
	long long k;
	cin >> t >> a >> k;
	if ((t = t - k) < 0) {
		a = a + t;
		if (a < 0) a = 0;
		t = 0;
	}

	cout << t << " " << a << endl;

	return 0;
}



Measured memory_bytes: 888
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    double n,m;cin >> n >> m;
    vi a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum+=a[i];
    }
    resort(a);
    if(a[m-1]>=sum*(1/(4*m))) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef pair<pair<int,int>,bool> piib;

const ll N=1e7+10;
const int MOD=1e9+7;

int n;

ll arr[N];

void init()
{
    for(int i = 1; i <= n; i++)
        for(int j = i; j<=n; j+=i)
            arr[j]++;
}

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

    //freopen("mosalah.in","r",stdin);

    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif // ONLINE_JUDGE

    cin >> n;
    init();
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ans+=(i*arr[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 81756
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e5 + 5;
int n, m;
vector <int> g[M];
 
int32_t main() 
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int u, v;	cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vector <int> ans(n + 1, 1e9);
	ans[1] = 1;
	queue <int> q;
	q.push(1);
	while(!q.empty())
	{
		auto u = q.front();
		q.pop();
		for(auto &v : g[u])
		{
			if(ans[v] != 1e9)	continue;
			ans[v] = u;
			q.push(v);
		}
	}
	int ok = 1;
	for(int i = 2; i <= n; i++)
		if(ans[i] == 1e9)
			ok = 0;
	if(!ok)
		return cout << "No", 0;
	cout << "Yes\n";
	for(int i = 2; i <= n; i++)
		cout << ans[i] << "\n";
    	return 0;
}

Measured memory_bytes: 12904
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,c,k;
    cin >> n >> c >> k;
    int t[n];
    for(int i = 0;i < n;i++)
    {
        cin >> t[i];
    }
    sort(t,t + n);
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        int lim = t[i] + k;
        int count = 0;
        while(i < n && t[i] <= lim && count < c)
        {
            count++;
            i++;
        }
        i--;
        ans++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 640
from collections import deque
K = int(input())

q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for _ in range(K):
    x = q.popleft()
    xmod = x % 10
    if xmod != 0:
        q.append(10 * x + xmod - 1)
    q.append(10 * x + xmod)
    if xmod != 9:
        q.append(10 * x + xmod + 1)
print(x)

Measured memory_bytes: 11956
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c,i;
    cin>>a>>b>>c;
    for(i=1;i<=100000;i++){
        if((a*i)%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

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

int main() {
  char op;
  int A, B;
  cin >> A >> op >> B;
  
  if (op=='+') {
    cout << A+B << endl;
  }
  else if (op=='-') {
    cout << A-B << endl;
  }
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n,k = iim()
r,s,p = iim()
t = list(input())
ans = 0
flag = [True]*n
for i,item in enumerate(t):
    if i >= k and flag[i-k]:
        if t[i] == 'r' and t[i-k] != 'r':
            ans += p
        elif t[i] == 's' and t[i-k] != 's':
            ans += r
        elif t[i] == 'p' and t[i-k] != 'p':
            ans += s
        else:
            flag[i] = False

    else:
        if t[i] == 'r':
            ans += p
        elif t[i] == 's':
            ans += r
        elif t[i] == 'p':
            ans += s

print(ans)

Measured memory_bytes: 10320
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b=mp()
print(a+b if b%a==0 else b-a)

Measured memory_bytes: 77292
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n;
char s[500010];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if (n%2!=0) return puts("No"),0;
	FOR(i,1,n/2) if (s[i*2-1]!='h' || s[i*2]!='i') return puts("No"),0;
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
A = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for i in range(n):
    l = 0
    for j in range(i+1,n):
        if  A[i] > A[j]:
            l += 1
    ans1 += l
    m = 0
    for j in range(i+1):
        if A[i] > A[j]:
            m += 1
    ans2 += l+m
print((ans1*k+ans2*(k*(k-1)//2))%(10**9+7))

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

int n, m, a[110][110];

int main()
{
    scanf("%d", &m);
    FOR(i, 1, 2) FOR(j, 1, m) scanf("%d", &a[i][j]);
    FOR(i, 1, 2) FOR(j, 1, m) a[i][j] += max(a[i - 1][j], a[i][j - 1]);
    printf("%d\n", a[2][m]);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
using namespace std;
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;}
typedef pair<int,int> P;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA

int poi(char s){
     if(s=='0') return 0;
     if(s=='1') return 1;
     if(s=='2') return 2;
     if(s=='3') return 3;
     if(s=='4') return 4;
     if(s=='5') return 5;
     if(s=='6') return 6;
     if(s=='7') return 7;
     if(s=='8') return 8;
     else return 9;
}

const int INF = 1001001001;
int main(){
    int n; cin >> n;
    bool key[1000];
    rep(i,1000) key[i]=0;
    string s; cin >> s;
    bool ok[10];
    rep(i,10) ok[i]=0;
    int ans=0;
    rep(i,1000){
        bool ok1,ok2,ok3;
        ok1=0;ok2=0;ok3=0;
        int key1=i/100;
        int key2=(i/10)-key1*10;
        int key3=i%10;
        rep(i,n){
            if(ok1!=1 && key1==poi(s[i])){
                ok1=1;
                continue;
            }
            if(ok2!=1 && ok1==1 && key2==poi(s[i])){
                ok2=1;
                continue;
            }
            if(ok3!=1 && ok2==1 && key3==poi(s[i])){
                ok3=1;
                continue;
            }
        }
        if(ok3==1) key[i]=1;
    }
    rep(i,1000){
        if(key[i]){
            ans++;

        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vi A(3*N);
  cin >> A;

  sort(rrng(A));
  i64 ans = 0;
  rep(i,N){
    ans += A[2 * i + 1];
  }
  
  cout << ans << "\n";
}

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

Measured memory_bytes: 2560
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑

int digits(int n) {
	int ans = 0;
	while (n) {
		++ans;
		n /= 10;
	}
	return ans;
}


int main() {
	int a, b, k[15];
	while (cin >> a && a > 0) {
		cin >> b;
		set<ll>s;
		for (int i = 0; i < a; ++i) { cin >> k[i]; }
		if (b == 2) {
			for (int i = 0; i < a; ++i) {
				for (int j = 0; j < a; ++j) {
					if (i == j) { continue; }
					s.insert(k[i] + k[j] * pow(10, digits(k[i])));
				}
			}
		}

		if (b == 3) {
			for (int i = 0; i < a; ++i) {
				for (int j = 0; j < a; ++j) {
					for (int kk = 0; kk < a; ++kk) {
						if (i == j || j == kk || i == kk) { continue; }
						s.insert(k[i] + k[j] * pow(10, digits(k[i])) + k[kk] * pow(10, digits(k[i]) + digits(k[j])));
					}
				}
			}
		}

		if (b == 4) {
			for (int i = 0; i < a; ++i) {
				for (int j = 0; j < a; ++j) {
					for (int kk = 0; kk < a; ++kk) {
						for (int l = 0; l < a; ++l) {
							if (i == j || j == kk || i == kk || i == l || j == l || kk == l) { continue; }
							s.insert(k[i] + k[j] * pow(10, digits(k[i])) + k[kk] * pow(10, digits(k[i]) + digits(k[j])) + k[l] * pow(10, digits(k[i]) + digits(k[j]) + digits(k[kk])));
						}
					}
				}
			}
		}

		cout << s.size() << endl;
	}
}



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

int n;
long result=0;

int Ju(int n)
{
  int res=1;
  for(int i=0;i<n-1;i++)
    res=res*10;
  return res;
}

int Check(long now)
{
  int a=0,b=0,c=0;
  
  int n=0;
  int now_check=now;
  while(now_check>=1)
  {
    now_check=now_check/10;
    n++;
  }
  
  for(int i=0;i<n;i++)
  {
    if(now/Ju(n-i)==3)
      a++;
    else if(now/Ju(n-i)==5)
      b++;
    else
      c++;
    now-=(now/Ju(n-i))*Ju(n-i);
  }
  
  if(a!=0&&b!=0&&c!=0)
    return 1;
  else
    return 0;
}
  
void dfs(long now)
{
  if(now>n)
    return;
  if(Check(now))
    result++;
  
  dfs(now*10+3);
  dfs(now*10+5);
  dfs(now*10+7);
  
}

int main()
{
  cin>>n;
  dfs(3);
  dfs(7);
  dfs(5);
  cout<<result<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}

int main(){
	int n,m;
	cin>>n>>m;
	
	vi a(m),s(m,0);
	REP(i,m){
		int b;
		cin>>a[i]>>b;
		REP(j,b){
			int c;
			cin>>c;
			s[i]|=1<<(c-1);
		}
	}
	
	vi dp(1<<n,INF);
	dp[0]=0;
	REP(i,m)REP(j,1<<n){
		chmin(dp[j|s[i]],dp[j]+a[i]);
	}
	
	if(dp[(1<<n)-1]==INF) cout<<-1<<endl;
	else cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

pattern=0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                pattern += 1
print(pattern)

Measured memory_bytes: 9112
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var ABCD = ToIntArray(Read());
            var A = ABCD[0];
            var B = ABCD[1];
            var C = ABCD[2];
            var D = ABCD[3];

            for (int i = 0; i < Pow(2, 3); i++)
            {
                var a = new string[3];
                for (int j = 0; j < 3; j++)
                {
                    if ((i >> j & 1) == 1)
                        a[j] = "+";
                    else
                        a[j] = "-";
                }

                var sum = a[0] == "+" ? A + B : A - B;
                sum = a[1] == "+" ? sum + C : sum - C;
                sum = a[2] == "+" ? sum + D : sum - D;
                if (sum == 7)
                {
                    Println($"{A}{a[0]}{B}{a[1]}{C}{a[2]}{D}=7");
                    return;
                }
            }
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13396