akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

// konoshita kara kaku

int main(void){
	int i,a=0;
	char s[10];
	chin(s);
	rep(i,strlen(s))a+=(s[i]-'0');
	print(a);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  string s; cin >> s;
  map<char, int> m;
  for(int i= 0; i< s.size(); i++){
    m[s[i]]++;
  }
  for(auto itr = m.begin(); itr != m.end(); itr++){
    if(itr->second % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  system("pause");
}

Measured memory_bytes: 504
h,n=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]

dp=[float('inf')]*(h+1)
dp[0]=0
for i in range(h):
    for j in range(n):
        if dp[i] == float('inf'):continue
        next=i+ab[j][0] if i+ab[j][0]<=h else h
        dp[next]=min(dp[next],dp[i]+ab[j][1])
print(dp[-1])


Measured memory_bytes: 74524
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
int main()
{
    int x,y;
    cin>>x>>y;
    if(y%2==0){
        if(y>=2*x && y<=4*x)
            cout<<"Yes";
        else
            cout<<"No";
    }
    else
        cout<<"No";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N = 1e6 + 5, mod = 998244353;

int n, m, ans, fac[N], inv[N];

inline int mul(int a, int b) { 
    return (LL) a * b % mod; 
}
inline void sub(int &a, int b) {
    a -= b; if(a < 0) a += mod;
}
inline int Pow(int a, int b = mod - 2) {
    int res = 1;
    for(; b; b >>= 1, a = mul(a, a))
        if(b & 1) res = mul(res, a);
    return res;
}
inline void init(int n) {
    inv[0] = fac[0] = 1;
    for(int i = 1; i <= n; ++i)
        fac[i] = mul(fac[i - 1], i);
    inv[n] = Pow(fac[n]);
    for(int i = n - 1; i; --i)
        inv[i] = mul(inv[i + 1], i + 1);
}
inline int C(int n, int m) {
    if(n < m || n < 0 || m < 0) return 0;
    return mul(fac[n], mul(inv[m], inv[n - m]));
}
int main() {
    cin >> n >> m;
    if(n > m) swap(n, m);
    init(n + m);
    ans = mul(C(n + m, n), n);
    for(int i = 1; i <= n; ++i) 
        sub(ans, mul(C(n + m - i * 2, n - i), C(i * 2 - 1, i)));
    ans = mul(ans, Pow(C(n + m, n)));
    ans = (n + m) - ans;
    printf("%d\n", (ans % mod + mod) % mod);
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  ll sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  FOR(i, 0, tx - sx) {
	cout << "R";
  }
  FOR(i, 0, ty - sy) {
	cout << "U";
  }
  FOR(i, 0, tx - sx) {
	cout << "L";
  }
  FOR(i, 0, ty - sy) {
	cout << "D";
  }

  cout << "D";
  FOR(i, 0, tx - sx + 1) {
	cout << "R";
  }
  FOR(i, 0, ty - sy+1) {
	cout << "U";
  }
  cout << "L";

  cout << "U";
  FOR(i, 0, tx - sx+1) {
	cout << "L";
  }
  FOR(i, 0, ty - sy+1) {
	cout << "D";
  }
  cout << "R" << endl;


  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define swap(a, b, type) {type tmp = a; a = b; b = tmp;}

int check(int n)
{
	int digit = 1;
	int before = n % 10;
	n /= 10;
	while (n > 0){
		if (n % 10 != before){
			return 0;
		}
		n /= 10;
		digit++;
	}
	return digit == 4;
}

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		int count = 0;
		
		if (check(n) != 0){
			puts("NA");
			continue;
		}
		
		while (n != 6174){
			int i, j;
			char l[8], s[8];
			
			sprintf(l, "%04d", n);
			sprintf(s, "%04d", n);
			for (i = 0; i < 3; i++){
				for (j = 0; j < 3 - i; j++){
					if (l[j] < l[j + 1]){
						swap(l[j], l[j + 1], char);
					}
					if (s[j] > s[j + 1]){
						swap(s[j], s[j + 1], char);
					}
				}
			}
			n = 0;
			for (i = 0; i < 4; i++){
				n = n * 10 + l[i] - s[i];
			}
			count++;
		}
		
		printf("%d\n", count);
	}
	
	return 0;
}

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

#define ll long long

using namespace std;

const int base = 1e9 + 7;

const int p = 31;

const int ln = 5004;

string s;
int n;

int deg[5005];

int ph[5005];

int GetHash(int l, int r)
{
    int x = (ph[r] - ph[l - 1] + base) % base;
    return (1LL * x * deg[ln - l]) % base;
}

bool check(int mid)
{
    if(mid == 0) return true;
    for(int i = 0; i <= n - 2 * mid; i++)
    {
        int hneed = GetHash(i + 1, i + mid);
        for(int j = i + mid; j <= n - mid; j++)
        {
            int hget = GetHash(j + 1, j + mid);
            //cout << i << ' ' << hneed << ' ' << j << ' ' << hget << endl;
            if(hget == hneed) return true;
        }
    }
    return false;
}



int bin_s()
{
    int l = 0, r = n;
    int mid;
    while(l < r)
    {
        mid = (l + r) >> 1;
        //cout << mid << endl;
        if(check(mid))
        {
            l = mid + 1;
        } else
            {
                r = mid;
            }
    }
    if(!check(l)) l--;
    return max(0, l);
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> s;
    deg[0] = 1;
    for(int i = 1; i <= 5004; i++) deg[i] = 1LL * deg[i - 1] * p % base;
    for(int i = 1; i <= s.length(); i++)
    {
        ph[i] = (1LL * ph[i - 1] + 1LL * (s[i - 1] - 'a' + 1) * deg[i - 1]) % base;
        //cout << "phi = " << ph[i] << endl;
    }
    cout << bin_s();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define ALL(x)	(x).begin(), (x).end()
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7,N=1000010;
typedef long long ll;
int n,w;
#define v_max 1000
#define n_max 110
#define w_max 1000000009
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s1,s2;cin>>s1>>s2;
	int n=s1.length();
	int m=s2.length();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if (i==0||j==0)dp[i][j]=0;
			else if(s1[i-1]==s2[j-1])dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int ind=dp[n][m];
	//cout<<ind<<"\n";
	char ans[ind+1];
	ans[ind]='\0';
	int i=n,j=m;
	while (i>=0&&j>=0){
		if (s1[i-1]==s2[j-1]){
			ans[ind-1]=s1[i-1];
			i--;j--;ind--;
		}
		else if(dp[i-1][j]>dp[i][j-1])i--;
		else j--;
	}
	cout<<ans<<"\n";
return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rer(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vi;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest) { 
	cout << arg << " "; Debug(rest...); }
template<class T>ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<< ", ";out<<v.back();}out << "]";return out;}
template<class S, class T>ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";return out;}
const int MAX_N = 500010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string str;

