akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
typedef pair<int, int> P;

double dp[6003][3000] = {};

int main(){
    int i, j, n;
    cin >> n;
    double p, res = 0.0;
    dp[3001][0] = 1.0;
    for(i=1; i<=n; i++){
        cin >> p;
        for(j=1; j<6002; j++){
            dp[j][i] = p * dp[j-1][i-1] + dp[j+1][i-1] * (1.0 - p);
        }
    }
    for(i=3002; i<6003; i++){
        res += dp[i][n];
    }
    printf("%.10f\n", res);
    return 0;
}

Measured memory_bytes: 140928
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Sep  1 20:36:57 JST 2020
 **/

signed main() {
    Int H, W;
    std::cin >> H >> W;
    std::map<Int, Int> mp;
    std::multiset<Int> s;
    REP(j, W) mp[j] = j, s.insert(0);
    REP(i, H) {
        Int l, r;
        std::cin >> l >> r, l--;
        Int x = -1;
        while (1) {
            auto it = mp.lower_bound(l);
            if (it == mp.end() || r < it->first) break;
            x = it->second;
            s.erase(s.find(it->first - it->second));
            mp.erase(it);
        }
        if (r != W && x != -1) mp[r] = x, s.insert(r - x);
        std::cout << (s.size() ? i + 1 + *s.begin() : -1) << "\n";
    }
}


Measured memory_bytes: 25488
#include <stdio.h>

int main(void)
{
	int a,b;
	
	int sum = 0;
	
	scanf("%d %d",&a,&b);
	
	if(a > b){
		sum = sum + a;
		a = a - 1;
	}else{
		sum = sum + b;
		b = b - 1;
	}
		
	if(a > b){
		sum = sum + a;
		a = a - 1;
	}else{
		sum = sum + b;
		b = b - 1;
	}
		
	printf("%d",sum);
	
	return 0;
	
}
		
	
	
	

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    string s;
    cin >> s;

    // 処理
    bool flg = false;
    if (s.size() % 2 == 0) {  //奇数はfalse
        for (int i = 0; i < 26; i++) {
            char moji = 'a' + i;
            if (count(all(s), moji) % 2 == 0) {
                flg = true;
            } else {
                flg = false;
                break;
            }
        }
    }

    // 出力
    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#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 FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#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
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 NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

// http://sesenosannko.hatenablog.com/entry/2017/09/01/214852
struct Bellman_Ford{
	struct edge{ll from, to, cost;};
	ll inf = 1e15;
	vector<edge> es;
	vector<ll> d;
	ll V,E;
	void init(ll v,ll e){
		V = v; E = e;
		d.resize(V);
	}
	void shortest_path(ll s){
		FOR(i,0,V) d[i] = inf;
		d[s] = 0;
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
				}
			}
		}
	}
	bool find_negative_loop(){
		FOR(i,0,V)d[i] = 0;
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i == V-1) return true;
				}
			}
		}
		return false;
	}
	bool shortest_path(int s, int t){ // t: destination
		FOR(i,0,V)d[i] = inf;
		d[s] = 0;
		FOR(i,0,2*V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i>=V-1 && e.to==t) return true;
				}
			}
		}	
		return false;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	Bellman_Ford bf;
	ll N,M;
	cin >> N >> M;
	bf.init(N,M);
	FOR(i,0,M){
		ll a,b,c;
		cin >> a >> b >> c;
		bf.es.push_back({a-1,b-1,-c});
	}
	if(bf.shortest_path(0,N-1)){
		cout << "inf" << endl;
	}else{
		cout << -bf.d[N-1] << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),

int n,k;
vi v;

bool f(int mnLen){//mnLen-0.999 , mnLen   , possible ?
    int cnt=0;
    for(int i:v){
        cnt+=ceil(i,mnLen)-1;
    }
    return cnt<=k;
}

signed main(){
    FASTER;
    cin>>n>>k;
    v=vi(n);cin>>v;
    
    int s=1,e=1e9,ans=-1;
    while(s<=e){
        int mid=(s+e)/2;
        if(f(mid))e=mid-1,ans=mid;
        else s=mid+1;
    }
    cout<<ans;
}



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

