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

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define deb(x)     cout << #x << " = "<<x<<endl

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)

int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;


ll gcd(ll  a , ll b) {
	return (b == 0) ? a : gcd(b, a % b);
}
ll binpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
ll powmod(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinv(ll n, ll p)
{
	return powmod(n, MOD - 2, MOD);
}
void max_self(ll &a, ll b) {
	a = max(a, b);
}
bool is_ap(vl v, int n) {
	ll d = v[1] - v[0];
	F0R(i, n) {
		if (v[i] != v[0] + i * d)
			return false;
	}
	return true;
}


int main(int argc, char const *argv[])
{
	// two magical lines to speed up IO
	cin.tie(0);
	ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	int a[n];
	int  sum = 0;
	int cnt = 0;
	F0R(i, n) {
		cin >> a[i];
		sum += a[i];
	}

	F0R(i, n) {
		if (4 * m * a[i] >= sum) {
			cnt++;

		}


	}
	if (cnt >= m)
		cout << "Yes\n";
	else
		cout << "No\n";




}




Measured memory_bytes: 3612
n = gets.to_i
reds = []
blues = []
n.times { reds << gets.split.map(&:to_i) }
n.times { blues << gets.split.map(&:to_i) }
reds.sort! { |a, b| b[0] <=> a[0] }
blues.sort! { |a, b| b[0] <=> a[0] }

reds.each do |red_x, red_y|
  tmp_y = 201
  tmp_i = nil
  blues.each_with_index do |(blue_x, blue_y), blue_i|
    break if blue_x <= red_x
    if red_x < blue_x && red_y < blue_y && blue_y < tmp_y
      tmp_y = blue_y
      tmp_i = blue_i
    end
  end
  blues.delete_at(tmp_i) if tmp_i
end

puts n - blues.size


Measured memory_bytes: 3836
# -*- coding: utf-8 -*-
h,w = input().split()
h = int(h)
w = int(w)

strs = ""
tmp = []

for j in range(w + 2):
    strs += "#"
for i in range(h):
    tmp.append(input())
print(strs)
for i in range(h):
    print("#" + tmp[i] + "#")
print(strs)


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

int main(){
  int n;

  while(cin >> n){
    int minA, maxV = -1;

    for(int i = 0; i < n; i++){
      int a, v;
      cin >> a >> v;

      if(maxV < v || maxV == v && minA > a){
        minA = a;
        maxV = v;
      }
    }

    cout << minA << " " << maxV << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
long long N,x;
void solve()
{


    cin >> N;
    vector<long long> v(N);
    for(long long int i = 0; i < N; i++)
    {
        cin>>x;
        v[i]=x;
    }
    sort(v.begin(), v.end());
    long long  ans = 0;
    for(long long i= N - 1; i >= 0; i--)
    {
        for(long long j= i - 1; j>= 0; j--)
        {
            auto itr = lower_bound(v.begin(), v.end(), v[i] + v[j]);
            long long ng = distance(itr, v.end());
            ans += (N - 1 -i) - ng;
        }
    }
    cout << ans << endl;
    return;
}

int main()
{
    solve();
    return 0;
}


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

ll N;

ll chuo(vector<ll> L) {
  if (N % 2 == 0) {
    return L[N / 2 - 1] + L[N / 2];
  } else {
    return L[(N - 1) / 2];
  }
}

int main() {
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  
  ll ans = chuo(B) - chuo(A) + 1;
  cout << ans << endl;
  return 0;
}


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

long long x[100010], v[100010];
long long sum1[100010], sum2[100010], sumN[100010];
long long sum_max1[100010], sum_max2[100010];
long long max_x1[100010], max_x2[100010]; //sum_max[i]に対応する寿司の場所

int main() {
	int n;
	long long c;
	long long sum = 0;

	cin >> n >> c;

	for (int i = 1; i <= n; i++) { //原点から時計周り
		cin >> x[i] >> v[i];
		sum += v[i]; //累積和
		sum1[i] = sum - x[i]; //解説のf(a)、時計周りが往復でないとき
		sum2[i] = sum - x[i] * 2; //時計周りが往復のとき
		if (sum_max1[i - 1] > sum1[i]) {
			max_x1[i] = max_x1[i - 1];
			sum_max1[i] = sum_max1[i - 1];
		}
		else {
			max_x1[i] = x[i];
			sum_max1[i] = sum1[i];
		}

		if (sum_max2[i - 1] > sum2[i]) {
			max_x2[i] = max_x2[i - 1];
			sum_max2[i] = sum_max2[i - 1];
		}
		else {
			max_x2[i] = x[i];
			sum_max2[i] = sum2[i];
		}
	}
	x[n + 1] = c;

	for (int i = n; i > 0; i--) { //反時計回り
		sumN[n - i + 1] = sumN[n - i] + v[i];
	}

	long long ans = 0, MAX = 0;
	for (int i = 0; i <= n; i++) {
		ans = sum_max1[n - i] + sumN[i];
		ans -= (c - x[n + 1 - i])*2;
		MAX = max(MAX, ans);

		ans = sum_max2[n - i] + sumN[i];
		ans -= (c - x[n + 1 - i]);
		MAX = max(MAX, ans);
	}
	cout << MAX << endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

ll mod = 1e9 + 7;

ll mpow(ll A, ll B) {
	if (B == 0) return 1;
	else if (B == 1) return A;
	else if (B % 2) return A * mpow(A, B - 1) % mod;
	else {
		ll hanbun = mpow(A, B / 2);
		return hanbun * hanbun % mod;
	}
}

ll mdiv(ll A, ll B) {
	return A * mpow(B, mod - 2) % mod;
}

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


	//解説みました

	int N;
	cin >> N;
	ll A[100000];
	rep(i, N) cin >> A[i];
	
	ll kaijou = 1;
	rep1(i, N) {
		kaijou = kaijou * i % mod;
	}

	ll B[100001] = {};
	rep1(i, N) {
		B[i] = (B[i - 1] + mdiv(kaijou, i)) % mod;
	}
	
	ll kotae = 0;
	rep1(i, N) {
		ll tasu = A[i - 1] * (B[i] + B[N - i + 1] - B[1] + mod) % mod;
		kotae = (kotae + tasu) % mod;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<math.h>
#include<stack>
#include<map>
#include<queue>
using namespace std;

int main()
{
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	long long mx=max(a,max(b,c));
	if(mx==a)a=0;
	else if(mx==b)b=0;
	else if(mx==c)c=0;
	cout<<mx*10+b+c+a;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <cstring>
#include <cassert>
using namespace std;

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

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        int n, m; scanf("%d%d", &n, &m);
        vector<int> h(n + 1);
        for(int i = 1; i <= n; i++) scanf("%d", &h[i]);
        int ans = n;
        vector<bool> vis(n + 1, 0);
        for(int i = 0; i < m; i++) {
            int u, v; scanf("%d%d", &u, &v);
            if(h[u] < h[v]) ans -= (!vis[u]), vis[u] = 1;
            else if(h[v] < h[u]) ans-= (!vis[v]), vis[v] = 1;
            else ans -= (!vis[u]) + (!vis[v]), vis[v] = vis[u] = 1;
        }
        printf("%d\n", ans);
    }  
    return 0;
}

Measured memory_bytes: 3804
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<map>
#include<queue>
#include<assert.h>
#include<stdio.h>
#include<stack>
#include<cstring>
#include<fstream>
using namespace std;
#define goup(i,a,b) for(int i=a;i<b;i++)
#define Goup(i,a,b) for(int i=a;i<=b;i++)
#define godown(i,a,b) for(int i=a;i>b;i--)
#define Godown(i,a,b) for(int i=a;i>=b;i--)
#define Gohead(i,a,b) for(int i=a;i;i=b)
typedef long long ll;
const int MaxDegree = 0x3f3f3f;
const double Mod = 1e9 + 7;
const double PI = acos(-1);
int main()
{
	int n, s[105] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	cin >> n;
	cout << s[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N,K;
vector <int > H;





int main()
{

	cin >> N;

	cout << N * (N+1) / 2 << endl;




}


Measured memory_bytes: 256
import sys
n=int(input())
k=2
arr=[int(i) for i in input().split()]
dp=[sys.maxsize]*(n+1)
dp[0]=0
for i in range(1,n):
    for j in range(1,3):
        dp[i]=min(dp[i-j]+abs(arr[i]-arr[i-j]),dp[i])
print(dp[n-1])
    
    



Measured memory_bytes: 52208
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	LL n, a;
	cin >> n;
	vector<LL> sum(n + 1);
	for (LL i = 0; i < n; ++i) {
		cin >> a;
		sum[i + 1] = sum[i] + a;
	}
	LL pos = lower_bound(sum.begin(), sum.end(), sum[n] / 2) - sum.begin();
	LL ans = abs(sum[pos] - (sum[n] - sum[pos]));
	--pos;
	ans = min(ans, abs(sum[pos] - (sum[n] - sum[pos])));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  vector<vector<int>> cnt(n, vector<int>(26,0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s[i].size(); j++) cnt[i][s[i][j] - 'a']++;
  }
  string res = "";
  for (int i = 0; i < 26; i++) {
    int d = 100000;
    for (int j = 0; j < n; j++) {
      d = min(d, cnt[j][i]);
    }
    while (d--) res += 'a' + i;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int M;
	while (cin >> M, M) {
		bool v[10] = {0};
		int n = 10;
		int m[20][20]; fill(&m[0][0], &m[0][0]+20*20, 1e9);
		for (int i = 0; i < M; ++i) {
			int a, b, c; cin >> a >> b >> c;
			m[a][b] = m[b][a] = c;
			v[a] = v[b] = true;
		}
		for (int i = 0; i < n; ++i) m[i][i] = 0;

		for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
			m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
		}

		int ans = 1e9, aid = -1;
		for (int i = 0; i < n; ++i) {
			if (v[i]) {
				int s = 0;
				for (int j = 0; j < n; ++j) if (v[j]) s += m[i][j];
				if (s < ans) ans = s, aid = i;
			}
		}
		cout << aid << " " << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct QU {
  V<> par, rank, _size;
  V<lint> res;

  QU(int n) : par(n), rank(n), _size(n, 1), res(n) { 
    iota(par.begin(), par.end(), 0);
  }

  int find(int a) {
    if (par[a] == a) return a;
    return find(par[a]);
  }

  bool same(int a, int b) { return find(a) == find(b); }

  int size(int a) { return _size[find(a)]; }

  void unite(int a, int b, lint c) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (rank[a] < rank[b]) {
      res[b] += _size[a] * c;
      res[a] += _size[b] * c - res[b];
      par[a] = b;
      _size[b] += _size[a];
    } else {
      res[a] += _size[b] * c;
      res[b] += _size[a] * c - res[a];
      par[b] = a;
      _size[a] += _size[b];
    }
    if (rank[a] == rank[b]) rank[a]++;
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  struct edge { int from, to; lint c; };
  V<edge> es(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b, c; cin >> a >> b >> c, a--, b--;
    es[i] = {a, b, c};
  }
  sort(es.begin(), es.end(), [](edge x, edge y) { return x.c > y.c; });
  QU qu(n);
  for (auto&& e : es) qu.unite(e.from, e.to, e.c);
  VV<> ch(n);
  int root = qu.find(0);
  for (int v = 0; v < n; v++) if (v != root) ch[qu.par[v]].push_back(v);
  queue<int> que;
  que.push(root);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int w : ch[v]) {
      qu.res[w] += qu.res[v]; que.push(w);
    }
  }
  for (int i = 0; i < n; i++) cout << qu.res[i] << '\n';
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int N,K;
  scanf("%d%d", &N,&K);
  string s;
  cin >> s;

  vector<int> v;

  int cnt = 0;
  int ref = 0;

  while(ref<N){
    while(s[ref]=='1'){
      ++cnt;
      ++ref;
      if(ref>=N) break;
    }
    v.PB(cnt);
    cnt = 0;
    

    while(s[ref]=='0'){
      ++cnt;
      ++ref;
      if(ref>=N) break;
    }
    v.PB(cnt);
    cnt = 0;

    if(ref>=N) {
        v.PB(0);
        break;
    }
  }

  int num = SZ(v);
//   FOR(i,0,num-1) cout << v[i];
//   cout << endl;

  if(v[num-1]==0 && v[num-2]==0){
      v.erase(v.begin()+num-1);
      v.erase(v.begin()+num-2);
  }

  num = SZ(v);

//   FOR(i,0,num-1) cout << v[i];
//   cout << endl;

  int ans = 0;
  int fivesum = 0;
  ref = 0;

  while((ref+2*K)<num){
    fivesum = 0;
    FOR(i,0,2*K) fivesum += v[ref+i];
    chmax(ans,fivesum);
    ref += 2;
  }

//   if(num-1-2*K>=0){
//   fivesum = 0;
//   FORD(i,num-1,num-2*K) fivesum += v[ref+1];
//   chmax(ans,fivesum);
//   }

  if(ans==0) ans = N;

  cout << ans << endl;

}

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

int main(){
	string s; cin >> s;
	if(s[0]==s[1] && s[1]==s[2]) puts("No");
	else puts("Yes");
}

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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=3030;
ll dp[N][N][4];
int f[N][N];
int n,m,k;
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>m>>k;
	for(int i=0;i<k;++i){
		int r,c,v;cin>>r>>c>>v;
		f[--r][--c]=v;
	}
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)
			for(int l=0;l<4;++l){
				dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][l]);
				dp[i][j+1][l]=max(dp[i][j+1][l],dp[i][j][l]);
				if(f[i][j]&&l<3){
					dp[i][j+1][l+1]=max(dp[i][j+1][l+1],dp[i][j][l]+f[i][j]);
					dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][l]+f[i][j]);
				}
			}
	ll res=0;
	for(int i=0;i<3;++i)
			res=max(res,f[n-1][m-1]+dp[n-1][m-1][i]);
	cout<<max(res,dp[n-1][m-1][3])<<endl;
}


