akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define PB push_back
#define F first
#define S second
using namespace std;
typedef pair<int,int>P;
typedef vector<int>V;
typedef vector<P>VP;
typedef queue<P>Q_P;
typedef priority_queue<P,VP,greater<P>>PQ;
V v[5001];
VP v1[5001];
int main(void){
	int n,m;
	P pp[5001],ppp;
	int x,y;
	int cost,now,next,MAX;
	int flg[5001],d[5001],flag;
	int i,j;
	PQ que1;
	Q_P que;
	cin>>n>>m;
	for(i=1;i<=n;i++)	cin>>pp[i].F>>pp[i].S;
	for(i=0;i<m;i++){
		cin>>x>>y;
		v[x].PB(y);
		v[y].PB(x);
	}
	for(i=1;i<=n;i++){
	    for(j=1;j<=n;j++)   flg[j]=0;
	    flg[i]=1;
		que.push(P(i,0));
		while(!que.empty()){
			ppp=que.front();
			now=ppp.F;	cost=ppp.S;
			que.pop();
			for(j=0;j<(int)v[now].size();j++){
				next=v[now][j];
				if(cost+1<=pp[i].S){
					if(flg[next]==0){
			            v1[i].PB(P(next,pp[i].F));
						que.push(P(next,cost+1));
			            flg[next]=1;
					}
				}
			}
		}
	}
	// for(i=1;i<=n;i++){
	   // printf("now_town=%d ",i);
		// for(j=0;j<(int)v1[i].size();j++){
			// printf("next_town=%d cost=%d    ",v1[i][j].F,v1[i][j].S);
		// }
		// printf("\n");
	// }
	for(i=1;i<=n;i++)   flg[i]=0;
	que1.push(P(0,1));
	while(!que1.empty()){
		//printf("check\n");
	    ppp=que1.top();
	    cost=ppp.F; now=ppp.S;
	    que1.pop();
		flag=0;
		for(j=1;j<=n;j++)	if(flg[j]==0)	flag=1;
		if(flag==0)	break;	
	    if(flg[now]==0){
			// printf("check\n");
	       d[now]=cost;
	       flg[now]=1;
	       for(j=0;j<v1[now].size();j++){
	            next=v1[now][j].F;
	            cost=v1[now][j].S;
	            if(flg[next]==0){
					// printf("check1\n");
	                que1.push(P(d[now]+cost,next));
	            }
	       }
	    }
	}
	cout<<d[n]<<endl;
	return 0;
}


