akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint x; std::cin >> x;
  lint ans = 0;
  lint y = x / 11;
  ans += y * 2;
  x -= y * 11;
  for (int z : {6,5}) {
    if (x <= 0) break;
    x -= z;
    // debug(x);
    ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(void){
    int n,m; cin>>n>>m;
    vector <int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
    }
    struct UnionFind tree(n);
    for(int i=0;i<m;i++){
        int a,b; cin>>a>>b;
        a--; b--;
        tree.unite(a,b);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(p[i] == i) ans++;
        else {
            if(tree.same(p[i], i)) ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
int N,A,B,C;
vector<int> L;
int dfs(int i,int a, int b, int c){
    if(i == N){
        if(a == 0 || b == 0 || c == 0){
            return INF;
        }
        return abs(a-A)+abs(b-B)+abs(c-C)-30;
    }
    int res0 = dfs(i+1,a,b,c) ;
    int res1 = dfs(i+1,a+L[i],b,c) + 10;
    int res2 = dfs(i+1,a,b+L[i],c) + 10;
    int res3 = dfs(i+1,a,b,c+L[i]) + 10;
    return min(min(min(res0,res1),res2),res3);

}


int main(){
cin >> N >> A >> B >> C;
L.resize(N);
for(int i = 0;i<N;i++){
    cin >> L[i];
}


cout << dfs(0,0,0,0) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		scanner.close();
		if(A <= 9 && B <= 9) {
			System.out.println(A*B);
		}else {
			System.out.println(-1);
        }
	}
}

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

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)


int main() {
	string a, b;
	cin >> a >> b;
	ff(i, 0, b.size()) {
		char t=b[i];
		a += t;
	}
	int x = stoi(a);
	//cout << x << endl;
	ff(i, 1, sqrt(x)+1) {
		if (x == i*i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, ans;
std::vector<std::pair<int, int>>red, blue;
std::vector<bool>flag;

int main()
{
	in >> N;
	red.resize(N), blue.resize(N), flag.resize(N);
	rep(i, N) in >> red[i].first >> red[i].second;
	rep(i, N) in >> blue[i].first >> blue[i].second;
	std::sort(red.begin(), red.end());
	std::sort(blue.begin(), blue.end());
	rep(i, N)
	{
		int maxY = -114514, it = -1;
		rep(j, N)
		{
			if (red[j].first >= blue[i].first) break;
			if (!flag[j] && maxY < red[j].second && red[j].second < blue[i].second)
			{
				maxY = red[j].second;
				it = j;
			}
		}
		if (it != -1)
		{
			++ans;
			flag[it] = true;
		}
	}
	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
require 'prime'
n=gets.to_i
t=n*(n+1)/2
e=t.prime_division[0][0]
g=t/e
s=g*(e-1)
q=[*1..n]
m=[]
until q.empty?
	w=0
	m<<[]
	(q.size-1).downto(0){|i|
		if w+q[i]<=g
			w+=q[i]
			m.last<<q[i]
			q.delete_at(i)
			break if w==g
		end
	}
	# assert
	raise("w != g") if w != g
end
x=0
r=""
m.size.times{|i|
	m[i].each{|k|
		(i+1...m.size).each{|j|
			m[j].each{|l|
				x+=1
				r<<"#{k} #{l}\n"
			}
		}
	}
}
puts x
puts r

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

using namespace std;

long long int n, p, a;
bool ans;

int main()
{
	cin >> n >> p;
	for (int i = 0; i< n; i++)
    {
		cin >> a;
		if (a % 2 == 1)
			ans = true;
	}
	if (!ans)
    {
		if (p == 0)
			cout << (long long int) (pow(2, n)) << endl;
		else
			cout << 0 << endl;
		return 0;
	}
	cout << (long long int) (pow(2, n-1)) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int N, M;
        cin >> N >> M;
        vector<int> A(N);
        for (int i = 0; i < N; i++)
        {
                cin >> A[i];
        }

        map<int, int> m;
        vector<int> sum(N + 1);
        sum[0] = 0;
        for (int i = 0; i < N; i++)
        {
                sum[i + 1] = (sum[i] + A[i]) % M;
        }

        ll ans = 0;
        for (int i = 0; i < sum.size(); i++)
        {
                ans += m[sum[i]];
                m[sum[i]]++;
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 3968
import java.util.*;

public class Main{

	public static void main(String[] args){
    	Scanner sc=new Scanner(System.in);
      
      	String input=sc.next();
      
      	String[] valueset=input.split("");
      
      	if(valueset[1].equals(valueset[2]) && (valueset[0].equals(valueset[1]) || valueset[1].equals(valueset[3]))){
        	System.out.println("Yes");
        }else{
          	System.out.println("No");
        }
    }	
  
}

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

void countsort(vector<int> &a,vector<int> &b,int maxi){
    vector<int> c(maxi + 1,0);
    int i;
    for(i = 0;i < (int)a.size();i++){
        c[a[i]]++;
    }
    for(i = 1;i <= maxi;i++){
        c[i] = c[i] + c[i - 1];
    }
    for(i = a.size() - 1;0<= i;i--){
        b[c[a[i]] - 1] = a[i];
        c[a[i]]--;
    }
}

int main(){
    int n,maxi = 0;
    cin >> n;
    vector<int>a(n),b(n);
    
    for(int i= 0;i < n;i++){
        cin >> a[i];
        maxi = max(maxi,a[i]);
    }
    
    countsort(a,b,maxi);
    
    for(int i= 0;i < n;i++){
        if(i > 0)cout << " ";
        cout << b[i];
    }
    cout << endl;
}


Measured memory_bytes: 18308
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = Array(N) {readLine()!!.toInt()}
    val (m0,m1) = A.sortedDescending().take(2)
    val list = mutableListOf<Int>()
    for (a in A)
        list.add(if(m0 != a) m0 else m1)
    println(list.joinToString("\n"))
}


Measured memory_bytes: 62784
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

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

    vector<vector<int>> b(2*k,vector<int>(2*k,0));
    vector<vector<int>> w(2*k,vector<int>(2*k,0));

    rep(i,n)
    {
        int x,y;
        string c;
        cin >> x >> y >> c;
        if(c=="W")
            w[y%(2*k)][x%(2*k)]++;
        else
            b[y%(2*k)][x%(2*k)]++;
    }

    vector<vector<int>> ab(2*k+1,vector<int>(2*k+1,0));
    vector<vector<int>> aw(2*k+1,vector<int>(2*k+1,0));

    rep(i,2*k)
        rep(j,2*k)
        {
            ab[i+1][j+1] = b[i][j] + ab[i][j+1] + ab[i+1][j] - ab[i][j];
            aw[i+1][j+1] = w[i][j] + aw[i][j+1] + aw[i+1][j] - aw[i][j];
        }

    int max_cnt = -1;

    rep(i,k)
        rep(j,k)
        {
            int bz0 = ab[k+i][2*k] - ab[i][2*k];
            int bz1 = ab[2*k][k+j] - ab[2*k][j];
            int bz2 = ab[k+i][k+j] - ab[i][k+j] - ab[k+i][j] + ab[i][j];
            int wz0 = aw[k+i][2*k] - aw[i][2*k];
            int wz1 = aw[2*k][k+j] - aw[2*k][j];
            int wz2 = aw[k+i][k+j] - aw[i][k+j] - aw[k+i][j] + aw[i][j];

            //printf("i=%d j=%d bz=%d,%d,%d wz=%d,%d,%d\n", i,j,bz0,bz1,bz2,wz0,wz1,wz2);

            int tmp_cnt = (ab[2*k][2*k]-bz0-bz1+2*bz2) + (wz0+wz1-2*wz2);
            //printf("ab[2*k][2*k]-bz0-bz1+2*bz2=%d wz0+wz1-2*wz2=%d tmp_cnt=%d\n", ab[2*k][2*k]-bz0-bz1+2*bz2,wz0+wz1-2*wz2,tmp_cnt);
            max_cnt = max(max_cnt,tmp_cnt);

            tmp_cnt = (aw[2*k][2*k]-wz0-wz1+2*wz2) + (bz0+bz1-2*bz2);
            //printf("aw[2*k][2*k]-wz0-wz1+2*wz2=%d bz0+bz1-2*bz2=%d tmp_cnt=%d\n", aw[2*k][2*k]-wz0-wz1+2*wz2,bz0+bz1-2*bz2,tmp_cnt);
            max_cnt = max(max_cnt,tmp_cnt);
        }

    cout << max_cnt << endl;
    return 0;
}

Measured memory_bytes: 63104
#include<stdio.h>

int main(void) {
   int a, b, c;
   int tmp;
   scanf("%d %d %d",&a, &b, &c);

   tmp = b;
   b = a;
   a = c;
   c = tmp;

   printf("%d %d %d\n", a, b, c);

   return 0;
}


Measured memory_bytes: 1688
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int[] dx = {0, 0, -1, 1};
        int[] dy = {-1, 1, 0, 0};
        char[] dirc = {'^', 'v', '<', '>'};

        int dataNum = sc.nextInt();
        while(dataNum-->0){
            int h = sc.nextInt(), w = sc.nextInt();
            char[][] map = new char[h][w];

            int x = 0, y = 0, dir = 0;
            for(int i=0; i<h; i++){
                char[] line = sc.next().toCharArray();
                for(int j=0; j<w; j++){
                    map[i][j] = line[j];
                    if(map[i][j]=='^'){ x = j; y = i; dir = 0;}
                    if(map[i][j]=='v'){ x = j; y = i; dir = 1;}
                    if(map[i][j]=='<'){ x = j; y = i; dir = 2;}
                    if(map[i][j]=='>'){ x = j; y = i; dir = 3;}
                }
            }

            int n = sc.nextInt();
            char[] command = sc.next().toCharArray();
            for(int i=0; i<n; i++){
                if(command[i]=='U') dir = 0;
                if(command[i]=='D') dir = 1;
                if(command[i]=='L') dir = 2;
                if(command[i]=='R') dir = 3;
                if(command[i]!='S'){
                    map[y][x] = dirc[dir];
                    int nx = x + dx[dir], ny = y + dy[dir];
                    if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
                    if(map[ny][nx]=='.'){
                        map[ny][nx] = dirc[dir];
                        map[y][x] = '.';
                        x = nx; y = ny;
                    }
                }else{
                    int nx = x, ny = y;
                    while(true){
                        nx += dx[dir]; ny += dy[dir];
                        if(nx<0 || nx>=w || ny<0 || ny>=h || map[ny][nx]=='#') break;
                        if(map[ny][nx]=='*'){
                            map[ny][nx] = '.';
                            break;
                        }
                    }
                }                
            }
            for(int i=0; i<h; i++) System.out.println(String.valueOf(map[i]));
            if(dataNum!=0) System.out.println();
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 27892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

const int MAX=410;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,C; cin >> N >> C;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    vector<vector<ll>> pows(MAX,vector<ll>(C+1,1));
    pows[0][0]=0;
    rep(i,MAX) rep2(j,1,C+1) pows[i][j]=pows[i][j-1]*i%MOD;
    rep(j,C+1) rep2(i,1,MAX) pows[i][j]=(pows[i][j]+pows[i-1][j])%MOD;
    vector<vector<ll>> dp(N+1,vector<ll>(C+1,0));
    dp[0][0]=1;
    rep(i,N){
        rep(j,C+1){
            rep(k,j+1){
                dp[i+1][j]=(dp[i+1][j]+dp[i][k]*((pows[B[i]][j-k]-pows[A[i]-1][j-k]+MOD)%MOD)%MOD)%MOD;
            }
        }
    }
    cout << dp[N][C] << endl;
}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }else if(s == "Rainy"){
        cout << "Sunny" << endl;
    }
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  rep(i, n) cin >> l[i];

  sort(l.begin(), l.end(), greater<int>());

  cout << accumulate(l.begin(), l.begin()+k, 0) << endl;

  return 0;
}


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

struct job{
	int a, b;
};

int cmp(const void* a, const void* b){
	return (*(struct job**)a)->b - (*(struct job**)b)->b;
}

int main(void){
	int n;
	struct job **jobs;
	scanf("%d", &n);
	jobs = malloc(sizeof(struct job*) * n);
	for(int i = 0; i < n; i++){
		jobs[i] = malloc(sizeof(struct job));
		scanf("%d %d", &jobs[i]->a, &jobs[i]->b);
	}
	qsort(jobs, n, sizeof(struct job), cmp);
	int time = 0;
	int f = 0;
	for(int i = 0; i < n; i++){
		time += jobs[i]->a;
		if(time > jobs[i]->b){
			f = 1;
			break;
		}
	}
	if(f)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}


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

#define int long long
#define double long double

using namespace std;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e9;

typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef tuple<int,int,int,int> F;

signed main() {

	int r, c, n;
	cin >> c >> r >> n;


	vector<P> v;

	auto calc = [&](int x, int y){
		if(y == 0) return x + INF;
		if(x == c) return c + y + INF * 2;
		if(y == r) return c + r + (c - x) + INF * 3;
		if(x == 0) return c + r + c + (r - y) + INF * 4;
		return -INF;
	};
	
	REP(i, 1, n+1){
		int x0, y0, x1, y1;
		cin >> x0 >> y0 >> x1 >> y1;
		int cnt = 0;
		if((x0 == 0 || x0 == c) || (y0 == 0 || y0 == r)) cnt++;
		if((x1 == 0 || x1 == c) || (y1 == 0 || y1 == r)) cnt++;

		if(cnt == 2){
			int d0 = calc(x0, y0);
			int d1 = calc(x1, y1);
			if(d0 > d1) swap(d0, d1);
			v.push_back(P(d0, +i));
			v.push_back(P(d1, -i));
		}
	}

	sort(all(v));

	stack<int> st;
	each(p, v){
		int id = p.second;

		if(id >= 1){
			st.push(id);
		}else{
			if(st.top() != -id){
				cout << "NO" << endl;
				return 0;
			}
			st.pop();
		}

	}
	assert(st.size() == 0);
	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 6384
#include <iostream>
using namespace std;
int A, B, C, D;
int main() {
	cin >> A >> B >> C >> D;
    
  	if (A + B < C + D) {
      cout << "Right" <<endl;
    }
  	else if (A + B == C + D) {
      cout << "Balanced" << endl;
    }
  	else {
      cout << "Left" << endl;
    }
}

Measured memory_bytes: 3584
import sys
n = int(input())
t1 , x1 , y1 = 0 , 0 , 0
for i in range(n):
    t2,x2,y2=map(int,input().split())
    if t2-t1<abs(x1-x2)+abs(y1-y2) or (t2-t1-abs(x1-x2)-abs(y1-y2))%2==1:
        print('No')
        sys.exit()
    t1,x1,y1=t2,x2,y2
print('Yes')


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

N = int(input())
X, Y, H = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)

for x in range(101):
    for y in range(101):
        hc = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] > 0}
        h0 = {H[i] + abs(X[i] - x) + abs(Y[i] - y) for i in range(N) if H[i] == 0}
        if len(hc) == 1:
            if (len(h0) > 0 and min(h0) >= list(hc)[0]) or len(h0) == 0:
                print(x, y, list(hc)[0])
                break


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define r(i,n) for(long long i = 0; i<n; i++)
typedef long long ll;
using namespace std;


int main() {
  int a[32];
  a[0]=a[1]=a[2]=a[4]=a[6]=a[10]=a[12]=a[14]=a[16]=a[18]=a[22]=a[28]=a[30]=1;
  a[3]=a[5]=a[8]=a[9]=a[13]=a[20]=a[21]=a[24]=a[25]=2;
  a[27]=a[29]=4;
  a[7]=a[11]=a[17]=a[19]=a[26]=5;
  a[15]=14;
  a[23]=15;
  a[31]=51;
  int n;
  cin >> n;
  cout<<a[n-1]<<endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define f first
#define s second

typedef long long ull;
typedef vector<pair<ull,ull>> vp;

const int MXW = 1e5+5;
ull N, W, w, v;
ull table[105][MXW], ans;
vp wv;

bool cmp(pair<ull,ull> &a, pair<ull,ull> &b)
{
	if (a.f == b.f) return a.s > b.s;
	else return a.f < b.f;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> W;
	for (int i=0;i<N;++i) {
		cin >> w >> v;
		wv.pb(mp(w,v));
	} sort(wv.begin(),wv.end(),cmp);
	for (int i=1;i<=N;++i) {
		for (int j=1;j<=W;++j) {
			if (j < wv[i-1].f) table[i][j] = table[i-1][j];
			else table[i][j] = max(table[i-1][j],table[i-1][j-wv[i-1].f] + wv[i-1].s);
			ans = max(table[i][j-1],max(ans,table[i][j]));
		} 
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 79360
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main () {
    char a, b; cin >> a >> b;
    if (a == 'H' && b == 'H') cout << 'H';
    if (a == 'H' && b == 'D') cout << 'D';
    if (a == 'D' && b == 'H') cout << 'D';
    if (a == 'D' && b == 'D') cout << 'H';
}

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

using namespace std;

const int mod = 1e9 + 7;

int n, tot;
int h[N], H[N], f[N][2];

inline int fpm(int x, int y) {
	int res = 1;
	while(y) {
		if(y & 1) res = 1LL * x * res % mod;
		x = 1LL * x * x % mod, y >>= 1;
	}
	return res;
}

void solve(int u, int l, int r) {
	bool flag = false;
	H[u] = h[r];
	for(int i = l; i < r; ++i)
		if(h[i] != h[i + 1]) {
			H[u] = min(H[u], h[i]);
			flag = true;
		}
	
	if(!flag) {
		f[u][0] = fpm(2, r - l + 1) - 2;
		f[u][1] = fpm(2, H[u]);
		return;
	}
	
	f[u][0] = 1, f[u][1] = 2;
	for(int i = l; i <= r; ++i) {
		h[i] -= H[u];
		if(!h[i])
			f[u][0] = (f[u][0] + f[u][0]) % mod;
	}
	
	int las = 1;
	for(int i = l; i <= r; ++i) {
		if(h[i - 1] == 0 && h[i] != 0) las = i;
		if(h[i] != 0 && h[i + 1] == 0) {
			int v = ++tot;
			solve(v, las, i);
			f[u][0] = f[u][0] * (f[v][0] + 2LL * f[v][1]) % mod;
			f[u][1] = 1LL * f[u][1] * f[v][1] % mod;
		}
	}
	
	f[u][0] = (f[u][0] - f[u][1] + mod) % mod;
	f[u][1] = 1LL * f[u][1] * fpm(2, H[u] - 1) % mod;
	
//	cerr << l << ' ' << r << ' ' << H[u] << ' ' << f[u][0] << ' ' << f[u][1] << endl;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &h[i]);
	
	solve(0, 1, n);
	
	int ans = (f[0][0] + f[0][1]) % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

using Graph = vector<vector<int>>;


int main() {
	int n; cin >> n;
	int x, y; cin >> x >> y;
	x--; y--;

	// グラフ入力受取 (ここでは無向グラフを想定)
	Graph G(n);
	for (int i = 0; i < n-1; ++i) {
		G[i].push_back(i+1);
		G[i+1].push_back(i);
	}

	G[x].push_back(y);
	G[y].push_back(x);

	// BFS のためのデータ構造
	

	// 初期条件 (頂点 0 を初期ノードとする)

	vector<int> ans(n);

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

		vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
		queue<int> que;

		dist[i] = 0;
		que.push(i); // 0 を橙色頂点にする

		// BFS 開始 (キューが空になるまで探索を行う)
		while (!que.empty()) {
			int v = que.front(); // キューから先頭頂点を取り出す
			que.pop();

			// v から辿れる頂点をすべて調べる
			for (int nv : G[v]) {
				if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

				// 新たな白色頂点 nv について距離情報を更新してキューに追加する
				dist[nv] = dist[v] + 1;
				que.push(nv);
			}
		}

		for (int j = i + 1; j < n; j++) {
			ans[dist[j]]++;
		}
	}

	for (int i = 1; i < n; i++) {
		cout << ans[i] << endl;
	}
	

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long h,base=1,ans=0;
int main()
{
	cin>>h;
	while(h>0)
	{
		ans+=base;
		base*=2;
		h>>=1;
	}
	cout<<ans<<endl;
	return 0;
} 

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

int main(){
  int N,K,Q;
  cin>> N >>K >>Q;
  int A[Q];
  int p[N];
  for (int i=0;i<Q;i++){
    cin >>A[i];
  }
  for (int i=0;i<N;i++){
    p[i]=K-Q;
  }
  for (int i=0;i<Q;i++){
    p[A[i]-1]++;
  }
  for(int i=0;i<N;i++){
    if (p[i]>=1){
      cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
  }
  return 0;
}

      

      
  
  

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?lang=jp&id=ITP1_8_D
int main(void) {
    char s[4096], p[4096], s2[4096];  /* 100バイト以上 */
    scanf("%s", s);
    scanf("%s", p);
    //例 s="vanceknowledgetoad"
    //例 p="advance"
    // s2 = "vanceknowledgetoad" + "vanceknowledgetoad"

    sprintf(s2, "%s%s", s, s);  // 文字列を連結する

    // strstr という関数で部分文字列を探す
    if(strstr(s2, p) == NULL)printf("No\n");
    else printf("Yes\n");

    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    int n, c=0, k=0;
    cin >> n;

    for(int i=1; i<=n; i=i+2){
        c=0;
        for(int j=1; j<=i; j++){
            if(i%j == 0)c++;
        }
        if(c==8)k++;
    }

    cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var rock = "g"[0]

// 2018-08-22T12:51:17+0800
// 2018-08-22T13:02:29+0800
func main() {
	var s string
	fmt.Scanf("%s", &s)
	out := 0
	for i := 0; i < len(s); i++ {
		if s[i] == rock {
			out++
		}
		//if i%2 == 0 {
		//	// Only has rock.
		//	out--
		//}
	}
	out -= (len(s) + 1) / 2
	fmt.Println(out)
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
string s;
int main() {
    ios::sync_with_stdio(0);
    cin >> s;
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'R') {
            cnt++;
        } else {
            ans = max(cnt, ans);
            cnt = 0;
        }
    }
    ans = max(cnt, ans);
    cout << ans << endl;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(n);
    for(auto &v: x) v = -1;
    int s, c;
    for(int i=0;i<m;i++){
        cin >> s >> c;
        if(x[s-1] > 0 && x[s-1] != c){
            cout << -1 << endl;
            return 0;
        }else{
            x[s-1] = c;
        }
    }

    for(int i = 0; i < n; i ++){
        if(i == 0 && x[i] == 0){
            if(n == 1){
                cout << 0 << endl;
            }else{
                cout << -1 << endl;
            }
            return 0;
        }
        if(x[i] == -1) cout << (i == 0 ? (n == 1?0:1) : 0);
        else cout << x[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int a,b,t;
    cin>>a>>b>>t;
    int ans=0;
    for(int i=1;i*a<t+1;i++){
        ans+=b;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
import qualified Data.Bits as Bits
import qualified Data.ByteString.Char8 as BS
import qualified Data.Char as Char
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import qualified Data.Vector.Unboxed.Mutable as UMVector
import qualified Data.Vector.Unboxed as UVector
import Data.Vector.Unboxed ((!))

xorLengths :: UVector.Vector Int -> Int -> Int -> [Int] -> [Int]
xorLengths as l xorVal acc
	| UVector.null as = acc
	| l >= UVector.length as = xorLengths (UVector.tail as) (l - 1) nextXor (l:acc)
	| xorVal' == xorVal + next = xorLengths as (l + 1) xorVal' acc
	| otherwise = xorLengths (UVector.tail as) (l - 1) nextXor (l:acc)
	where
		current = UVector.head as
		next = as ! l
		xorVal' = xorVal `Bits.xor` next
		nextXor = xorVal `Bits.xor` current

main :: IO ()
main = do
	n <- readLn
	as <- UVector.unfoldrN n (BS.readInt . BS.dropWhile Char.isSpace) <$> BS.getLine
	print $ sum $ xorLengths as 0 0 []


Measured memory_bytes: 21884
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
} 
int main() {
ll n,k; cin>>n>>k;
vl mp[100005]={};
rep(i,n){
ll r,l;
cin>>r>>l;
mp[r].pb(l);}
ll ans = 0;
priority_queue<ll> a;
repl(i,1,k+1){
for(auto p : mp[i]){
a.push(p);}
if(!a.empty()){
ans += a.top();
a.pop();}
}
cout << ans << endl;}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  int n = s.size();
  int zero = 0, one = 0;
  rep(i, n) {
    if(s[i] == '0') ++zero;
    else ++one;
  }
  cout << 2*min(zero, one) << endl;
}


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

struct Card {
    char suit, value;
};

bool isStable(vector<Card>& in, vector<Card>& out, int n) {
    rep(i, n) {
        if (in[i].suit != out[i].suit) {
            return false;
        }
    }
    return true;
}

void bubble_sort(vector<Card>& A, int n) {
    bool flag = 1;
    for (int i = 0; flag; i++) {
        flag = 0;
        for (int j = n - 1; j >= i + 1; j--) {
            if (A[j].value < A[j - 1].value) {
                swap(A[j], A[j - 1]);
                flag = 1;
            }
        }
    }
    rep(i, n) {
        if (i) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << "\n";
    cout << "Stable\n";
}

void selection_sort(vector<Card>& A1, vector<Card>& A2, int n) {
    int minj;
    rep(i, n) {
        minj = i;
        for (int j = i; j < n; j++) {
            if (A2[j].value < A2[minj].value) {
                minj = j;
            }
        }
        if (minj != i) {
            swap(A2[i], A2[minj]);
        }
    }
    rep(i, n) {
        if (i) cout << " ";
        cout << A2[i].suit << A2[i].value;
    }
    cout << "\n";
    if (isStable(A1, A2, n)) {
        cout << "Stable\n";
    } else {
        cout << "Not stable\n";
    }
}

void Main() {
    int n;
    cin >> n;
    vector<Card> A1(n), A2(n);
    rep(i, n) cin >> A1.at(i).suit >> A1.at(i).value;
    rep(i, n) A2.at(i) = A1.at(i);
    bubble_sort(A1, n);
    selection_sort(A1, A2, n);
}

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


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

int main()
{
   int N;
   int index = 0;
   int tmp;
   int count = 0;
   cin >> N;
   vector<int> vec(N);


   for (int i = 0; i < N; i++)
   {
      cin >> vec.at(i);
   }

   while (1)
   {
      tmp = vec.at(index);
      vec.at(index) = -1;
      index = tmp-1;
      count++;

      if (vec.at(index)==-1)
      {
         index = -1;
         count = -1;
         break;
      }
      if (index == 1)
      {
         break;
      }
   }
   
   cout << count << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;
ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  k--;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}

int main(void){
  ll n, m, k;
  cin >> n >> m >> k;
  
  ll ans = 0;

  ll t = nck(n*m-2,k-2);
  for (ll j = 1; j < m; j++){
    ans += j*(m-j) % MOD * n % MOD *n % MOD * t % MOD;
    ans = (ans % MOD);
  }
  for (ll i = 1; i < n; i++){
    ans += i*(n-i) % MOD * m % MOD *m % MOD * t % MOD;
    ans = (ans % MOD);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define MAX 1005
const ll MOD=1e9+7;
using namespace std;
ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  ll tmp=gcd(a,b);
  return (a/tmp)*(b/tmp)*tmp;
}

int main() {
  ll N,K;
  cin >> N >> K;
  vector< pair<ll,ll> > ab(N);
  rep(i,N){
    ll a,b;
    cin >> a >> b;
    ab[i]=make_pair(a,b);
  }
  sort(All(ab));
  ll i=0;
  while(1){
    if(K>ab[i].second){
      K -= ab[i].second;
      i++;
    }else{
      cout << ab[i].first << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a%2||b%2||c%2){
    cout<<0<<endl;
  }else{
    int CA=abs(c-a),AB=abs(a-b),BC=abs(c-b);
    ll ans=0;
    while(CA%2!=1&&AB%2!=1&&BC%2!=1){
      CA/=2;AB/=2;BC/=2;
      ans++;
      if(CA==0&&AB==0&&BC==0){
	ans=-1;
	break;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

void greedy(string t, vector<char>& history, char a, char b, char c, int i, int n, int k, int score, int& ans)
{
	if (history[i - k] == c)
	{
		if (i + k <= n - 1)
		{
			if (t[i + k] == b)
			{
				history[i] = b;
			}
			else if (t[i + k] == c)
			{
				history[i] = a;
			}
		}
	}
	else
	{
		ans += score;
		history[i] = c;
	}
}

int main()
{
	int n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	int ans = 0;

	vector<char> history(n);
	for (int i = 0; i < k; i++)
	{
		if (t[i] == 'r')
		{
			ans += p;
			history[i] = 'p';
		}
		else if (t[i] == 's')
		{
			ans += r;
			history[i] = 'r';
		}
		else if (t[i] == 'p')
		{
			ans += s;
			history[i] = 's';
		}
	}

	for (int i = k; i < n; i++)
	{
		if (t[i] == 'r') greedy(t, history, 'r', 's', 'p', i, n, k, p, ans);
		else if (t[i] == 's')greedy(t, history, 's', 'p', 'r', i, n, k, r, ans);
		else greedy(t, history, 'p', 'r', 's', i, n, k, s, ans);
	}
	cout << ans << endl;
}

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;
//ll a[maxn];

//check T
void solve()
{
	//cin >> n; rep(i, 0, n) cin >> a[i];
	string s;
	cin >> s;
	n = s.size();
	if(n&1){cout << "No\n"; return;}
	bool flag = 1;
	rep(i, 0, n)
	{
		if(i&1) flag &= s[i] == 'i';
		else flag &= s[i] == 'h';
	}
	cout << (flag?"Yes":"No") <<endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n), sm(n+1);
	rep(i, n) cin >>a[i];
	
	rep(i,n) sm[i+1] = sm[i] + a[i];
	
	ll ans = 1LL<<60;
	rep2(i, 1, n){
		ll sma = sm[i], smb = sm[n] - sm[i];
		ans = min(ans, abs(sma - smb));
	}
	cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/****************temporary declaration & definitoins*******************/
char g[100][100];
/**************************define functions****************************/

/****************************main function*****************************/
int main(void) {
	int h, w; cin >> h >> w;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			cin >> g[i][j];
		}
	}
	vector<int> hs, ws;
	for (int i = 0; i < h; i++) {
		bool check = true;
		for (ll j = 0; j < w; j++) {
			if (g[i][j] != '.') {
				check = false;
				break;
			}
		}
		if (check) hs.push_back(i);
	}
	for (int i = 0; i < w; i++) {
		bool check = true;
		for (ll j = 0; j < h; j++) {
			if (g[j][i] != '.') {
				check = false;
				break;
			}
		}
		if (check) ws.push_back(i);
	}
	for (ll i = 0; i < h; i++) {
		bool check = false;
		for (ll j = 0; j < w; j++) {
			if (!binary_search(all(hs), i) && !binary_search(all(ws), j)) {
				cout << g[i][j];
				check = true;
			}
		}
		if (check) {
			cout << endl;
		}
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int cnt = 0, cnt2 =0;
  for(int i=1; i<=n; i+=2){
    cnt =0;
    for(int j=1; j<=i; j++){
      if(i%j==0) cnt++;
    }
  if(cnt == 8) cnt2++;
  }
  cout << cnt2;
}


Measured memory_bytes: 256
def f(x,y):
    return x//y + (1 if x%y > 0 else 0)
n = int(input())
a,b = list(map(int,input().split()))
for i in range(n-1):
    c,d = list(map(int,input().split()))
    e = max(f(a,c),f(b,d))
    a,b = c*e,d*e
print(a+b)

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define N 10001
#define mod 1000000007

#define reg register
using namespace std;
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
int nt[N], fi[N], go[N], dp[N], a[N], cnt, n;
int inc(int x, int y){
    return x + y >= mod ? x + y - mod : x + y;
}
void add(int x, int y){
    nt[++cnt] = fi[x]; fi[x] = cnt; go[cnt] = y;
}
void DFS(int x, int fa){
    dp[x] = false;
    for(int i = fi[x]; i; i = nt[i]){
        int v = go[i]; if(v == fa) continue;
        DFS(v, x); 
        if(dp[v] == false && a[x] > a[v]) dp[x] = true;
    }
}
int main(){
    n = read();
    for(int i = 1; i <= n; i++) a[i] = read();
    for(int i = 1; i < n; i++){
        int x = read(), y =  read();
        add(x, y); add(y, x);
    }
    for(int i = 1; i <= n; i++){
        memset(dp, 0, sizeof dp);
        DFS(i, 0); if(dp[i]) printf("%d ", i);
    }
}

Measured memory_bytes: 512