akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
// #define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<(*i)<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;


int main() {

    int n;
    cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
}



Measured memory_bytes: 3592
size = STDIN.gets.to_i
str = STDIN.gets

temp = 0
maxNum = 0

str.each_char.with_index { |c, i|
  restSize = size - i + 1
  break if maxNum - temp > restSize

  if c == 'I'
    temp += 1
  else
    temp -= 1
  end
  maxNum = temp if temp > maxNum
}
puts(maxNum)

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
#define ll long long
using namespace std;
int main()
{
     int sum=0;
     int n;
     scanf("%d",&n);
     for(int i=1;i<=100000;i++)
     {
          int res=i*i;
          if(res>n)break;
          sum=res;
     }
     printf("%d\n",sum);
     return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool uruu(int n){
    bool f=false;
    if(n%4==0)f=true;
    if(n%100==0)f=false;
    if(n%400==0)f=true;
    return f;
}
int main(){
    int a,b;
    bool k=false;
    while(cin>>a>>b,a||b){
        bool f=true;
        if(k)cout<<endl;
        for(int i=a;i<=b;i++){
            if(uruu(i)){
                cout<<i<<endl;
                f=false;
            }
        }
        if(f)cout<<"NA"<<endl;
        k=true;
    }
    return 0;
}

Measured memory_bytes: 1160
from numpy import cumsum

N,M,X = map(int,input().split())
C = [0] * N
A = [None] * N
for i in range(N):
  c,*a = map(int,input().split())
  C[i] = c
  A[i] = a

INF = 10 ** 9
ans = INF
import itertools
for i in range(1,N + 1):
  for comb in itertools.combinations(range(N),i):
    cost = 0
    skills = [0] * M
    for c in comb:
      cost += C[c]
      for j in range(M):
        skills[j] += A[c][j]
    if cost >= ans:
      continue
    for s in skills:
      if s < X:
        break
    else:
      ans = cost

if ans == INF:
  print(-1)
else:
  print(ans)        


Measured memory_bytes: 27212
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#define _GLIBCXX_DEBUG
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.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; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく


//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

bool E[2005][2005];
vector<bool> seen;
typedef pair<int, int> P;
int D[2005];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

int main() {
    int N,M; cin >> N >> M;
    vector<int> left(M);
    vector<int> right(M);
    for (int i = 0; i < M; i++) cin >> left.at(i) >> right.at(i);

    vector<int> imos(N+2, 0);
    for (int i = 0; i < M; i++) {
        imos.at(left.at(i))++;
        imos.at(right.at(i) + 1)--;
    }
    for (int i = 1; i <= N; i++) {
        if (i == 0)continue;
        imos.at(i) = imos.at(i) + imos.at(i - 1);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (imos.at(i) == M) {
            ans++;
        }
    }
    if (N < ans) cout << N << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 1408
/*
    handle - pruvi007
    questionName - 
    Contest - 
    Topic - 
    Platform - 
*/
#include<bits/stdc++.h>
using namespace std;
#define ll          long long int
#define fast         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INF          1e18
#define MOD          1000000007
#define Vi           vector<ll> 
#define Vs           vector<string>
#define VI           vector<vector<ll> >
#define PII          pair<ll,ll> 
#define PSI          pair<string,ll>
#define PB           push_back


int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
int DX[] = {0,-1,-1,-1,0,1,1,1};
int DY[] = {-1,-1,0,1,1,1,0,-1};

int main()
{
    fast;
    int x;
    cin >> x;
    cout << (x>=30?"Yes\n":"No\n");
}

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

int main(void){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
    transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
    transform(s3.begin(), s3.end(), s3.begin(), ::toupper);
    cout << s1[0] << s2[0] << s3[0] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int32_t M1, D1, M2, D2;
  std::cin >> M1 >> D1 >> M2 >> D2;
  if (M2 == M1 + 1) {
    std::cout << 1 << std::endl;
  }
  else {
    std::cout << 0 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#pragma warning (disable:4996)
int main()
{
	int a, b, c;
	while (scanf("%d%d%d", &a,&b,&c) != EOF)
	{
		if (a == b)printf("%d", c);
		if (a == c)printf("%d", b);
		if (c== b)printf("%d", a);
	}
}

Measured memory_bytes: 128
N,M,Q = map(int,input().split())

lis = []

for i in range(N):

    lis.append([0] * N)

for i in range(M):

    L,R = map(int,input().split())

    lis[L-1][R-1] += 1

ylis = lis.copy()

for i in range(N):

    for j in range(N-1):

        ylis[i][j+1] += ylis[i][j]

tlis = lis.copy()

for i in range(N-1):

    i = N-1-i

    for j in range(N):

        tlis[i-1][j] += tlis[i][j]


for i in range(Q):

    p,q = map(int,input().split())

    print (ylis[p-1][q-1] + tlis[p-1][q-1] - lis[p-1][q-1])

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

const int N = 200005;
int T[N << 2], lz[N << 2];

#define mid ((l + r) >> 1)
void push(int v, int l, int r) {
	if (lz[v] == 0) return;
	if (l < r) lz[v << 1] += lz[v], lz[v << 1 | 1] += lz[v];
	T[v] += lz[v]; T[v] = min(T[v], N); lz[v] = 0; 
}

void upd_pos(int v, int l, int r, int x, int val) {
	push(v, l, r);
	if (l > r || l > x || r < x) return;
	if (l == r) { T[v] = val; return; }
	upd_pos(v << 1, l, mid, x, val); upd_pos(v << 1 | 1, mid + 1, r, x, val);
	T[v] = min(T[v << 1], T[v << 1 | 1]);
}

void upd(int v, int l, int r, int L, int R, int val) {
	push(v, l, r);
	if (l > r || R < l || L > r) return;
	if (L <= l && r <= R) { lz[v] = val; push(v, l, r); return; }
	upd(v << 1, l, mid, L, R, val); upd(v << 1 | 1, mid + 1, r, L, R, val);
	T[v] = min(T[v << 1], T[v << 1 | 1]);
}

int get(int v, int l, int r, int L, int R) {
	push(v, l, r);
	if (l > r || R < l || L > r) return N;
	if (L <= l && r <= R) return T[v];
	return min(get(v << 1, l, mid, L, R), get(v << 1 | 1, mid + 1, r, L, R));
}
#undef mid

int n, q;
int b[N];
vector<int> Q[N];
int f[N][2];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &b[i]);
		if (b[i] == 0) f[i][1] = 1; else f[i][0] = 1;
	}
	scanf("%d", &q);
	while(q--) {
		int l, r; scanf("%d %d", &l, &r);
		Q[l].push_back(r);
	}

	for (int i = 0; i < 4 * N; ++i) T[i] = N;
	upd_pos(1, 0, n, 0, 0);

	for (int i = 1; i <= n; ++i) {
		sort(Q[i].begin(), Q[i].end(), greater<int>());
		for (int j : Q[i]) {
			int mn = get(1, 0, n, 0, j);
			upd_pos(1, 0, n, j, mn);
		}
		upd(1, 0, n, 0, i - 1, f[i][0]);
		upd(1, 0, n, i, n, f[i][1]);
	}

	printf("%d\n", get(1, 0, n, 0, n));
}

Measured memory_bytes: 17536
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		ll cnt = 0;
		for (char c = 'a'; c <= 'z'; c++) {
			bool f[2] = {};
			for (int j = 0; j < i; j++)if (s[j] == c)f[0] = 1;
			for (int j = i; j < n; j++)if (s[j] == c)f[1] = 1;
			if (f[0] && f[1])cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x) upper_bound(all(v),x)
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

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

const int N = 100005;

ll dp[N];

int main(){
    IOS
    
    ll n;
    cin>>n;
    ll a[n+1];
    FOR(i,1,n+1){
        cin>>a[i];
    }
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    FOR(i,3,n+1){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n];
    cerr<<1.0/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <functional>
#include <iostream>
#include <algorithm>

#define ll long long

using namespace std;

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

  cin >> S;

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

  while (S.length()) {
    if (S.rfind("remaerd", 0) == 0) {
      S = S.substr(7);
    } else if (S.rfind("resare", 0) == 0) {
      S = S.substr(6);
    } else if (S.rfind("maerd", 0) == 0) {
      S = S.substr(5);
    } else if (S.rfind("esare", 0) == 0) {
      S = S.substr(5);
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}

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

int main() {
  string s;cin >> s;
  string ans = "Good";
  for (int i = 1; i < 4; i++)
  {
    if(s.at(i) == s.at(i-1)){
      ans = "Bad";
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())

/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}


////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	string s;
	map<string, int> count;
	for(int i = 0; i < n; i++)
	{
		cin>>s;
		count[s]++;
	} 
	int ct=0;
	for(auto i:count)
	{
		ct++;
	}
	cout<<ct<<endl;
}

Measured memory_bytes: 19308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int ans = 0;

		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		for (int i = 0; i < n; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			ans += (r - l + 1);
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 25716
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<int> cnt(26, 0);
    rep(i, H) rep(j, W) {
        char c;
        cin >> c;
        ++cnt[c - 'a'];
    }
    vector<int> mod_cnt(4, 0);
    rep(i, 26) ++mod_cnt[cnt[i] % 4];
    
    if (H % 2 && W % 2) {
        if (mod_cnt[2] <= (H - 1) / 2 + (W - 1) / 2 && mod_cnt[1] + mod_cnt[3] <= 1) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    } else if (H % 2) {
        if (mod_cnt[2] <= W / 2 && mod_cnt[1] + mod_cnt[3] <= 0) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    } else if (W % 2) {
        if (mod_cnt[2] <= H / 2 && mod_cnt[1] + mod_cnt[3] <= 0) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    } else {
        if (mod_cnt[1] + mod_cnt[2] + mod_cnt[3] <= 0) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
    return 0;
}


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

namespace ABC163C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] A = Console.ReadLine().Split(' ');
            int[] buka = new int[N];
            for (int i= 0; i < N - 1; i++)
            {
                buka[int.Parse(A[i]) - 1] += 1;
            }
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(buka[i]);
            }
        }
    }
}


