akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	int k, n;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; ++i)
		cin >> h[i];
	sort(h.begin(), h.end(), cmp);
	long long ans = 0;
	for (int i = k; i < n; ++i)
		ans += h[i];
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<limits.h>

int max(int a, int b) {
	return a > b ? a : b;
}

int main() {
	const int inf = -INT_MAX;
	int n;
	int arr[110];

	scanf("%d", &n);

	int i, j, sum = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
		sum += arr[i];
	}

	int f[100010] = {};

	for (i = 1; i <= sum; i++) {
		f[i] = inf;
	}

	for (i = 0; i < n; i++) {
		for (j = sum; j >= 0; j--) {
			if (f[j] >= 0) {
				f[j + arr[i]] = 1;
			}
		}
	}

	int result = 0;
	for (i = sum; i >0; i--) {
		if (i % 10 == 0) continue;
		if (f[i] >= 0) {
			result = i;
			break;
		}
	}

	printf("%d", result);

	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


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


int32_t main(int32_t argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
    vs args(argv, argv+argc);
    string sample = make_sample(args, "sample-1");
    ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#endif


    int K; cin >> K;

    int sum = 0;
    FOR(a, 1, K+1) {
        FOR(b, 1, K+1) {
            int gab = gcd(a, b);
            FOR(c, 1, K+1) {
                sum += gcd(gab, c);
            }
        }
    }

    int ans = sum;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5 + 10, inf = 1e9 + 10, mod = 1e9 + 7;
ll a[N], b[N], t[4 * N], d[N], ans;
ll get(int v, int tl, int tr, int l, int r)
{
    if(l <= tl && tr <= r)return t[v];
    else if(tr < l || r < tl)return 0;
    else
    {
        int mid = (tl + tr) / 2;
        return max(get(v + v, tl, mid, l, r), get(v + v + 1, mid + 1, tr, l, r));
    }
}
void up(int v, int tl, int tr, int pos, ll val)
{
    if(tl == tr)t[v] = val;
    else
    {
        int mid = (tl + tr) / 2;
        if(pos <= mid)up(v + v, tl, mid, pos, val);
        else up(v + v + 1, mid + 1, tr, pos, val);
        t[v] = max(t[v + v], t[v + v + 1]);
    }
}
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++)cin >> b[i];
    for(int i = 1; i <= n; i++)
    {
        d[i] = get(1, 1, n, 1, a[i] - 1) + b[i];
        up(1, 1, n, a[i], d[i]);
        ans = max(ans, d[i]);
    }
    cout << ans;
}


Measured memory_bytes: 11136
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

H,W = map(int,input().split())
grid = '*' * (W+2)
for _ in range(H):
    grid += '*' + input().rstrip() + '*'
grid += '*' * (W+2)

move = [1,-1,W+2,-(W+2)]

root = [None if x == '*' else -1 for x in grid]

answer = 0
for i in range((H+2)*(W+2)):
    if root[i] != -1:
        continue
    q = [i]
    root[i] = i
    counter = defaultdict(int)
    while q:
        x = q.pop()
        counter[grid[x]] += 1 
        for dx in move:
            y = x + dx
            if root[y] != -1:
                continue
            if grid[x] == grid[y]:
                continue
            root[y] = i
            q.append(y)
    answer += counter['.'] * counter['#']

print(answer)

Measured memory_bytes: 9120
/*
ID: Barry Wang
LANG: C++11
TASK: 
*/
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
#define X first
#define Y second
#define Chtolly return 0
/*---define types---*/
typedef long long ll;
typedef list<int> li;
typedef queue<int> qi;
typedef deque<int> dqi;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef unsigned int uint;
/*---define variables---*/
const int inf=(1<<29);
int n;
ll h[100005],dp[100005]; 
/*---define function---*/

