akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys

INF = float('inf')


def solve(N: int, K: int, h: "List[int]"):
    return len([x for x in h if x >= K])


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(f'{solve(N, K, h)}')


if __name__ == '__main__':
    main()


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

int main() {
  ll n,m;cin>>n>>m;
  vector<bool> x(n,false),y(n,false);
  vector<ll> a(m),b(m);
  rep(i,m) cin>>a.at(i)>>b.at(i);
  rep(i,m){
    if (a.at(i) == 1){
      x.at(b.at(i)-1) = true;
    }
    if (b.at(i) == n){
      y.at(a.at(i)-1) = true;
    }
  }
  bool ok = false;
  rep(i,n){
    if (x.at(i) && y.at(i)){
      ok = true;
    }
  }
  if (ok) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3456
N = int(input())
ma1 = 0
ma2 = 0
A = list(map(int,input().split()))
A.append(0)
a = sorted(A,reverse = True)

hold = 0
count = 0

for i in a:
  if i == hold:
    count += 1
  else:
    if count > 3 and ma1 == 0:
      ma1 = hold
      ma2 = hold
    elif count > 1:
      if ma1 == 0:
        ma1 = hold
      elif ma2 == 0:
        ma2 = hold
    hold = i
    count = 1
    if ma1 != 0 and ma2 != 0:
      break
    

print(ma1*ma2)
    


Measured memory_bytes: 14672
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p, x = zip(*[map(int, input().split()) for _ in range(m)])

sum_dflt = sum(t)
for i in range(m):
    print(sum_dflt - t[p[i] - 1] + x[i])


Measured memory_bytes: 9176
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

dic = defaultdict(int)

N = int(input())
ans = 0
for i in range(N):
    s = list(input())
    s.sort()
    ans += dic[''.join(s)]
    dic[''.join(s)] += 1

print (ans)

Measured memory_bytes: 18236
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,m,p,a[5010],b[5010],c[5010];
vector<edge>v[100010];
vector<int>V[100010];
bool h[3000];
int d[3000];
void dfs(int x,int k){
	for(edge e:v[x]){
		if(d[e.to]<d[x]+e.cost){
			if(k>=n){
				if(h[x]){
					cout<<-1<<endl;
					exit(0);
				}
			}
			else{
				d[e.to]=d[x]+e.cost;
				dfs(e.to,k+1);
			}	
		}
	}
}
void Dfs(int x){
	h[x]=true;
	for(int i:V[x]){
		if(!h[i])Dfs(i);
	}
}
signed main(){
	cin>>n>>m>>p;
	rep(i,m){
		cin>>a[i]>>b[i]>>c[i];
		c[i]-=p;
		a[i]--,b[i]--;
		v[a[i]].pb({b[i],c[i]});
		V[b[i]].pb(a[i]);
	}
	Dfs(n-1);
	fill(d,d+n,-INF);
	d[0]=0;
	dfs(0,0);
	cout<<max(0ll,d[n-1])<<endl;
	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define MAX_N 100
using namespace std;

bool table[MAX_N][MAX_N];

void make_table(int n, int k) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            table[i][j] = true;
        }
    }

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (!(k--))
                return;
            table[i][j] = false;
        }
    }
}

int main() {
    int n, k;
    cin >> n >> k;
    if ((n - 2) * (n - 1) / 2 < k) {
        cout << -1 << endl;
        return 0;
    }

    make_table(n, k);
    cout << (n - 1) * n / 2 - k << endl;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (table[i][j])
                cout << (i + 1) << ' ' << (j + 1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;
  string s;
  cin >> s;
  int n_red = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') ++n_red;
  }
  int l = 0, r = n-1;
  int ans = 0;
  while (l <= r) {
    while (l < n_red && s[l] == 'R') ++l;
    while (r >= n_red && s[r] == 'W') --r;
    if (l == n_red || r < n_red) break;
    swap(s[l++],s[r--]);
    ++ans;
  }
  l = 0, r = n-1;
  while (l <= r && s[l] == 'R') ++l;
  while (l <= r) {
    if (s[l] == 'R') ++ans;
    ++l;
  }
  cout << ans << endl;
  

}


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