Measured memory_bytes: 41856
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n; cin >> n;
	int taro = 0, hanako = 0;
	for (int i = 0; i < n; i++) {
		string s, t; cin >> s >> t;
		if (s == t) {
			taro++;
			hanako++;
		}
		else if (s > t) {
			taro += 3;
		}
		else {
			hanako += 3;
		}
	}
	cout << taro << " " << hanako << endl;


	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	vector<int> data;
	vector<int> data2;
	vector<int> dp(1000001, 10);
	vector<int> dp2(1000001, 1000000);
	long long int n = 0;
	for (long long int i = 1; ; i++) {
		n = i*(i+1)*(i+2)/6;
		if (n > 1000000) {
			break;
		}
		data.push_back(n);
		dp[n] = 1;
		if (n % 2 == 1) {
			data2.push_back(n);
			dp2[n] = 1;
		}
	}

	for (int i = 0; i < data.size(); i++) {
		for (int j = data[i]+1; j <= 1000000; j++) {
			dp[j] = min(dp[j], dp[j-data[i]]+1);
		}
	}

	for (int i = 0; i < data2.size(); i++) {
		for (int j = data2[i]+1; j <= 1000000; j++) {
			dp2[j] = min(dp2[j], dp2[j-data2[i]]+1);
		}
	}

	int a;
	while (cin >> a) {

		if (a == 0) {
			break;
		}
		cout << dp[a] << ' ' << dp2[a] << endl;
	}
	return 0;
}