int dp[MAX_N];
int nex[MAX_N];

void solve() {
	cin >> N >> str; str += "0";
	nex[N] = N;
	rer(i, N, 0) {
		if(str[i + 1] == '0') nex[i] = i + 1;
		else nex[i] = nex[i + 1];
		//debug(i, nex[i]);
	}
	rep(i, 0, N) {
		MAX(dp[i + 1], dp[i]);
		if(str[i] == '1') {
			if(nex[i] + 1 < N && str[nex[i] + 1] == '1') {
				MAX(dp[nex[i] + 2], dp[i] + nex[i] - i);
			}

			if(i + 1 < N && str[i + 1] == '0' && nex[i + 1] > i + 2) {
				MAX(dp[nex[i + 1]], dp[i] + nex[i + 1] - (i + 1) - 1);
				MAX(dp[nex[i + 1] - 1], dp[i] + nex[i + 1] - (i + 1) - 2);
			}
		}
	}
	cout << dp[N] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(5);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 4892
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    int N;
    cin >> N;

    vector<double> x(N);
    vector<string> u(N);

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


    double sum = 0;
    for (int i = 0; i < N; ++i) {
        if (u[i] == "BTC") {
            sum += 380000.0 * x[i];
        } else {
            sum += x[i];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(n)]
CD=[list(map(int,input().split())) for i in range(m)]
ans=[0]*n
for i in range(n):
    cnt=float('inf')
    dist=0
    a,b=AB[i]
    for j in range(m):
        c,d=CD[j]
        dist=abs(a-c)+abs(b-d)
        if cnt>dist:
            ans[i]=j
            cnt=dist
        else:
            continue
for i in range(n):
    print(ans[i]+1)

Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];

        for (int i = 0; i < N; i++)
            h[i] = sc.nextInt();


        int count = 0;

        for (int i = 0; i < N; i++)
            if (h[i] >= K)
                count++;

        System.out.println(count);

    }
}




Measured memory_bytes: 48240
#include <stdio.h>


int main (void){
  
 long int a=0,b=0,max=0,flag=0,n=0;
  scanf("%ld%ld%ld",&n,&a,&b);
 if(a*n>=b)
 {
     printf("%ld",b);
 }else{
     printf("%ld",a*n);
 }
return 0;
    
}


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

N = a[0]
M = a[1]

AC = [0] * N #ACの問題番号を1にする i = id -1
WA = [0] * N #WAの回数を入れる
WA_sum = 0
for i in range(M):
    a = list(map(str,input().split()))
    id_num = int(a[0])-1
    if AC[id_num] == 1:
        continue
    elif a[1] == 'WA':
        WA[id_num] += 1
    elif a[1] == 'AC':
        AC[id_num] = 1 
        WA_sum += WA[id_num]
        
