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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}


template<typename T>
class FenwickTree {
    const int n;
    std::vector<T> data;

public:
    FenwickTree(int count) : n(count), data(count, 0) { ; }

    void add(int pos, const T &value) {
        assert(0 <= pos && pos < n);
        for (int i = pos; i < n; i |= i + 1) data[i] += value;
    }

    // 区間 [0, pos) 番目の範囲の和を求める．(pos = 0 のときは 0 を返す．)
    T sum(int pos) const {
        assert(0 <= pos && pos <= n);
        T res = 0;
        for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1) {
            res += data[i];
        }
        return res;
    }

    // 区間 [l, r) 番目の範囲の和を求める．(l = r のときは 0 を返す．)
    T sum(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        return sum(r) + (-sum(l));
    }

    using value_type = T;
    using update_type = T;
};

int lastPos[500005];

void solve(long long N, long long Q, std::vector<long long> c,
           std::vector<long long> l, std::vector<long long> r) {
    FenwickTree<int> count(500005);
    memset(lastPos, -1, sizeof(lastPos));

    struct Query {
        int t;
        long long p;
        long long v;
        long long l;
        long long r;
        int idx;
    };
    vector<Query> qs;
    for (int i = 0; i < N; i++) {
        qs.push_back({0, i, c[i]});
    }
    vector<int> res(Q);
    for (int i = 0; i < Q; i++) {
        l[i]--;
        qs.push_back({1, r[i], -1, l[i], r[i], i});
    }
    sort(qs.begin(), qs.end(), [&](Query &a, Query &b) {
        if (a.p != b.p) return a.p < b.p;
        return a.t > b.t;
    });

    for (auto i : qs) {
        if (i.t == 1) {
            int sub = count.sum(i.l, i.r);
            res[i.idx] = sub;
        } else {
            if (lastPos[i.v] != -1) {
                count.add(lastPos[i.v], -1);
            }
            count.add(i.p, +1);
            lastPos[i.v] = i.p;
        }
    }

    for (auto i : res) {
        cout << i << endl;
    }


}

