akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 2e5 + 10 ;

vector<int>tree[4 * MAX] ;
int arr[MAX] ;

void build(int node , int l , int r)
{
	if(l == r)
	{
		tree[node].push_back(arr[l]) ;
		return ;
	}
	int mid = (l + r) >> 1 ;
	build(node << 1 , l , mid) ;
	build(node << 1 | 1 , mid + 1 , r) ;
	merge(tree[node << 1].begin(), tree[node << 1].end(), tree[node << 1 | 1].begin(), tree[node << 1 | 1].end(), inserter(tree[node], tree[node].begin()));
}

int query(int node , int l , int r , int from , int to , int x)
{
	if(from > r || to < l)
		return 0 ;
	if(l >= from && r <= to)
	{
		int idx = upper_bound(tree[node].begin() , tree[node].end() , x) - tree[node].begin() ;
		return (tree[node].size() - idx) ;
	}
	int mid = (l + r) >> 1 ;
	int a = query(node << 1 , l , mid , from  , to , x) ;
	int b = query(node << 1 | 1 , mid + 1 , r , from , to , x) ;
	return (a + b) ;
}

int readInt () {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

int main()
{
	int n ;
	n = readInt() ;
	for(int i = 1 ; i <= n ; ++i)
		arr[i] = readInt() ;
	build(1 , 1 , n) ;
	long long ans = 0ll ;
	for(int i = 1 ; i <= n ; ++i)
	{
		int l = i , r = n ;
		int a = i , c = i;
		while(l <= r)
		{
			int mid = (l + r) >> 1 ;
			int x = query(1 , 1 , n , i , mid , arr[i]) ;
			if(x <= 1)
			{
				l = mid+1 ;
				if(x == 1)
					a = mid ;
			}
			else
				r = mid - 1;
		}
		l = i , r = n ;
		while(l <= r)
		{
			int mid = (l + r) >> 1 ;
			int x = query(1 , 1 , n , i , mid , arr[i]) ;
			if(x == 0)
			{
				l = mid+1 ;
				c = mid ;
			}
			else
				r = mid - 1;
		}
		l = 1 , r = i ;
		int b = i , d = i;
		while(l <= r)
		{
			int mid = (l + r) >> 1 ;
			int x = query(1 , 1 , n , mid , i , arr[i]) ;
			if(x <= 1)
			{
				r = mid-1 ;
				if(x == 1)
					b = mid ;
			}
			else
				l = mid + 1;
		}
		l = 1 , r = i ;
		while(l <= r)
		{
			int mid = (l + r) >> 1 ;
			int x = query(1 , 1 , n , mid , i , arr[i]) ;
			if(x == 0)
			{
				r = mid-1 ;
				d = mid ;
			}
			else
				l = mid + 1;
		}
		long long x1 = (i - d + 1ll) * 1ll ;
		long long x2 = (a - c) * 1ll ;
		x1 = max(x1 , 0ll) ;
		x2 = max(x2 , 0ll) ;
		ans += (x1 * x2) * arr[i] * 1ll ;
		x1 = (d - b) * 1ll ;
		x2 = (c - i + 1ll) * 1ll ;
		x1 = max(x1 , 0ll) ;
		x2 = max(x2 , 0ll) ;
		ans += (x1 * x2) * arr[i] * 1ll ;
	}
	return printf("%lld\n" , ans) , 0 ;
}


Measured memory_bytes: 32764
#include <stdio.h>
int main(){
  int a[3][10][4]={0},i,j,k,n,p,b,f,r,v; /* b?£?f???r???????????¨?±????v???  [???][??¨?±?][?£?] */
  scanf("%d",&n);
  for(p=0;p<n;p++){
    scanf("%d%d%d%d",&b,&f,&r,&v);
    a[f-1][r-1][b-1]+=v;
  }
  
  
  for(k=0;k<4;k++){
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
	if(a[i][j][k]==0)printf(" 0");
	  else printf(" %d",a[i][j][k]);
      }
      printf("\n");
    }
    if(k!=3)printf("####################\n");
  }

  return 0;

}


    
  

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

struct hoge{
    ll a,b;
};
const bool operator<(const hoge x,hoge y){
    if(x.a==y.a)return x.b>y.b;
    return x.a>y.a;
}

int main(){fastio
    ll n;cin>>n;
    string s[n];
    map<string,ll> mp;
    rep(i,0,n-1){
        cin>>s[i];
        if(mp.find(s[i])==mp.end()){
            mp[s[i]]=1;
        }else{
            mp[s[i]]++;
        }
    }
    ll m;cin>>m;
    string t[m];
    rep(i,0,m-1){
        cin>>t[i];
        if(mp.find(t[i])==mp.end()){
            mp[t[i]]=-1;
        }else{
            mp[t[i]]--;
        }
    }
    pair<string,ll> item;
    ll ans=0;
    for(auto it=mp.begin();it!=mp.end();it++){
        item=*it;
        string s=item.first;
        ll l=item.second;
        //cout<<s<<' '<<l<<endl;
        ans=max(ans,l);
    }
    cout<<ans<<endl;
    
    
    return 0;
}




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