int main(){
  int n;
  cin >> n;  string ans = "";
  while (n != 0) {
    if(n % -2) {
      ans += "1";
      n -= 1;
    } else {
      ans += "0";
    }
    n /= -2;
  }
  reverse(ans.begin(), ans.end());
  if(ans == "") ans = "0";
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[]args) {
	Scanner t = new Scanner (System.in);
	int num,cont = 0, cont1=0;
	num =t.nextInt();
	String v;
	v=t.next();
	for(int i = 0;i<v.length();i++) {

	if(v.charAt(i)=='R'){
		cont++;
	}
		if(v.charAt(i)=='B') {
			cont1++;
		
	}
	}
		if(cont>cont1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22868
#include <stdio.h>

int main(void)
{
	int n;
	long int i, sum;

	scanf("%d", &n);

	sum = 0;

	for (i = 1; i <= n; i++)
	{
		if (i % 3 == 0 || i % 5 == 0)
			continue;
		sum += i;
	}

	printf("%ld", sum);

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;

pair<string,ll> p[n];
ll aa[n];
rep(i, n)
{
    cin >> p[i].first>>p[i].second;
    aa[i]=p[i].second;
    p[i].second=p[i].second*(-1);
}
sort(p,p+n);
rep(i,n)rep(j,n){
    if(aa[j]==(p[i].second*(-1)))cout << j+1 << endl;
}


return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);	
	int k, a, b; cin >> k >> a >> b;
	if (k <= a || b - a <= 2)
		cout << k + 1 << '\n';
	else 
		cout << 1LL * a + 1LL * (b - a) * ((k - a + 1) / 2) + 1LL * ((k - a + 1) % 2) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,x,i,j,k,sum,count;
	for(;;){
		scanf("%d %d",&n,&x);
		if(n==0&&x==0) break;
		count=0;
		for(i=1;i<=n-2;i++){
			for(j=i+1;j<=n-1;j++){
				if(i!=j){
					for(k=j+1;k<=n;k++){
						if(i!=k&&j!=k){
							sum=i+j+k;
							if(sum==x) count++;
						}
					}
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;
}



Measured memory_bytes: 2048
N,M=map(int,input().split())
PY=[]
for i in range(M):
    PY.append(list(map(int,input().split())))
    PY[i].append(i)
PY=sorted(PY,key=lambda x: x[1])
PY=sorted(PY,key=lambda x: x[0])

X=[1]
for i in range(1,M):
    if PY[i][0] == PY[i-1][0]:
        X.append(X[-1]+1)
    else:
        X.append(1)

for i in range(M):
    PY[i].append(str(PY[i][0]).rjust(6,'0')+\
              str(X[i]).rjust(6,'0'))

PY=sorted(PY,key=lambda x: x[2])

for i in range(M):
    print(PY[i][3])

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

int main() {
  double d,t,s;
  cin >> d >> t >> s;
  if (d/s <= t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long

int d = 365;
vector<vector<int>> s(d+1, vector<int>(26+1, 0));
vector<int> c(26+1);
vector<int> t(d);

ll calc(ll v, int d, vector<ll> last) {
    ll tmp = v;
    for(int i = 0; i < 26; i++) {
        tmp -= c[i]*(d-last[i]);
    }
    //return tmp-v;
    return tmp;
}

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

int main() {
    init();
    /////////////////
    vector<int> t(d);
    //for(int i = 0; i < d; i++) cin >> t[i];
    vector<ll> ans(d, 0);
    vector<ll> last1(26+1, 0), last2(26+1, 0);
    ll v = 0;
    ll tmp1 = 0, tmp2 = -1;
    for(int i = 0; i < d; i++) {
        //v += s[i][t[i]-1];
        //last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            //ans[i] -= c[j]*((i+1)-last[j]);
            //t[i] = j+1;
            last1[j] = i+1; // d
            tmp1 = calc(v+s[i][j], (i+1), last1);
            if(tmp2 < tmp1) {
                tmp2 = tmp1;
                last1 = last2;
                last2[j] = i+1;
                t[i] = j+1;
            }
            // v -= c[j]*((i+1)-last[j]);
        }
        last1 = last2;
        v += (tmp2-v);
        tmp1 = 0, tmp2 = -1;
        //cout << "v: " << v << endl;
    }
    
    for(int i = 0; i < d; i++) {
        //cout << "i: " << i << " " << t[i] << endl;
        cout << t[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3700
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	char* colors[] = { "black", "blue", "lime", "aqua"
		, "red", "fuchsia", "yellow", "white" };
	char buf[16];
	while (cin.getline(buf, sizeof(buf)), *buf != '0')
	{
		int r, g, b;
		sscanf(buf, "#%2x%2x%2x", &r, &g, &b);
		char* ans;
		double mind = 1e10;
		for (int i = 0; i < 8; ++i)
		{
			double rr = (i >> 2 & 1) * 0xff;
			double gg = (i >> 1 & 1) * 0xff;
			double bb = (i & 1) * 0xff;
			double d = sqrt((rr-r)*(rr-r) + (gg-g)*(gg-g) + (bb-b)*(bb-b));
			if (d < mind)
			{
				mind = d;
				ans = colors[i];
			}
		}
		puts(ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
//#define int long long
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}
#define vi vector<int>

using namespace std;

int target(int src){
	int tmp=1;
	while(tmp<=src){
		tmp*=2;
	}
	return tmp;
}

signed main(){
	int N;
	cin>>N;
	vi A(N);
	REP(i,N){
		cin>>A[i];
	}
	sort(A.begin(),A.end());//昇順
	//REP(i,A.size()) cout<<A[i]<<endl; 
	int ans=0;
	vector<bool> used(N,false);

	RREP(i,N){
		if(used[i]) continue;
		int t = target(A[i]);
		int u = t-A[i];
		int l = lower_bound(A.begin(), A.begin()+i, u) - A.begin();
		int r = upper_bound(A.begin(), A.begin()+i, u) - A.begin();
		//debug(t); debug(u); debug(l); debug(r);
		for(auto j = r-1; j>=l; --j){
			if(!used[j]&&!used[i]){
				used[j]=true; used[i]=true;
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    int ans1 = 0;
    for(size_t i = 0; i < n; i++)
    {
        cin >> t[i];
        ans1 += t[i];
    }
    int m;
    cin >> m;
    vector<int> p(m);
    vector<int> x(m);
    vector<int> ans(m);
    for(size_t i = 0; i < m; i++)
    {
        cin >> p[i] >> x[i];
        ans[i] = x[i] + ans1 -t[p[i]-1];
    }
    for(auto x:ans) cout << x << endl;
    return 0;
}

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

int main()
{
    char s[201], t[201];
    int len, n, h;
    while (1)
    {
        cin >> s;
        len = strlen(s);
        if (len == 1 && s[0] == '-')
            break;
        cin >> n;
        while (n--) {
            cin >> h;
            for (int i = 0, j = h; i < len; i++,++j%=len){
                if (i < h)
                    t[i] = s[j];
                else
                    t[i] = s[j];
            }
            for (int i = 0; i < len; i++)
                s[i] = t[i];
            s[len] = '\0';
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
using namespace std;

int main()
{
	int l, r ,d;
	scanf("%d %d %d",&l,&r,&d);
	int cnt=0;
	for(int i=l;i<=r;i++)
	{
		if(i%d==0)
		{
			cnt++;
		}
	}
	printf("%d\n",cnt);
		
	return 0;
}

Measured memory_bytes: 1720
N = int(input())
enable = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [-1 for i in range(N+1)]
for i in enable:
    if i <= N:
        dp[i] = 1

def find_min(x):
    min_res = float('INF')
    for i in enable:
        if x - i >= 0:
            min_res = min(min_res, dp[x-i])
    return min_res

for i in range(1, N + 1):
    if dp[i] == -1:
        dp[i] = find_min(i) + 1

print(dp[N])        

Measured memory_bytes: 3864
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        sc.close();

        // 主処理
        boolean isGood = false;
        for (int i = 0; i < n.length() - 2; i++) {
            if (n.charAt(i) == n.charAt(i + 1) && n.charAt(i + 1) == n.charAt(i + 2)) {
                isGood = true;
                break;
            }
        }
        String result = isGood ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


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

int main() {
	int n, q;
	while(cin >> n  >> q && (n || q)){
		int cnt[1000] = {0}, m, d;
		for(int i = 0; i < n; ++i){
			cin >> m;
			for(int j = 0; j < m; ++j){
				cin >> d;
				cnt[d]++;
			}
		}
		int maxium = 0, day = 0;
		for(int i = 1; i <= 100; ++i){
			if(maxium < cnt[i]){
				day = i;
				maxium = cnt[i];
			}
		}
		if(maxium >= q)
			cout << day << endl;
		else
			cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
	int n, a, b, train, taxi;
	scanf("%d %d %d", &n, &a, &b);
	train = n*a;
	taxi = b;
	if (train < taxi)
	{
		printf("%d", train);
	} else {
		printf("%d", taxi);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int tt[101], pp[101], xx[101];
int main() {
	long long n, t, m, p, x, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> t;
		tt[h] = t;
	}
	cin >> m;
	for (int h = 0; h < m; h++) {
		cin >> p >> x;
		pp[h] = p;
		xx[h] = x;
	}
	for (int h = 0; h < m; h++) {
		for (int i = 0; i < n; i++) {
			if (pp[h] == i + 1) {
				ans += xx[h];
			}
			else {
				ans += tt[i];
			}
		}
		cout << ans << endl;
		ans = 0;
	}
	cin >> n;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<cmath>
#include<unordered_map>
#include<vector>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
const int inf = (1e18)+7;
const int neginf = -1*((int)1e17 ) + 7 ; 

int32_t main() {
    fastio
        
    int n;
    cin>>n;
    
    map<string,int> mp1,mp2;
    
    string s;
    fo(i,n)
    {
        cin>>s;
        mp1[s]++;
    }
    
    int m;
    cin>>m;
    
    fo(i,m)
    {
        cin>>s;
        mp2[s]++;
    }
    
    int maxx = 0;
    for(auto it=mp1.begin();it!=mp1.end();++it)
    {
        maxx = max(maxx,mp1[it->F]-mp2[it->F]);
    }
    cout<<maxx;
return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
ll N;
int K;

int main(int argc, char** argv) {
  cin >> N >> K;

  map<ll, int> index; // num to index
  for (ll x=1; x*x<=N; x++) {
    index.insert({x, -1});
    index.insert({N/x, -1});
  }
  int i = 0;
  for (auto& kv : index) {
    kv.second = i++;
  }


  vector<vll> dp(K, vll(index.size()));

  int j = 0;
  for (auto kv : index) {
    dp[0][j++] = kv.first;
  }

  for (int i=1; i<K; i++) {

    int j=0;
    pair<ll,int> prev = *index.begin();
    for (auto kv : index) {
      if (j>0) {
        addmod(dp[i][j], dp[i][j] + dp[i][j-1]);
      }
      ll c = j==0 ? 1 : kv.first - prev.first;

      addmod(dp[i][j], c*(dp[i-1][index[N/kv.first]])%MOD);

      prev = kv;
      j++;
    }
  }

  cout << dp[K-1][index.size()-1] << endl;

  return 0;
}


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

int main() { 
    long long int n, k, sum = 0, ans = 0;
    cin >> n >> k;
    long long int h_;
    vector<long long int> h;
    for(int i = 0; i < n; ++i) {
        cin >> h_;
        h.push_back(h_);
    }

    if(n > k) {
        sort(h.rbegin(), h.rend());
        for(int i = 0; i < n; ++i) {
            if(i >= k) ans += h[i];
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
bool nouse(int n, int d)
{
  while(n != 0){
    if(n % 10 == d){
      return false;
    }
    n /= 10;
  }
  return true;
}
int main(void)
{
  int n, k;
  cin >> n >> k;
  int ans = n;
  vector<int> d(k);
  for(int i = 0; i < k; i++) cin >> d[i];
  while(true){
    bool flg = true;
    for(int i = 0; i < k; i++){
      if(!nouse(ans, d[i])) flg = false;
    }
    if(flg){
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // 文字列処理の関数
#include <ctype.h> // 文字変換(大文字/小文字)の関数

int main() {
char buf1[1];
scanf("%s",buf1);
char buf2[1];
scanf("%s",buf2);
int i,j;
if (buf1[0]=='A') i=10;
if (buf1[0]=='B') i=11;
if (buf1[0]=='C') i=12;
if (buf1[0]=='D') i=13;
if (buf1[0]=='E') i=14;
if (buf1[0]=='F') i=15;
if (buf2[0]=='A') j=10;
if (buf2[0]=='B') j=11;
if (buf2[0]=='C') j=12;
if (buf2[0]=='D') j=13;
if (buf2[0]=='E') j=14;
if (buf2[0]=='F') j=15;
if (i<j) printf("<\n");
if (i>j) printf(">\n");
if (i==j) printf("=\n");
return 0;
}

Measured memory_bytes: 128
# coding; utf-8
l, r = map(int, input().split())

if r-l > 2019:
        ans = 0
else:
        ans = 2019
        l = l%2019
        r = r%2019
        if l > r:
                r += 2019
        for i in range(l, r):
                for j in range(l+1, r+1):
                        if (i*j) % 2019 < ans:
                                ans = (i*j) % 2019

print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define ld long double
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846
 
const int N =1e3+5;
 
int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;	
	}
	 return res;	
   }

int n;
vi pr;

void cal(int n) {
	  vi a(n+1,1);
	  rep(i,2,n) {
		    if(!a[i]) continue;
		    pr.pb(i);
		    for(int j=2*i;j<=n;j+=i) a[j]=0;
		  }
	}

int can(vi a) {
	  cal(N);
	  set<int > st;
	  for(int x:a)  {
		    for(int p:pr) {
				  if(x%p==0) {
					    if(st.count(p)) return 0;
					    st.insert(p);
					    while(x%p==0) x/=p;
					  }
				}  
		  
		  if(x>1) {
			    if(st.count(x)) return 0;
			    st.insert(x);
			  }
		}    
			  
			  return 1;
	}
	
void solve() {	   
   cin>>n;
   vi a(n,0);
   rep(i,0,n) {
	     cin>>a[i];
	   }
  if(can(a)) {
	    cout<<"pairwise coprime\n";
	    return;
	  }	    
      int d=a[0];
      rep(i,0,n) d=__gcd(d,a[i]);
      if(d==1) cout<<"setwise coprime\n";
      else cout<<"not coprime\n";  
  }
	 
 
 
int32_t main() {
	cool;
	int t=1;	
   
    //~ cin>>t;
	while(t--)
	   solve();		   
	   
	   return 0;	   
}


Measured memory_bytes: 18740
N, K, Q = map(int, input().split())
a = list(map(int, input().split()))

d = [a]
a = sorted(a)
a.sort()
ans = a[Q-1] - a[0]

while True:
  d_temp = list()
  sub_temp = list()
  for sub in d:
    for c in sub:
      if c != a[0]:
        sub_temp.append(c)
      else:
        d_temp.append(sub_temp)
        sub_temp = list()
    d_temp.append(sub_temp)
    sub_temp = list()

  d = list()
  a = list()
  for sub in d_temp:
    if len(sub) < K:
      continue
    else:
      d.append(sub)
      sub = sorted(sub)
      a.extend(sub[0:len(sub)-K+1])

  a = sorted(a)

  if len(a) < Q:
    break
  else:
    ans = min(ans, a[Q-1] - a[0])

print(ans)


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

int main(){
  int a,b;
  cin>>a>>b;
  
  if( a < b ) cout<<"a < b"<<endl;
  if( a > b ) cout<<"a > b"<<endl;
  if( a == b ) cout<<"a == b"<<endl;

  return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#define llint long long
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

llint n;
vector<E> vec;
llint x[200005], p[200005];
vector<llint> G[200005];
multiset<P> S;

llint dp[200005][2];

void dfs(int v)
{
	for(int i = 0; i < G[v].size(); i++) dfs(G[v][i]);
	
	llint all = 1, zero = 1;
	for(int i = 0; i < G[v].size(); i++){
		llint u = G[v][i];
		all *= (dp[u][0] + dp[u][1]) % mod, all %= mod;
		zero *= dp[u][0], zero %= mod;
	}
	dp[v][0] = zero, dp[v][1] = all;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint d;
	for(llint i = 1; i <= n; i++){
		cin >> x[i] >> d;
		vec.push_back(E(P(x[i], 1LL), i));
		vec.push_back(E(P(x[i]+d, 0LL), i));
	}
	sort(vec.begin(), vec.end());
	
	
	for(int i = 0; i < vec.size(); i++){
		int id = vec[i].second;
		if(vec[i].first.second == 0){
			S.erase(P(x[id], id));
		}
		else{
			if(S.size()){
				auto it = S.end();
				it--;
				p[id] = it->second;
			}
			S.insert(P(x[id], id));
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(p[i] == 0) continue;
		G[p[i]].push_back(i);
	}
	
	llint ans = 1;
	for(int i = 1; i <= n; i++){
		if(p[i] == 0){
			dfs(i);
			ans *= (dp[i][0] + dp[i][1]) % mod;
			ans %= mod;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 37992
#include <atcoder/lazysegtree>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

ll mod = 998244353;

struct S {
    ll value;
    ll size;
};

struct F {
    ll b;
    ll c;
};

S op(S x, S y) {
    return S{(x.value+y.value)%mod, x.size+y.size};
}

S e() {
    return S{0, 0};
}

S mapping(F f, S x) {
    return S{(f.b*x.value + f.c*x.size)%mod, x.size};
}

F composition(F f, F g) {
    return F{(f.b*g.b)%mod, (f.c+f.b*g.c)%mod};
}

F id() {
    return F{1, 0};
}

int main() {
    int N, Q;
    scanf("%d %d", &N, &Q);
    vector<S> A(N);
    for (int i = 0; i < N; i++) {
        ll a;
        scanf("%lld", &a);
        A[i] = S{a, 1};
    }

    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> lsgt(A);
    for (int q = 0; q < Q; q++) {
        int T;
        scanf("%d", &T);
        if (T == 0) {
            int l, r;
            ll b, c;
            scanf("%d %d %lld %lld", &l, &r, &b, &c);
            lsgt.apply(l, r, F{b, c});
        }
        if (T == 1) {
            int l, r;
            scanf("%d %d", &l, &r);
            printf("%lld\n", lsgt.prod(l, r).value);
        }
    }

}

Measured memory_bytes: 35696
#include <stdio.h>
#include <ctype.h>

int main(void){
  char a;
  char x[]="abcdefghijklmnopqrstuvwxyz";
  char y[26]={0};
  int moji[30]={0};
  int i,j;

  while(scanf("%c",&a)!=EOF){   
    if(a>='a' && a<='z'){
      moji[a-'a']+=1;
    }else if(a>='A' && a<='Z'){
      moji[a-'A']+=1;
    }
  }

  for(i=0;i<26;i++){
    printf("%c : %d\n",x[i],moji[i]);
  }

  return 0;

}

Measured memory_bytes: 540
#include<iostream> 
using namespace std; 
int main(){
    int x,y; 
    cin >> x >>y;
    if(x==y){
    cout<<"a == b"<<endl;
    }else if(x>y){
    cout<<"a > b"<<endl;
    }else{
    cout<<"a < b"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
using namespace std;
int main(){
  int n; cin >> n;
  int a[52];
  int max_=-10000000;
  int min_=10000000;
  int maxid,minid;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    if(a[i] > max_){
      max_ = a[i];
      maxid = i;
    }
    if(a[i] < min_){
      min_ = a[i];
      minid = i;
    }
  }
  if(abs(max_) > abs(min_)){
    cout << 2*n-2 << endl;
    cout << maxid << " " << 2 << endl;
    cout << maxid << " " << 2 << endl;
    for(int i=2;i<=n-1;i++){
      for(int j=1;j<=2;j++){
        cout << i << " " << i+1 << endl;
      }
    }
  }else{
    cout << 2*n-2 << endl;
    cout << minid << " " << n-1 << endl;
    cout << minid << " " << n-1 << endl;
    for(int i=n-2;i>=1;i--){
      for(int j=1;j<=2;j++){
        cout << i+1 << " " << i << endl;
      }
    }
  }
}

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

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> vec(n);
	map<int,int> count;
	vector<int> temp;
	for(int i = 0; i < n; i++){
		cin >> vec[i];
		count[vec[i]]++;
	}
	for(pair<int,int> p : count){
		if(p.second >= 2){
			for(int i = 0; i < p.second/2; i++)
			temp.push_back(p.first);
		}
	}
	if(temp.size() < 2){
		cout << 0 << endl;
		return 0;
	}
	sort(temp.rbegin(), temp.rend());
	cout << temp[0]*temp[1] << endl;
}

Measured memory_bytes: 7296
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N, K = map(int, input().split())
h = list(map(int, input().split()))
ans = 0
for hi in h:
    if hi >= K:
        ans += 1
print(ans)


Measured memory_bytes: 19620
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define ll long long
using namespace std;
const int N=105,mo=998244353;
unordered_map<string,int>f;
string s;
string sub(string s,int l,int r){
	string t;fo(i,l,r)t=t+s[i];
	return t;
}
int get(string s){
	if(f.count(s))return f[s];
	if(s.size()==1)return f[s]=s[0]-'0'+1;
	int n=s.size(),su=(ll)get(sub(s,1,n-1))*(s[0]-'0'+1)%mo;
	fo(i,1,n/2){
		string a=sub(s,0,i-1),b;
		fo(j,2,n/i){
			fo(k,0,i-1)a[k]&=s[(j-1)*i+k];
			b=sub(s,i*j,n-1);
			su=((ll)get(a)*get(b)+su)%mo;
		}
	}
	return f[s]=su;
}
int main(){
	f[s]=1;
	cin>>s;
	cout<<get(s);
}

Measured memory_bytes: 5388
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

H, W = map(int, input().split())
wf = [list(map(int, input().split())) for _ in range(10)]
board = [list(map(int, input().split())) for _ in range(H)]

for _ in range(3):
    for i in range(10):
        for j in range(10):
            for k in range(10):
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

converted = sum([(wf[board[h][w]][1] if board[h][w] >= 0 else 0) for w in range(W) for h in range(H)])

print(converted)

Measured memory_bytes: 4468
#include<iostream>
#include<vector>
using namespace std;
using LL = long long;

int main() {
	LL N, K;
	cin >> N >> K;
	vector<LL> A(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	for (int i = K+1; i <= N; i++) {
		if (A[i - K] < A[i]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}


	return 0;



}

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

#define loop(i,n) for(int i=0;i<n;i++)

struct R {int from,to,len;};
vector<int> cards;
vector<R> ser;

int main(){
  int n,k,temp;
  bool blank;
  while(cin>>n>>k,n){
    blank=0;
    cards.clear();
    loop(_,k){
      cin>>temp;
      if(temp==0)blank=1;
      else cards.push_back(temp);
    }
    sort(cards.begin(),cards.end());
    loop(i,cards.size()){
      if(!ser.empty()&&ser.back().to+1==cards[i]){
        ser.back().to=cards[i];
        ser.back().len++;
      }else{
        ser.push_back((R){cards[i],cards[i],1});
      }
    }
    int m=0;
    loop(i,ser.size()){
      m=max(m,ser[i].len);
    }
    if(blank){
      m++;
      loop(i,ser.size()){
        if(i==0)continue;
        if(ser[i-1].to+2==ser[i].from){
          m=max(m,ser[i-1].len+1+ser[i].len);
        }
      }
    }
    cout<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 









int main()
{
     ll x,y,a,b,c;
     cin>>x>>y>>a>>b>>c;
     ll p[a],q[b],r[c];
     rep(i,a)cin>>p[i];
     rep(i,b)cin>>q[i];
     rep(i,c)cin>>r[i];
     sort(p,p+a);sort(q,q+b);
     reverse(p,p+a);reverse(q,q+b);
     vector<ll> res;
     for(int i=0;i<x;i++)res.push_back(p[i]);
     for(int i=0;i<y;i++)res.push_back(q[i]);
     for(int i=0;i<c;i++)res.push_back(r[i]);
     sort(res.rbegin(),res.rend());
     ll sum=0;
     for(int i=0;i<x+y;i++)
     sum+=res[i];
     cout<<sum;
}


























Measured memory_bytes: 8816
n = int(input())
S = [0]*n
for i in range(n):
    S[i] = int(input())

r = sum(S)
S.sort()
for i in range(n):
    if r%10 != 0:
        break
    if r%10 == 0 and S[i]%10!=0:
        r -= S[i]
        break
    if i==n-1:
        r = 0
print(r)

Measured memory_bytes: 3060
def resolve():
    R, C, K = map(int, input().split())
    G = [[0] * (C+1) for _ in range(R+1)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        G[r][c] = v

    DP1 = [0 for _ in range(C + 1)]  # c列目までとったとき、最新の行で1個以下とったという条件のもとの最大
    DP2 = [0 for _ in range(C + 1)]  # c列目までとったとき、最新の行で2個以下とったという条件のもとの最大
    DP3 = [0 for _ in range(C + 1)]  # c列目までとったとき、最新の行で3個以下とったという条件のもとの最大

    for r in range(1, R+1):
        for c in range(1, C+1):
            # 更新の順番に注意
            # mid = max(DP1[c], DP2[c], DP3[c]) + I[r][c]
            mid = DP3[c] + G[r][c]
            DP3[c] = max(DP3[c - 1], mid, DP2[c - 1] + G[r][c])  # 3個
            DP2[c] = max(DP2[c - 1], mid, DP1[c - 1] + G[r][c])  # 2個
            DP1[c] = max(DP1[c - 1], mid)  # 1個

    print(DP3[C])

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 146444
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] B = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = sc.nextInt() - (i + 1);
        }

        Arrays.sort(B);
        int meanB = B[N/2];

        long result0 = 0;
        long result1 = 0;
        long result2 = 0;

        for (int i = 0; i < N; i++) {
            result0 = result0 + Math.abs( B[i] - (meanB - 1) );
            result1 = result1 + Math.abs(B[i] - (meanB ));
            result2 = result2 + Math.abs(B[i] - (meanB + 1));
        }
        long result = Math.min(result0 , Math.min(result1,result2));
        System.out.println(result);
    }
}


Measured memory_bytes: 86176
n = int(input())
d = [None] * n
for i in range(n):
    d[i] = int(input())
d.sort(reverse=True)
previous = d[0]
cnt = 1
for i in range(1, n):
    if d[i] < previous:
        cnt += 1
        previous = d[i]
print(cnt)    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}


void solve()
{
    int n;
    cin>>n;
    vl a(n),b(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
        cin>>b[i];
    }

    sort(all(a));
    sort(all(b));
    if(n%2) {
        ll x = abs(b[n/2] - a[n/2])+1;
        cout<<x;
    }
    else {
        ll x = abs((b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1]))+1;
        cout<<x;
    }
}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int A,B;
  cin>>A>>B;
  int ans=0;
  FOR(N,A,B+1){
    int num=N,nun=0;
    while(num){
      nun=nun*10+num%10;
      num/=10;
    }
    if(N==nun){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t a, b;
  char c;
  std::cin >> a >> c >> b;
  if (c == '-') {
    std::cout << a - b << std::endl;
  } else {
    std::cout << a + b << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long LL;
const int N = 1e5 + 10;
const LL inf = 1e18 + 10;
int n, e, t, x[N]; LL f[N], g[N];

template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

int main() {
	in(n), in(e), in(t), g[n + 1] = inf;
	for (int i = 1; i <= n; ++i) in(x[i]);
	for (int i = n, j = n; i; --i) {
		for (;(x[j] - x[i] << 1) > t;) --j;
		f[i] = min(f[j + 1] + t, g[j + 1] - 2 * x[i]);
		g[i] = min(g[i + 1], f[i + 1] + 2 * x[i]);
	}
	printf("%lld\n", f[1] + e);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
typedef long long int ll;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	vi a(n);
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if((i+1)%2!=0 && a[i]%2!=0){
			ans++;
		}
	}
	cout<<ans<<"\n";
}	

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


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

int main(){
  ll n;
  cin >> n;
  vector<vector<ll>> p(n,vector<ll>(3));
  rep(i,n) rep(j,3) cin >> p.at(i).at(j);
  
  ll x=0,y=0,t=0;
  rep(i,n){
    if( i != 0 ){
      t = p.at(i).at(0) - p.at(i-1).at(0);
    }else{
      t = p.at(i).at(0);
    }
    ll dis = abs(p.at(i).at(1)-x) + abs(p.at(i).at(2) - y);
    if( (t-dis)%2 != 0 || t < dis ){
      cout << "No" << endl;
      return 0;
    }
    x = p.at(i).at(1);
    y = p.at(i).at(2);
  }
  
  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 5760
//Catchharsh
//Legendary Sage Jiraiya Sensei 
//https://codeforces.com/contest/877/problem/D
#include<bits/stdc++.h>
// #pragma GCC optimize "03"
#define ll  int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define F first
#define S second
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define debug(x) cout<<#x<<" = "<<x<<endl
#define catchharsh cout<<"\n---------catchharsh---------\n"
const ll MOD = 1e9+7;
const ll INF = 1011111111;
// const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
//inline ll add(ll a,ll b){a+=b;if(a>=MOD)a-=MOD;return a;}
//inline ll sub(ll a,ll b){a-=b;if(a<0)a+=MOD;return a;}
//inline ll mul(ll a,ll b){return (a*1ll*b)%MOD;}
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}
ll dx[]={1,-1,0,0};
ll dy[]={0,0,1,-1};
int32_t main()
{   
     IOS;
     ll n,m,i,j,k;
     cin>>n>>m>>k;
     vector< vector<ll> > grid(n, vector<ll> (m));
     vector< vector<bool> > visit(n, vector<bool> (m));
     vector< vector<ll> > dis(n, vector<ll> (m));
     ll xs,ys,xf,yf;
     cin>>xs>>ys>>xf>>yf;
     xs--;ys--;xf--;yf--;
     for(i=0;i<n;i++)
     {
      for(j=0;j<m;j++)
      {
        char c;
        cin>>c;
        if(c=='.') grid[i][j]=0;
        else grid[i][j]=1;
        dis[i][j]=-1;
        visit[i][j]=false;
      }
     }
     if(xs==xf && ys==yf) return cout<<0,0;
     queue< pair<ll,ll> > q;
     q.push({xs,ys});
     dis[xs][ys]=0;
     visit[xs][ys]=true;
     while(!q.empty())
     {
       if(visit[xf][yf]) break;
       ll now_x=q.front().F;
       ll now_y=q.front().S;
       q.pop();
       for(ll dir=0;dir<4;dir++)
       {
        for(ll len=1;len<=k;len++)
        {
          ll n_x=now_x+dx[dir]*len;
          ll n_y=now_y+dy[dir]*len;
          if(n_x < 0 || n_x >= n || n_y < 0 || n_y >= m)
            break;
          if(visit[n_x][n_y] && dis[now_x][now_y] + 1 > dis[n_x][n_y])
            break;
          if(grid[n_x][n_y])
            break;
          if(visit[n_x][n_y])
            continue;
          dis[n_x][n_y]=dis[now_x][now_y]+1;
          visit[n_x][n_y]=true;
          q.push({n_x,n_y});
        }
       }
     }
     cout<<dis[xf][yf];
     
     
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 15160