int main(){
  string S;
  cin >> S;
  long long l = S.size()-1;
  //cout << l << endl;
  long long ans = 0;
  for(long long bit = 0; bit < (1<<l) ; bit++){
    vector<long long> a;//+の挿入位置
    long long length = 1;//生成される数字の個数
    for(long long i = 0; i < l; i++){
      if(bit&(1<<i)){
        a.push_back(i+1);
        length++;
      }
    }
    a.push_back(l+1);
    long long flag = 0;
    for(long long i = 0; i < length; i++){
      //lengthが1の時は例外処理
      if(length==1){
        ans += stoll(S);
        break;
      }
      string tmp = "";
      for(long long j = flag; j < a.at(i); j++){
        tmp += S.at(j);
      }
      flag = a.at(i);
      long long num = stoll(tmp);
      ans += num;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <istream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>


using namespace std;


long long n;
long long ans;


void dfs (string s) {
    if (s != "" and stoll(s) > n) return;
    if (
            find(s.begin(), s.end(), '7') != s.end() and
            find(s.begin(), s.end(), '5') != s.end() and
            find(s.begin(), s.end(), '3') != s.end()) {
        ans++;
    }

    vector<char> cs = {'7', '5', '3'};
    for (char c: cs) {
        dfs(s+c);
    }
    return;
}


int main() {
    cin >> n;
    dfs("");
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*
import kotlin.math.absoluteValue
import kotlin.math.max

data class Item(val row: Int, val column: Int, val value: Int)
fun main() {
    val (row, column, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val items = Array(k) {
        val (r, c, v) = readLine()!!.trim().split(' ').map(String::toInt)
        Item(r, c, v)
    }.groupBy { it.row }
    val memo = Array(2){LongArray(column + 1){0L} }
    for (r in 1 .. row) {
        val current = memo[r and 1]
        val prev = memo[(r and 1) xor 1]
        val maxScore = LongArray(4){0L}
        val item = items[r]?.associateBy(Item::column) ?: mapOf()
        for (c in 1 .. column) {
            maxScore[0] = max(maxScore[0], prev[c])
            when(val i = item[c]) {
                null -> Unit
                else -> {
                    for (j in 1 .. 3) {
                        maxScore[4 - j] = max(maxScore[4 - j], maxScore[3 - j] + i.value)
                    }
                }
            }
            current[c] = maxScore.max()!!
        }
    }
    println(memo[row and 1].last())
}

Measured memory_bytes: 71864
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto& y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
auto INDEX = [](auto& x, auto& xs) { return &x - &xs[0]; };
void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = signed long long;
using ull = unsigned long long;

signed main() {
  async_io();
  int a, b, c;
  cin >> a >> b >> c;
  // [0..a] + [a+b % 60 .. $0 + a % 60] ...
  bool seeked[60] = {};
  for (int i = 0, j = 0;;) {
    if (seeked[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (i <= c and c <= i + a) {
      cout << 60 * j + c << endl;
      return 0;
    }
    seeked[i] = true;
    if (i + a + b >= 60) j++;
    i = (i + a + b) % 60;
  }
}

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

string s;
int size = 0, i = 0, all = 0;

list<int> rec(int start){
	list<int> areas;
	int area = 0;
	bool downed = false;
	for(i=start; i<size; i++){
		switch(s[i]){
		case '\\':
			if(downed)
				for(int tmp : rec(i))
					areas.push_back(tmp);
			downed = true;
			break;
		case '_':
			if(!downed) return areas;
			break;
		case '/':
			if(downed){
				area = i - start;
				//cout << "[" << start << "->" << i << "]" << endl;
				for(int tmp : areas)
					area += tmp;
				areas.clear();
				areas.push_back(area);
				downed = false;
			}
			return areas;
		}
	}
	return areas;
}


list<int> rec0(){
	list<int> areas;
	while(i < size){
		for(int area : rec(i))
			areas.push_back(area);
		i++;
	}
	return areas;
}

int main(){
	cin >> s;
	size = static_cast<int>(s.size());
	list<int> list = rec0();
	for(int area : list) all += area;
	cout << all << endl << list.size();
	for(int area : list) cout << ' ' << area;
	cout << endl;
	return 0;
}



Measured memory_bytes: 4716
#include<iostream>
#include<vector>
#include<algorithm>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
int main(){ IOS;
    int n;
    cin>>n;
    vector<int>dp(3,0);
    for(int day=0;day<n;day++){
        vector<int>new_dp(3,0);
        vector<int>c(3);
        for(int k=0;k<3;k++)
        cin>>c[k];
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(i!=j)
                new_dp[j]=max(new_dp[j],dp[i]+c[j]);
            }
        }
        dp=new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]});
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		int ans = 0;
		for(int i = 0; i < 3; i++){
			if(S.charAt(i) == 'R'){
				ans++;
			}
		}
		if(ans == 2 && S.charAt(1) == 'S'){
			ans--;
		}

		System.out.println(ans);

		stdIn.close();
	}
}


Measured memory_bytes: 35328
#include <bits/stdc++.h>
using namespace std;
//解答写し
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>>ans;
  if(n%2==1){
    for(int l=1,r=n-1;l<r;l++,r--){
      ans.emplace_back(l,r);
    }
  }else{
    bool flag=false;
    for(int l=1,r=n-1;l<r;l++,r--){
      if(!flag && r-l<=n/2){
        --r;
        flag=true;
      }
      ans.emplace_back(l,r);
    }
  }
  for(int i=0;i<m;i++){
   printf("%d %d\n",ans[i].first,ans[i].second);
  }
  return 0;
}

Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(a>=b){
    cout << "delicious" << endl;
  }else if(x+a>=b){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
}


Measured memory_bytes: 3548
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    long double v[n];
    for(int i = 0; i < n; i++) cin >> v[i];

    sort(v, v + n);

    long double ans = v[0];
    for(int i = 0; i < n - 1; i++) {
        ans = (ans + v[i + 1]) / 2;
    }

    cout << setprecision(20) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(int argc,char** argv){
  int a,b,t;
  cin >> a >> b >> t;
  cout << b * (t / a)<< endl;
  return 0;
}


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

bool kaibun(string S, int len){
    bool isOK = true;
    for(int i = 0; i <len-1; ++i){
        if(S[i] != S[len-i-1]){
            isOK = false;
            break;
        }
    }
    return isOK;
}

int main() {
    string S;
    cin >> S;
    
    int len = S.length();
    bool isOK = true;

    if(kaibun(S,len)
     &&kaibun(S.substr(0,(len-1)/2),(len-1)/2)
     &&kaibun(S.substr((len+3)/2-1,len),(len-1)/2))cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

signed main(){
	double a, b;
	cin >> a >> b;

	cout << ceil((a + b) / 2) << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
maxA = max(A)
dp = {}
for i in range(1, maxA+1):
    dp[i] = True
for i in range(N):
    if dp[A[i]]:
        tmp = 2 * A[i]
        while maxA >= tmp:
            if dp[tmp]:
                dp[tmp] = False
            tmp += A[i]
counter = 0
t = Counter(A)
for i in range(N):
    if dp[A[i]] and t[A[i]] == 1:
        counter += 1
print(counter)

Measured memory_bytes: 218044
#include<iostream>
using namespace std;
int main(){
	int S;
	int h,m,s;
		
	cin>>S;
	h=S/3600;
	m=(S-h*3600)/60;
	s=S-h*3600-m*60;
	
	cout<<h<<":"<<m<<":"<<s<<"\n";
}
	

Measured memory_bytes: 1164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;
		while ((line = br.readLine()) != null) {
			String[] splited = line.split(" ");
			int value = Integer.parseInt(splited[0]) + Integer.parseInt(splited[1]);
			System.out.println(Integer.toString(value).length());
		}
		br.close();
	}
}

Measured memory_bytes: 17004
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>


typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main()
{
	int n;
	ll y;
	
	int res1000, res5000, res10000;
	
	cin >> n >> y;
	
	res1000 = -1;
	res5000 = -1;
	res10000 = -1;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			int k = n - i - j;
			if (k >= 0) {
				ll total = 1000 * k + 5000 * j + 10000 * i;
				if (total == y) {
					res1000 = k;
					res5000 = j;
					res10000 = i;
					goto LOOP;
				}
			}
			
		}
	}
	LOOP:
	cout << res10000 << " " << res5000 << " " << res1000 << endl;
	return 0;
}

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