print('{} {}'.format(sum(AC),WA_sum))

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int sum1=0,sum2=0;
  for(int i=0;i<n;i++){
    int d;cin >> d;
    sum1+=d;
    sum2+=d*d;
  }
  cout << (sum1*sum1-sum2)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
ll ans;
void solve(int a[],int n)
{
	int b[1000],t[10005],vmin,vmax=10000;
	bool vis[1000];
	for(int i=0;i<n;i++)
	{
		b[i]=a[i];
		vis[i]=false;
	}
	sort(b,b+n);
	vmin=b[0];
	for(int i=0;i<n;i++)
	{
		t[b[i]]=i;//得出移动够各个元素（值不同）应该在数组中位置 
	}
	for(int i=0;i<n;i++)
	{
		int cur=i,m=vmax,sum=0,num=0;//查找新的环 
		while(1)//开始搜索下一个环 
		{ 
			vis[cur]=true;//将这个元素加入当前环 
			num++;//这个环的个数加1 
			sum+=a[cur];//环的weight加1 
			m=min(a[cur],m);//更新最小值，最终得到该环的最小值 
			cur=t[a[cur]];//得到将要移动到的位置 
			if(vis[cur]) break;//将要移动到的位置的元素已经在环中，环已经闭合，一个环已经找到 
		}
		ans+=min(sum+(num-2)*m,sum+m+(num+1)*vmin);//如果已经在某个环中或者根本不需要移动，那么成本为0，不影响结果 
	}
}
int main()
{	
	int n,a[1000];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	solve(a,n);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3248
open Str

let read_list () =
  split (regexp " +") (read_line ())

let max_heapify h ar i =
  let swap i j =
    let t = ar.(i) in
    ar.(i) <- ar.(j);
    ar.(j) <- t in
  let rec iter i =
    let l = 2 * i in
    let r = 2 * i + 1 in
    let mi =
      let ti = if l <= h && ar.(l) > ar.(i) then l else i in
      if r <= h && ar.(r) > ar.(ti) then r else ti in
    if mi <> i then
      begin
        swap mi i;
        iter mi
      end
  in
  iter i

let extract h ar =
  let ret = ar.(1) in
  ar.(1) <- ar.(h);
  max_heapify (h-1) ar 1;
  (h-1, ret)

let insert h ar k =
  let swap i j =
    let t = ar.(i) in
    ar.(i) <- ar.(j);
    ar.(j) <- t in
  let rec iter i =
    let p = i / 2 in
    if p = 0 || ar.(p) >= ar.(i) then h+1
    else (swap p i; iter p)
  in
  ar.(h+1) <- k;
  iter (h+1)
           
let () =
  let pq = Array.make 2000000 0 in
  let rec read h =
    match read_list () with
      "insert" :: n :: _ -> let nh = insert h pq (int_of_string n) in read nh
    | "extract" :: _ -> let (nh, v) = extract h pq in (string_of_int v |> print_endline); read nh
    | "end" :: _ -> ()
    | _ -> failwith "read"
  in
  read 0

Measured memory_bytes: 21300
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,m,c = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	k = 0
	for i in 1:n
		a = readline() |> split |> parseMap
		t = c
		for j in 1:m
			t += a[j]*b[j]
		end
		if t > 0
			k += 1
		end
	end
	println(k)
end
main()

Measured memory_bytes: 167616
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define gt first
#define gc second.first
#define gr second.second
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<E> g[225];
bool done[225];

void newedge(int from, int to, int cap){
	g[from].push_back(E(to,P(cap,g[to].size())));
	g[to].push_back(E(from,P(0,g[from].size()-1)));
}

int dfs(int v, int t, int f){
	int i,d;
	E e;
	if(v == t){
		return f;
	}
	done[v] = true;
	for(i=0; i<g[v].size(); ++i){
		e = g[v][i];
		if(!done[e.gt] && e.gc > 0){
			d = dfs(e.gt, t, min(f, e.gc));
			if(d > 0){
				g[v][i].gc -= d;
				g[e.gt][e.gr].gc += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	while(true){
		fill(done,done+225,false);
		int f = dfs(s, t, INF);
		if(!f){
			return flow;
		}
		flow += f;
	}
}

int main(void){
	int n,i,j,a,b,c,d,s,t,ans;
	P rd[123],bl[123];
	
	cin >> n;
	s = 2*n; t = 2*n+1;
	for(i=0; i<n; ++i){
		cin >> a >> b;
		rd[i] = P(a,b);
		newedge(s,i,1);
	}
	for(j=0; j<n; ++j){
		cin >> c >> d;
		bl[j] = P(c,d);
		newedge(n+j,t,1);
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(rd[i].first < bl[j].first && rd[i].second < bl[j].second){
				newedge(i,n+j,1);
			}
		}
	}
	ans = max_flow(s,t);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<ll> a(3 * n);
  for (auto &e : a)
    cin >> e;

  sort(a.begin(), a.end());

  ll sum = 0;
  int cnt = 0;
  for (int i = 3 * n - 2; cnt != n; i -= 2)
    sum += a[i], cnt++;
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vint b(n);
  rep(i,n) cin >> b[i];
  vint ans(n);
  bool flag = true;
  for(int i = 0;i < n;i++){
    bool inflag = false;
    for(int j = b.size()-1;j >= 0;j--){
      if(b[j] == j+1){
        ans[n-1-i] = b[j];
        inflag = true;
        b.erase(b.begin()+j);
        break;
      }
    }
    if(!(inflag)) flag = false;
  }
  if(flag){
    rep(i,n) cout << ans[i] << endl;
  }
  else cout << -1 << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <climits>
#include <cmath>
#include <queue>

//using integer = unsigned long long;
using integer = signed long long;

typedef struct {
  int a;
  int b;
} node;

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

  int line[N+1][N+1] = {0};

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      line[i][j] = 0;
    }
  }

  for (int i = 0; i < M; i++) {
    int a, b;
    std::cin >> a >> b;
    line[a-1][b-1] = 1;
    line[b-1][a-1] = 1;
  }

  std::vector<int> v(N-1);
  for (int i = 1; i < N; i++) {
    v[i-1] = i;
  }

#if 0
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      //std::cout << " " << line[i][j];
      line[i][j] = 0;
    }
    //std::cout << std::endl;
  }