Measured memory_bytes: 192792
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i <= n;){
        int l = i;
        while(l <= n && a[l] == l){
            l++;
        }
        debug(i, l);
        int k = l - i;
        if(k > 0){
            ans += (k + 1) / 2;
            i = l;
        }else i++;
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 640
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(readline().rstrip())

answer = 1
for i in range(1, N+1):
    answer = answer * i % MOD

answer = answer % MOD
print(answer)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> s(n+1);
    s[0] = 0;
    repf(i,1,n+1) {
        s[i] = (a[i-1]-s[i-1]/2)*2;
    }
    int diff = (s[n]-s[0])/2;
    rep(i,n) {
        if (i%2==0) {
            cout << s[i]+diff << ' ';
        } else {
            cout << s[i]-diff << ' ';
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
A = list(list(map(int, input().split())) for i in range(3))
N = int(input())
B = [int(input()) for i in range(N)]
result = [[0]*3 for i in range(3)]

for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j] == B[k]:
                result[i][j] = 1
                break
            else:
                result[i][j] = 0

if (result[0][0]==1 and result[0][1]==1 and result[0][2]==1) \
or (result[1][0]==1 and result[1][1]==1 and result[1][2]==1) \
or (result[2][0]==1 and result[2][1]==1 and result[2][2]==1) \
or (result[0][0]==1 and result[1][0]==1 and result[2][0]==1) \
or (result[0][1]==1 and result[1][1]==1 and result[2][1]==1) \
or (result[0][2]==1 and result[1][2]==1 and result[2][2]==1) \
or (result[0][0]==1 and result[1][1]==1 and result[2][2]==1) \
or (result[0][2]==1 and result[1][1]==1 and result[2][0]==1) :
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

sum1 = 0
sum2 = 0
sum3 = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            if i <= j <= k:
                sum1 += gcd(i, j, k)
                if i == j == k:
                    sum2 += gcd(i, j, k)
                if (i == j != k) or (j == k != i) or (k == i != j):
                    sum3 += gcd(i, j, k)

print(sum1 * 6 - sum2 * 5 - sum3 * 3)


Measured memory_bytes: 9520
n = int(input())
An = list(map(int, input().split()))

An.sort()
max_num = An[-1]

primes = [True] * max_num
once = [False] * max_num

i = 0
while i < n:
    once[An[i] - 1] = True

    j = 1
    while i + j < n:
        if An[i] == An[i + j]:
            once[An[i] - 1] = False
            j += 1
        else:
            break

    i += j

for i in range(n):
    if primes[An[i] - 1]:
        base = An[i]
        idx = An[i] * 2 - 1
        while idx < max_num:
            primes[idx] = False
            idx += base

ans = [x and y for (x, y) in zip(once, primes)]
print(ans.count(True))

Measured memory_bytes: 43476
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int n, m;
const int N = 11000;
const int M = 300;
LL A[N];
int B[N][M];
int top[M], sta[M][N];

int lb[N], rb[N], lc[N], rc[N], tot;
LL val[N], tag[N], ans;
void upd(int t)
{
    val[t] = max(val[lc[t]], val[rc[t]]);
}
void psdw(int t)
{
    tag[lc[t]] += tag[t];
    val[lc[t]] += tag[t];
    tag[rc[t]] += tag[t];
    val[rc[t]] += tag[t];
    tag[t] = 0;
}
int build(int l, int r)
{
    int t = ++ tot;
    lb[t] = l; rb[t] = r;
    if (l != r)
    {
        lc[t] = build(l, (l + r) / 2);
        rc[t] = build((l + r) / 2 + 1, r);
        upd(t);
    }
    else val[t] = A[l];
    return t;
}
void add(int t, int l, int r, int v)
{
    // if (t == 1) {cerr << l << " " << r << " " << v << endl;}
    if (l <= lb[t] && rb[t] <= r)
    {
        tag[t] += v; val[t] += v;
        return;
    }
    psdw(t);
    if (l <= rb[lc[t]]) add(lc[t], l, r, v);
    if (r >= lb[rc[t]]) add(rc[t], l, r, v);
    upd(t);
}
LL query(int t, int l, int r)
{
    if (l <= lb[t] && rb[t] <= r) return val[t];
    LL v = -1e18;
    psdw(t);
    if (l <= rb[lc[t]]) v = max(v, query(lc[t], l, r));
    if (r >= lb[rc[t]]) v = max(v, query(rc[t], l, r));
    return v;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 2; i <= n; ++ i)
    {
        scanf("%lld", &A[i]);
        A[i] += A[i - 1];
    }
    for (int i = 1; i <= n; ++ i)
        for (int j = 1; j <= m; ++ j)
            scanf("%d", &B[i][j]);
    build(1, n);
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= m; ++ j)
        {
            while (top[j] && B[i][j] >= B[sta[j][top[j]]][j])
            {
                add(1, sta[j][top[j] - 1] + 1, sta[j][top[j]], -B[sta[j][top[j]]][j]);
                top[j] --;
            }
            top[j] ++;
            sta[j][top[j]] = i;
            add(1, sta[j][top[j] - 1] + 1, sta[j][top[j]], B[sta[j][top[j]]][j]);
        }
        ans = max(ans, -A[i] + query(1, 1, i));
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 17152
Scanf.scanf "%s %d %d" (fun s x y ->
    let len = String.length s in
    let rec loop i dir first cur xl yl =
        if i = len then (
            if cur > 0 then (
                if first < 0 then cur, xl, yl else
                if dir then first, (cur :: xl), yl
                       else first, xl, (cur :: yl)
            ) else first, xl, yl
        ) else (
            if s.[i] = 'F' then loop (i + 1) dir first (cur + 1) xl yl else
                let first, xl, yl =
                    if cur > 0 then (
                        if first < 0 then cur, xl, yl else
                        if dir then first, (cur :: xl), yl
                               else first, xl, (cur :: yl)
                    ) else max first cur, xl, yl
                in
                loop (i + 1) (not dir) first 0 xl yl
        )
    in
    let fx, xl, yl = loop 0 true (-1) 0 [] [] in
    let judge p l =
        let a = Array.make 8192 false in
        a.(0) <- true;
        List.iter (fun v ->
            for j = 8191 downto v do
                a.(j) <- a.(j) || a.(j - v)
            done
        ) l;
        let sum = List.fold_left (+) 0 l in
        let rec loop i =
            if i = 8192 then false else
                if a.(i) && abs (sum - i * 2) = abs p then true else loop (i + 1)
        in
        loop 0
    in
    print_endline @@ if judge (x - fx) xl && judge y yl then "Yes" else "No"
)

Measured memory_bytes: 2816
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int x,y,z;cin>>x>>y>>z;
    int n = x+y+z;
    vector<long long> a(n),b(n),c(n);
    for(int i=0;i<n;++i)cin>>a[i]>>b[i]>>c[i];
    vector<pair<long long,int>> d(n),e(x+y);
    long long res = 0;
    for(int i=0;i<n;++i){
        res += c[i];
        a[i] -= c[i];
        b[i] -= c[i];
        d[i] = pair<long long, int>(a[i]-b[i],i);
    }
    sort(d.rbegin(),d.rend());
    long long tmp = 0,ma = 0;
    set<pair<long long,int>> as,bs,bs2;
    for(int i=0;i<x;++i){
        tmp += a[d[i].second];
        as.insert(pair<long long, int>(a[d[i].second],d[i].second));
    }
    for(int i=x;i<n;++i){
        bs2.insert(pair<long long, int>(b[d[i].second],d[i].second));
    }
    int t = 0;
    for(auto itr = bs2.rbegin();itr != bs2.rend() && t < y;itr++){
        bs.insert(*itr);
        tmp += itr->first;
        t++;
    }
    for(auto p:bs)bs2.erase(p);
    ma = tmp;
    for(int i = x; i < n-y; ++i){
        as.insert(pair<long long, int>(a[d[i].second],d[i].second));
        tmp += a[d[i].second] - as.begin()->first;
        as.erase(as.begin());
        if(bs.find(pair<long long,int>(b[d[i].second],d[i].second)) != bs.end()){
            bs.erase(pair<long long,int>(b[d[i].second],d[i].second));
            tmp += bs2.rbegin()->first - b[d[i].second];
            bs.insert(*bs2.rbegin());
            bs2.erase(*bs2.rbegin());
        }
        else{
            bs2.erase(pair<long long,int>(b[d[i].second],d[i].second));
        }
        ma = max(tmp,ma);
    }





    // for(int i=0;i<x+y;++i){
    //     int k = d[i].second;
    //     d[i] = pair<long long, int>(a[k]-b[k],k);
    // }
    // sort(d.rbegin(),d.rend());
    // for(int i=0;i<x;++i)res += a[d[i].second];
    // for(int i=x;i<x+y;++i)res += b[d[i].second];
    cout<<res + ma<<endl;
    return 0;
}