/*---main code---*/
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		dp[i]=0x7fffffff;
		cin>>h[i];
	}
	dp[1]=0;
	for(int i=1;i<n;++i){
		dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	cout<<dp[n]<<'\n';
	return 0;
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

// disjoin set
public class Main {
    static class UnionFind {

        private int parent[];
        private int rank[];

        public UnionFind(int Num_element) {
            parent = new int[Num_element];
            rank = new int[Num_element];
            for (int i = 0; i < Num_element; i++)
                parent[i] = i;
        }
        public void makeSet(int x) {
            parent[x] = x;
            rank[x] = 0;
        }

        public void union(int x, int y) {
            link(findSet(x), findSet(y));
        }

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


        public void link(int x, int y) {
            if (rank[x] > rank[y]) {
                parent[y] = x;
            } else {
                parent[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }
        public void command(int com, int x, int y){
            if(com == 0){
               //unite
                link(findSet(x), findSet(y));
            }else{
                //same
                if( findSet(x) == findSet(y))
                    System.out.println("1");
                else
                    System.out.println("0");
            }
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Disjoin set element number
        int Num_element;

        //Query times
        int Num_query;


            Num_element = sc.nextInt();
            Num_query = sc.nextInt();
            UnionFind Disjoin_set = new UnionFind(Num_element);
            for (int i=0;i<Num_query;i++){
                // '0' denotes unite and '1' denotes same operation.
                int com = sc.nextInt();
                int x = sc.nextInt();
                int y = sc.nextInt();
                Disjoin_set.command(com,x,y);
            }

    }
}



Measured memory_bytes: 106804
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int a = 0;
  while(a*a<=n) a++;
  a--;
  cout << a*a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
    int n,k;
    cin >> n>>k;
    vector<double> ar(n),prefix(n);
    for (auto &i : ar)
    {
        cin >> i;
        int temp = i;
        i = i * (i + 1) / 2.0;
        i = i / temp;
    }
    prefix[0]=ar[0];
    for (int i = 1; i < n ; i++)
        prefix[i]=prefix[i-1]+ar[i];
    double ans=prefix[k-1];
    for(int i=k;i<n;i++)
        ans=max(ans,prefix[i]-prefix[i-k]);
    cout<<fixed<<setprecision(14)<<ans;
    return 0;
}

Measured memory_bytes: 6424
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]

mod = 998244353
dp = [0]*n
dp[0] = 1
s = 0
for i in range(1, n):
    for j in range(k):
        if i-lr[j][0] < 0:
            continue
        elif i-lr[j][1] <= 0:
            s = (s + dp[i-lr[j][0]]) % mod
        elif 0 < i-lr[j][1]:
            s = (s + dp[i-lr[j][0]] - dp[i-lr[j][1]-1]) % mod
    dp[i] = s
print(dp[-1])

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

int main() {
	string s;
	int q;
	cin >> s >> q;
	deque<char> de;
	for(int i = 0; i < s.size(); ++i) de.push_back(s[i]);
	int inv = 0;
	while(q--) {
		int ty;
		cin >> ty;
		if(ty == 1) {
			if(inv == 0) inv = 1;
			else inv = 0;
		}
		else {
			int f; char c;
			cin >> f >> c;
			if(f == 1) {
				if(inv == 0) {
					de.push_front(c);
				}
				else de.push_back(c);
			}
			else {
				if(inv == 1) {
					de.push_front(c);
				}
				else de.push_back(c);
			}
		}
	}
	if(inv == 0) {
		while(!de.empty()) {
			cout << de.front();
			de.pop_front();
		}
	}
	else {
		while(!de.empty()) {
			cout << de.back();
			de.pop_back();
		}	
	}
	return 0;
}

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

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for(int &x : a)
		cin >> x;
	int ans=0;
	for(int i=0; i<n; ++i)
		for(int j=i+1; j<n; ++j)
			for(int k=j+1; k<n; ++k)
				if(a[i]^a[j]&&a[j]^a[k]&&a[i]^a[k]&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
					++ans;
	cout << ans << "\n";
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    int grupos = 1;
    char at = s[0];
    for(int i = 1; i < n; i++) {
        if(at != s[i]) grupos++;
        at = s[i];
    }

    grupos -= 2 * k;

    cout << min(n-1, n-grupos) << "\n";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ll i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();


  int a,b,c,k=0;
  cin>>a>>b>>c;
  for(int i = 101;i>=1;i--)
  {
    if(a%i == 0 && b%i ==0)k++;
    if(c==k)
    {
      cout<<i;
      return 0;
    }
  }


  return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

uint32_t p[100000];

struct {
	uint32_t x;
	uint32_t y;
} swapList[100000];

uint32_t ufTree[100000];

static uint32_t getRootIdx(const uint32_t idx) {
	uint32_t nextIdx = idx;
	while (1) {
		if (ufTree[nextIdx] == UINT32_MAX) {
			if ((idx != nextIdx) && (ufTree[idx] != nextIdx)) {
				ufTree[idx] = nextIdx;
			}
			return nextIdx;
		}
		nextIdx = ufTree[nextIdx];
	}
}

static void mergeTree(const uint32_t root0, const uint32_t root1) {
	ufTree[root1] = root0;
}

int main(void) {
	uint32_t N, M;

	scanf("%"PRIu32" %"PRIu32"\n", &N, &M);
	for (uint32_t idx = 0; idx < N - 1; idx++) {
		scanf("%"PRIu32" ", &(p[idx]));
		ufTree[idx] = UINT32_MAX;
	}
	scanf("%"PRIu32"\n", &(p[N - 1]));
	ufTree[N - 1] = UINT32_MAX;
	for (uint32_t idx = 0; idx < M - 1; idx++) {
		scanf("%"PRIu32" %"PRIu32"\n", &(swapList[idx].x), &(swapList[idx].y));
	}
	scanf("%"PRIu32" %"PRIu32, &(swapList[M - 1].x), &(swapList[M - 1].y));

	for (uint32_t idx = 0; idx < M; idx++) {
		const uint32_t xRoot = getRootIdx(swapList[idx].x - 1);
		const uint32_t yRoot = getRootIdx(swapList[idx].y - 1);
		if (xRoot != yRoot) {
			mergeTree(xRoot, yRoot);
			continue;
		}
	}

	uint32_t matchCount = 0;
	for (uint32_t idx = 0; idx < N; idx++) {
		if (getRootIdx(idx) == getRootIdx(p[idx] - 1)) {
			matchCount++;
		}
	}

	printf("%"PRIu32, matchCount);

	return 0;
}

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

arrey = [int(i) for i in input().split()]

for i in range(n):
    v = arrey[i]
    j = i - 1
    while j >= 0 and arrey[j] > v:
        arrey[j+1] = arrey[j]
        j = j - 1
        arrey[j+1] = v
    for k in range(n):
        print(arrey[k]) if k == n-1 else print(str(arrey[k])+' ',end='')

Measured memory_bytes: 8088
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S=sc.next();
		if(S.equals("AAA")||S.equals("BBB")) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}

	}
}