#endif

  int count = 0;
  do {
    bool ok = true;
    if (line[0][v[0]] == 0) {
      continue;
    }
    for (int i = 1; i < N-1; i++) {
      if (line[v[i-1]][v[i]] == 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      count++;
    }
  } while (std::next_permutation(v.begin(), v.end()));

  std::cout << count << std::endl;

  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  int ans = INF;
  for (int i = -100; i <= 100; ++i) {
    int sum = 0;
    for (int j = 0; j < N; ++j) {
      sum += (i - A[j]) * (i - A[j]);
    }
    ans = min(ans, sum);
  }
  printf("%d\n", ans);
  return 0;
}


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

int main(){
  int k,n;
  vector<int>a,dis;
  cin >> k >> n;
  a.resize(n);
  dis.resize(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    if(i>0)
      dis.at(i)=a.at(i)-a.at(i-1);
  }
  dis.at(0)=a.at(0)+(k-a.at(n-1));
  cout << k-*max_element(dis.begin(),dis.end()) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 200005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n, q;
ll val[maxn];
struct Edge { int to, nxt; } p[maxn << 1];

int head[maxn], cnt;
inline void addedge(int u, int v) {
    p[++cnt].to = v, p[cnt].nxt = head[u], head[u] = cnt;
    p[++cnt].to = u, p[cnt].nxt = head[v], head[v] = cnt;
}

inline void dfs(reg int x, reg int fa) {
    val[x] += val[fa];
    for (int i = head[x]; i; i = p[i].nxt)
        if (p[i].to != fa) dfs(p[i].to, x);
}

int main() {
    cin >> n >> q; reg int u, v;
    for (int i = 1; i < n; i++) cin >> u >> v, addedge(u, v);
    while (q--) {
        cin >> u >> v;
        val[u] += v;
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) cout << val[i] << " ";
    return 0;
}


Measured memory_bytes: 12416
import copy
n = int(input())
can = [0 for i in range(2001)]
can[0]=1

A = list(map(int,input().split()))
q = int(input())
Q = list(map(int,input().split()))
for i in range(len(A)):
    #can2 = [0 for i in range(2001)]
    #for j in range(len(can)):
        #can2[j]=can[j]
    can2 = copy.copy(can)
    for j in range(A[i],len(can)):
        can2[j] = max(can[j],can[j-A[i]])
    can = can2
    

for i in range(q):
    if can[Q[i]]==1:print('yes')
    else:print('no')


Measured memory_bytes: 6352
<?php
fscanf(STDIN, '%d %d %d', $w, $a, $b);
if($a + $w < $b){
    print $b - ($a + $w);
}elseif($a + $w >= $b && $a <= $b + $w){
    print 0;
}else{
    print $a - ($b + $w);
}

Measured memory_bytes: 4604
N = gets.to_i
A = gets.split.map &:to_i

a = A.group_by(&:itself).map{|i,ary| [i,ary.length]}.to_h

total = A.inject(&:+)
Q = gets.to_i
while line = gets
    b,c = line.split.map &:to_i
    count = a[b]
    if count then
        diff = (c-b)*count 
        total += diff
        a[b] = 0
        a[c] = 0 unless a[c]
        a[c] += count
    end
    puts total
end

Measured memory_bytes: 31504
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;
int main() {
	cin >> N >> M >> X;
	vector<int>v(N + 1, 0);
	for (int i = 0; i < M; i++) {
		cin >> A;
		v[A]++;
	}
	for (int i = 0; i < X; i++) {
		ans += v[i];
	}
	ans = min(ans, M - ans);
	cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    let stdin = std::io::stdin();
    stdin.lock().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut claims: Vec<Vec<(usize, u8)>> = vec![vec![]; n];

    for i in 0..n {
        let a_i: u8 = iter.next().unwrap().parse().unwrap();
        for _ in 0..a_i {
            let xj = iter.next().unwrap().parse::<usize>().unwrap() - 1;
            let yj = iter.next().unwrap().parse::<u8>().unwrap();
            claims[i].push((xj, yj));
        }
    }

    let mut ans: u32 = 0;

    'curr_subset: for subset_bit in 0_u16..(1 << n) {
        let mut visit_bit: u16 = 0;
        let mut stack: Vec<usize> = (0..n).filter(|i| subset_bit & 1_u16<<i != 0).collect();
        for i in &stack {
            visit_bit |= 1_u16<<i;
        }

        while !stack.is_empty() {
            let b = stack.pop().unwrap();
            for &(x, y) in &(claims[b]) {
                if (y == 0 && subset_bit & 1<<x != 0) || (y == 1 && subset_bit & 1<<x == 0) {
                    continue 'curr_subset;
                }
                if y == 1 && visit_bit & 1<<x == 0 {
                    stack.push(x);
                    visit_bit |= 1<<x;
                }
            }
        }
        ans = std::cmp::max(ans, subset_bit.count_ones());
    }

    println!("{}", ans);
}



Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#define int long long
using namespace std;