Measured memory_bytes: 17792
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    double W, H, x, y;
    cin >> W >> H >> x >> y;

    int ans;
    if (H == 2*y && W == 2*x) ans = 1;
    else ans = 0;
    cout << 0.5*H*W << " " << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AMaximizeTheFormula {
public:
	void solve(istream& in, ostream& out) {
        vector<int> a(3);
        rep(i,3) in >> a[i];
        sort(a.begin(),a.end());
        out << a[0] + a[1] + a[2] * 10 << endl;
	}
};

int main() {
	AMaximizeTheFormula solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
h,w,n=map(int,input().split())
sr,sc=map(int,input().split())
s=input()
t=input()

y=sr
for i,j in zip(s,t):
    if i=="U":
        y-=1
        if y==0:
            print("NO")
            exit()
    if j=="D" and y<h:
        y+=1
y=sr
for i,j in zip(s,t):
    if i=="D":
        y+=1
        if y==h+1:
            print("NO")
            exit()
    if j=="U" and y>1:
        y-=1

x=sc
for i,j in zip(s,t):
    if i=="L":
        x-=1
        if x==0:
            print("NO")
            exit()
    if j=="R" and x<w:
        x+=1

x=sc
for i,j in zip(s,t):
    if i=="R":
        x+=1
        if x==w+1:
            print("NO")
            exit()
    if j=="L" and x>1:
        x-=1

print("YES")


Measured memory_bytes: 44860
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-12
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T> void read(T &res)
{
    res=0;
    T f=1;char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        res=res*10+c-'0';
        c=getchar();
    }
    res*=f;
}
template<class T>
void out(T x)
{
    if(x<0){x=-x;putchar('-');}
    if(x>=10)
    {
        out(x/10);
    }
    putchar('0'+x%10);
}
bool Query(int64 t) {
    putchar('?');space;out(t);enter;fflush(stdout);
    char s[5];scanf("%s",s);
    return s[0] == 'Y';
}
void Solve(){
    int64 v=1;
    bool f=0;
    for(int i=1;i<=10;++i)
    {
        if(!Query(v)){f=1;v/=10;break;}
        v*=10;
    }
    if(!f){
        v = 1;
        for(int i= 1;i<=10;++i)
        {
            if(Query(v*10-1)){putchar('!');space;out(v);enter;return;}
            v*=10;
        }
    }
    int64 L=v,R=min(v*10-1,(int64)1e9);
    while(L<R)
    {
        int64 mid=(L+R+1)>>1;
        if(!Query(mid*10))L=mid;
        else R=mid-1;
    }
    putchar('!');
    space;
    out(L + 1);
    enter;
}
int main()
{
    Solve();
    return 0;
}


Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#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++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  string s,t;
  cin >> s;
  cin >> t;
  ull len = s.size();
  bool can = true;
  rep(i,len){
    if(s[i] == t[i]){

    }else{
      can = false;
    }
  }
  if(can){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
q, h, s, d = map(int, input().split())
n = int(input())
cheep_1 = min(q * 4, 2 * h, s)
if 2 * cheep_1 <= d:
    print(cheep_1 * n)
else:
    n1 = n % 2
    print(n // 2 * d + n1 * cheep_1)


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

int main()
{
    int n; cin >> n;
    int ans = 0;
    vector<ll> va(n), vb(n);
    ll sum_a = 0, sum_b = 0, s = 0;
    vector<pair<ll, int>> t;
    rep(i, n){
        cin >> va[i];
        sum_a += va[i];
    }
    rep(i, n){
        cin >> vb[i];
        sum_b += vb[i];
        if(va[i] < vb[i]){
            s += vb[i]-va[i];
            ans++;
        }
        else    t.emplace_back(pair<ll, int>(va[i]-vb[i], i));
    }
    if(sum_a < sum_b){
        cout << -1 << endl;
        return 0;
    }
    sort(t.begin(), t.end(), greater<pair<ll, int>>());
    for(int i = 0; i < t.size(); i++){
        if(s <= 0) break;
        s -= va[t[i].second]-vb[t[i].second];
        ans++;
    }
    cout << ans << endl;
    system("pause");
}

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

ll N, A, B;
const int MAX_N = 1.0e5 + 100;
ll X[MAX_N];

int main() {
    cin >> N >> A >> B;
    for (int i = 0; i < N; i++) cin >> X[i];

    ll ans = 0;
    for (int i = 0; i < N-1; i++) {
        if ((X[i+1]-X[i])*A > B) {
            ans += B;
        }
        else {
            ans += (X[i+1]-X[i])*A;
        }
    }

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


Measured memory_bytes: 1024
def solve():
    n = int(input())
    # ケーキをi個買う場合についてすべて調べる(0<=i<=n/4)
    for i in range(int(n/4) + 1):
        # nnはケーキをi個買った残りの金額
        nn = n - 4 * i
        # nnが7で割り切れれば買い方はある
        if nn % 7 == 0:
            print('Yes')
            return
    print('No')


solve()


Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")



void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll n,ans=0;
    scanf("%lld",&n);
    char s[n][15];
    rep(i,0,n){
        scanf("%s",s[i]);
    }
    ll a=0,b=0,l,c=0;
    rep(i,0,n){
        l=strlen(s[i]);
        if(s[i][0]=='B') b++;
        if(s[i][l-1]=='A') a++;
        if(s[i][l-1]=='A' && s[i][0]=='B') c++;
        rep(j,0,l-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B'){
                ans++;
                j++;
            }
        }
    }
    // printf("%lld %lld ",a,b);
    if(a==b && b==c &&a>0){
        a--;
    }
    ans+=min2(a,b);
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
  int A, B, C, cnt5, cnt7;
  cin >> A >> B >> C;
  
  cnt5 = 0;
  cnt7 = 0;
  
  if(A==5){
    cnt5++;
  }
  else if(A==7){
    cnt7++;
  }
  if(B==5){
    cnt5++;
  }
  else if(B==7){
    cnt7++;
  }
  if(C==5){
    cnt5++;
  }
  else if(C==7){
    cnt7++;
  }
  if(cnt5==2 && cnt7==1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" <<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int A,B;
    int C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    while(1){
        C=C-B;
        if(C<=0){
            printf("Yes");
            break;
        }
        A=A-D;
        if(A<=0){
            printf("No");
            break;
        }
    }

}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
char s[1050];
int n,a,b,c,d;
int main() {
	scanf("%s",s+1);
	n = strlen(s+1);
	for (int i=1;i<=n;i++) {
		if (s[i] == 'W') a = 1;
		if (s[i] == 'E') b = 1;
		if (s[i] == 'N') c = 1;
		if (s[i] == 'S') d = 1;	
	}
	puts((!(a^b))&&(!(c^d)) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007 
using namespace std;
void solve(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll w=0,r=0;
    for(ll i=0;i<s.size();i++){
        if(s[i]=='R')r++;
        else w++;
    }
    ll res=0;
    for(ll i=0;i<r;i++){
       if(s[i]=='W')res++;
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3744
import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val a = br.readLine().split(' ').map { it.toInt() }
    for (i in 0..Int.MAX_VALUE) {
        if (!a.all { ((it ushr i) and 1) == 0 }) {
            println(i)
            return
        }
    }
}

fun err(print: Any) {
    System.err.println(print)
}

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

int main() {

    int N;
    std::vector<int> W;

    std::cin >> N;
    W.resize(N);

    for(int i=0; i<N; ++i)
        std::cin >> W[i];

    int min = 100000000;
    for(int i=0; i<N; ++i)
    {
        int sum1 = 0;
        int sum2 = 0;
        for(int j=0; j<=i; ++j)
            sum1 += W[j];
        for(int j=i+1; j<N; ++j)
            sum2 += W[j];

        int diff = abs(sum1 - sum2);
        if(diff < min)
            min = diff;
    }

    std::cout << min << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	vll a(n);
	vll b(n);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	ll ans = 0;
	for(int i = n-1; i>=0; i--){
		a[i] += ans;
		ll t = a[i]%b[i];
		ans += (b[i] - t)%b[i];
	}
	cout << ans << endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)
int gcd(int p,int q){while(q){int t=p%q;p=q;q=t;}return p;}

int main(){
	int a;
	scanf("%d",&a);
	printf("%d",360/gcd(360,a));
}

Measured memory_bytes: 1720
#include <iostream>
#include <algorithm>

constexpr int MAX_N = 50001, MAX_M = 21;
constexpr int INF = 1000000000;

int n, m, c[MAX_M], t[MAX_N];

void fill_dp();

int main(){
	std::cin >> n >> m;
	for(int i = 0; i < m; ++i){
		std::cin >> c[i];
	}
	fill_dp();
	std::cout << t[n] << std::endl;
	return 0;
}

void fill_dp(){
	for(int i = 0; i < MAX_N; ++i) t[i] = INF;

	t[0] = 0;
	for(int i = 0; i < m; ++i){
		for(int j = c[i]; j < n + 1; ++j){
			t[j] = std::min(t[j], t[j - c[i]] + 1);
		}
	}
	return;
}

Measured memory_bytes: 3300
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        
        int count=0;
        for(int i=1;i<1000001;i++) {
        	if(i%7!=0) {
        		c-=a;
        		count++;
        	}else {
        		c-=a;
        		c-=b;
        		count++;
        	}
        	
        	if(c<=0)break;
        }
        System.out.println(count);

	}
}



Measured memory_bytes: 26580
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define PP std::pair<int,int>
int N, M;
std::vector<int> P[100010], L[100010];
bool usedp[100010];
bool usedl[100010];
int main() {
	std::cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		int K;
		std::cin >> K;
		for (int j = 1; j <= K; j++) {
			int tmp;
			std::cin >> tmp;
			P[i].push_back(tmp);
			L[tmp].push_back(i);
		}
	}
	std::queue<PP> q;
	q.push({ 1,1 });
	while (!q.empty()) {
		PP p = q.front();
		q.pop();
		if (p.first == 1) {
			for (auto u : P[p.second]) {
				if (!usedl[u]) {
					usedl[u] = true;
					q.push({ 0,u });
				}
			}
		}
		else {
			for (auto u : L[p.second]) {
				if (!usedp[u]) {
					usedp[u] = true;
					q.push({ 1,u });
				}
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		if (!usedp[i]) {
			std::cout << "NO" << std::endl;
			return 0;
		}
	}
	std::cout << "YES" << std::endl;
	return 0;
}

Measured memory_bytes: 9336
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();
		int T = scanner.nextInt();
		int answer = 0;
		int count = T/A;
		
		answer = B * count;
		System.out.println(answer);
	}
}

Measured memory_bytes: 21844
#include <iostream>


using namespace std;

const int MAXN = 3010;
int DP[MAXN][MAXN];
int SOL[MAXN][MAXN];

int N, M;
string S1, S2;
int main() {

    cin >> S1 >> S2;
    N = S1.length();
    M = S2.length();
    S1 = " " + S1;
    S2 = " " + S2;

    for(int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (S1[i] == S2[j]) {
                DP[i][j] = DP[i - 1][j - 1] + 1;
            } else {
                DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
            }
        }
    }

    string ans = "";
    int i = N, j = M;

    while (i >= 1 && j >= 1) {
        if (S1[i] == S2[j]) {
            ans = S1[i] + ans;
            i--;
            j--;
        } else {
            if (DP[i - 1][j] > DP[i][j - 1]) {
                i--;
            } else {
                j--;
            }
        }
    }

    //cout << DP[N][M] << endl;
    cout << ans;

    return 0;
}

Measured memory_bytes: 36096
N = int(input())

def isprime(p):
    if p == 1:
        return False
    for i in range(2, int(p**0.5+1)):
        if p%i == 0:
            return False
    return True

ans = []
for i in range(11, 55556, 10):
    if isprime(i):
        ans.append(i)
        N -= 1
    if N == 0:
        break
print(*ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m;cin>>n>>m;ll r;ll b,c;
    unordered_map <ll,ll> mp;ll sum=0;
    for(ll i=0;i<n;++i)
    {
        cin>>r;sum+=r;
        auto it=mp.find(r);
        if(it!=mp.end()){it->second++;}
        else
        {
            mp.insert(make_pair(r,1));
        }
    }
    map <ll,ll> omp(mp.begin(),mp.end());
    for(ll i=0;i<m;++i)
    {
        cin>>b>>c;
        for(auto it=omp.begin();it!=omp.end();++it)
        {
            if(it->first>=c){break;}
            ll ran=min(b,it->second);
            sum+=((c-it->first)*ran);
            auto it1=omp.find(c);
            if(it1!=omp.end()){it1->second+=ran;}
            else{omp.insert(make_pair(c,ran));}
            b=b-ran;
            it->second=it->second-ran;
            if(it->second==0){omp.erase(it->first);}
            if(b<=0){break;}
        }
    }
    cout<<sum;
}

Measured memory_bytes: 10660
#include<stdio.h>
#define N 100

int n,v[N][N],stat[N],d[N],f[N],time;
void dfs();
void dfs_init(int);

int main(){
  int u,b,i,j,m;
    scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      v[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&m);
    u--;
    for(j=0;j<m;j++){
      scanf("%d",&b);
      b--;
      v[u][b]=1;
    }
  }

  dfs();
  return 0;
}