int main(){
  int X;
  cin >> X;
  int kosu_max = X/100;
  if (X >= 100*kosu_max && X <= 105*kosu_max){
    cout << 1 << endl;
  }
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
S=input()
N=len(S)

K='keyence'

for n in range(7):
    if S[n]!=K[n]:
        if S[N-7+n:N]==K[n:7]:
            print('YES')
            break
        else:
            print('NO')
            break

    if n==6:
        print('YES')  

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

using namespace std;


#define PI 3.14159265
#define int long long

int MOD = 1e9 + 7;

int binpow(int a, int b){

	int res = 1;

	while(b){
		if(b & 1){
			res *= a;
			res %= MOD;
		}

		a *= a;
		a %= MOD;
		b >>= 1;
	}

	return res;
}

int ckn(int k, int n){
	int res = 1;

	for(int i = n; i > max(n - k, k); i--){
		res *= i;
		res %= MOD;
	}

	for(int i = 1; i <= min(k, n - k); i++){
		res *= binpow(i, MOD - 2);
		res %= MOD;
	}

	return res;
}


main(){

	int n, a, b; cin >> n >> a >> b;



	int left = (binpow(2, n) - 1 + MOD) % MOD; 
	int right = (ckn(a, n) + ckn(b, n)) % MOD;


	cout << (left - right + MOD) % MOD << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,h,w,wall,paper,count=0;
  scanf("%d%d%d",&n,&h,&w);
  for(int i=w;i<=n;i++){
    for(int j=h;j<=n;j++){
      count++;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int le[N],ri[N],a[N],n;
int A,B,C,cnt[4],h[4];
char e;
void del(int x){
	le[ri[x]]=le[x];
	ri[le[x]]=ri[x];
	h[a[x]]--;
}
int getmin(){
	int g=-1;
	for (int i=0;i<3;i++)
		if (cnt[i]!=-1&&(g==-1||cnt[g]>cnt[i]))g=i;
	cnt[g]=-1;
	return g;
}
int main(){
	for (e=getchar();e=='A'||e=='B'||e=='C';e=getchar())
		a[++n]=e-'A';
	for (int i=1;i<=n;i++)le[i]=i-1,ri[i]=i+1;
	ri[0]=1;le[n+1]=n;
	a[0]=a[n+1]=3;a[0]++;
	for (int i=ri[0];i<=n;i=ri[i]){
		if (a[i]==a[le[i]])del(i);
		else cnt[a[i]]++;
	}
	memcpy(h,cnt,sizeof h);
	A=getmin();
	B=getmin();
	C=getmin();
	if (!h[A])return 0;
	memset(cnt,0,sizeof cnt);
	int b1=0,c1=0;
	for (int i=ri[0];i<=n;i=ri[i]){
		if (a[i]==A){
			cnt[2*b1+c1]++;
			b1=c1=0;
		}
		if (a[i]==B)b1=1;
		if (a[i]==C)c1=1;
	}
	cnt[2*b1+c1]++; 
	if (a[le[n+1]]==C&&a[le[le[n+1]]]==A&&cnt[3]+cnt[2]<cnt[1])del(le[n+1]),cnt[1]--;
	for (int i=ri[0];i<=n;i=ri[i]){
		if (cnt[3]+cnt[2]>=cnt[1])break;
		if (a[i]==C){
			if (!le[i]&&a[ri[i]]==A)
				del(i),cnt[1]--;
			else if (a[le[i]]==A&&a[ri[i]]==A)
				del(le[i]),del(i),cnt[1]--;
		}
	}
	assert(cnt[3]+cnt[2]>=cnt[1]);
	for (int i=ri[0];i<=n;i=ri[i]){
		if (h[B]==h[C])break;
		if (a[i]==C){
			if (a[le[i]]!=a[ri[i]])
				del(i);
		}
	}
	assert(h[B]==h[C]);
	for (int i=ri[0];i<=n;i=ri[i]){
		if (h[A]==h[B])break;
		if (a[i]==B){
			if (a[le[i]]==C&&a[le[le[i]]]!=a[ri[i]])
				del(le[i]),del(i);
		}
		if (a[i]==C){
			if (a[le[i]]==B&&a[le[le[i]]]!=a[ri[i]])
				del(le[i]),del(i);			
		}
	}
	for (int i=ri[0];i<=n;i=ri[i])
		putchar('A'+a[i]);
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
vlong so;
int findFactors(ll num){
  ll i;
  bool fg=true;
  for (i = 2;i*i<=num; i++){ // 他の素数で割っていく
    while (num % i == 0){
      fg=false;
      so.push_back(i);
      num /= i;
    }
  }
  if(num!=1){
  so.push_back(num);
  }
  return 0;
}
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  if(n==1){
    cout<<0<<'\n';
    return(0);
  }
  findFactors(n);
  int now=2,count=1,ans=0,fg=1;
  ll test=1;
  rep(i,(int)so.size()){
    if(now==so[i]){
      count--;
      if(count==0){
        ans++;
        fg++;
      	count=fg;
      }
    }
    else{
      now=so[i];
      ans++;
      fg=2;
      count=2;
    }
  }
  cout<<ans<<'\n';
  return(0);
}


Measured memory_bytes: 3660
function main(input) {
    var n = input[0]-0;
    var list = input[1].split(" ").map(v=>v-0);
    var tlist = input[1].split(" ").map(v=>v-0);
    list.sort((a,b)=>a-b);
    var a = list[n/2-1];
    var b = list[n/2];
    for(var i=0;i<n;i++){
        if(tlist[i] <= a) console.log(b);
        else console.log(a);
    }
    
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));



Measured memory_bytes: 67652
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;
ll gcd(ll a, ll b){ return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b){ return a/gcd(a,b)*b; }

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  ll ans = 0;
  REP(i, n){
    cin >> a[i];
    ans += a[i]-1;
  }

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

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


int main(){

    long a, b, c;
    cin>>a>>b>>c;

    long res = 0;

    if(a%2==0 || b%2==0 || c%2==0)
        cout<<res<<'\n';
    else{
        res=min({a*b,b*c,c*a});
        cout<<res<<'\n';
    }

    // if(a%2==0&&b%2==0&&c%2==0)
    //     printf("%d\n",res);
    // else if(a%2!=0){
    //     res = b*c;
    //     printf("%d\n",res);
    // }
    // else if(b%2!=0){
    //     res = a*c;
    //     printf("%d", res);
    // }
    // else if(c%2!=0){
    //     res = a*b;
    //     printf("%d",res);
    // }

    return 0;
}

Measured memory_bytes: 256
import re

def selectionSort(A):
	replacenum=0
	for i in range(len(A)):
		minj = i
		for j in range(i,len(A)):
			if(A[j] < A[minj]):
				minj = j
		if(i!=minj):
			A[i],A[minj]=A[minj],A[i]
			replacenum+=1
	return replacenum

n=int(input())
a=list(map(int,input().split()))
num=selectionSort(a)

print(re.sub("[\[\]\,]","",str(a)))
print(num)


Measured memory_bytes: 6544
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	long long a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	long long ans1 = 0, ans2 = 0, ans3 = 0;
	ans1 = 2*c*min(x,y) + ((x>y)?(x-y)*a:(y-x)*b);
	ans2=  2*c*max(x,y);
	ans3 = a*x + b*y;
	cout << min(ans1, min(ans2, ans3)) << endl;
	
	return 0;
}

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

int main()
{
  int N,L;
  string S[101];
  cin>>N>>L;
  for (int i=0;i<N;i++)
    cin>>S[i];
  sort(S,S+N);
  for (int i=0;i<N;i++)
    cout<<S[i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int N;
	int A[200000];
	int i;
	int maxNum = 0;
	int secondMaxNum = 0;
	int maxPos;
	int secondMaxPos;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if (maxNum < A[i]) {
			maxNum = A[i];
			maxPos = i;
		}
	}

	for (i = 0; i < N; i++) {
		if (secondMaxNum < A[i] && i != maxPos) {
			secondMaxNum = A[i];
			secondMaxPos = i;
		}
	}

	for (i = 0; i < N; i++) {
		if (i != maxPos) {
			printf("%d\n", maxNum);
		}
		else {
			printf("%d\n", secondMaxNum);

		}
	}
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  auto C  = mvec<ll>(N);
  ll cv{};
  rep(i, 0, N){
    cin >> C[i];
    cv = max(cv, C[i]);
    C[i]--;
  }
  auto DP = mvec<ll>(N+1);
  auto lastappear = mvec<ll>(cv);
  DP[0] = 0;
  DP[1] = 1;
  lastappear[C[0]] = 1;
  rep(i, 1, N){
    DP[i+1] = DP[i] + (C[i] == C[i-1] ? 0 : DP[lastappear[C[i]]]);
    DP[i+1] %= MOD;
    lastappear[C[i]] = i+1;
  }
  cout << DP[N] << rt;
}

Measured memory_bytes: 4992
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<memory>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

long long solve(int h, int w, const vector<vector<int>> & s){
  vector<vector<int>> vertical(h, vector<int>(w));
  for(int i=1;i<h+1;i++){
    int last_block = 0;
    for(int j=1;j<w+2;j++){
      if(s[i][j]){
        for(int k=last_block+1;k<j;k++){
          vertical[i-1][k-1]=j-last_block-1;
        }
        last_block=j;
      }
    }
  }
  
  vector<vector<int>> horizontal(h, vector<int>(w));
  for(int j=1;j<w+1;j++){
    int last_block = 0;
  	for(int i=1;i<h+2;i++){
      if(s[i][j]){
        for(int k=last_block+1;k<i;k++){
          horizontal[k-1][j-1]=i-last_block-1;
        }
        last_block=i;
      }
    }
  }
  
  int ans = 0;
  for(int i=0;i < h; i++){
    for(int j=0;j<w;j++){
        //cerr << '[' << vertical[i][j] << ',' << horizontal[i][j] <<']';
  		ans = max(ans, vertical[i][j]+horizontal[i][j]);
    }
    //cerr<<endl;
  }
  return ans-1;
}

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> s(h+2, vector<int>(w+2, 1));
  for(int i=0;i < h; i++){
    string tmp;
    cin>>tmp;
    for(int j=0;j<w;j++){
      s[i+1][j+1] = tmp[j]=='#'?1:0;
    }
  }
  
  /*for(int i=0;i < s.size(); i++){
    for(int j=0;j<s[0].size();j++){
      cerr<<s[i][j]<<',';
    }
  cerr<<endl;
  }*/
  
  cout << solve(h, w, s);
  return 0;
}

Measured memory_bytes: 47360
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h+2, vector<char>(w+2, '.'));
  for (int i = 1; i <= h; i++){
    for (int j = 1; j <= w; j++){
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= h; i++){
    for (int j = 1; j <= w; j++){
      if (s[i][j] == '.'){
        int c = 0;
        if (s[i-1][j] == '#') c++;
        if (s[i+1][j] == '#') c++;
        if (s[i][j-1] == '#') c++;
        if (s[i][j+1] == '#') c++;
        if (s[i-1][j-1] == '#') c++;
        if (s[i-1][j+1] == '#') c++;
        if (s[i+1][j-1] == '#') c++;
        if (s[i+1][j+1] == '#') c++;
        cout << c;
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	private void doit() {
		Scanner sc = new Scanner(System.in);
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		while(true){
			String [] input = sc.next().split(",");
			if(input[0].equals("0")){
				break;
			}
			map.put(Integer.parseInt(input[0]), Integer.parseInt(input[1]));
		}
		TreeSet<Integer> t = new TreeSet<Integer>();
		for(int key: map.keySet()){
			t.add(map.get(key));
		}
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i : t){
			list.add(i);
		}
		
		while(sc.hasNext()){
			int in = sc.nextInt();
			int num = map.get(in);
			int ind = -1;
			for(int i = 0; i < list.size(); i++){
				if(num == list.get(i)){
					ind = list.size() - i;
					break;
				}
			}
			System.out.println(ind);
		}
		
	}

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

Measured memory_bytes: 12000
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

int n, a[N], b[N];

bool isval(int x){
	for (int i = 1; i <= n; i++){
		b[i] = (a[i] >= x);
	}
	int L = 0, R = n + 1;
	for (int i = n / 2 + 1; i >= 2; i--){
		if (b[i] == b[i - 1]){
			L = i;
			break;
		}
	}
	for (int i = n / 2 + 1; i < n; i++){
		if (b[i] == b[i + 1]){
			R = i;
			break;
		}
	}
	if (L == 0 && R == n + 1){
		return (b[n / 2 + 1] ^ (((n + 1) / 2 + 1) % 2));
	}
	if (L == 0){
		return b[R];
	}
	if (R == n + 1){
		return b[L];
	}
	if ((n / 2 + 1) - L < R - (n / 2 + 1)){
		return b[L];
	}
	return b[R];
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	n = 2 * n - 1;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int l = 1, r = n;
	while (r - l > 1){
		int md = (l + r) >> 1;
		if (isval(md)) l = md;
		else r = md;
	}
	cout << l;










	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}

int G[200000] ={};
std::multimap<int, int> m;

int grouping(int key, int g, int num)
{
    auto p = m.equal_range(key);
    for (auto it = p.first; it != p.second; ++it) {
        if(0 == G[it->second]){
            G[it->second] = g;
            num++;
            num = grouping(it->second, g, num);
        }
    }
    return num;
}

void execute()
{
    int N, M;
    int A[200000];
    int B[200000];


    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        m.emplace(A[i], B[i]);
        m.emplace(B[i], A[i]);
    }

    int g = 1;
    int ma = 1;
    for(int i = 0; i < M; i++){
        if(G[A[i]] != 0) continue;
        G[A[i]] = g;
        int n = grouping(A[i], g++, 1);
        if(ma < n) ma = n;
    }

    cout << ma << endl; 
}


Measured memory_bytes: 34012
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, K, Q := ReadInt(), ReadInt(), ReadInt()
	m := make(map[int]int)
	for i := 0; i < Q; i++ {
		a := ReadInt() - 1
		m[a]++
	}
	for i := 0; i < N; i++ {
		if K-Q+m[i] > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 8620
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = list(Counter(A).items())
b = dict(a)

ans = 0
for i, j in a:
    ans += (j * (j-1)) // 2

for i in A:
    c = b[i]
    hiku = (c * (c-1)) // 2 
    tasu = ((c-1) * (c-2)) // 2
    print(ans - hiku + tasu )

Measured memory_bytes: 34728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,X;
  cin >> K >> X ;
  for (int i = 1; i <= K; i++) {
   cout << X-(K-i) << ' ';
  }
  for (int i = 1; i < K; i++) {
    cout << X+i << ' ';
  }
    
  

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000050];
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		res+=abs(a[i]-a[i-1]);
	}res+=abs(a[n]);
	for(int i=1;i<=n;++i){
		printf("%d\n",res+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1]));
	}
	return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, M; cin >> N >> M;
  int vmin = 0, vmax = N + 1;
  for (int i = 0; i < M; ++i) {
    int L, R; cin >> L >> R;
    vmin = max(vmin, L);
    vmax = min(vmax, R);
  }
  cout << max(0, vmax - vmin + 1) << endl;
}


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