Measured memory_bytes: 21972
#include <stdio.h>
#include <math.h>
#include <string.h>


typedef long long ll;

int main() {
	char s[1005];
	scanf("%s", s);
	
	int l = strlen(s);
	if (s[l-1] == 's')
	{
		printf("%ses", s);
	}
	else
	{
		printf("%ss", s);
	}
	
	
	return 0;
}


Measured memory_bytes: 1736
import java.util.Scanner;

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

        long X = Long.parseLong(Xstr);
        long Y = Long.parseLong(Ystr);

        long count = 0L;

        long cursor = X;
        while(cursor <= Y){
            count = count + 1L;
            cursor = cursor * 2;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
    int n;
    cin>>n;
 string s;int c[4]={};
 for(int i=0;i<n;i++){
     cin>>s;
     if(s=="AC")c[0]++;
     if(s=="WA")c[1]++;
     if(s=="TLE")c[2]++;
     if(s=="RE")c[3]++;

 }
 cout<<"AC x "<<c[0]<<endl;
 cout<<"WA x "<<c[1]<<endl;
 cout<<"TLE x "<<c[2]<<endl;
 cout<<"RE x "<<c[3]<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 3596
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath> 
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f 
#define mem(a) (memset(a,0,sizeof(a))) 
typedef long long ll;
vector<int>v[200006];
int n,m,x,y,vis[200006];
bool flag;
void bfs(int x,int y,int k)
{
    if(x==y && k<=2)
    {
        printf("POSSIBLE\n");
        flag=true;
        return;
    }
    if(k>2) return;
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(!vis[v[x][i]])
        {
            vis[v[x][i]]=1;
            bfs(v[x][i],y,k+1);
            vis[v[x][i]]=0;
        }
    }
    vis[x]=0;
}
int main()
{
    ios::sync_with_stdio(false);
    scanf("%d%d",&n,&m);
    flag=false;
    memset(vis,0,sizeof(vis));
    while(m--)
    {
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    bfs(1,n,0);
    if(!flag) printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 12784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#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 SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};



ll ans[100010];

int main() {
    ll N, M, a, b;
    cin >> N >> M;
    vector<pair<ll,ll>> vec(M);
    FOR(i,0,M-1) {
        cin >> a >> b; --a, --b;
        vec[i].first = a;
        vec[i].second = b;
    }

    // calculation
    UnionFind uf(N);
    ans[M-1] = N*(N-1)/2;

    FORD(i,M-1,1) {
        if(uf.root(vec[i].second)==uf.root(vec[i].first)){
          ans[i-1] = ans[i];
        }
        else{
          ans[i-1] = ans[i] - uf.size(vec[i].second) * uf.size(vec[i].first);
          uf.merge(vec[i].second,vec[i].first);
        }
    }

    FOR(i,0,M-1) cout << ans[i] << endl;

    return 0;
}



Measured memory_bytes: 5248
# LCS
s = input()
t = input()
ls, lt = len(s), len(t)
dp = [[0 for i in range(ls + 1)] for j in range(lt + 1)]
prev = [[0 for i in range(ls + 1)] for j in range(lt + 1)]
for i in range(lt):
    for j in range(ls):
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
        if t[i] == s[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
# 復元
ans = []
x = lt
y = ls
while x > 0 and y > 0:
    if dp[x][y] == dp[x-1][y]:
        x -= 1
    elif dp[x][y] == dp[x][y-1]:
        y -= 1
    else:
        x -= 1
        y -= 1
        ans.append(t[x])
ans = reversed(ans)
print("".join(ans))

Measured memory_bytes: 231124
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
const int N=200500;
int n;
ll w[N];
ll dp[3005][3005];
ll f(int a, int b){
	if(a>b)return 0;
	ll &r=dp[a][b];
	if(r!=-1)return r;
	r=w[a]-f(a+1,b);
	r=max(r,w[b]-f(a,b-1));
	return r;
}
int main(){FIN;
	cin>>n;
	fore(i,0,n)cin>>w[i];
	memset(dp,-1,sizeof dp);
	cout<<f(0,n-1)<<"\n";
}

Measured memory_bytes: 72064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int n,i,s,sum;
	vi v;
	while(1){
		cin>>n;
		if(n==0)break;
		
		v.clear();
		rep(i,n){
			cin>>s;
			v.push_back(s);
		}
		sort(v.begin(),v.end());
		sum=0;
		for(i=1;i<n-1;i++){
			sum+=v[i];
		}
		cout<<sum/(n-2)<<endl;
	}
	
	
	
	
	
	
//////////////////////////////////////////////////////
return 0;}












Measured memory_bytes: 3032
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 505
int n,m,lx=-1,ly=-1;
char s[MAXN][MAXN],a[MAXN][MAXN],b[MAXN][MAXN];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	memcpy(a,s,sizeof s);
	memcpy(b,s,sizeof b);
	for(int i=1;i<=n;i++)
	{
		a[i][1]=b[i][m]='#';
		if(i&1)
		{
			for(int j=2;j<m;j++)
				a[i][j]='#';
		}
		else
		{
			for(int j=2;j<m;j++)
				b[i][j]='#';
		}
	}
	for(int i=1;i<=n;i++)
		printf("%s\n",a[i]+1);
	printf("\n");
	for(int i=1;i<=n;i++)
		printf("%s\n",b[i]+1);
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#define Lens 10005

using namespace std;
int n, q;
int r[Lens], l[Lens];

int Find(int x)
{
	
	while (r[x] != x)
		Find(x = r[x]);
	return x;
}

void Unite(int x, int y)
{
	int t1 = Find(x);
	int t2 = Find(y);
	if (t1 == t2)
		return;
	if (l[t1] > l[t2])
	{
		r[t2] = t1;

	}
	else
	{
		r[t1] = t2;
		if(l[t1]==l[t2])
		{
			l[t2]++;
	
		}

	}
}

void Same(int x, int y)
{
	int t1 = Find(x);
	int t2 = Find(y);
	if (t1 == t2)
		cout << '1' << endl;
	else
		cout << '0' << endl;
}

int main()
{
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		r[i] = i;
		l[i] = 0;
	}

	for (int i = 0; i < q; i++)
	{
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0)
			Unite(x, y);
		else if (com == 1)
			Same(x, y);
	}
	return 0;
}