int main() {
    long long N;
    scanf("%lld", &N);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> c(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &c[i]);
    }
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &l[i]);
        scanf("%lld", &r[i]);
    }
    solve(N, Q, std::move(c), std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 69904
def main():
    n, k = [int(x) for x in input().split()]
    hps = [int(x) for x in input().split()]

    ct = 0

    hps = sorted(hps)
    hps.reverse()

    if len(hps) <= k:
        print(0)
        return

    hps = hps[k:]

    remain = sum(hps)

    print(remain)




if __name__ == "__main__":
    main()

Measured memory_bytes: 26356
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m,k;
  cin >> n >> m >> k;
  ll a[n];
  rep(i,n) R a[i];
  ll dp[n+1];
  fill(dp,dp+n+1,MAXL);
  dp[0]=0;
  rep(i,n) {
    ll mx=0,mi=MAXL;
    rep(j,m) {
      if(i+j>=n) break;
      mx=max(mx,a[i+j]);
      mi=min(mi,a[i+j]);
      dp[i+j+1]=min(dp[i+j+1],dp[i]+k+(mx-mi)*(j+1));
    }
  }
  pr(dp[n]);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


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

int main(){
	int t,c;
	while(1){
		cin>>t;
		if(t==0) break;
		for(int i=0;i<9;i++){
			cin>>c;
			t-=c;
		}
		cout<<t<<endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#!/usr/bin/env python3
#AGC33 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w,n = LI()
sr,sc = LI()
sr -= 1
sc -= 1
h -= 1
w -= 1
s = input()
t = input()
l,r,d,u = 0,w,0,h
for i in range(n)[::-1]:
    if t[i] == 'R':
        if l > 0:
            l -= 1
    elif t[i] == 'L':
        if r < w:
            r += 1
    elif t[i] == 'D':
        if d > 0:
            d -= 1
    elif t[i] == 'U':
        if u < h:
            u += 1
    
    if s[i] == 'R':
        r -= 1
        if r < 0:
            print('NO')
            quit()
    elif s[i] == 'L':
        l += 1
        if l > w:
            print('NO')
            quit()
    elif s[i] == 'D':
        u -= 1
        if u < 0:
            print('NO')
            quit()
    elif s[i] == 'U':
        d += 1
        if d > h:
            print('NO')
            quit()
    
if l <= sc <= r and d <= sr <= u:
    print('YES')
else:
    print('NO')
            


Measured memory_bytes: 45360
#include<bits/stdc++.h>
using namespace std;
#define Fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
const int sz=1e5+10;
int ara[sz];
int dp[sz];
int n;
int inf=1e9;
int fun(int i)
{
    if(i==n-1)  return 0;
    else if(dp[i] != -1)  return dp[i];
    int a=inf,b=inf,x;
    if(i+1<n){
            x=abs(ara[i]-ara[i+1]);
        if(dp[i+1]==-1){
            dp[i+1]=fun(i+1);
        }
       a=x+dp[i+1];
    }
    if(i+2<n){
        x=abs(ara[i]-ara[i+2]);
        if(dp[i+2]==-1) dp[i+2]=fun(i+2);
    b=x+dp[i+2];
    }
    return dp[i]=min(a,b);

}
int main()
{
    Fast;
    int a,b,i,j,k,m,p,q,x,y,ct,t,w,sum,mx,clr,ans;
    string str;
    cin>>n;
    for(i=0;i<n;i++)  cin>>ara[i];
    memset(dp,-1,sizeof dp);
    ans=fun(0);
    cout<<ans<<endl;
}


Measured memory_bytes: 5760
N = int(input())
S = [input() for _ in range(N)]
seen = {}
cnt = 0
for ind,s in enumerate(S):
    x = list(s)
    x.sort()
    y = ''.join(x)
    if(y in seen):
        seen[y] += 1
    else:
        seen[y] = 1

for i in seen:
    if(seen[i]==1):continue
    x = seen[i]
    cnt += x*(x-1)//2
print(cnt)

Measured memory_bytes: 24976
// ??????????????????????????????
// ????????°?????????????????????????????´????????????L,R????????????????????????????????????
// R[0]??????????????\??????????????????L?????¨????´????R[0]???????????§???????????????????????§???
// ????????´?????????L???????´???°??????????????°??¨???????????¢????????????????????????
// ??????????????¬???????????¨?????????????????????????????????R[i]?????????????????????
// ?????????????????????????????§L????????£?????????????´???°???????¨???????????????°???
// ???????????????????????????????????°?????°???????????????
//  L[j], R[i]
//  L[j + 1], R[i]
//  ..

/* ALDS1_5_D: The number of inversions */

#include <iostream>
#include <cmath>

const int MAX_VALUE = pow(10, 9);

long long count_and_merge(int A[], int left, int mid, int right) {
    int n_left  = mid - left;
    int n_right = right - mid;
    int *L = new int[n_left + 1];
    int *R = new int[n_right + 1];

    for (int i = 0; i < n_left; i++)
        L[i] = A[left + i];
    for (int i = 0; i < n_right; i++)
        R[i] = A[mid + i];
    L[n_left] = R[n_right] = MAX_VALUE + 1;

    int i_l = 0, i_r = 0;
    long long n_invs = 0;
    int n_left_remains = n_left;
    for (int i_a = left; i_a < right; i_a++) {
        if (L[i_l] <= R[i_r]) {
            A[i_a] = L[ i_l++ ];
            n_left_remains--;
        } else {
            A[i_a] = R[ i_r++ ];
            n_invs += n_left_remains;
        }
    }
    return n_invs;
}

long long merge_sort(int A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        long long n_invs = 0;
        n_invs += merge_sort(A, left, mid);
        n_invs += merge_sort(A, mid, right);
        n_invs += count_and_merge(A, left, mid, right);
        return n_invs;
    }
    return 0;
}

long long count_inversions(int n, int A[]) {
    return merge_sort(A, 0, n);
}

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;
    int *A = new int[n];
    for (int i = 0; i < n; i++)
        std::cin >> A[i];

    long long n_invs = count_inversions(n, A);
    std::cout << n_invs << std::endl;
    return 0;
}

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

int main() {
  ll N;
  cin >> N;
  const int limit = 3501;

  for (ll h = 1; h <= limit; h++) {
    for (ll n = 1; n <= limit; n++) {
      if (4 * h * n - N * n - N * h == 0) continue;
      if ((N * h * n) % (4 * h * n - N * n - N * h) != 0) continue;
      ll w = (N * h * n) / (4 * h * n - N * n - N * h);
      if (w <= 0) continue;
      cout << h << " " << n << " " << w << endl;
      return 0;
    }
  }
  return 0;
}


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

int main() {
    bool flag = true;
    vector<vector<int>> field(3, vector<int>(3)), temp(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> field.at(i).at(j);
    vector<int> a(3), b(3);
    a.at(0) = 0;
    rep(i, 3) b.at(i) = field.at(0).at(i);
    rep(i, 2) a.at(i + 1) = field.at(i + 1).at(0) - b.at(0);
    rep(i, 3) rep(j, 3) {
        temp.at(i).at(j) = a.at(i) + b.at(j);
        if(temp.at(i).at(j) != field.at(i).at(j)) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <queue>
#include <ctime>
#include <iomanip>
#include <tuple>
#include <functional>
#include <map> 
#include <numeric> 

using namespace std;


#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define vp vector<pi>
#define msa(A, a, n) memset(A, a, n*sizeof(A))
#define msv(A, a) fill(A.begin(), A.end(), a);
#define msc(A, n) memset(A, '\0', n)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
#define pern(i, b) per(i, b - 1, 0)
#define repn(i, b) rep(i, 0, b)
#define repe(i, a, b) for(int i = a; i <= b; i++)
#define repen(i, b) repe(i, 1, b)
#define fast ios_base::sync_with_stdio();cin.tie(0);
#define endl "\n"
//#define MYDEBUG

void my_return(int code)
{
#ifdef MYDEBUG
	std::cout << "\n\nTime = " << fixed << std::setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
	exit(code);
}

int main()
{
	fast
#ifdef MYDEBUG
		freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int x;
	cin >> x;
	cout << ((x == 0) ? 1 : 0) << endl;


	my_return(0);
}


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

int main() {
  
  string s;
  
  int k = 0;
  int l = 0;
  int m = 0;
  
  cin >> s;
  
  for (int i = 0; i < 4; i++){
    
    if (s.at(0) == s.at(i)){
      k++;
    }
  }
  
  for (int i = 0; i < 4; i++){
    
    if (s.at(1) == s.at(i)){
      l++;
    }
  }
  
  for (int i = 0; i < 4; i++){
    
    if (s.at(2) == s.at(i)){
      m++;
    }
  }
  
  if(k == 2 && l == 2 && m == 2){
    
    cout << "Yes" << endl;
  }
  
  else{
    
    cout << "No" << endl;
  }
  
  
  
 
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
#ARC081C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()

count=0
h=0
w=0
i=0
while(1):
#for i in range(0,n-1):
	if(i<n-1):
		if(hoge[n-1-i]==hoge[n-2-i]):
			if(count==0):
				h=hoge[n-1-i]
				count+=1
				i+=1
			else:
				w=hoge[n-1-i]
				break
		i+=1
	else:
		break
print(w*h)

#print(hoge)


Measured memory_bytes: 63340
#include <bits/stdc++.h>
typedef long long  ll;
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fora(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<endl; 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<"No"; return 0;}
const ll MOD = 1e9 + 7;
const int N = 200005;
const int INF = 1e8;
const ll MOD1=998244353;
using namespace std;

int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 vector<int> powd(7);
 powd[0]=1;
 for(int i=1;i<=5;i++) powd[i]=powd[i-1]*10;
 
 int n;
 cin>>n;
 ll ans=0;
 for(int i=n;i>=10;i--)
 {
           string s=to_string(i);
           ll cnt=0;
           int k=s.size();
           int b=s[0]-'0';
           int e=s[k-1]-'0';
           if(e==0) continue;
          int cur=1;
          int t=k-3;
          for(int j=1;j<k-1;j++) 
          {
                    cur+=(s[j]-'0')*powd[t];
                    t--;
          }
          // cout<<cur<<" ";
           if(e<b)
           {
                     cnt+=2*powd[k-2];
           }
           if(e==b)
           {
                     cnt+=2*cur+1;
           }
           ll d=0;
           for(int j=k-3;j>=0;j--) d+=powd[j];
           cnt+=2*d;
           ans+=cnt;
           
         // cout<<cnt<<" ";
 }
 if(n<10) 
 {
           cout<<n;
           return 0;
 }
 cout<<ans+9;
 return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, m;
    cin >> n >> m;
    multiset<ll> a;
    int i;
    rep(i, n) {
        ll v;
        cin >> v;
        a.insert(v);
    }
    rep(i, m) {
        auto it = a.rbegin();
        a.insert(*it / 2);
        a.erase(a.find(*it));

    }
    ll ans(0);
    for (auto v: a) {
        ans += v;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8364
def main():
  n, a, b, c = map(int, input().split())

  l = [int(input()) for i in range(n)]

  def test(i, x, y, z):
    if(i == n):
      if(x == 0 or y == 0 or z == 0):
        return float('inf')
      return abs(a - x) + abs(b - y) + abs(c - z)

    res = test(i + 1, x, y, z)

    res = min(res, (test(i + 1, x + l[i], y, z) + (0 if x == 0 else 10))) 
    res = min(res, (test(i + 1, x, y + l[i], z) + (0 if y == 0 else 10))) 
    res = min(res, (test(i + 1, x, y, z + l[i]) + (0 if z == 0 else 10))) 

    return res

  print(test(0, 0, 0, 0))

if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N, A, B; cin >> N >> A >> B;
    cout << min(N*A, B) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	string s;
	cin>>s;
	int p=0;
	rep(i,s.size()){
		if(s[i]=='p')++p;
	}
	int n=s.size();
	cout<<n/2-p<<endl;
}


Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class DColoringEdgesOnTree {
public:
    vector<int> g[200010];
    int k = 0;
    int n;
    map<pair<int, int>, int> visit;
    map<pair<int, int>, int> res;

    void dfs(int u, int pu){
        int color = 1;
        for(auto e : g[u]){
            if(visit[make_pair(e, u)]) continue;
            visit[make_pair(e, u)] = 1;
            visit[make_pair(u, e)] = 1;

            if(color == res[make_pair(u, pu)]) color++;
            res[make_pair(e, u)] = color;
            res[make_pair(u, e)] = color;
            color++;
            dfs(e, u);
        }
    }

	void solve(std::istream& in, std::ostream& out)
	{
	    in >> n;
        vector<int> a(n), b(n);
        for(int i=0; i<n-1; i++){
            in >> a[i] >> b[i];
            a[i]--; b[i]--;
            g[a[i]].push_back(b[i]);
            g[b[i]].push_back(a[i]);
        }

        for(int i=0; i<n; i++){
            if(k < g[i].size()){
                k = g[i].size();
            }
        }

        out << k << endl;
        dfs(0, 0);
        for(int i=0; i<n-1; i++){
            out << res[make_pair(a[i], b[i])] << endl;
        }
	}
};


int main() {
	DColoringEdgesOnTree solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 34176
#include <stdio.h>
int main(void){
int x,a,b,count;
  scanf("%d %d %d",&x,&a,&b);
  x=x-a;
  for(;;){
    x=x-b;
  if(x<0){break;}
  count++;
}
printf("%d",x+b);
return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = Integer.parseInt(sc.next());
    	int B = Integer.parseInt(sc.next());
    	int C = Integer.parseInt(sc.next());
    	int X = Integer.parseInt(sc.next());

    	int ans = 0;
    	for (int a=0; a<=A; a++){
    		for (int b=0; b<=B; b++){
        		int c_estimated = (X - a * 500 - b * 100)/50;
        		if (c_estimated>=0 && c_estimated <= C){
        			ans++;
        		}
        	}
    	}
    	System.out.println(ans);
    }
}


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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		string s;
		cin>>s;
		int sum = 0;
		for(auto it:s)
		{
			sum+= (it-'0');
		}		
		if(sum%9)
		cout<<"No";
		else
		cout<<"Yes";
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int minimum = 200;

  for (int i=0; i<=N; i++) {
    int A;
    cin >> A;

    int j = 0;
    while (A%2==0) {
      A /= 2;
      j++;
    }

    minimum = min(minimum,j);
  }

  cout << minimum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
 
#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
 
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b) {
        cout << "No" << endl;
        return 0;
    }

    if (a<b){
        if (a<c and c<b) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (b<c and c<a){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
 
 
    return 0;
}

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

int main() {
  int h[10];
  int a, b, c;
  for(int i=0; i<10; i++) {
    cin >> h[i];
  }
  a = b = c = -1;
  for(int i=0; i<10; i++) {
    if (h[i] > c) {
      if (h[i] > b) {
        if (h[i] > a) {
          c = b;
          b = a;
          a = h[i];
        }
        else {
          c = b;
          b = h[i];
        }
      } else {
        c = h[i];
      }
    }
  }
  cout << a << endl;
  cout << b << endl;
  cout << c << endl;
}

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

int main() {
	
	string s;
	cin>>s;
	int l=s.length(),ch=1;
	for(int i=0;i<l;i++)
		if((s[i]=='R' && (i+1)%2==0) || (s[i]=='L' && (i+1)%2 !=0) )
			ch=0;
	if(ch) cout<<"Yes\n";
	else cout<<"No\n";
	
	
	return 0;
}

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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n)
    {
        cin >> l.at(i);
    }

    int d = 0;
    int cnt = 0;
    rep(i, n)
    {
        d += l.at(i);
        if (d <= x) {
            cnt++;
        }
    }

    cout << cnt + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	for(int i = 0; i < n-1; i++)
		cin >> c[i];
	int ans = 0;
	int prev = 1e9 + 10;
	for(int i = 0; i < n; i++){
		ans += b[a[i]-1];
		if(prev == a[i]-2){
			ans += c[a[i]-2];
		}
		prev = a[i]-1;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> vec(2*N,0); //左側が0、右側が1
  for(int i=1; i<2*N; i++){
    if(S[i] == S[i-1]){
      vec[i] = 1 - vec[i-1];
    }
    else{
      vec[i] = vec[i-1];
    }
  }
  
  bool flag = true;
  int64_t ans = 1;
  int64_t MOD = 1e9+7;
  int L = 0;
  for(int i=0; i<2*N; i++){
    if(vec[i] == 0){
      L++;
    }
    else{
      ans *= L;
      L--;
      ans %= MOD;
    }
  }
  if(L != 0 || S[0] == 'W'){
    flag = false;
  }
  
  for(int i=0; i<N; i++){
    ans *= i+1;
    ans %= MOD;
  }
  
  if(flag){
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 1412
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>

using namespace std;

	long long dp[3001][3001];
	string s; int n; 
	#define MOD 1000000007


int main(){

	for(int i = 1; i < 3001; i++) dp[1][i] = 1;

	// relativan poredak nam u isto vrijeme govori koje
	// smo rjesili i koje nismo , ako nam je bitno da je svaki od brojeva koristen 1put ! 
	
	cin >> n;
	cin >> s;
	
	
	for(int i = 2; i <= n; i++){
		for(int j = 1; j <= i; j++){
			
			if(s[s.size() - i + 1] == '>'){
				dp[i][j] += ((dp[i-1][j-1] - dp[i-1][0])%MOD + MOD)%MOD;
			}
			else{
				dp[i][j] += ((dp[i-1][i] - dp[i-1][j-1])%MOD + MOD)%MOD;
			} 
			
		}
		
		for(int j = 1; j <= n; j++){
			dp[i][j] += dp[i][j-1];
			dp[i][j]%=MOD;
		}
	}
	
	cout << dp[n][n];
	
	// REZIME ! 
	
	





	return 0;
}

Measured memory_bytes: 70656
# -*- coding: utf-8 -*-

# N: 正の整数
N = int(input())
# S: 長さNの英小文字からなる文字列S
S = input()

if(N % 2 != 0):
    print("No")
else:
    t1 = S[0: N//2]
    t2 = S[N//2:  ]
    if t1 == t2:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x % 2 == 0 && (x % 3 != 0 && x % 5 != 0)) {
			cout << "DENIED";
			return 0;
		}
	}
	cout << "APPROVED";
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    
    cin >> n;
    
    int dim1[n];
    
    for(int i = 0; i < n ; i++){
        cin >> dim1[i];
    }
    
    for(int i = n - 1; i > 0 ; i--){
        cout << dim1[i] << " " ;
    }
    
    cout << dim1[0] << endl;
}


Measured memory_bytes: 3084
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}


fn main() {
    input!{
        adash: i32,
        b: i32,
        cdash: i32,
        d: i32,
    }
    let mut turn = 0;
    let mut a = adash;
    let mut c = cdash;
    while a > 0 && c > 0 {
        if turn == 0 {
            c = c - b;
            turn = 1;
        }
        else {
            a = a - d;
            turn = 0;
        }
    }
    if a <= 0 {
        println!("No");
    }
    else {
        println!("Yes");
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());

  cout << a[n-1] - a[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    int n, r;
    cin >> n >> r;
    if(n<=10) cout << r + 100 * (10-n) << endl;
    else cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF+7;
const LL LLINF = 1e18;
#define int LL
VI A, T;
VI M;

signed main(void) {
    int N;
    cin >> N;
    A.resize(N);
    T.resize(N);
    M.resize(N);
    REP(i, N) scanf("%d", &T[i]);
    REP(i, N) scanf("%d", &A[i]);
    int aa = LLINF,tt = 0;
    REP(i, N) {
        if (aa < A[i] || tt > T[i]) {
            cout << 0 << endl;
            return 0;
        } else {
            aa = A[i]; tt = T[i];
        }
    }
    int ans = 1;
    REP(i, N) {
        if (i == 0) {
            if (T[0] > A[0]) {
                cout << 0 << endl;
                return 0;
            }
            M[i] = 1;
        } else if (i == N - 1) {
            if (A.back() > T.back()) {
                cout << 0 << endl;
                return 0;
            }
            M[i] = 1;
        } else {
            if (T[i] == T[i-1]&&A[i] == A[i+1]) {
                M[i] = min(T[i], A[i]);
            } else if (T[i] == T[i-1]) {
                if (A[i] > T[i]) {
                    cout << 0 << endl;
                    return 0;
                }
                M[i] = 1;
            } else if (A[i] == A[i+1]) {
                if (T[i] > A[i]) {
                    cout << 0 << endl;
                }
                M[i] = 1;
            } else {
                if (T[i] != A[i]) {
                    cout << 0 << endl;
                    return 0;
                } else {
                    M[i] = 1;
                }
            }
        }
    }
    if (T.back() != A[0]) {
        cout << 0 << endl;
        return 0;
    }
    REP(i, N) {
        ans = (ans * M[i]) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <tuple>

#include <algorithm>

using namespace std;

using Restrun = tuple<string, int, int>;
int main() {
	int n;

	cin >> n;
	
	vector < Restrun > rs;


	for (int i = 0; i < n; i++) {

		string s;
		int p;

		cin >> s >> p; 

		Restrun r = Restrun(s, 100 - p, i + 1);
		rs.push_back(r);
	}

	sort(rs.begin(), rs.end());

	for (auto&& r : rs) {
		cout << get<2>(r) << endl;
	}

	return 0;
}

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

#define rep(i, n)  for (int i = 0; i < (n) ; ++i)
#define mod 1000000007

using namespace std;
using ll=long long;
const ll INF = 100000000;

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

    if (s.length() > k) {
        for (int i = 0; i < k; ++i) {
            cout << s[i];
        }
        cout << "...";
    } else {
        cout << s;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int main() {
    int l = read(), r = read();
    if (r - l >= 2019 * 3) { cout << 0 << endl; return 0; }
    else {
        reg int ans = 0x7f7f7f7f;
        for (int i = l; i <= r; i++)
            for (int j = l; j <= r; j++)
                if (i != j)
                    ans = min(ans, ((i % 2019) * (j % 2019) % 2019));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long int L, R;
long long int j, i;
long min, temp;

int find()
{
	min = 4076361;
	scanf("%lld %lld", &L, &R);
	if (L / 2019 != R / 2019)
	{
		return 0;
	}
	for (j = L + 1;j <= R;j++)
	{
		for (i = L;i < j;i++)
		{
			temp = ((i * j) % 2019);
			if (temp < min)
			{
				min = temp;
			}
		}
	}
	return min;
}

int main()
{
	printf("%d", find());
}

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

ll MOD = 998244353;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    ll N,K;
    cin>>N>>K;
    typedef pair<ll,ll> P;
    vector<P> lr(K);
    rep(i,K){
        ll l,r;
        cin>>l>>r;
        ++r;
        lr[i] = P(l,r);
    }

    vector<ll> dp(N);
    dp[0] = 1;
    dp[1] = -1;

    rep(i,N){
        if(i>0) dp[i] += dp[i-1];
        rep(j,K){
            ll l,r;
            l = lr[j].first;
            r = lr[j].second;
            // if(i+l<N) dp[i+l]+= dp[i];
            // if(i+r<N) dp[i+r]-= dp[i];
            if(i+l<N) dp[i+l]= (dp[i+l]+ dp[i])%MOD;
            if(i+r<N) dp[i+r]= (dp[i+r]-dp[i])%MOD;
            // if(i+r<N){
            //     dp[i+r] -= dp[i];
            //     if(dp[i+r]<0) dp[i+r]+=MOD;
            //     else dp[i+r]%=MOD;
            // }
        }
    }
    ll ans = dp[N-1]%MOD;
    if (ans<0) ans +=MOD;
    cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 4736
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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; }
ll n, m;
vector<int> a, b;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n ;
    a.resize(n);
    b.resize(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    vector<vector<int>>dp((1<<n)+1,vector<int>(55,INF));
    dp[0][0]=0;
    rep(bit,(1<<n)){
        int con=0;//立ってるbit
        rep(i,n){
            if(bit&(1<<i))con++;
        }
        vector<pair<int,int>>ords;
        int iter=con;
        rep(i,n){
            if(!(bit& (1<<i))){
                ords.push_back(make_pair(i,iter));
                iter++;
            }
        }
        rep(s,51){
            if(dp[bit][s]>=INF)continue;
            for(auto p:ords){
                int ns=-1;
                if(abs(p.first-con)%2==0)ns=a[p.first];
                else ns=b[p.first];
                if(ns>=s){
                    chmin(dp[bit|(1<<p.first)][ns],dp[bit][s]+abs(p.second-con));
                }
            }
        } 
    }
    int res=INF;
    for(int s=0;s<=50;s++){
        chmin(res,dp[(1<<n)-1][s]);
    }
    if (res < INF)
        cout << res << "\n";
    else cout<<-1<<"\n";
}


Measured memory_bytes: 67968
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  vi A(N), B(N);
  rep(i, 0, N) { cin >> A[i] >> B[i]; }
  sort(all(A));
  sort(all(B));
  if (N % 2) {
    cout << B[N / 2] - A[N / 2] + 1 << endl;
  } else {
    int k = N / 2 - 1;
    int l1 = A[k];
    int l2 = A[k + 1];
    int h1 = B[k];
    int h2 = B[k + 1];
    if (l1 > l2) swap(l1, l2);
    if (h1 > h2) swap(h1, h2);
    dump(l1, l2, h1, h2);
    int ans = (l2 - l1) + (h2 - h1) + (h1 - l2) * 2 + 1;
    cout << ans << endl;
  }
  return (0 ^ _ ^ 0);
}



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

#define all(v) v.begin(), v.end()
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    string s; cin >> s;
    int n = s.size();
    ll ans = 0;
    for(int bit = 0; bit < (1 << (n - 1)); bit++){
        ll cur = 0;
        for(int i = 0; i < n; i++){
            cur = cur * 10 + (s[i] - '0');
            if(bit & (1 << i)){
                ans += cur;
                cur = 0;
            }
        }
        ans += cur;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
A,B,K = map(int,input().split())
for i in range(K):
    if i%2 == 0:
        if A%2 == 1:
            A -= 1
        B += A//2
        A -= A//2
    else:
        if B%2 == 1:
            B -= 1
        A += B//2
        B -= B//2
print(A,B)

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;
const ll N= 1e5+1,mod = 1e9+7;
ll dp[N];
int main() {
// 	freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	ll i,j,x,y,n,c=0;
	sc(n);
	for(i=1;i<=n;i++){
		sc(x);sc(y);
		dp[x]++;dp[y+1]--;
	}
	for(i=1;i<N;i++)dp[i]+=dp[i-1];
	for(i=1;i<N;i++)if(dp[i])c++;
	pr(c);

}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    
    int n; cin>>n;
    //　都市、点数、番号の組
    vector<tuple<string,int,int>> a;
    for(int i=1;i<=n;i++){
        string s;
        int p;
        cin>>s>>p;
        p=-p;
        a.push_back(tie(s,p,i));
    }
    sort(all(a));

    rep(i,n){
        cout<<get<2>(a[i])<<endl;
    }

    return 0;
}

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

const int N=100005;
const long long INF=0x3f3f3f3f3f3f3f3f;
int n,a[N][3];
long long dp[N][3];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
		}
	}
	printf("%lld\n",max(dp[n][0],max(dp[n][1],dp[n][2])));
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
#define dd c=getchar()
inline ll read(){
	ll x=0,f=1;char dd;
	for(;!isdigit(c);dd)if(c=='-')f=-1;
	for(;isdigit(c);dd)x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#undef dd
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10|48);
}
inline ll sqr(ll x){return x*x;} 
int main(){
    return write(sqr(read())-read()),puts(""),0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <cstdio>

int main()
{
    using namespace std;
    
    double x1, x2, y1, y2;
    double dis;
        
    cin >> x1 >> y1 >> x2 >> y2;
    
    dis = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    printf("%.8lf\n", dis); 
    
    return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<string>
#define lint long int
int main(void) {
	int i, a[4];
	std::cin >> i;
	a[0] = (int)i*0.001;
	a[1] = (int)i*0.01 - a[0] * 10;
	a[2] = (int)i*0.1 - a[0] * 100 - a[1] * 10;
	a[3] = i - a[0] * 1000 - a[1] * 100 - a[2] * 10;
	if (a[0] + a[1] + a[2] + a[3] < 10 && a[0] + a[1] + a[2] + a[3] >= 0 && a[0] + a[1] + a[2] + a[3] == 7)
		std::cout << a[0] << "+" << a[1] << "+" << a[2] << "+" << a[3] << "=" << a[0] + a[1] + a[2] + a[3];
	else if (a[0] - a[1] + a[2] + a[3] < 10 && a[0] - a[1] + a[2] + a[3] >= 0 && a[0] - a[1] + a[2] + a[3] == 7)
		std::cout << a[0] << "-" << a[1] << "+" << a[2] << "+" << a[3] << "=" << a[0] - a[1] + a[2] + a[3];
	else if (a[0] + a[1] - a[2] + a[3] < 10 && a[0] + a[1] - a[2] + a[3] >= 0 && a[0] + a[1] - a[2] + a[3] == 7)
		std::cout << a[0] << "+" << a[1] << "-" << a[2] << "+" << a[3] << "=" << a[0] + a[1] - a[2] + a[3];
	else if (a[0] + a[1] + a[2] - a[3] < 10 && a[0] + a[1] + a[2] - a[3] >= 0 && a[0] + a[1] + a[2] - a[3] == 7)
		std::cout << a[0] << "+" << a[1] << "+" << a[2] << "-" << a[3] << "=" << a[0] + a[1] + a[2] - a[3];
	else if (a[0] + a[1] - a[2] - a[3] < 10 && a[0] + a[1] - a[2] - a[3] >= 0 && a[0] + a[1] - a[2] - a[3] == 7)
		std::cout << a[0] << "+" << a[1] << "-" << a[2] << "-" << a[3] << "=" << a[0] + a[1] - a[2] - a[3];
	else if (a[0] - a[1] + a[2] - a[3] < 10 && a[0] - a[1] + a[2] - a[3] >= 0 && a[0] - a[1] + a[2] - a[3] == 7)
		std::cout << a[0] << "-" << a[1] << "+" << a[2] << "-" << a[3] << "=" << a[0] - a[1] + a[2] - a[3];
	else if (a[0] - a[1] - a[2] + a[3] < 10 && a[0] - a[1] - a[2] + a[3] >= 0 && a[0] - a[1] - a[2] + a[3] == 7)
		std::cout << a[0] << "-" << a[1] << "-" << a[2] << "+" << a[3] << "=" << a[0] - a[1] - a[2] + a[3];
	else if (a[0] - a[1] - a[2] - a[3] < 10 && a[0] - a[1] - a[2] - a[3] >= 0 && a[0] - a[1] - a[2] - a[3] == 7)
		std::cout << a[0] << "-" << a[1] << "-" << a[2] << "-" << a[3] << "=" << a[0] - a[1] - a[2] - a[3];
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		StringTokenizer st = new StringTokenizer(str, " ");
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int c = Integer.parseInt(st.nextToken());
		int count = 0;

		for(int i = a; i <= b; i++){
			if(c % i == 0){
				count++;
			}
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 24232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
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;}

int H,W;

signed main(){
	vector<pair<int,int>>ans;
	while(cin>>H>>W,H||W){
		vector<pair<int,int>>v;
		FOR(i,1,151){
			FOR(j,i+1,151){
				v.push_back({i*i+j*j,i});
			}
		}
		sort(ALL(v));
		REP(i,v.size()){
			if(H*H+W*W<v[i].first){
				ans.push_back({v[i].second,sqrt(v[i].first-v[i].second*v[i].second)});
				break;
			}else if(H*H+W*W==v[i].first&&H<v[i].second){
				ans.push_back({v[i].second,sqrt(v[i].first-v[i].second*v[i].second)});
				break;
			}
		}
	}
	for(auto e:ans){
		cout<<e.first<<" "<<e.second<<endl;
	}
}


Measured memory_bytes: 3236