struct Node{
	int l, r;
};

const int N = 2e5 + 10;
const long long mod = 1e9 + 7;

int a[N], last[N];
long long sum[N];
vector <Node> sav;

bool cmp(const Node& x, const Node& y){
	return x.r < y.r;
}

int main(){
	int n, sz, d;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	memset(last, 0, sizeof(last));
	for (int i = 1; i <= n; i++){
		if (last[a[i]] && last[a[i]] < i - 1) sav.push_back((Node){last[a[i]], i});
		last[a[i]] = i;
	}
	memset(sum, 0, sizeof(sum));
	sum[0] = 1;
	sz = (int)sav.size();
	for (int i = 0; i < sz; i++){
		d = upper_bound(sav.begin(), sav.end(), (Node){0, sav[i].l}, cmp) - sav.begin();
		sum[i + 1] = (sum[i] + sum[d]) % mod;
	}
	printf("%lld\n", sum[sz]);
	return 0;
}

Measured memory_bytes: 5104
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    int S;
    cin >> S;
    if((S/1000 == S%1000/100) || (S%1000/100 == S%100/10) || (S%100/10 == S%10))cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long  int ll;
typedef long double ld;
#define endl '\n'
using namespace std;
const ll N = 1e5+7,mod = 1e9+7;
ll dp[N][2],visit[N]={0};
vector<ll> vec[N];