Measured memory_bytes: 323160
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
typedef long long ll;
using namespace std;
int main(){
	ll n,ans=0;
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			ans+=i;
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int a, v, b, w, t;
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  long long int p = abs(a-b);
  long long int q = (v-w)*t;
  if(p <= q) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)
ll n,ans = 0;
pair<ll, ll> s[114141], c[114514];

int main() {
	
	cin >> n;
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		c[i] = make_pair(a + b, i);
		s[i] = make_pair(a, b);

	}
	sort(c, c + n,greater<pair<ll,ll>>());
	REP(i, n) {
		if (i % 2 == 0) ans += s[c[i].second].first;
		else ans -= s[c[i].second].second;
	}
	cout << ans << endl;
}

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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  
  if (S == U){
    A--;
  }
  else {
    B--;
  }
  
  cout << A << " " << B << endl;
  return 0;  
}

Measured memory_bytes: 256
require "time"
t0 = Time.strptime("0 0 0", "%H %M %S")
t1 = Time.strptime("2 0 0", "%H %M %S")
loop do
   break if gets =~ /^-1/
   t = Time.strptime($_, "%H %M %S")
   puts (t0 + (t1 - t)).strftime("%H:%M:%S")
   puts (t0 + 3 * (t1 - t)).strftime("%H:%M:%S")