n0 = n2 = n4 = 0
for ai in a:
    if ai % 4 == 0:
        n4 += 1
    elif ai % 2 == 0:
        n2 += 1
    else:
        n0 += 1

print('Yes' if n0 <= n4 or n2 == 0 and n0 <= n4 + 1 else 'No')


Measured memory_bytes: 14252
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

const int MaxN = 1e5+5;
typedef long long LL;
LL N;
LL a[MaxN],b[MaxN],c[MaxN];
LL F[MaxN],S[MaxN];
LL ans = 0;

int main(){
	cin >> N;
	for(LL i = 1;i <= N;i++)cin >> a[i];
	for(LL i = 1;i <= N;i++)cin >> b[i];
	for(LL i = 1;i <= N;i++)cin >> c[i];
	sort(a+1,a+N+1);
	sort(b+1,b+N+1);
	sort(c+1,c+N+1);
	for(LL i = 1;i <= N;i++){
		LL q = lower_bound(a+1,a+N+1,b[i])-a;
		if(q > N){
			F[i] = N;
		}
		else{
			F[i] = q-1;
		}
		LL p = upper_bound(c+1,c+N+1,b[i])-c;
		if(p > N){
			S[i] = 0;
		}
		else{
			S[i] = N-p+1;
		}
	}
	//for(LL i = 1;i <= N;i++)cout << F[i] << "   ";
	/*for(LL i=  1;i <= N;i++){
		LL hed = 1,en = N,q = (hed+en)/2;
		while(en > hed){
			if(a[q] < b[i] && a[q+1] >= b[i] && a[q]!= 0|| a[q]<b[i] && a[q+1] == 0 && a[q]!= 0){
				break;
			}
			if(b[i] <= a[1]){q = 0;break;}
			if(a[q] >= b[i]){
				en = q-1;
				q = (hed + en)/2;
			}
			else{
				hed = q+1;
				q = (hed + en)/2;
			}
		}
		F[i] = q;
		//printf("asda\n");
	}
	//for(int i =1; i <= N;i++)printf("%d   ",F[i]);
    for(LL i=  1;i <= N;i++){
		LL hed = 1,en = N,q = (hed+en)/2;
		while(hed <en){
			if(c[q-1] <= b[i] && c[q] > b[i] &&c[q]!=0 || c[q]!=0 && c[q] > b[i] && c[q-1] == 0){
				break;
			}
			if(b[i] >= c[N]){q = N+1;break;}
			if(c[q] > b[i]){
				en = q-1;
				q = (hed + en)/2;
			}
			else{
				hed = q+1;
				q = (hed + en)/2;
			}
		}
		S[i] = N-q+1;
		//printf("asda\n");
	}*/
//	for(int i = 1; i <= N;i++)printf("%d    ",S[i]);
	for(LL i = 1;i <= N;i++){
		ans += F[i]*S[i];
	}
	cout << ans <<endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    int n,in[30];
    while (~scanf("%d", &n)) {
        REP(i,1,n) scanf("%d", &in[i]);

        int ans = 0;
        REP(i,2,n-1)
            if (in[i-1]<in[i] && in[i]<in[i+1])
                ans++;
            else if(in[i-1]>in[i] && in[i]>in[i+1])
                ans++;
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
double e;
int main(){
    int a,b,c,d;
    double e;
    cout << fixed << setprecision(10);
    cin >> a >> b;
    c = a/b;
    d = a%b;
    
   
    cout << c <<" "<< d <<" "<< (double)a/b <<endl;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

int k;
ll a[(int)1e5 + 10];
ll ptr;
void rec(int numsz, ll tmp) {
    if(ptr >= 1e5) return;
    if(!numsz) {
        a[++ptr] = tmp;
        return;
    }
    if(!tmp) {
        for(int i = 1; i < 10; ++i) rec(numsz - 1, tmp * 10 + i);
        return;
    }
    int add = tmp % 10;
    if(add > 0)
        rec(numsz - 1, tmp * 10 + add - 1ll);
    rec(numsz - 1, tmp * 10 + add);
    if(add < 9)
        rec(numsz - 1, tmp * 10 + add + 1ll);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin >> k;
    for(int i = 1; i < 11; ++i) rec(i, 0);
    sort(a + 1, a + 100001);
    cout << a[k];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

ll solve(ll h,ll w)
{
	ll s1,s2,s3;
	ll mn = (1LL << 60);
	srep(i,1,h){
		s1 = i*w;
		s2 = (h-i)*(w/2);
		s3 = (h-i)*(w-w/2);
		cmn(mn,max({s1,s2,s3}) - min({s1,s2,s3}));
		s2 = w*((h-i)/2);
		s3 = w*((h-i)-(h-i)/2);
		cmn(mn,max({s1,s2,s3}) - min({s1,s2,s3}));
	}
	return mn;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin >> h >> w;
	cout << min(solve(h,w),solve(w,h)) << "\n";
    return 0;
}


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

int main() {
	string s; cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		s.erase(s.begin() + s.size() - 1);
		if (s.size() % 2 != 0)continue;
		if (s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size() / 2)) {
			cout << s.size() << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int rect = 0, hishi = 0;
	char k;
	
	int a, b, c;
	while(cin >> a >> k >> b >> k >> c)
	{
		if(pow(a, 2.0) + pow(b, 2.0) == pow(c, 2.0))
			rect++;
		if(a == b)
			hishi++;
	}

	cout << rect << endl << hishi << endl;
}

Measured memory_bytes: 0
def chmax(a, b):
    if a == 'X':
        a = b
    elif len(a) < len(b):
        a = b
    elif len(a) == len(a):
        if a < b:
            a = b
    return a

match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = ['X' for _ in range(10010)]

N, M = map(int, input().split())
A = list(map(int, input().split()))

dp[0] = ''

for i in range(N-1):
    if dp[i] == 'X':
        continue
    for a in A:
        dp[i+match[a-1]] = chmax(dp[i+match[a-1]], dp[i] + str(a))

print(dp[N])

Measured memory_bytes: 30196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    vector<set<int>> v(n);
    rep(i, 0, n) {
        int k;
        cin >> k;
        rep(j, 0, k) {
            int a;
            cin >> a;
            v[i].insert(a);
        }
    }

    int ans = 0;
    rep(i, 1, m + 1) {
        bool flag = true;
        rep(j, 0, n) {
            if (!v[j].count(i)) {
                flag = false;
            }
        }
        if (flag) ans++;
    }

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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int):
    print(N*(N+1)//2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


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

long long  solve_func(long long H){
    if (H==1){
        return 1;
    }else{
        return 1 + 2 * solve_func(H/2);
    }
}

void solve(long long H){
    printf("%lld\n",solve_func(H));
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    solve(H);
    return 0;
}


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

int main(){
    int N; cin >> N;
    int H_max = 0, ans = 0;
    for(int i = 0; i < N; i++){
        int H; cin >> H;
        H_max = max(H_max, H);
        if(H >= H_max) ans++;
    }

    cout << ans << endl;    
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;
ll N, M; 

vector<vector<ll > > warshall(vector<vector<ll > > GRAPH){
    //中継点に関して
    for(ll reley = 0; reley < N; reley++){
        for(ll from = 0; from < N; from++){
            for(ll to = 0; to < N; to++){
                //中継した方がコストがかからないか否か
                //小さい順からコストが自明に決まっていく
                GRAPH[from][to] = min(GRAPH[from][to], GRAPH[from][reley] + GRAPH[reley][to]);
            }
        }
    }

    return GRAPH;
}

int main(){

    //頂点数と辺の数
    ll L;
    cin >> N >> M >> L;

    vector<vector<ll > > G;
    //L以下の頂点に辺を貼ったグラフ
    vector<vector<ll > > G2;
    G.assign(N, vector<ll >());
    G2.assign(N, vector<ll >());
    
    //初期化
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < N; j++){
            G[i].push_back(INF);
            G2[i].push_back(INF);
        }       
    }
    //cout << G.size() << " " << G[0].size() << endl;
    //辺入力
    for(ll i = 0; i < M; i++){   
        ll u, v, w;
        cin >> u >> v >> w;
        //適宜揃える
        u--;
        v--;
        //有向か無向かでコメントアウト　多重辺も防止
        G[u][v] = min(G[u][v], w);
        G[v][u] = min(G[v][u], w);
    }

    //ワーシャルフロイド実行
    G = warshall(G);

    //もう一度グラフを作る
    //L以下の燃料でたどり着ける町同士をつなぐ(燃料を補給せずに行ける町まで)
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < N; j++){
            if(G[i][j] <= L ){
                G2[i][j] = 1;
            }
        }
    }

    //ワーシャルフロイド実行
    G2 = warshall(G2);

    ll Q; cin >> Q;

    //確認
    vector<ll > ans;
    for(ll i = 0; i < Q; i++){
        ll s, t; cin >> s >> t;
        s--; t--;
        if(G2[s][t] == INF){
            cout << -1 << endl;
        }else{
            //最初の町へは補給無しで行けるので
            cout << G2[s][t] - 1 << endl;
        }
    }

}

Measured memory_bytes: 3712
#include <stdio.h>
int main ()
{
    char a[100000];
    int i,n,count=1;
    scanf("%d",&n);
    scanf("%s",a);
    for(i=0;i<n-1;i++)
    {
        if(a[i]!=a[i+1])
            count++;
    }
    printf("%d\n",count);

}


Measured memory_bytes: 256
# h,n,*a=map(int,open(0).read().split())

# h = int(input())
h, k = [int(x) for x in input().split()]
# k = int(input())

# ヨコ
m = [int(x) for x in input().split()]

# タテ
# m = [int(input()) for _ in range(N)]

if h <= sum(m):
  print('Yes')

else:
  print('No')

Measured memory_bytes: 13836
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
#include <map>
using namespace std;
long long INF = 1000000009;
map<int, int> mp;
int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	sort(p.rbegin(), p.rend());
	p.at(0) /= 2;
	int sum = 0;
	for (int i = 0; i < n; i++) sum += p.at(i);
	cout << sum << endl;
}