void dfs(ll a)
{
    for(int i=0;i<vec[a].size();i++){
        if(visit[vec[a][i]])
            continue;
        visit[vec[a][i]]++;
        dfs(vec[a][i]);
        dp[a][0] = (dp[a][0]*((dp[vec[a][i]][0]+dp[vec[a][i]][1])%mod))%mod;
        dp[a][1] = (dp[a][1]*dp[vec[a][i]][0])%mod;
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        dp[i][0]=1;
        dp[i][1]=1;
    }
    visit[0]++;
    dfs(0);
    cout<<(dp[0][0]+dp[0][1])%mod<<endl;
}



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

# 大きい方から決めていく

MOD = 10 ** 9 + 7

N,M = map(int,input().split())
A = set(int(x) for x in input().split())
B = set(int(x) for x in input().split())

# 決まった行数、列数を持つ
row = 0
col = 0
answer = 1
for x in range(N*M,0,-1):
    in_A = x in A
    in_B = x in B
    if in_A and in_B:
        # そこに書き込むしかない
        row += 1
        col += 1
    elif in_A and (not in_B):
        # すでに書き込まれたcolからひとつ選ぶ
        row += 1
        answer *= col
    elif in_B and (not in_A):
        col += 1
        answer *= row
    else:
        # 既に最大が確定しているところから適当にとる
        rest = row * col - (N*M-x)
        answer *= rest
    answer %= MOD