end

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll A, B, N; cin >> A >> B >> N;
    cout << floor(A*min(N,(B-1))/B) - A*floor(min(N,(B-1))/B) << endl;
    return 0;
}


Measured memory_bytes: 3780
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ws := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ws[i])
	}
	result := true
	for i := 1; i < n; i++ {
		if ws[i][0] != ws[i-1][len(ws[i-1])-1] {
			result = false
		}
		for j := 0; j < i; j++ {
			if ws[i] == ws[j] {
				result = false
			}
		}
		if result == false {
			break
		}
	}
	if result {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


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

char buf[100000+10];

int main(void) {
  scanf("%s", buf);
  int n = strlen(buf);
  vector<int> res;
  int i = 0;
  while(i < n) {
    int i1 = i;
    int odd = 0;
    int even = 0;
    while(i < n && buf[i] == 'R') {
      (i % 2 == 0 ? even : odd) += 1;
      ++i;
    }
    int ir = i-1;
    while(i < n && buf[i] == 'L') {
      (i % 2 == 0 ? even : odd) += 1;
      ++i;
    }
    for(int j = i1; j < i; ++j) {
      if(j == ir) {
        res.push_back(ir % 2 == 0 ? even : odd);
      } else if(j == ir+1) {
        res.push_back(ir % 2 == 0 ? odd : even);
      } else {
        res.push_back(0);
      }
    }
  }
  REP(i, n) {
    printf("%d%c", res[i], i == n-1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 1020
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e18;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;

int a[N];
void solve(){
	int n;
	cin >> n;
	for(int i =1;i<=n;i++){
		cin >> a[i];
	}

	// for(int i =1;i<=20;i++){
	// 	int k = i;
	// 	int cur = k;
	// 	for(int j =1;j<=n;j++){
	// 		cur -= (cur % a[j]);
	// 	}
	// 	cout << cur << endl;
	// }
	int lo = 2,hi= 1e18;
	int ans = INF;
	for(;lo<=hi;){
		int k = (lo + hi)>>1ll;
		int cur = k;
		for(int i =1;i<=n;i++){
			cur -= (cur % a[i]);
		}
		if(cur == 2){
			ans = min(ans,k);
			hi = k-1;
		}
		else if(cur > 2) hi = k-1;
		else lo = k+1;
	}
	// cout << ans << endl;
	int x = ans;	
	lo = 2,hi = 1e18;
	ans = -1;
	for(;lo<=hi;){
		int k = (lo + hi)>>1ll;
		int cur = k;
		for(int i =1;i<=n;i++){
			cur -= (cur % a[i]);
		}
		if(cur == 2){
			ans = max(ans,k);
			lo = k+1;
		}
		else if(cur > 2) hi = k-1;
		else lo = k+1;
	}
	int y = ans;
	if(x == INF || y == -1){
		cout << -1 << endl;
		return;
	}
	cout << x << " " << y << endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 4424
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            double a = Math.sqrt(Math.pow(x[i], 2) + Math.pow(y[i], 2));
            if (a <= d) {
                sum++;
            }
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 61676
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
  int i,j,N,Q,l,r,count;
  scanf("%d %d", &N, &Q);
  char S[N];
  int isAC[N],numAC[N];
  scanf("%s", S);
  isAC[0]=0;
  for(i=1;i<N;i++){
    if(S[i-1]=='A' && S[i]=='C'){
        isAC[i]=1;
      } else {
      isAC[i]=0;
    }
  }
  numAC[0]=0;
  for(i=1;i<N;i++){
    numAC[i]=numAC[i-1]+isAC[i];
    /*printf("%d\n",numAC[i]);*/
  }
  
  
  
  for(i=0;i<Q;i++){
    scanf("%d %d", &l, &r);
    count=numAC[r-1]-numAC[l-2]-isAC[l-1];
    printf("%d\n",count);
  }

    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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 = 1e18;

int dp[101][4][4][4];

const int MOD = 1e9+7;
// const int MOD = 998244353;
const int MAX = 1000001;
int fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

int COM(int n,int k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int powMOD(int n,int r){
    if(r==0)return 1;
    if(r%2==0)return powMOD(n,r/2)*powMOD(n,r/2)%MOD;
    if(r%2==1)return powMOD(n,r-1)*n%MOD;
}

void add(int &x, int y){
    x += y;
    x %= MOD;
    return;
}

void sub(int &x, int y){
    x -= y;
    x %= MOD;
    if(x < 0) x += MOD;
    return;
}

void mul(int &x, int y){
    x *= y;
    x %= MOD;
    return;
}

signed main(){
    int n; cin >> n;
    //だめなのは
    //AGC ACG GAC A?GC AG?C
    //0=A 1=C 2=G 3=T
    REP(i,4)REP(j,4)REP(k,4){
        if(i == 0 and j == 2 and k == 1) continue;//AGC
        if(i == 0 and j == 1 and k == 2) continue;//ACG
        if(i == 2 and j == 0 and k == 1) continue;//GAC
        dp[3][i][j][k] = 1;
    }
    for(int s = 4; s <= n; s++){
        REP(i,4)REP(j,4)REP(k,4)REP(nex,4){
            if(j == 0 and k == 2 and nex == 1) continue;//AGC
            if(j == 0 and k == 1 and nex == 2) continue;//ACG
            if(j == 2 and k == 0 and nex == 1) continue;//GAC
            if(i == 0 and k == 2 and nex == 1) continue;//A?GC
            if(i == 0 and j == 2 and nex == 1) continue;//AG?C
            add(dp[s][j][k][nex],dp[s-1][i][j][k]);
        }
    }
    int ans = 0;
    REP(i,4)REP(j,4)REP(k,4) add(ans,dp[n][i][j][k]);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
 
int main(){
  ll a,n;
  //vi c;
  cin >> n;
  vi d(100000, 0);
  for(int x=1; x<101; x++){
    for(int y=1; y<101; y++){
      for(int z=1; z<101; z++){
        a=x*x+y*y+z*z+x*y+y*z+z*x;
        d[a]++;
    }
  }
  }
  //sort(c.begin(),c.end());
  // rep(i,200000){
  //   cout << c[i] << endl;
  // }
  for(int i=1; i<n+1; i++){
    cout << d[i] << endl;
  }
    return 0;
  }
  

Measured memory_bytes: 3752
s = list(input())
c = int(0)
result = int(0)
result2 = int(0)

for i in s:
        if(i=="A" or i=="C" or i=="G" or i=="T"):
                c+=1
                result2 = c
        else:
                if(c>result):
                        result = c
                c=0
if(result > result2):
        print(result)
else:
        print(result2)

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

ll comper(string &S, int h, int low) {
  if (h >= low) {
    return 0;
  }
  else if (low - h == 1) {
    return S.at(h) - '0';
  }
  else {
    return comper(S, h+1, low) + (S.at(h) - '0') * pow(10, low - h - 1);
  }
}
    

int main() {
  string S;
  cin >> S;
  int sz = S.size();
  int low, h;
  vector<vector<ll>> ncat(sz, vector<int64_t>(sz + 1));
  ll ans = 0;
  for (h=0; h < sz; h++){
    for (low=h+1; low < sz + 1; low++) {
      ncat.at(h).at(low) = comper(S, h, low);
      if (h == 0 && low == sz)  ans += ncat.at(h).at(low);
      else if (h == 0 && low != sz)  ans += pow(2, sz - low - 1) * ncat.at(h).at(low);
      else if (h != 0 && low == sz)  ans += pow(2, h - 0 - 1) * ncat.at(h).at(low);
      else  ans += pow(2, sz - low - 1) * pow(2, h - 0 - 1) * ncat.at(h).at(low);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
for _ in range(n):
  a = list(map(int,input().split()))
  b = 0
  c = 0
  for i in range(10):
    if a[i] > b:
      b = a[i]
    elif a[i] > c:
      c = a[i]
    else:
      print("NO")
      break
    if i == 9:
      print("YES")


Measured memory_bytes: 5592
import java.io.*;
import java.util.HashMap;
import java.util.List;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        HashMap<String, Integer> cnt = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String v = in.readLine();
            cnt.put(v, cnt.getOrDefault(v, 0) + 1);
        }
        List<String> ac = List.of("AC", "WA", "TLE", "RE");
        for(String s : ac) {
            int c = cnt.getOrDefault(s, 0);
            System.out.println(s + " x " + c);
        }
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

struct segtree{
    static const int SEG=1<<19;
    vint dat,put;
    segtree():dat(SEG*2,INF),put(SEG*2,INF){}
    inline void push(int k){
        chmin(dat[k],put[k]);
        if(k<SEG-1){
            chmin(put[k*2+1],put[k]);
            chmin(put[k*2+2],put[k]);
        }
    }
    void update(int a,int b,int x,int k=0,int l=0,int r=SEG){
        push(k);
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            put[k]=x;
            push(k);
            return;
        }
        update(a,b,x,k*2+1,l,(l+r)/2);
        update(a,b,x,k*2+2,(l+r)/2,r);
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
    int query(int a,int b,int k=0,int l=0,int r=SEG){
        push(k);
        if(r<=a||b<=l)return INF;
        if(a<=l&&r<=b)return dat[k];
        return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

int N,K;
int A[111111],B[111111];
int S[111111];

int dp[111111];
signed main(){
    cin>>N>>K;
    rep(i,N){
        cin>>A[i]>>B[i];
        A[i]*=2;
    }
    rep(i,N){
        if(A[i]>K&&B[i]==1){
            cout<<-1<<endl;
            return 0;
        }
    }

    rep(i,N)S[i+1]=S[i]+A[i];
    vint lis;
    rep(i,N+1){
        lis.pb(S[i]%K);
    }
    sort(all(lis));lis.erase(unique(all(lis)),lis.end());
    segtree seg;
    for(int i=N-1;i>=0;i--){
        int w=lower_bound(all(lis),S[i]%K)-lis.begin();
        int z=seg.query(w,w+1);
        if(z==INF){
            dp[i]=S[N]-S[i];
        }
        else{
            dp[i]=((S[z]-S[i])/K+1)*K+dp[z];
        }
        if(B[i]==1){
            int l=lower_bound(all(lis),S[i]%K)-lis.begin();
            int r=lower_bound(all(lis),S[i+1]%K)-lis.begin();
            if(l<r){
                seg.update(l+1,r,i);
            }
            else{
                seg.update(l+1,lis.size(),i);
                seg.update(0,r,i);
            }
        }
    }

    rep(i,lis.size()){
        if(seg.query(i,i+1)==INF){
            cout<<S[N]<<endl;
            return 0;
        }
    }

    seg=segtree();

    int ans=INF;
    rep(i,N){
        int w=lower_bound(all(lis),S[i]%K)-lis.begin();
        if(seg.query(w,w+1)==INF){
            chmin(ans,S[i]+dp[i]);
        }

        if(B[i]==1){
            int l=lower_bound(all(lis),S[i]%K)-lis.begin();
            int r=lower_bound(all(lis),S[i+1]%K)-lis.begin();
            if(l<r){
                seg.update(l+1,r,i);
            }
            else{
                seg.update(l+1,lis.size(),i);
                seg.update(0,r,i);
            }
        }
    }

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


Measured memory_bytes: 37108
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n,m=map(int,input().split())
    print('Yes' if 2*n<=m<=4*n and m%2==0 else 'No')

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

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

    string T;

    rep(i,S.size()) {
        if(S[i]!='B') {
            T.push_back(S[i]);
        }
        else {
            if (T.size()==0) {
                continue;
            }
            else {
                T.pop_back();
            }
        }
    }
    rep(i,T.size()) {
        cout << T[i];
    }
    cout << endl;

}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var s string
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		if s == "Y" {
			fmt.Println("Four")
			return
		}
	}
	fmt.Println("Three")
}


Measured memory_bytes: 512
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}

function Main({ int, str, strs, ints }: NormalInput) {
  const S=str();
  console.log((S[2]==S[3]&&S[4]==S[5])?"Yes":"No")
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		if(s.charAt(s.length() - 1) != 's') {
			s = s + "s";
		}else {
			s = s + "es";
		}

		System.out.println(s);
	}

}


Measured memory_bytes: 38400
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


class SegmentTree:
    def segfunc(self,x,y):
        #ここに評価
        return x + y

    #nは総数、initがlist,ide_eleが元
    def __init__(self,n,init,ide_ele):
        self.n = n
        self.ide_ele = ide_ele
        self.num = 2**(n-1).bit_length()
        self.seg = [ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1] = init[i]
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
    
    
    def update(self,k,x):
        k += self.num-1
        self.seg[k] += x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[2*k+1],self.seg[2*k+2])
    
    def query(self,p,q):
        if q <= p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p > 1:
            if p & 1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p //= 2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res


n,k = m()

Seg = SegmentTree(n,[0 for i in range(n)],0)
a = l()

data = []
for i in range(k):
    po = l()
    po.append(i)
    data.append(po)

data.sort(key = lambda x:x[1])

where = [-1 for i in range(n)]
ans = [0 for i in range(k)]
left = -1
for i in range(k):
    aaa = data[i]
    aaa[0] -= 1
    aaa[1] -= 1
    if aaa[1] > left:
        for j in range(left+1,aaa[1]+1):
            popopo = a[j]-1
            if where[popopo] != -1:
                Seg.update(where[popopo],-1)
            Seg.update(j,1)
            where[popopo] = j
        left = aaa[1]
    ans[aaa[2]] = Seg.query(aaa[0],aaa[1]+1)

for i in range(k):
    print(ans[i])


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

int main() {
  string s;
  cin>>s;
  if(s[6]>'4' || s[5]=='1') cout<<"TBD"<<endl;
  else cout<<"Heisei"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k ;
  cin >> n >> k;
  vector<ll> num(n) ;
  REP(i,n){
    cin >> num[i] ;
  }
  ll ans = 0 ;
  sort(ALL(num)) ;
  REP(i,max((ll)0,n-k)){
    ans += num[i] ;
  }
  cout << ans <<endl;
    
  
  
  
  
  
  return 0 ;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 4e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

int arr[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int mid = arr[(n / 2) - 1];
  int mid2 = arr[(n / 2)];
  cout << mid2 - mid;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main (){

	int a,b,c;
	
	scanf ("%d %d", &a, &b);
	
	if (a<10){
		c = 100*(10-a);
	printf("%d",b+c);
	}else{
		printf ("%d", b);
	}
	return 0;
}

Measured memory_bytes: 3204
k = int(input())
a = [[1] * 10]
ps = 0
s = 0
for i in range(10000):
  for j in range(1, 10):
    ps = s
    s += a[i][j]
    if s >= k:
      break
  else:
    a.append([a[i][j-1] + a[i][j] + a[i][j+1] if j != 0 and j != 9 else a[i][0] + a[i][1] if j == 0 else a[i][8] + a[i][9] for j in range(10)])
    continue
  break
n = i
ans = str(j)
for i in range(n - 1, -1, -1):
  k -= ps
  m = j
  s = 0
  for j in range(max(0, m - 1), min(10, m + 2)):
    ps = s
    s += a[i][j]
    if s >= k:
      break
  ans += str(j)
print(int(ans))
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n){cin>>a[i];}
    map<int,int>l,r;
    rep(i,0,n){
        l[i+a[i]]++;
        r[i-a[i]]++;
    }
    int ans = 0;
    for(auto p:l){
        if(r[p.first]){
            ans+=l[p.first]*r[p.first];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 39052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int dx[4] = {1,-1,0,0}, dy[4] = {0,0,-1,1}; 
int dis[405][405];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w; cin >> h >> w;
    vector<string> v(h);
    rep(i,h) cin >> v[i];
    rep(i,401) rep(j,401) dis[i][j] = INF;
    int cnter = 0;
    rep(i,h) {
        rep(j,w) {
            if(v[i][j]=='.') cnter++;
        }
    }
    if(cnter==2) {
        cout << 1 << endl;
        return 0;
    }
    rep(i,h) {
        rep(j,w) {
            rep(k,4) {
                if(v[i][j]=='#') continue;
                int next_x = j + dx[k], next_y = i + dy[k];
                if(next_x>=0 && next_x<w && next_y>=0 && next_y<h && v[next_y][next_x]!='#'){
                    dis[i*w+j][next_y*w+next_x] = 1;
                }
            }
        }
    }


    int n = 401;


    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i,n) {
        rep(j,n) {
            if(dis[i][j]==INF) continue;
            ans = max(ans,dis[i][j]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <string>
using namespace std;




int main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2;
	int temp1, temp2;
	temp1 = y1 - y2;
	x3 = x2 + temp1;
	x4 = x1 + temp1;
	temp2 = x2 - x1;
	y3 = y2 + temp2;
	y4 = y1 + temp2;
	cout << x3 << " "<< y3<< " " << x4<<" " << y4 << endl;

	return 0;


}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long N, long long K) { print(N - K + 1); }

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
a =[]
for i in range(h):
    row = list(input())
    if '#' in row:
        a.append(row)
    else:
        h -= 1
num = []
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            num.append(i)
            break
    
for i in range(h):
    for j in num:
        print(a[i][j],end = '')
    print()

Measured memory_bytes: 42968