Measured memory_bytes: 256
M,D=map(int,input().split())
ans=0
try:
  for d in range(22,D+1):
    for m in range(1,M+1):
      D1=d//10
      D2=d-10*D1
      if D1*D2==m and D1>=2 and D2>=2:
        ans+=1
except:
  pass
print(ans)   

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int LL
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

const int MXN = 205;
LL in[MXN];
bool kto[MXN];

void ksoruj(vector<LL> &B, LL x)
  {
  sort(ALL(B));
  reverse(ALL(B));
  for(auto &i: B)
    {
    if((x ^ i) < x)x ^= i;
    }
  if(x == 0)return;
  for(auto &i: B)
    {
    if((i ^ x) < i)i ^= x;
    }
  B.PB(x);
  }
bool uzyskam(vector<LL> &B, LL x)
  {
  sort(ALL(B));
  reverse(ALL(B));
  for(auto &i: B)
    {
    if((x ^ i) < x)x ^= i;
    }
  if(x == 0)return 1;
  return 0;
  }

void solve()
  {
  int n;
  cin >> n;
  FOR(i, 1, n)
    {
    cin >> in[i];
    }
  FOR(i, 1, n)
    {
    char c;
    cin >> c;
    kto[i] = c - '0';
    }
  vector<LL> mam;
  FORD(i, n, 1)
    {
//    debug(i, mam);
    if(kto[i] == 0)ksoruj(mam, in[i]);
    else
      {
      if(uzyskam(mam, in[i]) == 0){cout << "1" << endl;return;}
      }
    }

  cout << "0" << endl;
  }