print(answer)

Measured memory_bytes: 3316
#include<iostream>
#define max(a,b) (a)>(b)?(a):(b);
using namespace std;
const int MAXN=1e5+10;
int H[MAXN]= {0},N,ans=0,l=-1,r=-1;

int main() {
	cin>>N;
	for(int i=0; i<N; i++)
		cin>>H[i];
	for(int i=1; i<N; i++) {
		if(H[i]<=H[i-1]) {
			if(l==-1) {
				l=i-1;
			}
			r=i;
			ans=max(ans,H[l]-H[r]);
		} else l=-1;
	}
	if(ans>=2) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <vector>
#include <queue>


typedef long long llong;
using namespace std;

#define SMALL_LIMIT 1e-30

struct Point {
	double x;
	double y;
};
double dist(Point a, Point b) {
	return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}

int main() {
	int n;
	Point a, b;
	double ra, rb;
	double d;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a.x >> a.y >> ra >> b.x >> b.y >> rb;
		d = dist(a, b);
		if (d + rb -ra< 0)cout << 2 << endl;
		else if (d + ra-rb <0)cout << -2 << endl;
		else if (0 >-d+ ra + rb)cout << 0 << endl;
		else cout << 1 << endl;

	}
	return 0;
}
 


Measured memory_bytes: 3136
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <functional>
#include <sstream>
#include <string>
#include <iomanip>
using namespace std;
#define LOG(x) cout << #x << " := " << (x) << endl
#define _LOG(x) cout << "Momentai " << x << endl
typedef long long ll;
typedef long double Lf;