Measured memory_bytes: 3176
from collections import deque

def Topologicalsort(v):
    start=deque()
    for i in xrange(v):
        if indeg[i]==0 :
            start.append(i)
    if len(start)>1:
        flag=True
    else:
        flag=False
    while len(start)>0:
        i=start.popleft()
        ans.append(i)
        cnt=0
        for j in g[i]:
            indeg[j]-=1
            if indeg[j]==0:
                cnt+=1
                start.append(j)
                if cnt>1:
                    flag=True
    return ans,flag

def solve(n,m):
    for i in xrange(m):
        wt,lt=map(int,raw_input().split())
        wt-=1;lt-=1
        g[wt].append(lt)
        indeg[lt]+=1
    ans,flag=Topologicalsort(n)
    if flag:
        for i in xrange(n):
            print(ans[i]+1)
        print(1)
    else:
        for i in xrange(n):
            print(ans[i]+1)
        print(0)

n=int(raw_input())
m=int(raw_input())
indeg=[0]*n
g=[[] for _ in xrange(n)]
ans=[]

solve(n,m)

Measured memory_bytes: 10360
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e;
	cin>>a;
	b=a%10;
	c=a%100;
	d=a-c;
	e=d/100;
	if (e==b)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

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

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; }
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

int N, K;


// *********************************************************
int main(){

    cin >>  N>>  K;

    vll A(N+1);

    for(int i=1; i<=N; i++){
        cin >> A.at(i);
        if(i>K){
            if(A.at(i) > A.at(i-K)){
                cout << "Yes" << endl;
            }else{
                cout << "No" <<endl;
            }
        }
    }
   


    return 0;
}