Measured memory_bytes: 8860
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
// I LOVE IT :D
#define int long long
using namespace std;
inline int in() {int32_t x ; scanf("%d",&x) ; return x ; }
inline string getStr() {char ch[1000000] ; scanf("%s",ch) ; return ch ;}
const int MAX_N = 1e4 + 5;
int pr[MAX_N];
int sz[MAX_N];
int find(int p)
{
    if (pr[p] == p ) return p;
    return pr[p] = find(pr[p]);
}
int32_t main()
{
    int n = in() , q = in();
    for (int i = 0 ; i < n ; i ++)
        pr[i] = i , sz[i] = 1;
    for (int i = 0 ; i < q ; i ++)
    {
        bool tp = in();
        int u = in() , v = in();
        if (tp) // same
        {
            cout << (find(u) == find(v)) << "\n";
        }
        else // unite
        {
            u = find(u) , v = find(v);
            if (sz[u] < sz[v]) swap(u , v);
            pr[v] = u;
            if (sz[v] == sz[u]) sz[u] ++;
        }
    }
}

Measured memory_bytes: 1364
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAX_HW = 1401;
int dp[MAX_HW][MAX_HW];
int board[MAX_HW][MAX_HW];
int H, W;
int main() {
  scanf("%d %d", &H, &W);
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      scanf("%d", &board[i][j]);
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      dp[i][j] = (board[i][j] + 1) % 2;
    }
  }
  int res = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (board[i][j] == 0) {
        dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
      }
      if (dp[i][j] > res){
      	res = dp[i][j];
      }
    }
  }
  printf("%d\n", res * res);
  return 0;
}

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

int compare(const void *a,const void *b){
	return *(int*)a - *(int*)b;
}