int n,d,a,ans,num[500005]={0};
struct Node{
	int id;
	int h;
}node[200005];

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')c=getchar(),t=-1;
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return s*t;
}

bool cmp(Node p,Node q){
	return p.id<q.id;
}

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

void add(int x,int y){
	for(int i=x;i<=n;i+=lowbit(i))
	num[i]+=y;
}

int get(int x){
	int s=0;
	for(int i=x;i;i-=lowbit(i))
	s+=num[i];
	return s;
} 

signed main(void){
	n=read();
	d=read();
	a=read();
	for(int i=1;i<=n;i++){
		node[i].id=read();
		node[i].h=read();
		node[i].h=(node[i].h+a-1)/a;
	}
	sort(node+1,node+1+n,cmp);
	int b=0;
	for(int i=1;i<=n;i++){
		int aa=node[i].h;
		add(i,aa-b);
		b=aa;
	}
	for(int i=1;i<=n;i++){
		int now=get(i);
		if(now<=0)continue;
		int l=i,r=n,mid;
		int from=i,to=i;
		while(l<=r){
			mid=(l+r)/2;
			if(node[mid].id-node[i].id<=2*d){
				to=max(to,mid);
				l=mid+1;
			}
			else
			r=mid-1;
		}
		ans+=now;
		add(from,-now);
		add(to+1,now);
//		for(int j=1;j<=n;j++)
//		printf("%d ",get(j));
//		printf("\n");
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 6272
N,M,C = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
T = []

N.times do |i|
  a_i = gets.split.map(&:to_i)
  T << i if a_i.map.with_index {|a, j| a*(b[j])}.inject(:+) + C > 0
end

puts T.size

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

long long n, k, x, y, ans, M=1e9+7, a[2005];
int main() {
	int i, j;
	cin >> n >> k;
	for(i=0; i<n; i++) cin >> a[i];
	x = (k * (k-1) / 2) % M;
	y = (k * (k+1) / 2) % M;
	for(i=0; i<n; i++) {
		for(j=0; j<i; j++) {
			if(a[j] < a[i]) ans = (ans + x) % M;
		}
		for(j=i+1; j<n; j++) {
			if(a[j] < a[i]) ans = (ans + y) % M;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1)%LEN;
}

P dequeue(){
  P R;
  R = Q[head];
  head = (head+1)%LEN;

  return R;
}

int min(int x,int y){
  return x < y ? x : y;
}

int main(){
  int i, q,time = 0,a;
  P u;

  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n+1;

  while(head != tail){
    u = dequeue();
    a = min(q,u.t);
    u.t -= a;
    time += a;
    if(u.t > 0){
      enqueue(u);
    }
    else{
      printf("%s %d\n",u.name,time);
    }
  }

  return 0;
}


Measured memory_bytes: 11860
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>s;
	s[3]='8';
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n,x,y,b=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>x>>y;
    if(x==y)
      b++;
    else
      b=0;
    if(b==3){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

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

signed main() {
  int N;
  cin >> N;
  vec<int> v(N);
  bool existOdd = false;
  rep (i, N) {
    cin >> v[i];
    if (v[i]&1) existOdd = true;
  }

  puts(existOdd ? "first" : "second");

  return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
a = [num % MOD if num >= MOD else num for num in a]

sum_list = [0]
for i in range(n):
	sum_list.append((a[i] + sum_list[i]) % MOD)
# print(sum_list)

ans = 0
for i in range(len(a)):
	ans += a[i] * (sum_list[-1] - sum_list[i + 1])
	ans %= MOD

print(ans)

Measured memory_bytes: 119496
#include<queue>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define rg register
#define il inline
using namespace std;
const int O=100010,inf=127;
struct _{int id,v;}x,_x,y,_y;
il int read ( ){
    rg int o=0,fl=1;
    char ch=getchar();
    while(!isdigit(ch))fl^=ch=='-',ch=getchar();
    while(isdigit(ch))o=o*10+ch-'0',ch=getchar();
    return fl?o:-o;
}
int n=read(),a[O],Q[O];
int main ( ){
    for(int i=1;i<=n;i++)a[i]=read();
    for(int i=1;i<n;i+=2)Q[a[i]]++;
    for(int i=1;i<=O;i++)
	if(Q[i]>x.v)_x.v=x.v,_x.id=x.id,x.v=Q[i],x.id=i;
	else if(Q[i]>_x.v)_x.v=Q[i],_x.id=i;
    memset(Q,0,sizeof(Q));
    for(int i=2;i<=n;i+=2)Q[a[i]]++;
    for(int i=1;i<=O;i++)
	if(Q[i]>y.v)_y.v=y.v,_y.id=y.id,y.v=Q[i],y.id=i;
	else if(Q[i]>_y.v)_y.v=Q[i],_y.id=i;
    if(x.id==y.id){
	int h=x.v+_y.v;
	if(h<_x.v+y.v)h=_x.v+y.v;
	printf("%d",n-h);
    }
    else printf("%d",n-x.v-y.v);
    return 0;
}


Measured memory_bytes: 896
N = int(input())
S = input()

count = 0

for a in [str(a) for a in range(10)]:
    pos_a = S.find(a)
    if pos_a >= 0:
        for b in [str(b) for b in range(10)]:
            pos_b = S.find(b, pos_a+1)
            if pos_b >= 0:
                for c in [str(c) for c in range(10)]:
                    if S.find(c, pos_b+1) >= 0:
                        count += 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
        long long int t,u=0,l;
        string s;
        cin>>s;
            if(s[2]==s[3] && s[4]==s[5])
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
    return 0;
}










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

int main() {
  int N,D;
  int count=0;
  
  cin >> N >> D;
  
  vector<vector<int>> data(N, vector<int>(D));
 
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
    for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
         
        int dis2=0;
      for(int k=0;k<D;k++){
        dis2 += (data.at(i).at(k)-data.at(j).at(k))*(data.at(i).at(k)-data.at(j).at(k));
      }
      for(int m=1;m<400;m++){
          if(dis2 ==m*m){
            count++;
          }
      }
    }
  }
  
  
  cout << count << endl;
            
  

        
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

#define ll long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++);
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/

using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}
map<string, int> memo;


int main() {
	//sort(a.begin(),a.end());
	int a, b;
	cin >> a >> b;
	if (a > b) {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
	}
	else {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
	}
	return 0;
}









Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<ctime>
const  int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int INT = 0x3f3f3f3f;
typedef long long ll;
typedef long double lw;
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define mem(a,x) memset(a,x,sizeof a)
using namespace std;
int w, h;
int mp[30][30];
int sx, sy;
int dir[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
int minn;
int judge(int x, int y)
{
	if (x < 0 || x >= h || y < 0 || y >= w || mp[x][y] == 1 || mp[x][y] == -1)
		return false;
	return true;
}
void dfs(int x, int y, int step)
{
	step++;
	if (step > 10)
	{
		return;
	}
	fo(i, 0, 4)
	{
		int nowx = x + dir[i][0], nowy = y + dir[i][1];
		if (judge(nowx, nowy))
		{
			while (judge(nowx, nowy) && mp[nowx][nowy] != 3)//遇到障碍物停止
			{
				nowx += dir[i][0];
				nowy += dir[i][1];
			}
			if (mp[nowx][nowy] == 1)
			{
				mp[nowx][nowy] = 0;
				dfs(nowx - dir[i][0], nowy - dir[i][1], step);//在障碍物后退一格开始搜
				mp[nowx][nowy] = 1;
			}
			else if (mp[nowx][nowy] == 3)
			{
				minn = min(minn, step);
				return;
			}
		}
	}
}
int main()
{
	while (~scanf("%d%d", &w, &h) && w)
	{
		minn = 11;
		fo(i, 0, h)
			fo(j, 0, w)
		{
			sc(mp[i][j]);
			if (mp[i][j] == 2)
				sx = i, sy = j;
		}
		dfs(sx, sy, 0);
		if (minn != 11)
			cout << minn << endl;
		else
			puts("-1");
		mem(mp, -1);
	}
	return 0;
}



Measured memory_bytes: 3164
// C - To Infinity
// https://atcoder.jp/contests/abc106/tasks/abc106_c
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 1, count = 0;
  string s, t;
  cin >> s;
  cin >> k;
  if (s.size() == 1)
  {
    cout << s << endl;
  }
  else if (s[0] == '1')
  {
    while (s[ans] == '1')
    {
      ans++;
    }
    if (ans >= k)
      cout << 1 << endl;
    else
      cout << s[ans] << endl;
  }
  else
  {
    cout << s[0] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

   string s, t;
   cin >> s >> t;
   if (s.length() < t.length())
      swap(s, t);
   int n = s.length();
   int m = t.length();

   using pii = pair <int, int>;
   vector <vector <int>> dp(n + 1, vector <int> (m + 1, 0));
   vector <vector <pii>> parent(n + 1, vector <pii> (m + 1));
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         if (s[i - 1] == t[j - 1]) {
            parent[i][j] = {i - 1, j - 1};
            dp[i][j] = 1 + dp[i - 1][j - 1];
         } else {
            if (dp[i - 1][j] > dp[i][j - 1]) {
               parent[i][j] = {i - 1, j};
            } else {
               parent[i][j] = {i, j - 1};
            }
            dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
         }
      }
   }

   int x = n, y = m;
   string ans;
   while (x > 0 && y > 0) {
      if (s[x - 1] == t[y - 1])
         ans += s[x - 1];
      auto p = parent[x][y];
      x = p.ff;
      y = p.ss;
   }

   reverse(ans.begin(), ans.end());

   cout << ans << '\n';

   return 0;
}

Measured memory_bytes: 105984
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;

#define ll long long

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	if (a%b == 0)return b;
	return gcd(b, a%b);

}
//最大公約数

ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}
//最小公倍数