int32_t main()
  {
  ios_base::sync_with_stdio(0); 
  int z;
  cin >> z;
  while(z--)solve();
  }


Measured memory_bytes: 3584
#https://atcoder.jp/contests/abc156/tasks/abc156_b
N,K = map(int,input().split())
q, mod = divmod(N,K)
mod_list = [mod]
while True:
    q , mod =divmod(q,K)
    mod_list.append(mod)
    #print(q)
    #print(mod)
    if q <=0 :
        break
if mod_list[-1] == 0:
    result = len(mod_list) - 1
else:
    result =len(mod_list)
print(result)

Measured memory_bytes: 9188
N = float(input())

if N==0:
  print(0)
else:
  q = N
  r_s = []

  while q!=1:
    hoge = (q-1) / (-2)
    if hoge.is_integer():
      r = int(1)
      q = float(hoge)
    else:
      r = int(0)
      q = float(q/(-2))
  
    r_s.append(r)
  r_s.append(1)
  r_s = r_s[::-1]

  for i in range(len(r_s)):
    print(r_s[i], end="")

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

int main()
{

    int h,w;

    while(cin>>h>>w)
    {

        if(h==0)return 0;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }

}


Measured memory_bytes: 3104
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  // tmp0 = input[0].split(" ")
  // N = Number(tmp0[0])
  // M = Number(tmp0[1])
  a = Number(input[0])
  b = Number(input[1])
  c = Number(input[2])
  d = Number(input[3])
  e = Number(input[4])
  k = Number(input[5])

  if(((b-a) > k) || ((c-a) > k) || ((d-a) > k) || ((e-a) > k)
  || ((c-b) > k) || ((d-b) > k) || ((e-b) > k)
  || ((d-c) > k) || ((e-c) > k)
  || ((e-d) > k))
  {
    console.log(":(")
  }else{
    console.log("Yay!")
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("4 30\n6 18\n2 5\n3 10\n7 9\n")

Measured memory_bytes: 22076
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define se second
#define fi first
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define y1 y12313312312
#define endl '\n'
#define gcd __gcd
//#define int ll

using namespace std;
//using namespace __gnu_pbds;

//template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e6 + 40, T = 4 * N, inf = 1e9 + 7;

int n, m, f, r, l, e, w, o, z, test, id, x, y;
int a[N];
bool ch, d[N];

void freop()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void boos()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

main()
{
    //freop();
    boos();
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    d[0] = 0;
    for (int i = 1; i <= m; i++)
    {
        ch = 0;
        for (int j = 0; j < n; j++)
        {
            if (i - a[j] < 0) continue;
            ch |= !d[i - a[j]];
        }
        if (ch) d[i] = 1;
    }
    if (d[m] == 1) cout << "First";
    else cout << "Second";
}




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

int main(){
  int N;
  cin>>N;
  multiset<int64_t> S;
  vector<int64_t> A(N);
  for(int i=0;i<N;++i){
    cin>>A[i];
  }

  for(int i=0;i<N;++i){
    if(S.empty()){
      S.insert(A[i]);
    }
    else{
      auto iter=S.begin();
      int64_t B=*iter;
      if(B>=A[i]){
        S.insert(A[i]);
      }
      else{
        auto iter=S.lower_bound(A[i]);
        --iter;
        S.erase(iter);
        S.insert(A[i]);
      }
    }
  }

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

Measured memory_bytes: 5760
/**
*	Author: Apoorva Mittal
*	
**/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define nl   "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i >= b; i--)
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define init(i, k) memset(i, k, sizeof i)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define inp(a) rep(i,0,a.size()) cin>>a[i]; 
#define out(a) rep(i,0,a.size()) cout<<a[i]<<" "; \
                cout<<endl;
#define out2d(a)    \
    rep(i,0,a.size())\
    {rep(j,0,a[0].size())\
    cout<<a[i][j]<<" ";\
    cout<<endl;}      
#define flush			fflush(stdout);
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define precise(x) 		cout<<fixed<<showpoint<<setprecision(x);
#define setbit(x)       __builtin_popcountll(x)
#define gcd(a,b)        __gcd(a,b)
#define deb(x) cout<<#x<<" "<<x<<endl;
#define Y				"YES"
#define N 				"NO"
const int mod = 1e9 + 7;
struct HASH{ 
  // unordered_map<pair<int,int>,int,HASH>m;
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
int lcm(int a, int b) { return (a * (b / __gcd(a, b))); }
int ncr(int n,int r){int res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
// ====== Useful functions begin ======
inline int add(int a,int b) {return ((a%mod)+(b%mod))%mod;}
inline int sub(int a,int b) {return ((a%mod)-(b%mod)+mod)%mod;}
inline int mul(int a,int b) {return ((a%mod)*(b%mod))%mod;}
// ====== Useful functions end ======
int pwr(int x,int n){
    if(!n) return 1;
    if(n&1) return mul(x, pwr(mul(x,x),(n-1)/2));
    else return pwr(mul(x,x),n/2);
}
int modinv(int n){ 
    return pwr(n,mod - 2); 
}
const int inf = 1e18;
const int maxn = 1e3 + 5;

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

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


void solve()
{
   int m,n; cin>>m>>n;
   int sum=0;
   rep(i,0,n)
   {
       int a;cin>>a; sum+=a;
   }
   if(sum>m)
   cout<<-1<<endl;
   else cout<<(m-sum)<<endl;

}
signed main()
{	
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

	speed;
	int t=1;
	// cin>>t;
	
	for(int tt=1;tt<=t;tt++)
	{
		// cout<<"Case #"<<tt<<": ";
		solve();
	}
}


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

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

    vector<uint64_t> a(3 * n);
    for (auto i = 0; i < 3 * n; i++) cin >> a[i];

    sort(a.begin(), a.end(), greater<>());
    uint64_t sum = 0;
    for (auto i = 1; i < 2 * n; i += 2) {
        sum += a[i];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void){
	int n,m;
	cin>>n>>m;
	int cards[200];
	for(int i=0;i<2*n;++i) cards[i]=i+1;
	for(int i=0,k;i<m;++i){
		cin>>k;
		if(k){//
			int A[200],B[200];
			for(int j=0;j<k;++j){
				A[j]=cards[j];
			}
			for(int j=k;j<2*n;++j){
				B[j-k]=cards[j];
			}
			for(int j=0;j<2*n-k;++j){
				cards[j]=B[j];
			}
			for(int j=2*n-k;j<2*n;++j){
				cards[j]=A[j-(2*n-k)];
			}
		}else{//リフル
			int A[200],B[200];
			for(int j=0;j<n;++j){
				A[j]=cards[j];
			}
			for(int j=n;j<2*n;++j){
				B[j-n]=cards[j];
			}
			for(int j=0;j<2*n;++j){
				if(j%2){//odd
					cards[j]=B[j/2];
				}else{//even
					cards[j]=A[j/2];
				}
			}
		}
	}
	for(int i=0;i<2*n;++i) cout<<cards[i]<<endl;
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream in = System.in;
        OutputStream out = System.out;
        FastScanner fs = new FastScanner(in);
        PrintWriter pw = new PrintWriter(out);
        StringBuilder S = new StringBuilder(fs.next());
        int red = 0, blue = 0;
        for(int i = 0; i < S.length(); i++) {
            if(S.charAt(i) == '0') red++;
            else blue++;
        }
        pw.println((red < blue ? red : blue) * 2);
        pw.close();
    }
}

class FastScanner {

    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
 
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
 
    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                    throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }
 
    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    }
 
}


Measured memory_bytes: 23252
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
int main(){
	int D,G;
	int p[10],c[10];
	int questionmin=9999;
	scan(D);scan(G);
	rep(i,D){
		scan(p[i]);scan(c[i]);
	}
	rep(mask,(1<<D)){
		int pointsum=0,questionnum=0,nokorimax=-1;
		rep(i,D){
			if(mask>>i&1){
				pointsum+=100*(i+1)*p[i]+c[i];
				questionnum+=p[i];
			}
			else{
				nokorimax=i;
			}
		}
		if(pointsum<G){
			int nokoriquestion=(G-pointsum-1)/(100*(nokorimax+1))+1;
			if(nokoriquestion<p[nokorimax]){
				questionnum+=nokoriquestion;
				pointsum+=nokoriquestion*(100*(nokorimax+1));
			}
			else{
				continue;
			}
		}
		if(pointsum>=G&&questionnum<questionmin){
			questionmin=questionnum;
		}
	}
	prin(questionmin);
	return 0;
}


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

int main(){
	int N, M, city1, city2;
	cin >> N >> M;
	int map[N];
	for (int i=0;i<N;i++){
		map[i] = 0;
	}
	for (int i=0;i<M;i++){
		cin >> city1 >> city2;
		map[city1-1]++;
		map[city2-1]++;
	}
	for (int i =0;i<N;i++){
		cout << map[i] << endl;
	}

}

Measured memory_bytes: 256
/*************************
author : coldbeer
2019-05-21 12:12:02 PM IST
*************************/
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

class dsu{
	vector<int> parent,rnk;
	int component;
	public:
	void init(int n){
		parent.assign(n + 1,-1);
		rnk.assign(n + 1,0);
		component = n;
	}

	void make_set(int x){
		parent[x] = x;
	}

	int find_set(int x){
		if(x != parent[x]){
			return (parent[x] = find_set(parent[x]));
		}
		return parent[x];
	}

	void unite(int x,int y){
		int a = find_set(x);
		int b = find_set(y);
		if(a != b){
			component--;
			if(rnk[a] < rnk[b]){
				parent[a] = b;
				rnk[b]++;
			}
			else{
				parent[b] = a;
				rnk[a]++;
			}
		}
	}

	int getRank(int i){
		return rnk[i];
	}

	int getComp(){
		return component;
	}
};

dsu md;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,m; cin >> n >> m;

	md.init(n);
	for(int i = 1;i < n + 1;i++)
		md.make_set(i);

	while(m--){
		int x,y,z; cin >> x >> y >> z;
		md.unite(x,y);
	}

	cout << md.getComp() << endl;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
a = list(map(int, input().split(" ")))

c = [0, 0, 0, 0, 0, 0, 0, 0, 0]

for rate in a:
    if (rate >= 1) and (400 > rate):
        c[0] += 1
    elif (rate >= 400) and (800 > rate):
        c[1] += 1
    elif (rate >= 800) and (1200 > rate):
        c[2] += 1
    elif (rate >= 1200) and (1600 > rate):
        c[3] += 1
    elif (rate >= 1600) and (2000 > rate):
        c[4] += 1
    elif (rate >= 2000) and (2400 > rate):
        c[5] += 1
    elif (rate >= 2400) and (2800 > rate):
        c[6] += 1
    elif (rate >= 2800) and (3200 > rate):
        c[7] += 1
    else:
        c[8] += 1
        
color_rigid = len([i for i, e in enumerate(c[:8]) if e != 0])

print ("%d %d"%(max(1, color_rigid), color_rigid + c[8]))

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

int main() {
    string s;
    long K;
    cin>>s;
    cin>>K;
    for(long i=0;i<s.size();++i){
        if((K >= 'z' - s[i] + 1) & (s[i]!='a')){
            K -= 'z' - s[i] + 1;
            s[i] = 'a';
        }
        if(K==0)break;
    }
    if(K>0){
        s[s.size()-1] += K % 26;
        while(s[s.size()-1] > 'z'){
            s[s.size()-1] -= 'a';
        }
    }
    cout<<s<<endl;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

 Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key)
    {
      if(k < u->key) u=u->left;
      else u=u->right;
    }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y; 
}