int main(void){
	int n,m;
	int a[100],b[100];
	int i,j;
	int sa;
	int a_sum = 0, b_sum = 0;
	int flag = 0;
	while(scanf("%d %d",&n,&m)){
		if(n == 0 && m == 0){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%d",&a[i]);
			a_sum += a[i];
		}
		for(i = 0;i < m;i++){
			scanf("%d",&b[i]);
			b_sum += b[i];
		}
		if(a_sum - b_sum > 0){
			sa = a_sum - b_sum;
		}
		else{
			sa = (a_sum - b_sum) * -1;
		}
		qsort(a,n,sizeof(int),compare);
		qsort(b,m,sizeof(int),compare);
		if(sa == 0){
			for(i = 0;i < n;i++){
				for(j = 0;j < m;j++){
					if(a[i] == b[j]){
						flag = 1;
						printf("%d %d\n",a[i],a[i]);
						break;
					}
				}
				if(flag == 1){
					break;
				}
			}
			if(flag == 0){
				printf("-1\n");
			}
		}
		else if(sa % 2 == 0){
			sa = sa / 2;
			for(i = 0;i < n;i++){
				for(j = 0;j < m;j++){
					if((a[i] - b[j] == sa) || (a[i] - b[j] == (sa * -1))){
						a_sum = a_sum - a[i] + b[j];
						b_sum = b_sum - b[j] + a[i];
						if(a_sum == b_sum){
							printf("%d %d\n",a[i],b[j]);
							flag = 1;
							break;
						}
						else{
							a_sum = a_sum + a[i] - b[j];
							b_sum = b_sum + b[j] - a[i];
						}
					}
				}
				if(flag == 1){
					break;
				}
			}
			if(flag == 0){
				printf("-1\n");
			}
		}
		else{
			printf("-1\n");
		}
		for(i = 0;i < 100;i++){
			a[i] = 0;
			b[i] = 0;
		}
		flag = 0;
		a_sum = 0;
		b_sum = 0;
	}
	return 0;
}

Measured memory_bytes: 616
import Data.List
import Control.Monad


toFloat :: Int -> Double
toFloat = fromRational . toRational

solve [] d = 0
solve (a:as) d = if l01 <= (toFloat d)
                    then 1 + solve as d
                    else solve as d
                    where
                        x = a!!0
                        y = a!!1
                        l01 = sqrt $ toFloat ((x)^2 + (y)^2)

main = do
    [n,d] <- map read . words <$> getLine :: IO [Int]
    xyn <- replicateM n (map read . words <$> getLine) :: IO [[Int]]
    print $ solve xyn d


Measured memory_bytes: 172784
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ull n;