int main() {
	
	map<ll, ll> mp;
	ll N, sum = 0, ans = 0;
	vector<ll> V;

	mp[0] = 1;
	V.push_back(0);

	cin >> N;
	
	for (ll i = 0; i < N; i++) {
		ll a;
		cin >> a;
		sum += a;
		mp[sum]++;
		V.push_back(sum);
	}
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	for (ll i = 0; i < V.size(); i++) {
		ans += mp[V[i]] * (mp[V[i]] - 1) / 2;
	}
	cout << ans << endl;

	/*
	0, 1, 4, 0, 2, 4, 2;
	0, 1, 0, 1, 0, 1, 0, 1;
	*/

	return 0;
}

Measured memory_bytes: 14320
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int[] c = new int[8];
        c[0] = 1;c[1] = 2;c[2] = 1;c[3] = 2;c[4] = 1;c[5] = 4;c[6] = 1;c[7] = 4;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int[] b = a.Split(' ').Select(int.Parse).ToArray();
            int[] f = new int[3];
            f[0] = 1000000000;
            for (int i = 0; i < 8; i++)
            {
                int e = 0;
                char[] h = new char[8];
                for (int j = 0; j < 8; j++)
                {
                    int d = j + i;
                    if (d >= 8)
                        d -= 8;
                    int g = b[j] - c[d];
                    if (g < 0)
                        g = 0;
                    e += g;
                    h[j] = (char)(c[d] + '0');
                }
                if (f[0] > e)
                {
                    f[0] = e;
                    f[1] = i;
                    string k = new string(h);
                    f[2] = int.Parse(k);
                }
                if (f[0] == e)
                {
                    string k = new string(h);
                    int l = int.Parse(k);
                    if (f[2] > l)
                    {
                        f[1] = i;
                        f[2] = l;
                    }
                }
            }
            int m = f[1];
            for (int i = 0; i < 8; i++)
            {
                int n = m + i;
                if (n >= 8)
                    n -= 8;
                if (i == 0)
                    Console.Write(c[n]);
                else
                    Console.Write(" " + c[n]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9432
int a[10010]; 
int main(void){ 
  int n,m; 
  scanf("%d%d",&n,&m); 
  for(int i=0;i<m;i++)
    scanf("%d",&a[i]); 
  int s=0; 
  for(int i=0;i<m;i++)
    s+=a[i]; 
  if(s>n){  
    printf("-1\n"); 
  }
  else{ 
    printf("%d\n",n-s); 
  } 
}


Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s == "RRR")
        cout << "3" << endl;
    else if(s == "SRR" || s == "RRS")
        cout << "2" << endl;
    else if(s == "SSS")
        cout << "0" << endl;
    else cout << "1" << endl;
    return 0;
}

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