Measured memory_bytes: 4772
MOD = 998244353
def pow(n,k,m):#n^k mod m
    ans = 1
    while k>0:
        if(k & 1):ans = (ans*n) % m
        n = (n*n)%m
        k >>= 1
    return ans

n = int(input())
a =[int(input()) for i in range(n)]
s = sum(a)
dp1 = [0 for i in range(s+1)] #dp1[x]:Bの和=xとなるような塗り方の総数

dp1[0] = 1

for i in  a:
    dpp1 = [0 for i in range(s+1)]
    for j in range(s+1):
        if j+i <= s:dpp1[j+i] = (dp1[j]+dpp1[j+i]) % MOD
        dpp1[j] = (dp1[j]*2 + dpp1[j]) % MOD
    dp1 = dpp1[:]

if s % 2 == 1:
    ans1 = sum(dp1[(s//2) + 1:]) % MOD
    print((pow(3,n,MOD)-ans1*3) % MOD)
    exit()

ans1 = sum(dp1[(s//2):]) % MOD

dp2 = [0 for i in range(s+1)]

dp2[0] = 1

for i in a:
    dpp2 = [0 for i in range(s+1)]
    for j in range(s+1):
        if j+i <= s:dpp2[j+i] = (dp2[j]+dpp2[j+i]) % MOD
        dpp2[j] = (dp2[j] + dpp2[j]) % MOD
    dp2 = dpp2[:]

print((pow(3,n,MOD)-(ans1*3 - dp2[s//2]*3)) % MOD)

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int rest = Math.max(0, a - 2 * b);
            out.println(rest);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;


void solve(){
    int n;
    cin >> n;
    int ans = 1e9;
    for(int i = 0;i < n; i++){
        int x;
        cin >> x;
        int cnt = 0;
        while(x % 2 == 0){
            cnt++;
            x /= 2;
        }
        ans = min(cnt, ans);
    }
    cout << ans;
    
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 666666666
#define ll long long
#define ld long double

vector<int>g[200005];
int in[200005];
int DP[200005];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        in[v]++;
    }

    queue<int>q;
    for(int i=1; i<=n; i++)
        if(in[i]==0)q.push(i);

    while(!q.empty())
    {
        int c = q.front();
        q.pop();
        DP[c]++;
        for(auto&u:g[c])
        {
            DP[u]=max(DP[u],DP[c]);
            if(--in[u]==0)q.push(u);
        }
    }

    cout<<*max_element(DP,DP+n+1)-1;
}


Measured memory_bytes: 8832
#include <stdio.h>

int main(void){
	int n,i,j,l,m,k;
	char mark;
	int a[4][14]={0};
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%c", &mark);
		scanf("%c %d",&mark,&k);
		if(mark =='S'){
		m=0;
		}else if(mark =='H'){
		m=1;
		}else if(mark =='C'){
		m=2;
		}else if(mark =='D'){
		m=3;
		}
		a[m][k]=1;
	}
	
	for(j=0;j<4;j++){
		for(l=1;l<=13;l++){
			if(a[j][l]==0){
				if(j==0){
				mark ='S';
				}else if(j==1){
				mark ='H';
				}else if(j==2){
				mark ='C';
				}else if(j==3){
				mark ='D';
				}
				printf("%c %d\n",mark,l);
		}
		}
	}
return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int n;
ull x, a[200200], s[200200], ans;

int main() {
	ans = ~ans;
	scanf("%d%lld",&n,&x);
	for (int i=1;i<=n;i++) scanf("%llu",a+n-i+1);
	for (int i=1;i<=n;i++) s[i] = s[i-1] + a[i];
	for (int k=1;k<=n;k++) {
		ull res = s[n] * 5ll + x * (n + k);
		for (int i=k*2;i<=n;i+=k) {
			res += (s[n] - s[i]) * 2ll;
		}
		ans = min(ans,res);
	}
	printf("%llu\n",ans);
}

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

int main(int argc, char *argv[])
{
	string a,b;

	cin >> a;

	if (a=="Sunny") cout << "Cloudy" << endl;
	if (a=="Cloudy") cout << "Rainy" << endl;
	if (a=="Rainy") cout << "Sunny" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <math.h>
#include <list>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 105
#define MAX_M 100

int N;
int B[MAX_N];
int A[MAX_N];

int main()
{
    int N, M, C;
    int a = 0;
    cin >> N >> M >> C;
    rep(i, M) cin >> B[i];
    rep(i, N)
    {
        rep(j, M) cin >> A[j];
        int ans = 0;
        rep(j, M) ans += A[j] * B[j];
        ans += C;
        if (ans > 0)
            a++;
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M);
    vector<char> c(M);
    for (int i = 0; i < M; i++) {
        cin >> s.at(i) >> c.at(i);
        s[i]--;
    }

    int st = 1;
    for (int i = 0; i < N - 1; i++) {
        st *= 10;
    }
    int en = st * 10;
    if (N == 1) st = 0;
    for (int i = st; i < en; i++) {
        bool flag = true;
        string S = to_string(i);
        for (int j = 0; j < M; j++) {
            if (S[s[j]] != c[j]) flag = false;
        }
        if (flag) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split(' ')]
# A = '0 33 43 62 29 0 8 52 56 56 19 11 51 43 5 8 93 30 66 69'.split(' ')
# A = [int(i) for i in A]

def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter)

bubble_sort(A, n)

Measured memory_bytes: 7696
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
    int a[3];
    for (int i = 0; i < 3; i++){
        cin >> a[i];
    }
    sort (a, a + 3);
    int count = 0;
    int dif[2];
    for (int i = 0; i < 2; i++){
        dif[i] = a[2] - a[i];
        count += dif[i]/ 2;
    }
    if ((dif[0] % 2 == 0) && (dif[1] % 2 == 0)){
        cout << count << endl;
    }
    else if (dif[0] * dif[1] % 2 == 1){
        cout << count + 1 << endl;
    }
    else if (dif[0] * dif[1] % 2 == 0){
        cout << count + 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
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 k = sc.nextInt();

		int sum = 0;

		while (a != 0 && k != 0) {
			sum++;
			a--;
			k--;
		}

		while (b != 0 && k != 0) {
			b--;
			k--;
		}

		while (c != 0 && k != 0) {
			sum--;
			c--;
			k--;
		}

		System.out.println(sum);

		sc.close();
	}

}


Measured memory_bytes: 36244
#include<bits/stdc++.h>
using namespace std;
string str;
bool flag;
int main()
{
	cin>>str;
	int len=str.length();
	for(int i=0;i<len;i++)
	{
		if(str[i]=='C')flag=1;
		if(str[i]=='F'&&flag)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

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

const ll MAXN = 200000;

ll H, W, ans=0;
vector<char> v(22,'#');
vector<vector<char>> S(22, v);

void bfs(ll sx, ll sy, ll gx, ll gy){
    queue<pair<ll, ll>> Q;
    vector<ll> vc(H+2, 0);
    vector<vector<ll>> color(W+2, vc), cost(W+2, vc);
    Q.push(make_pair(sx, sy));
    color[sx][sy] = 1;
    cost[sx][sy]=0;
    if(S[sx][sy]=='#'||S[gx][gy]=='#') return;
    while(!Q.empty()){
        pair<ll, ll> p = Q.front();
        Q.pop();
        if(color[p.first+1][p.second]==0&&S[p.first+1][p.second]=='.') {                
            Q.push(make_pair(p.first+1, p.second));
            color[p.first+1][p.second] = 1;
            cost[p.first+1][p.second]=cost[p.first][p.second]+1;
        }
        if(color[p.first-1][p.second]==0&&S[p.first-1][p.second]=='.') {                
            Q.push(make_pair(p.first-1, p.second));
            color[p.first-1][p.second] = 1;
            cost[p.first-1][p.second]=cost[p.first][p.second]+1;
        }
        if(color[p.first][p.second+1]==0&&S[p.first][p.second+1]=='.') {                
            Q.push(make_pair(p.first, p.second+1));
            color[p.first][p.second+1] = 1;
            cost[p.first][p.second+1]=cost[p.first][p.second]+1;
        }
        if(color[p.first][p.second-1]==0&&S[p.first][p.second-1]=='.') {                
            Q.push(make_pair(p.first, p.second-1));
            color[p.first][p.second-1] = 1;
            cost[p.first][p.second-1]=cost[p.first][p.second]+1;
        }
    }
    ans = max(ans, cost[gx][gy]);
}

void bfsinit(){
    for(int i1=1;i1<=H;i1++) {
        for(int j1=1;j1<=W;j1++) {
            for(int i2=1;i2<=H;i2++) {
                for(int j2=1;j2<=W;j2++) {
                    bfs(j2, i2, j1, i1);
                }
            }
        }
    }
}

signed main(){
    cin >> H >> W;
    for(int j=1;j<=H;j++){
        for(int i=1;i<=W;i++) cin >> S[i][j];
    }
    bfsinit();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int N=101010;
ll ct[N]={};

int main()
{
    int n;
    ll k;
    scanf(" %d %lld", &n, &k);

    rep(i,n)
    {
        int a,b;
        scanf(" %d %d", &a, &b);
        ct[a] += b;
    }

    int ans=1;
    ll s=0;
    while(1)
    {
        if(s+ct[ans]>=k) break;
        s += ct[ans];
        ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
n, m = map(int, input().split())
N = [input() for _ in range(n)]
M = [input() for _ in range(m)]
flg = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if all(M[k] == N[i + k][j : j + m] for k in range(m)):
            flg = True
            break
print(['No','Yes'][flg])


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

typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  vector<int> ans(26,-1);
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    vector<int> tmp(26, -1);
    for(int j=0; j<s.length(); j++){
      if(tmp[s[j]-'a'] == -1) tmp[s[j]-'a'] = 1;
      else tmp[s[j]-'a'] += 1;
    }
    if(i==0){
      for(int k=0; k<26; k++){
        ans[k] = tmp[k];
      }
      continue;
    }
    for(int k=0; k<26; k++){
      if(ans[k] == -1) continue;
      if(tmp[k] == -1) ans[k] = -1;
      else ans[k] = min(ans[k], tmp[k]);
    }
  }
  for(int i=0; i<26; i++){
    if(ans[i] == -1) continue;
    for(int j=0; j<ans[i]; j++){
      cout << string({'a'+i});
    }
  }
  cout << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int main(int argc, const char * argv[]) {
    int n;
    scanf("%d",&n);
    int arr[n+1];
    for(int i=0;i<=n;i++)arr[i]=0;
    for(int i=0;i<n-1;i++){
        int tmp;
        scanf("%d",&tmp);
        arr[tmp]++;
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",arr[i]);
    }
    return 0;
}


Measured memory_bytes: 2456
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
K = 0
S = 0
T = []
if sum(A) < sum(B):
    K = -1
else:
    for i in range(N):
        if A[i] < B[i]:
            K += 1
            S = S + B[i] - A[i]
        elif A[i] > B[i]:
            T.append(A[i] - B[i])
        else:
            continue
T.sort()
L = 0
while S > L:
    L += T.pop()
    K += 1
print(K)


Measured memory_bytes: 18356
#include<bits/stdc++.h>
using namespace std;
 
typedef long long lint;
typedef long double louble;
 
template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}
 
namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;
 
const int _ = 200007 , N = 2000 , _N = N + N + 3 , mo = 1000000007;
 
template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
 
inline lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}
 
inline lint inva(lint a)
{
	return powa(a,mo-2);
}
 
int jc[_],rjc[_];
 
inline void fuck(int n=_-1)
{
	jc[0]=jc[1]=rjc[0]=1;
	for(int i=2;i<=n;i++)jc[i]=1ll*jc[i-1]*i%mo;
	rjc[n]=inva(jc[n]);
	for(int i=n-1;i>=1;i--)rjc[i]=rjc[i+1]*(1ll+i)%mo;
}
 
inline lint C(int n,int m)
{
	if(n<m || n<0 || m<0)return 0;
	return 1ll*jc[n]*rjc[m]%mo*rjc[n-m]%mo;
}
 
int n,va[_],vb[_],g[_N][_N]={0};
 
#define gs(a,b) (g[(a)+N+1][(b)+N+1])
 
int main()
{
	n=ty();
	for(int i=1;i<=n;i++)va[i]=ty(),vb[i]=ty(),gs(-va[i],-vb[i])++;
 
	fuck();
	
	lint ans=0;
	for(int i=-N;i<=N;i++)
		for(int j=-N;j<=N;j++)
			ad(gs(i,j),gs(i-1,j)),ad(gs(i,j),gs(i,j-1));
	for(int i=1;i<=n;i++)
		ad(ans,gs(va[i],vb[i])),dl(ans,C(va[i]+va[i]+vb[i]+vb[i],va[i]+va[i]));
	printf("%lld\n",ans*inva(2)%mo);
	
	return 0;
}

Measured memory_bytes: 65920
fun main(args: Array<String>) {
    abc149d()
}

fun abc149d() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val points = readLine()!!.split(' ').map { it.toInt() }
    val t = readLine()!!.map {
        when (it) {
            'r' -> 0
            's' -> 1
            else -> 2
        }
    }.toIntArray()

    fun cap3(value: Int): Int {
        return if (value >= 3) value % 3 else value
    }

    val chosen = IntArray(n) { -1 }
    var answer = 0L

    for (i in 0 until n) {
        val c = t[i]
        val win = cap3(c + 2)
        val list = if (i + 1 <= k) listOf(0, 1, 2) else listOf(0, 1, 2).filterNot { it == chosen[i - k] }
        val choose = if (win in list) win else -1
        chosen[i] = choose

        answer += if (choose == win) points[choose] else 0
    }

    println(answer)
}


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

int main(){

  int n,m,q;

  cin >> n >> m >> q;

  int size = n;

  bool table[n];

  vector<int> vec;
  list<int> l;

  for(int i=0;i<n;i++){
    table[i] = true;
    vec.push_back(i);
    l.push_back(i);
  }

  list<int>::iterator index=l.begin();

  for(int i=0;i<m;i++){
    int tmp=0,j=0;
    cin >> tmp;
    /*for(list<int>::iterator i = l.begin();i!=l.end();i++){
      cout << *i << " ";
    }
    cout << endl;*/
    if(tmp%2==0){
      while(j!=tmp){
        index++;
        if(index==l.end()){
          index = l.begin();
        }

        j++;
        //cout << j << " " << *index<<endl;
      }
      table[*index] = false;
      list<int>::iterator tmp=index;
      index++;
      if(index==l.end()){
        index = l.begin();
      }
      l.erase(tmp);

    }
    else{
      while(j!=tmp){
        if(index==l.begin()){
          index = l.end();
          index--;
        }
        else{
          index--;
        }
        j++;
      }
      table[*index] = false;
      list<int>::iterator tmp=index;
      index++;
      if(index==l.end()){
        index = l.begin();
      }
      l.erase(tmp);
    }
    /*for(int i=0;i < n;i++){
      cout << table[i] << " ";
    }
    cout << endl;*/
  }


  index = l.begin();

  /*for(int i=0;i < l.size();i++){
    table[*index] = true;
  }*/
  //cout << "ok" << endl;
  for(int i=0;i<q;i++){
    int ansindex,ans;
    cin >> ansindex;
    ans = (table[ansindex]) ? 1 : 0;
    cout << ans << endl;
  }


    return 0;
}

/*
     0
        1
9          2
8            3
  7        4
    6    5







*/

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int>data(N);
  for(int i=0;i<N;i++){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  int ans=0;
  for(int i=0;i<K;i++){
    ans+=data.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>


int main(void){
    int a,b,c;
    while(1){
        scanf("%d %d %d",&a,&b,&c);
        if(a==0&&b==0&&c==0)break;
        else{
            int unko=0;
            int po;
            for(int i=0;i<a;i++){int buri;scanf("%d",&buri);unko+=buri;if(i==b-1)po=buri;}
            int ans;
            if(po!=0)ans=unko*100*(100-c)/(100*po);
            else ans=0;
            printf("%d\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 2032
#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 vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w, k;
	cin >> h >>w >>k;
	vector<string> s(h);
	rep(i, h) cin >>s[i];
	
	int p=h+w;
	ll ans =0;
	rep(i, 1<<p){
		VI ckd(p);
		//rep(j, p) if(i>>j &1) ckd[j] =1;
		int csm = 0;
		rep(y, h) if(i>>y &1){
			rep(x, w) if(i>>(x+h) &1) csm += s[y][x]=='#';
		}
		if(csm == k) ans++;
	}
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 3628