int main()
{
  int c[100];
  int i, j;
  ull x=26;

  cin >> n;

  for (i=0; n>x; i++) {
//printf("n=%lld\n", n);
    n -= x;
    x *= 26;
  }
//printf("i=%d\n", i);
  n--;
  for (j=0; j<=i; j++) {
    c[j] = n%26;
//printf("n = %lld, c[%d] = %d\n", n, j, c[j]);
    n /= 26;
  }

  for (j=i; j>=0; j--) {
    printf("%c", c[j]+'a');
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>

using namespace std;

int main(){

  string s;
  cin >> s;

  string a = "";

  for (int i = 0; i < s.size(); i++){
    if (s[i] != 'B'){
      a += s[i];
    }
    else {
      if (!a.empty()){
        a.erase(a.size() - 1);
      }
    }
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back

#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const double pi=acos(-1);
void solve()
{
    double r;
    cin>>r;
    double ans=pi*2*r;
    printf("%.6f\n",ans);
}
int main()
{
	//int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#pragma warning(disable:4996)

using namespace std;

vector<long long> c, parent, d, ct, ans;
vector<bool> used;
vector<vector<long long>> adj, plist;

void dfs(int id) {
	ct[id] = 1;
	long long x, s, v;
	for (auto p : adj[id]) {
		if (parent[p] == -1) {
			parent[p] = id;

			x = plist[c[id]].size();
			s = 0;
			dfs(p);
			while (plist[c[id]].size() > x) {
				s += plist[c[id]].back();
				plist[c[id]].pop_back();
			}

			ct[id] += ct[p];

			v = ct[p] - s;
			ans[c[id]] += v * (v + 1) / 2;
		}
	}

	plist[c[id]].push_back(ct[id]);
}

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

	long long n, i, j, k, a, b, level, x, total;
	cin >> n;
	c.resize(n + 1);
	used.assign(n + 1, false);
	for (i = 1; i <= n; i++) {
		cin >> c[i];
		used[c[i]] = true;
	}
	adj.resize(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	parent.assign(n + 1, -1);
	parent[1] = 0;
	ct.resize(n + 1);
	plist.resize(n + 1);

	ans.assign(n + 1, 0);
	dfs(1);

	for (i = 1; i <= n; i++) {
		if (used[i]) {
			x = 0;
			for (auto p : plist[i]) x += p;
			ans[i] += (n - x) * (n - x + 1) / 2;
			ans[i] = n * (n + 1) / 2 - ans[i];
		}
		else ans[i] = 0;
		cout << ans[i] << "\n";
	}

	return 0;
}


Measured memory_bytes: 44556
import sys
from collections import defaultdict
from heapq import heappop, heappush
from operator import itemgetter

readline = sys.stdin.readline

N = int(readline())
town = [None] * N
for i in range(N):
    x, y = map(int, readline().split())
    town[i] = (i, x, y)

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)


def Kruskal(edges):
    edge = []
    total = 0

    uf = UnionFind(N)
    Q = sorted(edges, reverse=True)

    while len(edge) < N - 1 and Q:
        cost, e = Q.pop()
        if uf.find(e[0]) != uf.find(e[1]):
            total += cost
            edge.append(edge)
            uf.union(*e)
    return total


edges = []
for xy in [1, 2]:
    town = sorted(town, key=itemgetter(xy))
    for i in range(N - 1):
        t1, t2 = town[i], town[i + 1]
        d = t2[xy] - t1[xy]
        edges.append((d, (t1[0], t2[0])))
print(Kruskal(edges))


Measured memory_bytes: 61880
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a,b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
    return 0;
}


Measured memory_bytes: 256
li = []
for i in range(3):
    li.append(int(input()))
X = int(input())

ans = 0

for i in range(li[0]+1):
    for j in range(li[1]+1):
        for k in range(li[2]+1):
            if i*500 + j*100 + k*50 == X:
                ans += 1

print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
#include <string> 
#include <set>
typedef long long ll;
using namespace std;
unsigned long long x = 1e18;

int main() {
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() <= k)
        cout << s << endl;
    else {
        for (int i = 0; i < k; ++i) {
            cout << s[i];
        }
        cout << "...";
    }
    
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int s = a+b;
  int d = a-b;
  int t = a*b;
  int ans = max(s,t);
  ans = max(ans,d);
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define umax(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
const int N=3005;

int n,T,w[N],v[N],dp[N][N<<1],used[N];

int main(){
    scanf("%d%d",&n,&T);
    T*=2;
    T-=1;
    for(int i=0;i<n;++i){
        scanf("%d%d",&w[i],&v[i]);
        w[i]*=2;
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<=T;++j){
            dp[i+1][j]=dp[i][j];
            if(j>=w[i]) dp[i+1][j]=umax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
        }
    }
    int r=n,c=T;
    while(r>0 && c>0){
        if(c<w[r-1]) --r;
        else{
            if(dp[r][c-w[r-1]]+v[r-1]>dp[r-1][c]){
                c-=w[r-1];
                used[r-1]=true;
                --r;
            }
            else{
                --r;
            }
        }
    }
    int Max=0;
    for(int i=0;i<n;++i){
        if(used[i]) continue;
        Max=umax(Max,v[i]);
    }
    printf("%d\n",dp[n][T]+Max);
    return 0;
}

Measured memory_bytes: 70656
MAX=100000
isprime=[1]*(MAX+1)
isprime[0]=0
isprime[1]=0

for i in range(2,int(pow(MAX,0.5)+1)):
    if isprime[i]==1:
        for j in range(i*2,MAX+1,i):
            isprime[j]=0

islike2017=[0]*(MAX)
for i in range(MAX):
    if isprime[i]==1 and isprime[int((i+1)/2)]==1:
        islike2017[i]=1

cumsum=[0]*(MAX+1)
for i in range(1,MAX+1):
    cumsum[i]=cumsum[i-1]+islike2017[i-1]

Q=int(input())
l=0
r=0
for i in range(Q):
    l, r = map(int, input().split())
    r=r+1
    print(cumsum[r]-cumsum[l])

Measured memory_bytes: 9844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}


const int N = (1 << 17);
const int M = N + 5;


int n;
int p[M];
int m;
vector<pii> a[2 * M];

int tryGet(int v, int p, int q) {
	q = max(0, min(q, (int)a[v].size() - 1));
	while(q >= 0 && a[v][q].first > p) q--;
	if (q < 0) return 0;
	while(q < (int)a[v].size() && a[v][q].first < p) q++;
	if (q == (int)a[v].size()) return 0;
	if (a[v][q].first == p)
		return a[v][q].second;
	else
		return 0;
}
void tryAdd(int v, int p, int x) {
	if (a[v].empty() || a[v].back().first != p)
		a[v].push_back(mp(p, x));
	else
		a[v].back().second = add(a[v].back().second, x);
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);


	scanf("%d", &n);
	n = 1 << (n - 1);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
		p[i]--;
	}
/*
	n = 1 << 17;
	for (int i = 0; i < n; i++)
		p[i] = i;
	shuffle(p, p + n, rng);
*/
	int ans = 0;

	for (int i = 0; i < n; i++) {
		int x = n + i;
		int u = n + p[i];
		while(u > 1) {
			x = mult(x, u);
			a[n + i].push_back(mp(u, x));
			u /= 2;
		}
		reverse(all(a[n + i]));
	}
	for (int v = n - 1; v > 0; v--) {
		int p = 0, q = 0;
		while(p < (int)a[2 * v].size() || q < (int)a[2 * v + 1].size()) {
			if (p < (int)a[2 * v].size() &&
				(q == (int)a[2 * v + 1].size() ||
					a[2 * v][p] < a[2 * v + 1][q])) {
				int x = mult(a[2 * v][p].second, tryGet(2 * v + 1, a[2 * v][p].first ^ 1, q));
				x = mult(x, mult(v, a[2 * v][p].first / 2));
				ans = add(ans, x);
				tryAdd(v, a[2 * v][p].first, mult(a[2 * v][p].second, v));
				p++;
			} else {
				tryAdd(v, a[2 * v + 1][q].first, mult(a[2 * v + 1][q].second, v));
				q++;
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2005;
int n, z, w, ans;
int a[N];
int dp[N][2];

int solve(int x, int k) {
    if (dp[x][k] != -1) return dp[x][k];
    int ret = abs(a[x] - a[n]);
    if (k == 0) {
        for (int i = x + 1; i < n; ++i)
            ret = max(ret, solve(i, 1 - k));
    } else {
        for (int i = x + 1; i < n; ++i)
            ret = min(ret, solve(i, 1 - k));
    }
    return dp[x][k] = ret;
}
int main() {
    memset(dp, 255, sizeof dp);
    cin >> n >> z >> w;
    a[0] = w;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    cout << solve(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 3768
while True:

    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print()


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

#define ll long long
#define pb push_back
#define x first
#define y second

using namespace std;

int main()
{
    //freopen("test.in","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    string s; cin>>s;
    int ans=0, cnt=0;
    vector<int> v;
    for(int i=0;i<s.length();i++)
    {
        if(i==0) cnt++;
        else if(s[i]==s[i-1])cnt++;
        else v.pb(cnt), cnt=1;
    }
    v.pb(cnt);
    for(int i=0;i<v.size()-1;i++)
    {
        ans+=v[i]/3*2;
        v[i]%=3;
        if(v[i]==2) ans+=2, v[i+1]--;
        else if(v[i]) ans++;
    }
    ans+=v.back()/3*2+(v.back()%3>0);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 1552
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to WzW
*/


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<ctype.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 1;


int main()
{
	int a[5];scanf("%d%d%d",&a[1],&a[2],&a[3]);
	sort(a + 1 ,a + 3 + 1);
	int ans = 0;
	if(a[3] - a[1] > 1) {
		int t = (a[3] - a[1]) / 2;
		ans += t;a[1] += t * 2; 
	}
	if(a[3] - a[2] > 1){
		int t = (a[3] - a[2]) / 2;
		ans += t;a[2] += t * 2;
	}
	if(a[1] == a[2] && a[1] != a[3]){
		ans++;
	} else if(a[1] == a[3] && a[1] != a[2]){
		ans += 2;
	}else if(a[2] == a[3] && a[1] != a[2]){
		ans += 2;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline

def main():
    mod = 10**9+7
    n,a,b=map(int,input().split())
    f=1
    fa=0
    for i in range(1,b+1):
        f=(f*(n-i+1)*pow(i,mod-2,mod))%mod
        if i==a:
            fa=f
    ans=(pow(2,n,mod)-fa-f-1)%mod
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40044
#include <stdio.h>
#include <stdint.h>

#define MODULAS (1000000000+7)

int main(void)
{
	int i,n;
	int64_t power;

	scanf("%d",&n);
	power=1;
	for (i=1;i<=n;++i)
	{
		power*=i;
		if (power>=MODULAS)
		{
			power%=MODULAS;
		}
	}
	printf("%d\n",power);

	return 0;
}




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

using namespace std;

#ifdef KACTL
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#endif
#define all(x) begin(x), end(x)

using ll = int64_t;
using ld = long double;
using pii = pair<int32_t, int32_t>;
using vi = vector<int32_t>;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;

    vector<pii> brackets;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int a = 0;
        int p = 0;
        for (char c : s) {
            if (c == '(') ++p;
            else --p;
            a = min(a, p);
        }

        brackets.emplace_back(a, p);
    }

    // growers and shrinkers
    // put all growers first: can exch with shrinker and its fine
    // abcABfgh
    sort(all(brackets), [&](const pii& l, const pii& r) {
        if ((l.second >= 0) != (r.second >= 0)) {
            return l.second >= 0;
        }

        if (l.second >= 0 and r.second >= 0) {
            return l.first > r.first;
        } else {
            return l.second - l.first > r.second - r.first;
        }
    });

    int s = 0;
    for (auto& p : brackets) {
        if (s + p.first < 0) {
            cout << "No\n";
            return 0;
        }
        s += p.second;
    }

    cout << (s == 0 ? "Yes\n" : "No\n");

    return 0;
}


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

using namespace std;

int main(){
  
 	int N;
  	cin>>N;
  	int K;
  	cin>>K;
  	vector<int> h(N);
  	for(int i=0;i<N;i++){
    	cin>>h[i];
    }
  	
 	vector<int> dp(N);
  	dp[0]=h[0];
  	dp[1]=abs(h[0]-h[1]);
  	for(int i=2;i<=min(K,N-1);i++){
      int this_min=INT_MAX;
      for(int j=i-1;j>=1;j--){
        int curr_min=dp[j]+abs(h[j]-h[i]);
        this_min=(curr_min<this_min ? curr_min:this_min);
      }
      dp[i]=min(abs(h[0]-h[i]),this_min);
    }
    
  	for(int i=K+1;i<N;i++){
      int dp_min=INT_MAX;
      for(int j=i-1;j>= max((i-1-(K-1)),1);j--){
        int dp_curr_min=dp[j]+abs(h[j]-h[i]);
        dp_min=(dp_curr_min<dp_min ? dp_curr_min:dp_min);
      }
      dp[i]=dp_min;
      
    }
    
  	cout<<dp[N-1]<<endl;
  
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>
#include <cstdlib>
#include <typeinfo>
using namespace std;

int main(){
	double n, m, x = 0, y = 0, arg=0;
	while (1)
	{
		double a, b;
		scanf("%lf,%lf", &a, &b);
		if (a == 0 && b == 0)break;
		double rad = arg * PI / 180;
		x += a*cos(rad);
		y += a*sin(rad);
		arg += b; 
	
	}
	cout << (int)y << endl << (int)x << endl;
}

Measured memory_bytes: 1236
n, m = gets.chop.split.map(&:to_i)
py = []

m.times do |i|
  p, y =  gets.chop.split.map(&:to_i)
  py << [p, y, i]
end

py = py.sort_by {|x| [x[0], x[1]]}


tmp = py[0][0]
count = 1

m.times do |i|

  if tmp == py[i][0] then
    py[i][3] = count

    count += 1
  else
    tmp = py[i][0]
    count = 1
    py[i][3] = count
    count += 1
  end

end


py = py.sort_by{ |x| x[2]}


for elm in py
  puts sprintf("%06d",elm[0]) + sprintf("%06d",elm[3])
end


Measured memory_bytes: 34896
from sys import stdin
from itertools import accumulate
import bisect

n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

lin = [0]*(10**5)

for i in li:
    lin[i[0]-1] += i[1]

lis = list(accumulate(lin))

print(bisect.bisect_left(lis,k)+1)

Measured memory_bytes: 35124
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int W = scanner.nextInt();
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int minDistance = 0;
		
		for (int i = 1; i > 0;) {
			if (Math.abs(a-b) <= W){
				System.out.println(minDistance);
				break;
			}else {
			minDistance += i;
			W++;
			}
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int a,b,c,d;
	while(cin>>a>>b>>c>>d,a){
		int out=0;
		while(1){
			if(EPS-b+(double)(a+out*d)/c>0)break;
			out++;
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 3028
K, A, B = $stdin.read.split(/\n| /).map(&:to_i)

if B - A >= K
  puts "OK"
else
  a = A%K
  b = B%K

  if a == 0 || b == 0
    puts "OK"
  else
    if (B/K)-(A/K) >= 1
      puts "OK"
    else
      puts "NG"
    end
  end
end

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

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

  string c;
  int ans = 0;
  rep(i, 10) rep(j, 10) rep(k, 10){
    c[0] = i + '0';
    c[1] = j + '0';
    c[2] = k + '0';
    int id = 0;
    rep(si, n){
      if(s[si] == c[id]){
        id++;
        if(id == 3) break;
      }
    }
    if(id == 3) ans++;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3616
def between(x, y, a):
    lrg = max(x, y)
    sml = min(x, y)
    if (sml <= a <= lrg):
        return True
    else:
        return False

while (True):
    pos = [10, 10]
    result = 'No'
    N = int(input()) # Total number of jewels
    if N == 0:
        break
    jewelPositions = list()
    for i in range(N):
        jewelPos = list(map(int, input().split()))
        jewelPositions.append(jewelPos)

    M = int(input()) # Number of instructions
    # instructions = list()
    for i in range(M):
        # print('==== Currently at ', pos)
        instruction = input().split()
        # print('instruction : ', i)
        if (result == 'Yes'):
            continue
        instruction[1] = int(instruction[1])
        if (instruction[0] == 'E'):
            move = ('x', instruction[1])
        elif (instruction[0] == 'W'):
            move = ('x', -1*instruction[1])
        elif (instruction[0] == 'N'):
            move = ('y', instruction[1])
        elif (instruction[0] == 'S'):
            move = ('y', -1*instruction[1])
        else:
            raise NotImplementedError

        # print('>>>>>>>>>>>>>>> pos: ', pos, ', move: ', move)
        jewelToRemove = []
        for jewel in jewelPositions:

            '''
            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (pos[0] <= jewel[0] <= pos[0]+move[1])) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (pos[1] <= jewel[1] <= pos[1]+move[1])):
            '''


            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (between(0, move[1], jewel[0]-pos[0]))) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (between(0, move[1], jewel[1]-pos[1]))):
                # print('---- Collecting a jewel at ', jewel)
                # jewelPositions.remove(jewel)
                jewelToRemove.append(jewel)
            else:
                # print('xxxx Jewel not collected at ', jewel)
                pass

        for jewel in jewelToRemove:
            jewelPositions.remove(jewel)

        if (move[0] == 'x'):
            pos[0] += move[1]
        elif (move[0] == 'y'):
            pos[1] += move[1]

        if not jewelPositions:
            """
            if empty,
            all jewels are collected
            """
            result = 'Yes'
        else:
            pass
        # print('jewels are left at ', jewelPositions)
    print(result)

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

int main() {
  ll n;
  cin >> n;
  string r;
  while (n != 0) {
    n--;
    r.push_back('a' + (n % 26));
    n /= 26;
  }
  reverse(r.begin(), r.end());
  cout << r << endl;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int x, a, b;
    cin >> x >> a >> b;

    cout << (x - a) % b << endl;

    return 0;
}


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


int main(){
    string s;
    cin >> s;

    if(s.substr(0, 4) == "YAKI"){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w;
  cin >> h >> w;
  vector<vl> c(10, vl(10)), g(h, vl(w));
  rep(i, 10) rep(j, 10) cin >> c[i][j];
  rep(i, h) rep(j, w) cin >> g[i][j];
  rep(k, 10) rep(i, 10) rep(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  ll ans = 0;
  rep(i, h) rep(j, w) {
    ll k = g[i][j];
    if(abs(k) != 1) ans += c[k][1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3892
n,k = list(map(int, input().split()))
v = list(map(int, input().split()))

dp=[[[-1 for i in range(k+1)] for j in range(n+1)] for l in range(n+1)]

def f(a, b, d):
    if d == 0: return 0
    if a == b and d > 1 and v[a] > 0: return v[a]
    if a == b and d > 1 and v[a] <= 0: return 0
    if dp[a][b][d] != -1: return dp[a][b][d]
    maxi = max(v[a] + f(a+1, b, d - 1), v[b] + f(a, b - 1, d - 1))
    if v[a] < 0 and d > 1:
        maxi = max(maxi, f(a + 1, b, d - 2))
    if v[b] < 0 and d > 1:
        maxi = max(maxi, f(a, b - 1, d - 2))
    maxi = max(maxi, 0)
    dp[a][b][d]=maxi
    return maxi


print(f(0, n-1, k))

Measured memory_bytes: 51292
import sys


def buy(money, stock, price):
    p, q = divmod(money, price)
    stock += p
    money = q
    return money, stock


def sell(money, stock, price):
    money += stock * price
    stock = 0
    return money, stock


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    money = 1000
    stock = 0
    for i in range(n):
        if i == n - 1:
            money, stock = sell(money, stock, a[i])
        else:
            if a[i] < a[i + 1]:
                money, stock = buy(money, stock, a[i])
            elif a[i] > a[i + 1]:
                money, stock = sell(money, stock, a[i])
    print(money)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9272
# 0でない数字がちょうどK個
S = input().strip()
K = int(input())
N = len(S)

'''
桁DP
dp[i][j][k] := 
i桁目まで使って
j個の0ではない数値を使って
k=0:i桁目までSと一致
  1:S未満(以下？)
'''
dp = [[[0]*2 for _ in range(K+1)] for _ in range(101)]
dp[0][0][0] = 1

for i in range(N):
    for j in range(K+1):
        for k in range(2):
            nd = int(S[i])
            # 0-9まで調べていく
            for d in range(10):
                ni, nj, nk = i+1, j, k
                if d > 0:
                    nj += 1
                if nj > K:
                    continue
                if k == 0:
                    if d > nd:
                        continue
                    elif d != nd:
                        nk = 1
                dp[ni][nj][nk] += dp[i][j][k]

print(sum(dp[N][K]))


Measured memory_bytes: 41072
#include <stdio.h>
int main(){
  int n,m,c,count = 0;
  int b[21];
  scanf("%d %d %d",&n,&m,&c);
  for (int i = 0; i < m; i++) {
    scanf("%d",&b[i]);
  }

  for (int i = 0; i < n; i++) {
    int ans = c;
    for (int j = 0; j < m; j++) {
      int a;
      scanf("%d",&a);
      ans += a * b[j];
    }
    if (ans > 0) {
      count++;
    }
  }
  printf("%d\n",count);
}


Measured memory_bytes: 128