int main(){
  int n,alice=0,bob=0;
  cin>>n;
  vector<int> a(n);
  for (int i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end(),greater<int>());
  for (int i=0;i<n;i+=2){
    alice+=a.at(i);
  }
  for (int i=1;i<n;i+=2){
    bob+=a.at(i);
  }
  cout<<alice-bob<<endl;
}

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

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int itemCount = int.Parse(Reader.ReadLine());
        this.list = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).OrderBy(a=>a).ToArray();
        long startVal = 0;
        int idx = 0;
        int targetIdx = this.list.Length - 1;
        while (idx < itemCount)
        {
            startVal += this.list[idx];
            bool comp = false;
            long val = startVal;
            if (idx == itemCount - 1)
            {
                break;
            }
            for (int i = idx+1; i < itemCount; i++)
            {
                if (list[i] > val * 2)
                {
                    idx = i;
                    startVal = val;
                    break;
                }
                val += list[i];
                if (i == itemCount - 1)
                {
                    comp = true;
                    targetIdx = idx;
                }
            }
            if (comp)
            {
                break;
            }
        }
        int ans = itemCount - targetIdx;
        Console.WriteLine(ans);
        
    }

    long[] list;




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


6
40 1 30 2 7 20


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 34140
#include "bits/stdc++.h"
using namespace std;

