akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s,t;
int main(void){
    cin>>s>>t;
    if(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  if(k>=n){
    cout << 0 << endl;
  }else{
    long long int s=0;
    for(int i=0;i<n-k;i++){
      s+=h.at(i);
    }
    cout << s << endl;
  }
}

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

bool answer = true;

void judge(vector<int> &B){
  sort(B.begin(),B.end());
  for(int i; i < B.size(); i++){
    if(i == B.size() - 1){
      break;
    }
    if(B.at(i) == B.at(i+1)){
       answer = false; 
       break;
      }
    if(answer == false){
      break;
    }
  }
  return;
}

int main(){
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i; i < N; i++){
    cin >> A.at(i);
  }  
  
  judge(A);
  
  if(answer){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1024
import sys
import numpy as np


def cal(X):
    ret = 0
    for i in range(X.shape[0] - 1):
        for j in range(i + 1, X.shape[0]):
            r = 0
            for k in range(X.shape[1]):
                r += (X[i, k] - X[j, k]) ** 2
            d = np.sqrt(r)
            if d - int(d) < 0.000001:
                ret += 1
    return ret


sin_ = sys.stdin.read()
ain = np.fromstring(sin_, dtype=np.int64, sep=' ')
N = ain[0]
D = ain[1]
X = ain[2:N*D + 2].reshape((N, D))
ans = cal(X)
print(ans)

Measured memory_bytes: 12504
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

s, w = map(int,input().split())
ans = 0
if(s-w<=0):
    print("unsafe")
else:
    print("safe")


Measured memory_bytes: 74880
#include <iostream>

using namespace std;

char hoge(char *seq) {
  for (int i = 0; i < 3; ++i) {
    if ((seq[i] == seq[i+3]) && (seq[i] == seq[i+6]) && (seq[i] != 's'))
      return seq[i];
    if ((seq[i*3] == seq[i*3+1]) && (seq[i*3] == seq[i*3+2]) && (seq[i*3] != 's'))
      return seq[i*3];
  }
  if ( ((seq[0] == seq[4]) && (seq[0] == seq[8]) && (seq[4] != 's')) ||
       ((seq[2] == seq[4]) && (seq[2] == seq[6]) && (seq[4] != 's')) )
    return seq[4];

  return 'd';
}

int main() {
  while (true) {
    char seq[9];
    for (int i = 0; i < 9; ++i)
      cin >> seq[i];

    if (cin.fail())
      break;

    cout <<hoge(seq) << endl;
  }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll ,ll>;
const ll INF = 1LL<<61LL;

vector<ll> visited;
vector<vector<P> > es;
vector<ll> color;

void dfs(ll now, ll black){
	visited[now] = true;
	color[now] = black % 2;
	for(auto &e : es[now]){
		if(!visited[e.first])
			dfs(e.first, black + e.second);
	}
}

int main(){
	ll N, M;
	cin >> N;
	visited.assign(N, false);
	color.assign(N, 100);
	es = vector<vector<P> >(N, vector<P>(0));
	for(int i=0;i<N-1;i++){
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		es[a].push_back(P(b, c));
		es[b].push_back(P(a, c));
	}
	dfs(0, 0);
	for(auto &&x : color)
		cout << x << endl;
}


Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

string s;
bool b[510][510];
bool used[510][510];

bool f(int l, int r){
	if(used[l][r]) return b[l][r];
	used[l][r] = true;
	if(r-l == 0) return b[l][r] = true;
	if(r - l < 3) return false;
	if(s[l] != 'm' || s[r-1] != 'w') return false;
	for(int i = l + 1; i < r- 1; i++){
		if(s[i] != 'e') continue;
		if(f(l + 1, i) && f(i+1, r-1)) return b[l][r] = true;
	}
	return false;
}

int main(){
	cin>>s;
	int n = s.size();
	cout<<(f(0, n)?"Cat":"Rabbit")<<endl;
}

Measured memory_bytes: 3668
n, m = map(int, input().split())
num_list = sorted(list(map(int, input().split())), reverse=True)
flg = 0
for i in num_list[:m]:
    if i < sum(num_list) / (4 * m):
        flg = 1
        break
if flg == 0:
    print("Yes")
else:
    print("No")

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


int main(){
    int h,w;
    cin>>h>>w;

    vector<string> a(h);
    rep(i,h) cin>>a[i];

    vector<bool> row(h, false);
    vector<bool> col(w, false);

    rep(i,h)rep(j,w){
        if(a[i][j] == '#') row[i] = true, col[j] = true;
    }

    rep(i,h){
        if(row[i] == true){
            rep(j,w){
                if(col[j] == true) cout<< a[i][j];
            }
            cout << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main(int argc, char const *argv[])
{
    unordered_set<char> s;
    string ss;
    cin >> ss;
    rep(i, 3) {
        s.insert(ss[i]);
    }
    if(s.size() == 2) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lld long double
#define fi first
#define se second
#define w(x) ll x;cin>>x;while(x--)
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main(){
    fio;
    string s;   cin>>s;
    ll sum=0;
    vector<int> v;
    for(int i=0;i<s.length();i++){
        if(s[i]=='B'){
            v.push_back(i);
        }
    }
    reverse(v.begin(),v.end());
    int size=s.length()-1;
    for(int i=0;i<v.size();i++){
        sum+=(size-v[i]);
        size-=1;
    }
    cout<<sum<<'\n';
    return 0;
}

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

int main(void){
    vector<int> A(10010);
    vector<char> op(5010);
    
    for(int i=0;i<5010;i++){
        cin>>A.at(2*i)>>op.at(i)>>A.at(2*i+1);
        if(op.at(i)=='+')cout<<A.at(2*i)+A.at(2*i+1)<<endl;
        else if(op.at(i)=='-')cout<<A.at(2*i)-A.at(2*i+1)<<endl;
        else if(op.at(i)=='*')cout<<A.at(2*i)*A.at(2*i+1)<<endl;
        else if(op.at(i)=='/')cout<<A.at(2*i)/A.at(2*i+1)<<endl;
        else if(op.at(i)=='?'){break;}
    }
}



Measured memory_bytes: 3124
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}


#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;


int G[600][600];


void solve(vec v,int t){
    int m=v.size();
    vec v1,v2;
    if(m==1)return;
    rep(i,m){
        if(i%2)v1.pb(v[i]);
        else v2.pb(v[i]);
    }
    for(auto a:v1)for(auto b:v2){
        G[a][b]=G[b][a]=t;
    }
    solve(v1,t+1);
    solve(v2,t+1);
}
main(){
    int n=in();
    vec w;
    rep2(i,1,n)w.pb(i);  
    solve(w,1);
    rep2(i,1,n-1){
        rep2(j,i+1,n){
            cout<<G[i][j]<<" ";
        }
        cout<<endl;
    }
}

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

using namespace std;

int k, d, a[15];
string n;
set<int> s;

int main() {
    cin >> n >> k;
    for (int i = 0; i <= 9; ++i)
        s.insert(i);
    for (int i = 1; i <= k; ++i) {
        cin >> d;
        s.erase(d);
    }
    for (int i = 1; i <= n.size(); ++i)
        a[i] = int(n[i - 1] - '0');
     
    int id = n.size() + 1;       
    for (int i = 1; i <= n.size(); ++i) {
        if (s.lower_bound(a[i]) == s.end()) { 
            id = i - 1;
            while (id >= 1 && s.upper_bound(a[id]) == s.end())
                --id;
            break;
        }
        if (*s.lower_bound(a[i]) > a[i]) {
            id = i;
            break;
        }
    }
    if (id == 0) {
        if (*s.begin() == 0)
            cout << *s.upper_bound(0);
        else
            cout << *s.begin();
    }
    else {
        for (int i = 1; i < id; ++i)
            cout << a[i];
        if (id != n.size() + 1)
            cout << *s.upper_bound(a[id]);
    }
    ++id;
    for (id; id <= n.size(); ++id)
        cout << *s.begin();
    return 0;
}

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

using namespace std;

int main() {
  int P, Q, R;
  cin >> P >> Q >> R;

  int min1 = min(P+Q, Q+R);
  int min2 = min(min1, R+P);

  cout << min2 << endl;



  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
from collections import deque
q = deque([])
cnt = 0
for i in range(n):
    if s[i]==')':
        if cnt >0:
            cnt-=1
        else:
            q.appendleft('(')
        q.append(')')
    else:
        q.append('(')
        cnt += 1
if cnt:
    for _ in range(cnt):
        q.append(')')
print(''.join(q))



Measured memory_bytes: 64220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<ll>> a(n, vector<ll>(3));
  for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
  ll res = 0;
  for (int i = 0; i <= (1 << 3); i++) {
    vector<int> state(3, 1);
    for (int j = 0; j < 3; j++) 
      if ((1 << j) & i) 
        state[j] = -1;
    vector<ll> nums;
    for (int j = 0; j < n; j++) {
      ll cur = 0;
      for (int k = 0; k < 3; k++) {
        if (state[k] * a[j][k] > 0) cur += abs(a[j][k]);
        else cur -= abs(a[j][k]);
      }
      nums.push_back(cur);
    }
    sort(nums.rbegin(), nums.rend());
    ll ans = 0;
    for (int j = 0; j < m; j++)
      ans += nums[j];
    res = max(res, ans);
  }
  cout << res << '\n';
  return 0;
}


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

using namespace std;

int main(void) {
  int T; cin >> T;
  auto comp = [](pair<long long, long long> a, pair<long long, long long> b) {
    return a.second > b.second;
  };
  long long MAX = 1000000000000LL, test = 2000000000LL;

  for (int zzz = 0; zzz < T; zzz++) {
    long long N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    priority_queue<
      pair<long long, long long>,
      vector<pair<long long, long long>>,
      decltype(comp)
    > que {comp};

    set<long long> ex;

    que.push(make_pair(N, 0));

    while (que.top().first != 1) {
      pair<long long, long long> a = que.top();
      que.pop();

      auto it = ex.find(a.first);
      if (it != ex.end()) continue;

      ex.insert(a.first);

      if (a.first/2 >= 1) {
        if (a.first%2 != 0) {
          que.push(make_pair(a.first/2, a.second + min(a.first - a.first/2 > test ? MAX : (a.first - a.first/2) * D, A + D)));  
          que.push(make_pair(a.first/2 + 1, a.second + min(a.first - a.first/2 > test ? MAX : (a.first - a.first/2 + 2) * D, A + D)));
        } else {
          que.push(make_pair(a.first/2, a.second + min(a.first - a.first/2 > test ? MAX : (a.first - a.first/2) * D, A)));
        }
      }
      
      if (a.first/3 >= 1) {
        if (a.first%3 != 0) {
          que.push(make_pair(a.first/3, a.second + min(a.first - a.first/3 > test ? MAX : (a.first - a.first/3) * D, B + a.first%3 * D)));  
          que.push(make_pair(a.first/3 + 1, a.second + min(a.first - a.first/3 > test ? MAX : (a.first - a.first/3 + 3) * D, B + (3-a.first%3) * D)));
        } else {
          que.push(make_pair(a.first/3, a.second + min(a.first - a.first/3 > test ? MAX : (a.first - a.first/3) * D, B)));
        }
      }

      if (a.first/5 >= 1) {
        if (a.first%5 != 0) {
          que.push(make_pair(a.first/5, a.second + min(a.first - a.first/5 > test ? MAX : (a.first - a.first/5) * D, C + a.first%5 * D)));  
          que.push(make_pair(a.first/5 + 1, a.second + min(a.first - a.first/5 > test ? MAX : (a.first - a.first/5 + 5) * D, C + (5-a.first%5) * D)));
        } else {
          que.push(make_pair(a.first/5, a.second + min(a.first - a.first/5 > test ? MAX : (a.first - a.first/5) * D, C)));
        }
      }

    }

    cout << que.top().second + D << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  int ans=0;
  bool flag=1;
  while(flag){
    flag=0;
    for(int j=n-1;j>0;j--){
      if(A[j]<A[j-1]){
	swap(A[j],A[j-1]);
	flag=1;
	ans++;
      }
    }
  }
  for(int i=0;i<n;i++) cout<<A[i]<<" \n"[i==n-1];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3092
#include <cstdio>

using namespace std;

int N;
#define N_MAX 200000
int A[N_MAX+1];
int num[N_MAX+1];

void solve() {
}

int main() {
  scanf("%d", &N);
  for (int i = 2; i <= N; i++) scanf("%d", &A[i]);

  for (int i = 2; i <= N; i++)
    num[A[i]]++;

  for (int i = 1; i <= N; i++)
    printf("%d\n", num[i]);

}



Measured memory_bytes: 3272
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int init_count=0;

//        int xy_list [][] = new int[n*(n-1)/2][2];
//        List<Integer> x_list = new ArrayList<>();
//        List<Integer> y_list = new ArrayList<>();


        int xy[][] = new int[n][2];
        for (int i=0; i<n; i++){
            xy[i][0] = sc.nextInt();
            xy[i][1] = sc.nextInt();
        }

        for (int j=0; j<n; j++){
            for (int k=j+1; k<n; k++ ){
                int p = xy[j][0]-xy[k][0];
                int q = xy[j][1]-xy[k][1];
                int count=0;
                for (int l=0; l<n; l++){
                    for (int m=0; m<n; m++){
                        if ((xy[l][0]-xy[m][0]==p)&(xy[l][1]-xy[m][1]==q)){
                            count++;
                        }
                    }
                }
                init_count = Math.max(init_count, count);
            }
        }
        System.out.println(n-init_count);


    }
}



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

bool sait(int a, int b) {
  return (a + 9) % 10 > (b + 9) % 10;
}

int main() {
  vector<int> a(5);
  REP(i, 5)
    cin >> a.at(i);
  sort(a.begin(), a.end(), sait);
  
  int time = 0;
  REP(i, 4)
    time += (a.at(i) + 9) / 10 * 10;
  time += a.at(4);
  
  cout << time << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

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

int main() {
	llint n;
	cin >> n;
	vllint a(n);
	llint mx = 0;
	rep(i, n) {
		cin >> a[i];
		a[i]--;
		mx = max(a[i], mx);
	}
	vllint table(n, 1);
	vllint now(mx + 1, 0);
	rep(i, n) {
		if (i == 0) {
			now[a[i]]++;
		}
		else {
			if (a[i] != a[i - 1]) {
				table[i] = table[i - 1] + now[a[i]];
				now[a[i]] += table[i - 1];
				table[i] %= 1000000007;
				now[a[i]] %= 1000000007;
			}
			else {
				table[i] = table[i - 1];
			}
		}
	}
	cout << table[n - 1] << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, x, y)   for (__typeof(x) i = x; i < y; i++)
#define repr(i, x, y)   for (__typeof(x) i = x; i > y; i --)
#define endl "\n"
#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define rSort(x)                     sort((x).rbegin(),(x).rend())
#define X                           first
#define Y                           second
#define sep                         ' '
#define SZ(x)                       ll(x.size())
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define pb                          push_back
#define mp                          make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define first X
#define second Y

const ll N = 1e6 + 7;
const ll M = 1e17 + 7;



int32_t main()
{
     IOS;
     ll n,m2;
     double m;
     cin >> n >> m;
     
     m*=100;
  	 m2=m;
  	 ll ans= n*m2;
     //cout << ans << sep;
     
     cout << ans/100<<endl;
     //cout << (9888666969998*96)/100+9888666969998;
     
}

    
     
     
    

Measured memory_bytes: 3736
#include <bits/stdc++.h>
//https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define debug(var)                  \
    do {                            \
        std::cout << #var << " : "; \
        view(var);                  \
    } while (0)
template <typename T>
void view(T e) { std::cout << e << std::endl; }

template <typename T>
void view(const std::vector<T>& v) {
    for (const auto& e : v) {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}

template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
    for (const auto& v : vv) {
        view(v);
    }
}

using namespace std;
//yosupo
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using tpl = tuple<T, T, T>;

// Binary Indexed Tree (BIT)
// https://www.slideshare.net/hcpc_hokudai/binary-indexed-tree
template <typename T>
struct BIT {
   private:
    vector<T> array;
    const int n;

   public:
    // 初期化
    BIT(int _n) : array(_n + 1, 0), n(_n) {}

    // 一番目からi番目までの累積和を求める
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += array[i];
            i -= i & -i;  // LSB減算
        }
        return s;
    }

    // [i, j]の要素の累積和
    T sum(int i, int j) {
        T ret_i = sum(i - 1);
        T ret_j = sum(j);
        return ret_j - ret_i;
    }

    // i番目に要素xを追加
    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;  // LSB加算
        }
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    V<int> C(N + 1);  // BITに合わせて1-indexed
    for (int i = 1; i <= N; ++i) {
        cin >> C[i];
    }
    V<tpl<int>> Query;
    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        Query.emplace_back(r, l, i);
    }
    sort(Query.begin(), Query.end());

    V<int> ans(Q);
    // 左からk番目までに、色iの玉が存在するか、
    // 存在するなら最も右にいる玉の場所を格納
    V<int> MRB(N + 1, -1);
    BIT<int> Fenwrick_Tree(N);
    int R = 1;

    for (auto q : Query) {
        int r = get<0>(q);
        int l = get<1>(q);
        int idx = get<2>(q);
        for (; R <= r; ++R) {
            int c = C[R];
            if (MRB[c] != -1) {
                assert(Fenwrick_Tree.sum(MRB[c], MRB[c]) == 1);
                assert(C[MRB[c]] == c);
                Fenwrick_Tree.add(MRB[c], -1);
            }
            Fenwrick_Tree.add(R, 1);
            MRB[c] = R;
        }
        ans[idx] = Fenwrick_Tree.sum(l, r);
    }

    for (int i = 0; i < Q; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 17356
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = []
for _ in range(d):
    t.append(int(input()))

cl = sum(c)
D = [0]*26
sas = 0

for i in range(d):
    for j in range(26):
      D[j] += 1
    T = t[i] 
    S = s[i][T-1]
    C = c[T-1]
    D[T-1] = 0
    dc = 0
    for j in range(26):
      dc += D[j]*c[j]
    sas += S - dc
    print(sas)

Measured memory_bytes: 9368
#include<cstdio>
#include<cmath>
#include<complex>
#include<string>
#include<map>
#include<iostream>
using namespace std;
typedef complex<double> xy_t;
const double eps=1e-11;
double x[4],y[4];
int N;

int main(){
  cin>>N;
  for(int t=0;t<N;t++){
    for(int i=0;i<4;i++)
      cin >> x[i] >> y[i];
    xy_t a[2]={
      xy_t(x[0],y[0])-xy_t(x[1],y[1]),
      xy_t(x[2],y[2])-xy_t(x[3],y[3])};
    bool p = abs((conj(a[0])*a[1]).imag()) < eps;
    cout << (p ? "YES" : "NO") <<endl;
  }
  return 0;

}

Measured memory_bytes: 1228
# Python 3 program to print the Kth 
# prime greater than N 

# set the MAX_SIZE of the array to 10^6 
MAX_SIZE = int(1e6) 

# initialize the prime array 
prime = [True] * (MAX_SIZE + 1) 

# Code for Sieve of Eratosthenes 
def seive(): 
	p = 2
	
	while (p * p <= MAX_SIZE): 
		
		# if prime[p] is not changed, 
		# then it is a prime 
		if (prime[p] == True): 
			
			# update all multiples of p 
			for i in range(p * p, MAX_SIZE, p): 
				prime[i] = False
		p += 1

# Function to find the kth prime 
# greater than n 
def kthPrimeGreaterThanN(n, k): 
	res = -1
	
	# looping through the numbers 
	# greater than n 
	for i in range(n, MAX_SIZE): 
		
		# decrement k if i is prime 
		if (prime[i] == True): 
			k -= 1
		
		# store the kth prime greater than n 
		if (k == 0): 
			res = i 
			break
	
	return res 

# Driver Code 
n = int(input())
k = 1
seive() 
print(kthPrimeGreaterThanN(n, k)) 	
# This code is contributed by Rupesh Rao

Measured memory_bytes: 10996
for i in range(3000):
    x = list(input().split(" "))
    idx = 0
    if x[0] == "0" and x[1] == "0":
        break
    for j in x:
        x[idx] = int(j)
        idx += 1
    x.sort()
    print(x[0], x[1])

Measured memory_bytes: 7708
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ret=0;
    while(n--)
    {
        int x;
        cin>>x;
        while(x%2==0)
            x/=2,ret++;
    }
    cout<<ret<<endl;
}


Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long N = 1e5+1;
 
typedef long long ll;
typedef long double ld;  

void test_case()
{
    ll n,i,j;
    ll a[5];
    f(i,0,5)
    {
        cin >> a[i];
    }
     f(i,0,5)
    {
        if(a[i] == 0)
        {
            cout << i+1 <<'\n';
        }
    }

}
 
int32_t main()
{
    IOS(); 
    
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

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

R,C,K = map(int,input().split())

dp = [[0]*4 for i in range(C+1)]
prev = [0]*(C+1)
tb = [[0]*(C+1) for i in range(R+1)]

for i in range(K):
    r,c,v = map(int,input().split())
    tb[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        pmx = 0
        for k in range(4):
            mx = dp[j-1][k]
            if k > 0:
                mx = max(mx,dp[j-1][k-1]+tb[i][j])
            if k == 0:
                mx = max(mx,prev[j])
            elif k == 1:
                mx = max(mx,prev[j]+tb[i][j])
            dp[j][k] = mx
            pmx = max(pmx,mx)
        prev[j] = pmx

print(prev[C])


Measured memory_bytes: 145628
using System;
public class Program
{
    public static void Main(string[] args)
    {
        // 整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int b = int.Parse(input[0]);
        int c = int.Parse(input[1]);
        int ans = 1;
        while (b >= c)
        {
            b = b / c;
            ans++;
        }
        //出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
int main(void){
    // Your code here!
    int n,c,p[100],s=0;
    scanf("%d%d",&n,&c);
    for(int i=0;i<c;i++){
        scanf("%d",&p[i]);
        s+=p[i];
    }
    n++;
    int d=0;
    d=s/n;
    if(s%n!=0)d++;
    printf("%d\n",d);
    return 0;
    
}



Measured memory_bytes: 2096
# 駅jjを出発する時刻は、
#S[j]+F[j]×kS[j]+F[j]×kとなる(kは車両数)。
#出発する時刻は現在時刻tt以上である必要があるので、
#S[j]+F[j]×k≥tS[j]+F[j]×k≥tとする。 式変形
import math
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N): # 駅iを始点とする
  t = 0 # 現在時刻
  for j in range(i, N-1):
    c, s, f = CSF[j]
    if t <= s: # 始発がまだ
      t = s+c
    else: # 始発以降      
      t = math.ceil(t / f) * f + c
  print(t)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1002;

ll n,m,ans=0;
vector<ll> x,y,z;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	x.resize(n);
	y.resize(n);
	z.resize(n);
	FOR(i,0,n){
		cin>>x[i]>>y[i]>>z[i];
	}
	
	FOR(i,0,2){//0sei 1hu
		FOR(j,0,2){
			FOR(k,0,2){
				ll xx=0,yy=0,zz=0;
				priority_queue<P> q;
				FOR(l,0,n){
					ll o=0;
					if(i==0)o+=x[l];
					else o-=x[l];
					if(j==0)o+=y[l];
					else o-=y[l];
					if(k==0)o+=z[l];
					else o-=z[l];
					q.push(mp(o,l));
				}
				FOR(i,0,m){
					xx+=x[q.top().se];
					yy+=y[q.top().se];
					zz+=z[q.top().se];
					q.pop();
				}
				if((i==0&&xx<0)||(i==1&&xx>0)){
					continue;
				}
				if((j==0&&yy<0)||(j==1&&yy>0)){
					continue;
				}
				if((k==0&&zz<0)||(k==1&&zz>0)){
					continue;
				}
				ans=max(ans,abs(xx)+abs(yy)+abs(zz));
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}


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

using namespace std;
 
int main()
{
  string N;
  cin >> N;
  
  int l= N.length();
  int sum=0;
  int Number=0;
  //cout << "l=" << l << endl;
  for(int i=0;i<l;i++)
  {
    //cout << N.at(i) << endl;
    //cout << ( (N.at(i)-'0')*10^(l-i-1)) << endl ;

    sum += (N.at(i)-'0');
    
  }
  //cout << "sum=" << sum << endl;
  //cout << stoi(N) << endl ;
  
  if(stoi(N)%sum == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }    
}


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

using namespace std;

int main(){
  int x,y;
  cin >> x >> y;
  if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)){
    cout<<"Yes"<<endl;
  }
  else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)){
    cout<<"Yes"<<endl;
  }
  else if(x==2&&y==2){
    cout << "Yes" << endl;
  }
  else cout << "No" <<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.LinkedList;

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<String> processes = new LinkedList<>();
		int numProcesses = scanner.nextInt();
		int quantum = scanner.nextInt();
		int timestamp = 0;
		String result = "";
		//get all processes from scanner
		scanner.nextLine();
		for (int i = 0; i < numProcesses; i++) {
			processes.add(scanner.nextLine());
		}
		scanner.close();
		
		while (!processes.isEmpty()) {
			//parse process
			String[] process = processes.remove().split(" ");
			String name = process[0];
			int timeLeft = Integer.parseInt(process[1]);
			
			//decrement time left and add back to queue if necessary
			if (timeLeft-quantum > 0) {
				processes.add(name + " " + (timeLeft-quantum));
				timestamp += quantum;
			}
			else {
				timestamp += timeLeft;
				System.out.println(name + " " + (timestamp));
			}
		}
	}
}


Measured memory_bytes: 105180
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define pi acos(-1.0)
#define ll long long
#define pb push_back
#define Mod 1000000007
#define limit 1000008
using namespace std;

void solve(int t)
{
    ll a,k,i,j,n,sum=1000,mx=0,ind,ct=1;
    cin >> n;
    ll D[n+5];
    for(i=0; i<n; i++)
        cin >> D[i];
    for(i=1 ; i<n; i++)
    {
        if(D[i]>D[i-1])
        {
            ct = sum/D[i-1];
            sum += ct*(D[i]-D[i-1]);
        }
    }
    cout <<sum <<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int t,tt=1;
 //   cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}





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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int p[200005];

int main(){
  int n, k;
  cin >> n >> k;
  REP(i, n) cin >> p[i];
  int res = 0;
  REP(i, k) res += p[i];
  int tmp = res;
  REP(i, n-k) {
    tmp += p[k+i];
    tmp -= p[i];
    chmax(res, tmp);
  }
  cout << fixed;
  cout << setprecision(10) << (res+k)/2.0 << endl;

  return 0;
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)

		int dp[1010][1010];
int main(){
	int n;
	cin>>n;
	lp(z,n){
		string s1,s2;
		cin>>s1>>s2;
		lp(i,s1.size()+1){
			lp(j,s2.size()+1){
				dp[i][j]=0;
			}
		}
		lp(i,s1.size()){
			lp(j,s2.size()){
				dp[i+1][j+1]=max(dp[i+1][j+1],max(dp[i+1][j],dp[i][j+1]));
				if(s1[i]==s2[j]){
					dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
				}
			}
		}
		cout<<dp[s1.size()][s2.size()]<<endl;
	}
	return 0;
}


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

int main()
{
  int N,K,x;
  cin >> N >> K;
  int ans = 0;
  rep(i, N) {
    cin >> x;
    ans += 2*min(abs(x), abs(K-x));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char s[10];
	scanf("%s", s);
	if (s[0] == 'S') {
		printf("Cloudy");
	}
	if (s[0] == 'R') {
		printf("Sunny");
	}
	if (s[0] == 'C') {
		printf("Rainy");
	}
	return 0;
}

Measured memory_bytes: 760
#!/usr/bin/python
from sys import stdin

def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    trees = [int(input()) for i in range(N)]
    trees.sort()

    s = []
    for i in range(N-K+1):
        s.append(trees[i+K-1] - trees[i])

    print(min(s))



if __name__ == '__main__':
    main()


Measured memory_bytes: 11288
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int N,Q; cin >> N >> Q;
    string S; cin >> S;
    vector <int> T(N+1,0);
    for (int i=1; i<N; i++){
        if (S[i-1]=='A' && S[i]=='C'){
            T[i]=T[i-1]+1;
        }else T[i]=T[i-1];
    }
    
    int L,R;
    rep(i,Q){
        cin >> L >> R;
        cout << T[R-1]-T[L-1] << endl;
    }
    return 0;
    
    
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;
int x[10];
int main(){
    int r, D, x2000;
    cin>>r>>D>>x2000;
    x[0]=x2000;
    for(int i=1; i<=10; ++i){
        x[i] = (r*x[i-1])-D;
    }
    for(int j=1; j<=10; ++j){
        cout<<x[j]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1016
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

h,w = map(int,input().split())
ans = ["#"*(w+2)]
for i in range(h):
    s = input()
    s = "#"+s+"#"
    ans.append(s)
ans.append("#"*(w+2))
for i in range(len(ans)):
    print(ans[i])


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

namespace Main
{
    public static class Program
    {

        static void Main(string[] arg)
        {
            var answer = 0;
            var line = GetIntList(Console.ReadLine());
            var lineB = GetIntList(Console.ReadLine());

            for(int i = 0; i < line[0]; i++)
            {
                int sum = 0;
                var lineA = GetIntList(Console.ReadLine());
                for (int j = 0; j < line[1]; j++)
                {
                    sum += lineA[j] * lineB[j];
                    
                }
                sum += line[2];
                answer += sum > 0 ? 1 : 0;
            }



            Console.WriteLine(answer);
            Console.ReadLine();

        
        }
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();

        }
        private static double[] GetDoubleList(string line)
        {
            return line.Split(' ').Select(x => double.Parse(x)).ToArray();

        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}


Measured memory_bytes: 13268
import numpy as np

def main():
    n,x,y=map(int,input().split())
    Dist=[]
    for i in range(1,n+1):
        A=np.arange(1,n+1)
        D1=np.abs(A-i)
        D2=np.abs(i-x)+np.abs(y-A)+1
        D3=np.abs(i-y)+np.abs(x-A)+1
        D=np.minimum(np.minimum(D1,D2),D3)
        Dist.append(D)
    Dist=np.concatenate(Dist)
    Cnt=np.bincount(Dist,minlength=n)
    print('\n'.join((Cnt[1:]//2).astype(str)))

if __name__=='__main__':
    main()

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

int main(){
    int N,M,ans;
    long long MIN,dist;
    cin>>N>>M;
    vector<int> A(N),B(N),C(M),D(M);
    for(int i=0;i<N;++i) cin>>A[i]>>B[i];
    for(int i=0;i<M;++i) cin>>C[i]>>D[i];

    for(int i=0;i<N;++i){
        MIN = 1e18;
        for(int j=M-1;j>=0;--j){
            dist = abs(A[i]-C[j]) + abs(B[i]-D[j]);
            if(MIN >= dist){
                MIN = dist;
                ans = j+1;
            }
        }
        cout<<ans<<endl;
    }
    
}

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

//------------------------------------------------------------
using ll = long long;
#define int ll

#define FOR(i, s, e) for (ll i = ll(s); i < (ll)e; ++i)
#define RFOR(i, s, e) for (ll i = ll(e) - 1; i >= ll(s); --i)
#define REP(i, n) for (ll i = 0, i##_size = n; i < i##_size; ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)

//------------------------------------------------------------
template <class T>
struct arr : public vector<T> {
	arr() {}
	arr(ll n, T v = T()) : vector<T>(n, v) {}

	void init(ll n, T v = T()) {
		this->clear();
		this->resize(n, v);
	}
	ll sz() const {
		return (ll)this->size();
	}
	void pb(T v) {
		this->push_back(v);
	}
	void sort() {
		std::sort(this->begin(), this->end());
	}
	void rsort() {
		std::sort(this->begin(), this->end(), greater<T>());
	}
};
using aint = arr<ll>;
using aaint = arr<arr<ll>>;

template <class T>
struct que : public queue<T> {
	ll sz() const {
		return (ll)this->size();
	}
	T popfront() {
		T v = this->front();
		this->pop();
		return v;
	}
};

//------------------------------------------------------------
struct input_ar {
	ll n;
	input_ar(ll n_) : n(n_) {}

	template <class T>
	operator arr<T>() {
		arr<T> var(n);
		REP(i, n) {
			cin >> var[i];
		};
		return var;
	}
};

struct input {
	template <class T>
	operator T() {
		T var;
		cin >> var;
		return var;
	}

	input_ar operator()(ll N){
		return input_ar(N);
	}
} input;

template <class T>
void output(T var) {
	cout << (var) << '\n';
}

//------------------------------------------------------------
template <class T> void chmin(T& a, T b) { if (b < a) { a = b; } }
template <class T> void chmax(T& a, T b) { if (b > a) { a = b; } }

struct bfs {
	aint froms;
	aint steps;

	bfs(int N, aaint const& adjacency) {
		froms.init(N, -1);
		steps.init(N, -1);

		que<ll> queue;
		queue.push(0);
		froms[0] = 0;
		steps[0] = 0;

		while (queue.empty() == false) {
			ll p = queue.popfront();

			for (ll n : adjacency[p]) {
				if (froms[n] != -1) {
					continue;
				}

				froms[n] = p;
				steps[n] = steps[p] + 1;
				queue.push(n);
			}
		}
	}
};

//------------------------------------------------------------
void myMain();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(16);
	myMain();
	return 0;
}

//------------------------------------------------------------
void myMain() {
	int N = input;
	aint mins;
	aint maxs;
	REP(i, N) {
		int a = input;
		int b = input;
		mins.pb(a);
		maxs.pb(b);
	}
	mins.sort();
	maxs.rsort();

	if (N % 2 == 0) {
		int l = mins[N / 2 - 1] + mins[N / 2];
		int r = maxs[N / 2 - 1] + maxs[N / 2];
		int c = r - l + 1;
		output(c);
	}
	else {
		int l = mins[N / 2];
		int r = maxs[N / 2];
		int c = r - l + 1;
		output(c);
	}
}


Measured memory_bytes: 6664
#include <iostream>
using namespace std;
int main(){
  int sum=0,num,num1;
  cin >>　num;
  num1=num;
  if(num<10){
  }
  else{
 	num=num%10;
  }
  switch (num) {
		case 3:
			std ::  cout << "bon"<< endl;
			break;
    case 0:
    case 1:
    case 6:
    case 8:
			std ::  cout << "pon"<< endl; 
			break;
		default:
			std ::  cout << "hon"<< endl;
			break;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>

int main(){
	int H, W, i, j;
	scanf("%d %d", &H, &W);
	while( H != 0 && W != 0){
		for( i = 0; i < H; i++){
			for( j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &H, &W);
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
 
using namespace std;
#define lli long long int 
#define pb push_back
#define fi(i,a,p) for(int i = a; i < p; i++)
#define pp pair<ll , ll>
#define mp make_pair
#define setzero(a) memset(a,0,sizeof(a))
#define setdp(a) memset(a,-1,sizeof(a))

const int N = 51;
int main(){
	int a[5];
	fi(i,0,5){
		cin>>a[i];
	}
	fi(i,0,5){
		if(a[i]==0){
			cout<<i+1;
			break;
		}
	}

 return 0;
}

Measured memory_bytes: 3644
N, K = map(int, input().split())


input_dict = {}

for _ in range(N):
    a, b = map(int, input().split())
    if a in input_dict:
        input_dict[a] += b
    else:
        input_dict[a] = b

input_dict = sorted(input_dict.items(), key=lambda x:x[0])

for i in range(len(input_dict)):
    K -= input_dict[i][1]
    if K <= 0:
        print(input_dict[i][0])
        break

Measured memory_bytes: 15068
#include <stdio.h>
#include <string.h>

int n, m, h1[101], w1[101], h2[101], w2[101], dp[101][101];

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

int main(void){
    int x, y;
    while(scanf("%d", &n) != EOF && n){
        h1[0] = w1[0] = h2[0] = w2[0] = 0;
        for(x = 1; x <= n; x++){
            scanf("%d%d", h1+x, w1+x);
        }
        scanf("%d", &m);
        for(x = 1; x <= m; x++){
            scanf("%d%d", h2+x, w2+x);
        }
        for(x = 0; x <= n; x++){
            for(y = 0; y <= m; y++){
            }
        }
        dp[0][0] = 0;
        for(x = 0; x <= n; x++){
            memset(dp[x], 0, sizeof(dp[x]));
        }
        for(x = 0; x <= n; x++){
            for(y = 0; y <= m; y++){
                if(x){
                    dp[x][y] = max(dp[x][y], dp[x-1][y]);
                    if(h1[x] > h2[y] && w1[x] > w2[y]){
                        dp[x][y] = max(dp[x][y], dp[x-1][y] + 1);
                    }
                }
                if(y){
                    dp[x][y] = max(dp[x][y], dp[x][y-1]);
                    if(h1[x] < h2[y] && w1[x] < w2[y]){
                        dp[x][y] = max(dp[x][y], dp[x][y-1] + 1);
                    }
                }
            }
        }
        printf("%d\n", dp[n][m]);
    }
    return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long ,long long > pll;
typedef unsigned long long ull;
typedef long double ld;
 
const int mn=1e6+69;
vector<set<int> > kg(mn);
vector<int> inf(mn);
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	map<string,int> m;
	m["AC"]=0; m["TLE"]=0; m["RE"]; m["WA"]=0;
	int n;
	string verd;
	cin>>n;
	while(n--)
	{
		cin>>verd;
		m[verd]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
}

Measured memory_bytes: 54072
from math import factorial

N,M = map(int,input().split())

def foo(N,M):
	if N == M+1 or N+1 == M:
		tm = factorial(min(N,M))
		return(tm*max(N,M)*tm)

	elif N==M:
		return((factorial(N)**2)*2)

	else:
		return(0)

print(foo(N,M)%(10**9+7))

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

using namespace std;
using ll = int64_t;
using P = std::pair<int, int>;

const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for(int i = 0; i < T; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<int>());
    int sum = 0;
    for(int i = 1; i < T; i++) {
        sum += a[i];
    }

    int d = a[0] - sum - 1;

    if(d >= 0) {
        cout << d << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,ans = 0;scanf("%lld",&n);
  ll a[n*3];
  for(i=0;i<n*3;i++) scanf("%lld\n",&a[i]);
  sort(a,a+n*3,greater<ll>());
  for(i=1;i<n*2;i+=2) ans += a[i];
  printf("%lld\n",ans);
}

Measured memory_bytes: 6120
#include<bits/stdc++.h>
using namespace std;
int max1=0;
int main()
{
	int h,t;
	scanf("%d%d",&h,&t);
	int x;
	for (int i=1;i<=t;i++)
	{
		scanf("%d",&x);
		max1=max(max1,x);
	}
	printf("%d\n",max(max1*2-1-h,0));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{ 
    string S;
    cin>>S;
    if(S=="AAA")
    {
    cout<<"No";
    }
    else if(S=="BBB")
    {
    cout<<"No";
    }
    else
    {
    cout<<"Yes";
    }
    return 0; 
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10**9+7

def cmb(n, r):
    x, y = 1, 1
    for i in range(r):
        x = x*(n-i)%mod
        y = y*(i+1)%mod
    #フェルマーの小定理
    return x*pow(y, mod-2, mod)%mod

print((pow(2, n, mod)-cmb(n, a)-cmb(n, b)-1)%mod)

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	for (char & ch : s) if (ch == '?') ch = 'D';
	cout << s << '\n';
	return 0;
}

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

int main () {
  char c;
  cin >> c;
  if (c == 'a'){
    cout << "vowel" << endl;
  }
  else if (c == 'i'){
    cout << "vowel" << endl;
  }
  else if (c == 'u'){
    cout << "vowel" << endl;
  }
  else if (c == 'e'){
    cout << "vowel" << endl;
  }
  else if (c == 'o'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 384