string s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll ans = 0;
    cin >> s;
    for (int i = 0; i < (1 << (s.size()-1)); ++i) {
        ll x = 0;
        for (int j = 0; j < s.size(); ++j) {
            x = 10*x + (s[j] - '0');
            if ((1 << j) & i) ans += x, x = 0;
        }
        ans += x;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<map>
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int h,w,n;
vector<string> s;
bool inf(int y,int x){return(y>=0&&y<h&&x>=0&&x<w)?1:0;}
int bfs(int sy,int sx){
	int ret=0;
	queue<P> que;
	que.push(P(sy,sx));
	vector<vector<int> > d(h,vector<int>(w,INF));
	d[sy][sx]=0;
	while(!que.empty()){
		P t=que.front();
		que.pop();
		int y=t.first,x=t.second;
		
		
		for(int i=0;i<4;i++){
			int ny=dy[i]+y,nx=dx[i]+x;
			if(inf(ny,nx)&&d[ny][nx]>d[y][x]+1&&s[ny][nx]!='#'){
				que.push(P(ny,nx));
				d[ny][nx]=d[y][x]+1;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(d[i][j]!=INF)
				ret++;
		}
	}
	return ret;
}
int main(){
	while(cin>>w>>h,h||w||n){
		s=vector<string>(h);
		for(int i=0;i<h;i++){
			cin>>s[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(s[i][j]=='@'){
					cout<<bfs(i,j)<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
/*
 * coder: @SumitRaut
 */
#include <iostream>

using namespace std;
#define ll long long
ll mod=1e9+7;
inline void solve() {
    int n;
    cin>>n;
    ll ans=0,pre,tmp;
    cin>>pre;
    while(--n) {
        cin>>tmp;
        ans=(ans+pre*tmp%mod)%mod;
        pre=(pre+tmp)%mod;
    }
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    //freopen("int.txt","r",stdin);
    #endif
    // int t; cin>>t; while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
int main(){
	int a[5];
	int tmp;
	int i, I;
	for(i=0;i<5;i++)
	{
		scanf("%d", &a[i]);
	}
	for(i=0;i<5;i++)
	{
		for(I=0;I<5;I++)
		{
			if(a[i]>a[I])
			{
				tmp=a[i];
				a[i]=a[I];
				a[I]=tmp;
			}
		}
	}
	for(i=0;i<5;i++)
	{
		printf("%d", a[i]);
		if(i+1<5)
		{
			printf(" ");
		}
		else
		{
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct node
{
	int cost, x, y, o, hori;
	node(int cost, int x, int y, int o, int hori)
		: cost(cost), x(x), y(y), o(o), hori(hori) {}
};
bool operator<(const node& a, const node& b)
{
	return a.cost > b.cost;
}
int main()
{
	int W, H, f, m, o, c[10][10];
	while (scanf("%d%d", &W, &H), W|H)
	{
		scanf("%d%d%d", &f, &m, &o);
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
				scanf("%d", &c[i][j]);

		static int visit[10][10][1<<10][51];
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
				for (int k = 0; k < 1 << W; ++k)
					for (int l = 0; l <= m; ++l)
					visit[i][j][k][l] = false;

		int res = -1;
		priority_queue<node> q;
		for (int i = 0; i < W; ++i)
			q.push(node(0, i, 0, o, 0));
		while (!q.empty())
		{
			node e = q.top(); q.pop();
			if (e.cost > f)
				break;
			else if (e.x < 0 || e.x >= W
				|| (e.y != H &&
					(e.o <= 1 || visit[e.y][e.x][e.hori][e.o])))
				continue;
			else if (e.y == H && e.o >= 1)
			{
				res = e.cost;
				break;
			}

			visit[e.y][e.x][e.hori][e.o] = true;
			--e.o;
			if (!(e.hori & (1 << e.x)))
			{
				e.hori |= 1 << e.x;
				if (c[e.y][e.x] < 0)
					e.cost -= c[e.y][e.x];
				else
					e.o = min(m, e.o + c[e.y][e.x]);
			}

			q.push(node(e.cost, e.x, e.y+1, e.o, 0));
			q.push(node(e.cost, e.x-1, e.y, e.o, e.hori));
			q.push(node(e.cost, e.x+1, e.y, e.o, e.hori));
		}

		if (res != -1)
			printf("%d\n", res);
		else
			puts("NA");
	}

	return 0;
}

Measured memory_bytes: 20000
[N,K] = [int(s) for s in input().rstrip().split(' ')] #Nモンスター数,K必殺技回数
H = [int(s) for s in input().rstrip().split(' ')] #各モンスターの体力
S = 0 #通常攻撃の回数
if K >= N:
    print(0)
else:
    H_0 = sorted(H, reverse = True)
    h_0 = H_0[K:]
    print(sum(h_0))

Measured memory_bytes: 26180
var a,b:longint;

begin
  readln(a,b);
  if a+b > a-b then 
  begin
    if a+b > a*b then writeln(a+b)
    else writeln(a*b);
  end 
  else begin
    if a-b > a*b then writeln(a-b)
    else writeln(a*b);
  end;
end.


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

int main(){
    int N, M;
    cin >> N >> M;
    long long e[N+2];
    e[1] = 1;
    rep2(i, 1, N+1){
        e[i+1] = 2*e[i];
    }
    long long dp[M+1][e[N+1]];
    dp[0][0] = 0;
    rep2(i, 1, e[N+1]){
        dp[0][i] = -1;
    }
    long long a;
    int b;
    rep2(i, 1, M+1){
        cin >> a >> b;
        int c[b];
        rep(j, b){
            cin >> c[j];
        }
        rep(k, e[N+1]){
            long long sum = 0;
            rep(j, b){
                if(k % e[c[j]+1] >= e[c[j]]){
                    sum += e[c[j]];
                }
            }
            if(dp[i-1][k-sum] == -1){
                dp[i][k] = -1;
            }
            else if(dp[i-1][k] == -1){
                dp[i][k] = dp[i-1][k-sum] + a;
            }
            else{
                dp[i][k] = min(dp[i-1][k-sum]+a, dp[i-1][k]);
            }
        }
    }
    cout << dp[M][e[N+1]-1] << endl;
}

Measured memory_bytes: 32256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// rtsq ルート, int 2*10^9, __gcd

int main() {
  int A, B, T;
  ci(A, B, T);
  co(T / A * B);
}

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

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

const int MAX = 1<<17 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

ll n, mat[17][17], cost[MAX], dp[MAX] ;

void sol( ){
    cin >> n ;
    for( int i = 0 ; i < n ; i++ )
        for( int j = 0 ; j < n ; j++ )
            cin >> mat[i][j] ;
    for( int i = 1 ; i < MAX ; i++ ){
        for( int j = 0 ; j < 17 ; j++ ){
            if( i&(1<<j) )
                for( int k = 0 ; k < 17 ; k++ ){
                    if( i&(1<<k) )
                        cost[i] += mat[j][k] ;
                }
        }
        cost[i] >>= 1 ;
    }
    for( int i = 1 ; i < MAX ; i++ ){
        for( int j = i ; j ; j = (j-1)&i ){
            dp[i] = max( dp[i], dp[i^j] + cost[j] ) ;
        }
    }
    cout << dp[(1LL<<n)-1] << nl ;
}

signed main( ){
  timesaver ;
//  int t = 1 ; cin >> t ; while(t--)
  {
      sol( );
  }
}

Measured memory_bytes: 2304
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if((-100<=x) && (x<=100) && (-100<=y) && (y<=100) && (0<W) && (W<=100)
	&& (0<H) && (H<=100) && (0<r) && (r<=100)){
	
		if(x-r<0 || x+r>W || y-r<0 || y+r>H){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <tuple>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;

const int DEPTH = 18;
struct SegTree {
	int val[1 << (DEPTH + 1)];
	SegTree() {
		int i;
		rep(i, (1 << (DEPTH + 1))) val[i] = 0;
	}
	void add(int l, int r, int v, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return;
		if (l <= a && b <= r) {
			val[id] += v;
			return;
		}
		add(l, r, v, a, (a + b) / 2, id * 2 + 1);
		add(l, r, v, (a + b) / 2, b, id * 2 + 2);
	}
	int query(int pos) {
		pos += (1 << DEPTH) - 1;
		int ret = val[pos];
		while (pos > 0) {
			pos = (pos - 1) / 2;
			ret += val[pos];
		}
		return ret;
	}
};

int n, d, a;
int x[200000], h[200000];
SegTree seg;

signed main() {
	int i;
	static P pa[200000];
	
	cin >> n >> d >> a;
	rep(i, n) cin >> pa[i].first >> pa[i].second;
	sort(pa, pa + n);
	rep(i, n) { x[i] = pa[i].first; h[i] = pa[i].second; }
	rep(i, n) { seg.add(i, i + 1, h[i]); }
	
	int ans = 0;
	rep(i, n) {
		int val = seg.query(i);
		if (val <= 0) continue;
		
		int r = upper_bound(x, x + n, x[i] + 2 * d) - x;
		
		int cnt = (val + a - 1) / a;
		seg.add(i, r, -a * cnt);
		ans += cnt;
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	string s;
	for(int i=0;i<n;i++)cin>>s;
	int yosen=0;
	int i=0;
	vector<bool> tuuka(n);
	long kai=0;
	for(i=0;i<n;i++){
		if(s.at(i) == 'a' && yosen < (a+b)){
			yosen++;
			tuuka[i]=true;
		}
		else if((s.at(i) == 'b' && kai < b) && yosen < (a+b)){
			yosen++;
			tuuka[i]=true;
			kai++;
		}else if(s.at(i)=='c'){
			tuuka[i]==false;
		}
		else tuuka[i]==false;
	}
	for(i=0;i<n;i++){
		if(tuuka[i]==true)cout<<"Yes"<<endl;
		else if(tuuka[i]==false) cout<<"No"<<endl;
	}
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int main() {
  int64_t A, B, C;
  cin >> A >> B >> C;
  if (A%2==0||B%2==0||C%2==0) {
    cout << 0 << endl;
  }
  else {
    cout << min((min((A*B),(B*C))),(C*A)) << endl;
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <sstream>
#include <complex>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using iii = pair<int, ii>;
using viii = vector<iii>;

using ll = long long int;
using vc = vector<char>;
using vb = vector<bool>;
using ib = pair<int, bool>;
using vib = vector<ib>;

const ll MOD = 1000 * 1000 * 1000 + 7;
#define INF 1000 * 1000 * 1000
#define EMPTY -10
#define mp(a, b) make_pair(a,b)

void calcular(int lAct, vi const& letras, ll & res, ll totalAct) {
	if (lAct == letras.size()) {
		res = (res + totalAct) % MOD;
	}
	else {
		calcular(lAct + 1, letras, res, totalAct);
		calcular(lAct + 1, letras, res, (totalAct * letras[lAct]) % MOD);
	}
}

bool resuelveCaso() {
	int n;
	cin >> n;
	if (!cin) return false;
	string s;
	cin >> s;
	vi letras('Z' - 'A' + 1,0);

	for (int i = 0; i < s.size(); ++i) {
		++letras[s[i] - 'a'];
	}

	vi letrasP;

	for (int i = 0; i < letras.size(); ++i) {
		if (letras[i] != 0) letrasP.push_back(letras[i]);
	}

	ll res = 0;
	calcular(0, letrasP, res, 1);
	cout << res - 1 << '\n';

	return true;
}

int main() {
	while (resuelveCaso()) {}
	return 0;
}

Measured memory_bytes: 512
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
int cnt[N];
vector < int > g[N];
int n, m, k;

int main () {
	SpeedForce;
	
	multiset < int > s;
	
	cin >> n >> m >> k;
	for (int i = 1; i <= k; ++i) {
		int x, y;
		cin >> x >> y;
		++cnt[y];
		g[x].pb(y);
	}
	
	for (int i = 1; i <= m; ++i) {
		s.insert(cnt[i]);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (auto it : g[i]) {
			s.erase(s.find(cnt[it]));
		
			--cnt[it];
			
			s.insert(cnt[it]);
		}
		//cout << sz(g[i]) << ' ' << *s.rbegin() << '\n';
		ans = max(ans, sz(g[i]) + *s.rbegin());
		
		for (auto it : g[i]) {
			s.erase(s.find(cnt[it]));
		
			++cnt[it];
			s.insert(cnt[it]);
		}
	}
	
	cout << ans << '\n';
	
	return Accepted;
}

// B...a


Measured memory_bytes: 42336
n=int(input())
a=list(map(int,input().split()))

import math

del_0=a[0]

if n==2:
    print(max(a))
    exit()
#print(a)
for i in range(n):
    #print(">>>>>>>>>",i+1)
    if i==2:
        del_1=max([math.gcd(a[0],a[1]),math.gcd(a[2],a[1]),math.gcd(a[2],a[0])])
        #print(([math.gcd(a[0],a[1]),math.gcd(a[2],a[1]),math.gcd(a[2],a[0])]))
    elif i>2:
        del_1=max(del_0,math.gcd(del_1,a[i]))
        #print(del_1)

    del_0=math.gcd(del_0,a[i])
    #print(del_0)
print(del_1)

Measured memory_bytes: 84668
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int a[100005],n,ans;
int main(){
	cin>>n;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	vector<int>vec;
	rep(i,n){
		if(a[i]==i+1){
			vec.pb(i+1);
		}
	}
	int prev = -1;
	rep(i,vec.size()){
		if(i+1==vec.size() || vec[i+1]!=vec[i]+1){
			//[prev+1,i]
			ans += (i-prev+1)/2;
			prev = i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1276
#include<stdio.h>
#include<string.h>
int main(void){
  int i,k;
  char a[10];
  scanf("%s",a);
  k=strlen(a);
  for(i=0;i<k;i+=2){
    if(!(a[i]=='h'&&a[i+1]=='i')){
      printf("No");
      return 0;
    }
  }
    printf("Yes");
    return 0;
  }

Measured memory_bytes: 128
double n,p[333][333][333],r;
c[4];
f(i,j,k)
{
	if(i|j|k&&p[i][j][k]==0)
	{
		p[i][j][k]=(
			(i?i/n*(f(i-1,j,k),r+n/(i+j+k)):0)+
			(j?j/n*(f(i+1,j-1,k),r+n/(i+j+k)):0)+
			(k?k/n*(f(i,j+1,k-1),r+n/(i+j+k)):0)
		)*n/(i+j+k);
	}
	r=p[i][j][k];
}
main(a)
{
	for(scanf("%lf",&n);~scanf("%d",&a);)c[a]++;
	printf("%.9f",r,f(c[1],c[2],c[3]));
}

Measured memory_bytes: 260224
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    const int m = 3;   
    vector<vi> a(m, vi(m));
    rep(i, m) rep(j, m) cin >> a[i][j];
    int n; cin >> n;
    rep(_, n){
        int x; cin >> x;
        rep(i, m) rep(j, m){
            if(a[i][j] == x) a[i][j] = 0;
        }
    }

    bool res = false;

    // hor
    rep(i, m){
        bool ok = true;
        rep(j, m){
            ok &= (a[i][j] == 0);
        }
        res |= ok;
    }
    // ver
    rep(j, m){
        bool ok = true;
        rep(i, m){
            ok &= (a[i][j] == 0);
        }
        res |= ok;
    }
    // dia
    rep(i, m){
        bool ok = true;
        rep(i, m){
            ok &= (a[i][i] == 0);
        }
        res |= ok;
    }
    rep(i, m){
        bool ok = true;
        rep(i, m){
            ok &= (a[i][m-1-i] == 0);
        }
        res |= ok;
    }

    cout << (res ? "Yes":"No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << 1 << endl;
  } else if (a != b && b!= c && a!=c) {
    cout << 3 << endl;
  } else {
    cout << 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256