void treeDelete(Node z){
  Node y; 
  Node x; 
  if( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
  if( y->left != NIL ) x = y->left;
  else x = y->right;
  if( x != NIL ) x->parent = y->parent;
  if( y->parent == NIL ) root = x;
  else if( y == y->parent->left ) y->parent->left = x;
  else y->parent->right = x;
  if( y != z ) z->key = y->key;
  }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x; 
    if( z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z; 
  else y->right = z;  
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL) {
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x, t;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      if(com[0]=='f')
	{
	  scanf("%d",&x);
	  Node a=treeSearch(root,x);
	  if(a!=NIL) printf("yes\n");
	  else printf("no\n");
	}
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }
  }

  return 0;
}



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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)


int main(void)
{
	ll n;
	cin >> n;
	vector<ll> vs(n);
	rep(i, n) {
		cin >> vs[i];
	}
	vector<ll> ans;
	while (vs.size() > 0) {
		vector<P> os;
		rep(i, vs.size()) {
			os.emplace_back(vs[i], vs[i] - (i + 1));
		}
		int t = -1;
		rep(i, vs.size()) {
			auto e = os[i];
			if (e.second == 0) {
				t = i;
			}
		}
		if (t < 0) {
			cout << -1 << endl;
			return 0;
		}
		else {
			ans.push_back(vs[t]);
			vs.erase(vs.begin() + t);
		}
	}
	for (auto e = ans.rbegin(); e != ans.rend(); e++) {
		cout << *e << endl;
	}
	return 0;
}


Measured memory_bytes: 256