int n,k,x,dist = 0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(x < k - x)
			dist += x * 2;
		else
			dist += abs(k - x) * 2;
	}
	cout<<dist;
	return 0;
}

Measured memory_bytes: 256
//from Kuugo
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
 
int w,h,n,l[N],r[N],f[N],g[N],ans;
 
struct node{int x,y;}a[N];
vector<node> ql,qr;
bool cmp(node a,node b){return a.y<b.y;}
 
void build(int t,int x,int y){
	l[t]=x;r[t]=y;f[t]=0;g[t]=0;
	if (x==y) return;
	build(2*t,x,(x+y)/2);
	build(2*t+1,(x+y)/2+1,y);
}
 
void modify(int t,int x,int y,int z){
	if (x<=l[t]&&y>=r[t]) {f[t]+=z;g[t]+=z;return;};
	if (x<=r[2*t]) modify(2*t,x,y,z);
	if (y>=l[2*t+1]) modify(2*t+1,x,y,z);
	f[t]=max(f[2*t],f[2*t+1])+g[t];
}
 
void solve(){
	sort(a+1,a+n+1,cmp);
	build(1,0,n);modify(1,0,0,w);
	ql.clear();ql.push_back((node){0,-1});ql.push_back((node){0,0});
	qr.clear();qr.push_back((node){w,-1});qr.push_back((node){w,0});
	for (int i=1;i<=n;i++){
		ans=max(ans,(f[1]+a[i].y)*2);
		if (a[i].x<=w/2){
			for (int j=ql.size()-1;j&&ql[j].x<=a[i].x;ql.pop_back(),j--)
				modify(1,ql[j-1].y+1,ql[j].y,ql[j].x-a[i].x);
			ql.push_back((node){a[i].x,i-1});
		}
		else {
			for (int j=qr.size()-1;j&&qr[j].x>=a[i].x;qr.pop_back(),j--)
				modify(1,qr[j-1].y+1,qr[j].y,a[i].x-qr[j].x);
			qr.push_back((node){a[i].x,i-1});
		}
		ql.push_back((node){0,i});
		qr.push_back((node){w,i});
		modify(1,i,i,w-a[i].y);
	}
	ans=max(ans,(f[1]+h)*2);
}
 
int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if (f==-1) puts("!!!!");
	return x*f;
}
 
int main(){
	w=read();h=read();n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	solve();
	for (int i=1;i<=n;i++) swap(a[i].x,a[i].y);
	swap(h,w);solve();
	printf("%d\n",ans);
	return 0;
}

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

int main(){
	int a,b;
	int c,d;

	cin>>a>>b>>c>>d;

	if(a+b > c+d) cout<<"Left\n";
	if(a+b < c+d) cout<<"Right\n";
	if(a+b == c+d) cout<<"Balanced\n";
	
}

	

Measured memory_bytes: 256