void dfs(){
  int u;
  for(u=0;u<n;u++) stat[u]=0;
  time =0;

  for(u=0;u<n;u++){
    if(stat[u]==0) dfs_init(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

void dfs_init(int m){
  int b;
  stat[m] =1;
  time++;
  d[m]= time;
  for(b=0;b<n;b++){
    if(v[m][b]==0) continue;
    if(stat[b]==0) dfs_init(b);

  }
  stat[m]=2;
  time++;
  f[m]= time;
}



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

long long MOD = 1000000007;

map<long long, int> factorize(long long n) {
    map<long long, int> ret;
    for(long long i=2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++ret[i];
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

long long powmod(long long x, long long n) {
    long long ret = 1;
    while(n > 0) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

long long inv(long long k) {
    return powmod(k, MOD - 2);
}


int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    map<int, int> cnt;
    for(int i=0; i<N; ++i) {
        auto fac = factorize(A[i]);
        for(auto p : fac) {
            cnt[p.first] = max(cnt[p.first], p.second);
        }
    }

    long long lcm = 1;
    for(auto p : cnt) {
        lcm = lcm * powmod(p.first, p.second) % MOD;
    }

    long long ans = 0;
    for(int i=0; i<N; ++i) ans = (ans + lcm * inv(A[i]) % MOD) % MOD;
    cout << ans << '\n';
}

Measured memory_bytes: 768
N = int(input()) 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.append(0)
A.append(0)
m = 0
M = sum(A)
for i in range (N+1):
  m = B[i] - A[i]
  if m <= 0:
    m = 0
    A[i] -= B[i]
  else:
    A[i] = 0
    A[i+1] -= m
    if A[i+1] < 0:
      A[i+1] = 0
print(M - sum(A))

Measured memory_bytes: 18624
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int main() {
	int N,K;
	cin >> N >> K;
	vector<double> p(N);
	vector<double> k(N);
	vector<double> S(N ,0);
	double max = 0;
	for (int i = 0; i < N; i++) {
		cin >> p.at(i);
		k.at(i) = ((1 / 2.0) * (p.at(i) + 1));
	}
	S.at(0) = k.at(0);
	for (int i = 1; i < N; i++) {
			S.at(i) = S.at(i - 1) + k.at(i);
	}
	for (int i = 0; i < K; i++) {
		max = max + k.at(i);
	}
	for (int i = 0; i < N - K  ; i++) {
		if (S.at(i + K ) - S.at(i) > max) {
			max = S.at(i + K ) - S.at(i);
		}
	}
	cout << fixed << setprecision(12) <<  max << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <functional>
using namespace std;

int a, b, c;

int main() {
	cin >> a >> b >> c;
	if (a + b >= c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ssize = s.size();
  vector<P> ps;
  rep(i, ssize - 1) {
    if (s[i] == '\\') {
      int pos = -1;
      int j = i + 1;
      while (j < ssize) {
        if (s[j] == '\\') pos -= 1;
        else if (s[j] == '/') {
          pos += 1;
          if (pos == 0) break;
        }
        j++;
      }
      if (j != ssize) ps.push_back({i, j}); 
    }
  }
  vector<int> is;
  int total = 0;
  int m = -1;
  for (int i = 0; i < ps.size(); i++) {
    if (ps[i].first > m) {
      m = ps[i].second;
      is.push_back(0);
    }
    is[is.size() - 1] += ps[i].second - ps[i].first;
    total += ps[i].second - ps[i].first;
  }
  printf("%d\n", total);
  int issize = is.size();
  printf("%d", issize);
  rep(i, is.size()) {
    printf(" %d", is[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3388
#include <bits/stdc++.h>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;using std::queue;using std::priority_queue;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;using std::swap;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::vector<int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}

namespace ndifix{
template<class T> void sort(T &v){std::sort(v.begin(),v.end());}
template<class T> void rsort(T &v){std::sort(v.rbegin(),v.rend());}

}

int main(){
  int n;cin>>n;
  vector<string> w(n);
  for(int i=0;i<n;i++)cin>>w[i];
  string prev=w[0];
  set<string> done;done.insert(prev);
  for(int i=1;i<n;i++){
	  if(w[i][0]!=prev[prev.size()-1]){cout<<"No"<<endl;return 0;}
	  if(done.count(w[i])){cout<<"No"<<endl;return 0;}
	  done.insert(w[i]);
	  prev=w[i];
  }
  cout<<"Yes"<<endl;
  return 0;
}


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

const int M = 1e9 + 7;
const int INF = 1e9 + 5;

int main() {
	int n, w;
	cin >> n >> w;
	vector<int> val(n), weight(n);
	
	for(int i = 0; i < n; i++) {
		cin >> weight[i] >> val[i];
	}
	
	vector<ll> dp(w+1);
	
	for(int i = 1; i <= n; i++) {
		vector<ll> new_dp(w+1);
		for(int j = 1; j <= w; j++) {
			if(weight[i-1] <= j) {
				new_dp[j] = max(dp[j], dp[j - weight[i-1]] + val[i-1]);
			}
			else {
				new_dp[j] = dp[j];
			}
		}
		dp = new_dp;
	}
	
	cout << dp[w] << "\n";
}


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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  //長方形の左下の座標
  int x1 = 0, y1 = 0;
  //長方形の右上の座標
  int x2 = w, y2 = h;
  rep(i,n){
    int x, y, a;
    cin >> x >> y >> a;
    if(a==1){
      if(x1 <= x) x1 = x;
    }else if(a==2){
      if(x2 >= x) x2 = x;
    }else if(a ==3){
      if(y1 <= y) y1 = y;
    }else {
      if(y2 >= y) y2 = y;
    }
  }
  int ans = (x2 - x1) * (y2 - y1);
  if(x1 > x2 || y1 > y2){
    cout << 0 << endl;
  }else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
W, H, X, Y = gets.split.map(&:to_i)

space_h = [X * H, W * H - X * H].min
space_w = [Y * W, W * H - Y * W].min

puts "#{W * H / 2.0} #{W / 2.0 == X && H / 2.0 == Y ? 1 : 0}"


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
typedef pair<ll,ll> pll;
const int inf   = 1<<29;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  ll n,k;
  cin>>n>>k;
  ll a[n],b[n];
  pll p[n];
  ll cnt=0;
  rep(i,n){
    cin>>a[i]>>b[i];
    p[i]=pll(a[i],b[i]);
    }
  sort(p,p+n);
  rep(i,n){
    cnt+=p[i].second;
    if(cnt>=k){
      cout<<p[i].first<<endl;
      break;
      }
    }
  return 0;
}



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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

bool Q();
int E();
int T();
int F();
int N();
string B();

string enc;
string str;
string alpha;
int idx;
int ans;

bool flag;

string sign = "01+-*()=";

bool isok(char c) {
  return idx < (int)str.size() && str[idx] == c;
}

bool Q() {
  flag = true;
  if(count(all(str), '=') != 1) return false;

  int lh = E();
  if(!flag) return false;
  if(!isok('=')) return false;
  idx++; // =

  int rh = E();
  if(!flag) return false;
  if(idx != (int)str.size()) return false;

  return lh == rh;
}

int E() {
  int res = T();
  if(!flag) return 0;
  while(flag && (isok('+') || isok('-'))) {
    int ope = (str[idx] == '+' ? 1 : -1);
    idx++; // +/-
    int ri = T();
    if(!flag) return 0;
    res += ope*ri;
  }
  return res;
}

int T() {
  int res = F();
  if(!flag) return 0;
  while(flag && isok('*')) {
    idx++;
    int ri = F();
    if(!flag) return 0;
    res *= ri;
  }
  return res;
}

int F() {
  if(isok('-')) {
    idx++;
    int res = F();
    if(!flag) return 0;
    return -res;
  }
  if(isok('(')) {
    idx++;
    int res = E();
    if(!flag) return 0;
    if(!isok(')')) { flag = false; return 0; }
    idx++; // )
    return res;
  }
  int res = N();
  if(!flag) return 0;
  return res;
}

int N() {
  string tmp = B();
  if(tmp.empty() || (tmp.size() > 1 && tmp[0] == '0')) { flag = false; return 0; }
  reverse(all(tmp));
  int res = 0, p = 1;
  rep(i, tmp.size()) {
    res += (tmp[i]-'0')*p;
    p *= 2;
  }
  return res;
}

string B() {
  string res = "";
  while(idx < (int)str.size() && isdigit(str[idx])) res += str[idx++];
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> enc;
  for(char c : enc) {
    if(isalpha(c)) alpha.push_back(c);
  }
  sort(all(alpha));
  alpha.erase(unique(all(alpha)), alpha.end());
  if(alpha.size() > sign.size()) {
    cout << 0 << endl;
    return 0;
  }

  ans = 0;
  sort(all(sign));
  set<string> st;
  do {
    //cout<<sign<<endl;
    idx = 0;
    str = enc;
    for(char &c : str) {
      if(isalpha(c)) c = sign[alpha.find(c)];
    }
    if(st.count(str)) continue;
    st.insert(str);
    if(Q()) {
      //cout << idx << " " << str << endl;
      ans++;
    }
  } while(next_permutation(all(sign)));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7572
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

string s,t,tt;
LL n=1,ans=0,a[200010],mid=-1,cur[30],dat[800010];
vector <LL> v[30],vv[30];
bool fr[200010];

void upd(LL k)
{
	dat[k]++;
	while(k>0)
	{
		k=(k-1)/2;
		dat[k]=dat[k*2+1]+dat[k*2+2];
	}
}

LL query(LL k,LL lb,LL ub,LL tlb,LL tub)
{
	if(ub<tlb||tub<lb) return 0;
	if(tlb<=lb&&ub<=tub) return dat[k];
	return query(k*2+1,lb,(lb+ub)/2,tlb,tub)+query(k*2+2,(lb+ub)/2+1,ub,tlb,tub);
}

int main()
{
	cin>>s;
	rep(i,s.size()) v[s[i]-'a'].pb(i);
	LL num=0;
	rep(i,26) if(v[i].size()%2==1) num++;
	if(num>1)
	{
		puts("-1");
		return 0;
	}
	rep(i,26)
	{
		rep(j,v[i].size()/2) fr[v[i][j]]=true;
		if(v[i].size()%2==1) mid=i;
	}
	rep(i,s.size())
	{
		if(!fr[i])
		{
			tt.pb(s[i]);
			continue;
		}
		ans+=i-t.size();
		t.pb(s[i]);
	}
	reverse(t.begin(),t.end());
	rep(i,tt.size())
	{
		if(tt[i]-'a'==mid)
		{
			ans+=i;
			tt.erase(tt.begin()+i);
			break;
		}
	}
	rep(i,tt.size()) vv[tt[i]-'a'].pb(i);
	rep(i,t.size()) a[vv[t[i]-'a'][cur[t[i]-'a']++]]=i;
	while(n<tt.size()) n*=2;
	rep(i,tt.size())
	{
		ans+=query(0,0,n-1,a[i]+1,tt.size()-1);
		upd(a[i]+n-1);
	}
	cout<<ans<<endl;
	return 0;
}

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

#define MAX (1000000007)

 
bool trioCompare(const pair<pair<int, int>,int>& firstElof, const pair<pair<int, int>,int>& secondElof)
{
    return firstElof.second > secondElof.second;
}


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


    pair<pair<int, int>,int> diff[2500];
    pair<int, int> p[50];
    
    for (int i = 0; i < n; i++)
    {
        cin >>p[i].first>>p[i].second;
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; i+j <n; j++)
        {
            pair<int, int> temp;
            temp.first = p[i].first-p[i+j].first;
            temp.second = p[i].second-p[i+j].second;
            if(temp.first<0){
                temp.first*=-1;
                temp.second*=-1;
            }
            if(temp.first==0){
                if(temp.second<0){
                    temp.second*=-1;
                }
            }
            int k;
            int count = i*n+j-1;
            for (k = 0; k < count; k++)
            {
                if(temp == diff[k].first){
                    diff[k].second++;
                    break;
                }
            }
            if(k==count){
                diff[count].first.first = temp.first;
                diff[count].first.second = temp.second;
                diff[count].second = 1;
            }
        }
    }

    // sort(p,p+n, pairCompare);

    sort(diff,diff+n*n, trioCompare);

    // for (int i = 0; i < n*n; i++)
    // {
    //     cerr << diff[i].first.first<< " "<< diff[i].first.second<<" " << diff[i].second << endl;
    // }
    
    cout << n-diff[0].second <<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
   cin.tie(0);  
   ios::sync_with_stdio(false);
   int now=0,n,l[101],x,cnt=1;
   cin>>n>>x;
   FOR(i,n){
     cin>>l[i];
     now=now+l[cnt-1];
     if(now<=x) cnt++;
     else break;
   }
   cout<<cnt<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t A, B, M;
    cin >> A >> B >> M;

    vector<int64_t> a(A);
    int64_t ma = numeric_limits<int64_t>::max();
    for (auto&& aa : a) {
        cin >> aa;
        ma = min(aa, ma);
    }

    vector<int64_t> b(B);
    int64_t mb = numeric_limits<int64_t>::max();
    for (auto&& bb : b) {
        cin >> bb;
        mb = min(bb, mb);
    }

    int64_t ans = ma + mb;
    for (auto i : irange(0L, M)) {
        int64_t x, y, c;
        cin >> x >> y >> c;

        ans = min(ans, a[x - 1] + b[y - 1] - c);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m;
string str;

int main(){
	cin >> n;
	
	ll ans = 0;
	for(ll a = 1; a*a < n; a++){
		if(n%a == 0 && a < n/a-1){
			ans += n/a-1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    if(x <= a*a*b/2){
        double l = 2.0*x/(a*b);
        cout << setprecision(8) << atan2(b,l)*180/M_PI;
    }
    else{
        double dx = x - a*a*b/2;
        double l = 2*dx/(a*a);
        cout << setprecision(8) << atan2(b-l,a)*180/M_PI;
    }
}

Measured memory_bytes: 256