akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
dp = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    e = x * 2
    while e <= 10 ** 6:
        dp[e] = False
        e += x
ret = 0
for x in a:
    if c[x] == 1 and dp[x] == True:
        ret += 1
print(ret)


Measured memory_bytes: 52444
import java.util.Scanner;

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

        while(sc.hasNextLine()){
            sb.append(sc.nextLine().toLowerCase());
        }

        char now;
        char a = 'a';
        int[] data = new int[26];
        String line = sb.toString();

        for(int i = 0; i < line.length(); i++){
            now = line.charAt(i);
            for(int j = 0; j < 26; j++){
                if(now == (char)(a+j)){
                    data[j]++;
                    break;
                }
            }
        }

        for(int i = 0; i < 26; i++){
            System.out.println((char)(a+i) + " : " + data[i]);
        }
    }
}


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

typedef pair<int, int> P;

const int MAX_N = 20000;

int N, K;
P data[MAX_N];

int dp[2000][2001];

vector< vector<int> > gb;

int main(){
    scanf("%d%d", &N, &K);
    for(int x = 0; x < N; x++){
        scanf("%d%d", &data[x].second, &data[x].first);
        fill(dp[x], dp[x]+K+1, 0);
    }
    sort(data, data+N);
    int cnt = 0;
    dp[0][1] = data[0].second;
    for(int x = 1; x < N; x++){
        if(data[x-1].first != data[x].first){
            gb.push_back(vector<int>(dp[x-1], dp[x-1]+K+1));
            fill(dp[x-1], dp[x-1]+K+2, 0);
            cnt = 0;
        }
        ++cnt;
        for(int y = 1; y <= cnt; y++){
            dp[x][y] = max(dp[x-1][y],
                           dp[x-1][y-1] + data[x].second + 2*(y-1));
        }
    }
    gb.push_back(vector<int>(dp[N-1], dp[N-1]+N));
    vector<int> va = vector<int>(gb[0]), vb(K+1);
    fill(vb.begin(), vb.end(), 0);
    for(int x = 0; x < gb.size()-1; x++){
        for(int s = 0; s <= K; s++){
            for(int i = 0; i <= s; i++){
                vb[s] = max(vb[s], va[i] + gb[x+1][s-i]);
            }
        }
        for(int s = 0; s <= K; s++){
            va[s] = vb[s];
        }
    }
    int ans = 0;
    for(int x = 0; x <= K; x++){
        ans = max(ans, va[x]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 17136
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    ans = [0]*N
    for i in A:
        ans[i-1] += 1

    for i in ans:
        print(i)

if __name__ == '__main__':
    resolve()


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

int main(){
  int n;
  cin >> n;
  if(n >= 1000) cout << "ABD" << "\n";
  else cout << "ABC" << "\n";
}

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

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

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll arr[5];
    fr(i,0,5)
        cin>>arr[i];
    fr(i,0,5)
    {
        if(arr[i]==0)
        {
            cout<<i+1<<endl;
            return;
        }
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

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

using vint = vector<int>;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    int la = a.size(), lb = b.size(), lc = c.size();
    int ans = la + lb + lc;

    auto compstr = [&](string &a, string &b, int lc) {
        int la = a.size(), lb = b.size();
        vint ab(la);
        for (int i = 0; i < la; i++) {
            int flag = 1;
            for (int j = 0; j < lb && i + j < la; j++)
                if (a[i + j] != '?' && b[j] != '?' && a[i + j] != b[j]) {
                    flag = 0;
                    break;
                }
            if (!flag) continue;
            ab[i] = 1;
            ans = min(ans, max(la, i + lb) + lc);
        }
        return ab;
    };
    vint ab = compstr(a, b, lc), ac = compstr(a, c, lb),
         ba = compstr(b, a, lc), bc = compstr(b, c, la),
         ca = compstr(c, a, lb), cb = compstr(c, b, la);
    auto checkstr = [&](vint &ab, vint &bc, vint &ac, int lc) {
        int la = ab.size(), lb = bc.size();
        for (int i = 0; i < la; i++) {
            if (!ab[i])
                continue;
            for (int j = 0; j < lb || i + j < la; j++) {
                if (j < lb && !bc[j])
                    continue;
                if (i + j < la && !ac[i + j])
                    continue;
                ans = min(ans, max(la, max(i + lb, i + j + lc)));
            }
        }
    };
    checkstr(ab, bc, ac, lc);
    checkstr(ac, cb, ab, lb);
    checkstr(ba, ac, bc, lc);
    checkstr(bc, ca, ba, la);
    checkstr(ca, ab, cb, lb);
    checkstr(cb, ba, ca, la);

    cout << ans;
}

Measured memory_bytes: 3696
#include <string>
#include <iostream>
using namespace std;
int n; string s;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		int sum = 0;
		for (char c : s) sum += c - 48;
		int ret = ((sum - 1) / 9) + (s.size() - 1);
		if (ret % 2 == 1) cout << "Fabre wins." << endl;
		else cout << "Audrey wins." << endl;
	}
}

Measured memory_bytes: 3108
// Problem : E - Bomber
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_e
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 300005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
set<pp> s;
vector<int> mp[maxn];
int v[maxn];
void solve()
{
	int n,m,w;
	cin >> n >> m >> w;
	rep(i,0,w)
	{
		int x,y;
		cin >> x >> y;
		mp[x].pb(y);
		v[y]++;
	}
	for(int i=1;i<=m;i++)
	s.insert({-v[i],i});
	int ans = -s.begin()->ff;
	for(int i=1;i<=n;i++)
	{
		for(auto x:mp[i])
		{
			s.erase({-v[x],x});
			v[x]--;
			s.insert({-v[x],x});
		}
		ans = max(ans,(int)mp[i].size()-s.begin()->ff);
		for(auto x:mp[i])
		{
			s.erase({-v[x],x});
			v[x]++;
			s.insert({-v[x],x});
		}
	}
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


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

struct card{
    char suit,value;
};

void show(int n,struct card c[])
{
    for(int i=0;i<n;i++)
    {
        if(i>0)cout<<" "<<c[i].suit<<c[i].value;
        else cout<<c[i].suit<<c[i].value;
    }
    cout<<endl;
}

void bubble(int n,struct card c[])
{
    for(int i=0;i<n;i++)
    {
        for(int j=n-1;j>=i+1;j--)
        {
            if(c[j].value<c[j-1].value)
            {
                swap(c[j],c[j-1]); 
            }
        }
    }
}

void selection(int n,struct card c[])
{
    int min;
    for(int i=0;i<n-1;i++)
    {
        min = i;
        for(int j=i;j<n;j++)
        {
            if(c[j].value<c[min].value)
            {
                min = j;
            }
        }
        card t = c[i];c[i]=c[min];c[min]=t;
    }
}

bool isStable(struct card c1[],struct card c2[],int n)
{
    for(int i=0;i<n;i++)
    {
        if(c1[i].suit!=c2[i].suit)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    card c1[n];
    card c2[n];
    for(int i=0;i<n;i++)
    {
        cin>>c1[i].suit>>c1[i].value;
    }

    for(int i=0;i<n;i++)
    {
       c2[i]=c1[i];
    }
    bubble(n,c1);
    show(n,c1);
    cout<<"Stable"<<endl;

    selection(n,c2);
    show(n,c2);
    if(isStable(c1,c2,n)) 
    {
        cout<<"Stable"<<endl;
    }
    else cout<<"Not stable"<<endl;

    return 0;
}


Measured memory_bytes: 3128
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let k: usize = sc.read();
    let n: usize = sc.read();

    if k % 2 == 0 {
        print!("{}", k / 2);
        for _ in 1..n {
            print!(" {}", k);
        }
        println!();
        return;
    } else {
        let x = (k + 1) / 2;
        let mut ans = vec![x; n];
        for _ in 0..(n / 2) {
            let length = ans.len();
            if ans[length - 1] == 1 {
                ans.pop();
            } else {
                ans[length - 1] -= 1;
                while ans.len() < n {
                    ans.push(k);
                }
            }
        }

        for i in 0..ans.len() {
            if i > 0 {
                print!(" ");
            }
            if ans[i] != 0 {
                print!("{}", ans[i]);
            }
        }
        println!();
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10492
# 2020/02/09
# Educational DP Contest / DP まとめコンテスト - B

# Input
n, k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10 ** 10] * n
dp[0] = 0

for i in range(1, n):
    j = max(0, i-k)
    while(j < i):
        dp[i] = min(dp[i], abs(h[i] - h[j]) + dp[j])
        j = j + 1

# Output
print(dp[n-1])

Measured memory_bytes: 52448
class Vector:
    def __init__(self):
        self._container = []
    
    def pushback(self, x):
        self._container.append(x)
    
    def randomAccess(self, index):
        return self._container[index]
    
    def popback(self):
        return self._container.pop()
        
num_operations = int(input())
vector = Vector()

for _ in range(num_operations):
    line = input()
    if line[0] in ('0', '1'):
        operation, target = line.split()
        target = int(target)
    else:
        operation = line[0]
        
    if operation == '0':
        vector.pushback(target)
    elif operation == '1':
        print(vector.randomAccess(target))
    elif operation == '2':
        vector.popback()


Measured memory_bytes: 13372
#include <iostream>
 
using namespace std;
 
int main(){
  int X, A, B;
  cin >> X >> A >> B;
  if(A-B>=0){
    cout << "delicious" << endl;
  }else if(A-B+X>=0){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int a[1000];
	int i;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	/* DENIEDと出力するのは、偶数かつ、3または5の倍数以外の数字が存在するときのみ */
	for (i = 0; i < n; i++)
	{
		/* 奇数の場合、倍数の判定をしない */
		if (a[i] % 2 == 0)
		{
			if (a[i] % 3 != 0 && a[i] % 5 != 0)
			{
				printf("DENIED\n");
				return 0;
			}
		}	
	}
	
	printf("APPROVED\n");

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;
int main() {

	int A, B, C;
	cin >> A >> B >> C;
	cout << min({ A + B, B + C, C + A }) << endl;

	
	return 0;
}

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

Measured memory_bytes: 600
#include<stdio.h>

int main(void){
    register int i;
    int n;
    scanf("%d",&n);
    int a[n];
    for(i = 0;i < n;i++)scanf("%d",&a[i]);
    int ans = 0;
    for(i = 0;i < n;i++)if(!(i%2) && a[i] % 2)ans++;
    printf("%d",ans);
}

Measured memory_bytes: 1728
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
  int K; cin >> K;
  queue<ll> que;
  for(int i = 1; i <= 9; i++) que.push(i);
  int cnt = 0;
  ll ans;
  while(!que.empty()) {
    ll v = que.front(); que.pop();
    if(++cnt == K) {
      ans = v;
      break;
    }
    if(v % 10 == 0) {
      que.push(v*10);
      que.push(v*10+1);
    } else if(v % 10 == 9) {
      que.push(v*10+9-1);
      que.push(v*10+9);
    } else {
      que.push(v*10+(v%10)-1);
      que.push(v*10+(v%10));
      que.push(v*10+(v%10)+1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        for(int i = A; i <= B; i++)
        {
            if (i % k == 0)
            {
                System.out.print("OK");
                return;
            }
        }
        System.out.print("NG");
    }
}


Measured memory_bytes: 35820
#include<iostream>
#include<algorithm>
using namespace std;
struct Card{
    char mark;
    int number;
};
struct Card A[100001],B[100001];
int n,v; char c;
void merge(struct Card A[],int left,int mid,int right){
    int n1=mid-left,n2=right-mid; 
    struct Card L[50001],R[50001];
     for(int i=0;i<n1;i++)L[i]= A[left+i];
     for(int i=0;i<n2;i++)R[i]=A[mid+i];
     L[n1].number=R[n2].number=2000000000;
     int i=0,j=0;
     for(int k=left;k<right;k++){
         if(L[i].number<=R[j].number){A[k]=L[i++];}
         else{ A[k]=R[j++];}
     }
}
void mergeSort(struct Card A[],int left,int right){
    int mid;
    if(left+1<right){
        mid=(left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}
int partition(struct Card A[],int p,int r){
    struct Card x=A[r]; int i=p-1;
    for(int j=p;j<r;j++){
        if(A[j].number<=x.number){
            i++;
            swap(A[i],A[j]);
        }
    }
   swap(A[i+1],A[r]);
    return i+1;
}
void quicksort(struct Card A[],int p,int r){
    if(p<r){
        int q=partition(A,p,r);
        quicksort(A,p,q-1);
        quicksort(A,q+1,r);
    }
}
int main(){
    bool equal=true;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>c>>v;
        A[i].mark=B[i].mark=c;
        A[i].number=B[i].number=v;
    }
    mergeSort(B,0,n);
    quicksort(A,0,n-1);
    for(int i=0;i<n;i++){
        if(A[i].mark!=B[i].mark) equal=false;
    }
    if(equal) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    for(int i=0;i<n;i++) cout<<A[i].mark<<" "<<A[i].number<<endl;
    return 0;
}


Measured memory_bytes: 5400
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;

    vector<long int> A(N);
    for(int i=0; i<N; ++i) cin >> A.at(i);
    long int max=A.at(0), sum=0;
    for(int i=1; i<N; ++i){
        if(A.at(i)<max){
            sum += max - A.at(i);
        }else{
            max = A.at(i);
        }
    }
    cout << sum <<endl;
}

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

#define ll long long int
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9 + 7;
//typedef unsigned long long u64;

int main()
{
	IOS;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		ll a,b,c,k;
		cin>>a>>b>>c>>k;
		ll sum=0;
		if(k<=a)
        {
            cout<<k<<endl;
        }
		else
        {
        if(k>a)
        {
            sum+=a;
            k-=a;
        }
        k-=b;
        if(k>0)
        {
            sum-=k;
        }
        cout<<sum<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X;
	cin >> X;
	int mn = X/100;
	if(X%100 <= mn*5)cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

typedef long long int ll;

int MAX(int a, int b){return a>b?a:b;}
int MIN(int a, int b){return a>b?b:a;}
int compare(const void* a, const void* b){return *(int*)a - *(int*)b;}
ll llMAX(ll a, ll b){return a>b?a:b;}
ll llMIN(ll a, ll b){return a>b?b:a;}
ll digits(ll a){ll tmp=a; ll cnt=0; while(tmp>0){tmp/=10; cnt+=1;} return cnt;}

int main(void){
    // sizeof(int):4(byte)

    ll n,k;
    scanf("%lld %lld", &n,&k);

    ll a[100000];
    for(int i=0; i<100000; i++){
        a[i] = 0;
    }

    for(int i=0; i<n; i++){
        int d1,d2;
        scanf("%d %d", &d1,&d2);

        a[d1-1] += d2;
    }

    ll sum = 0;
    for(int i=0; i<100000; i++){
        sum += a[i];

        if(k <= sum){
            printf("%d\n", i+1);
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
using namespace std;
long long int n,m,ans,amari,ahokusa;

 int main()
 {
    while(scanf("%lld%lld",&n,&m) != -1)
    {
         ans  = n*m;
         if(n < m)
         {
             ahokusa = n;
             n = m;
             m = ahokusa;
         }
         amari = n % m;
         while(amari != 0)
         {
            n = m;
            m = amari;
            amari = n % m;
         }
         ans = ans / m;
         printf("%lld %lld\n",m,ans);
    }

     return 0;

 }

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int n, k; cin >> n >> k;
	cout << (n % k == 0 ? 0 : 1) << endl;
	return 0;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int m = n/2;
    int res = (n&1) ? b[m]-a[m]+1 : (b[m-1]+b[m]) - (a[m-1]+a[m]) +1;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 4800
"use strict"
let input = require('fs').readFileSync('/dev/stdin','utf8');
let arr = input.split('\n')
for (let i in arr) {
	let list = arr[i].split(' ');
	let a = parseInt(list[0]);
	let b = parseInt(list[2]);
	let op = list[1];
	let ans = null;
	if (op === '+') ans = a + b;
	if (op === '-') ans = a - b;
	if (op === '*') ans = a * b;
	if (op === '/') ans = Math.floor(a / b);
	if (op === '?') break;
	console.log(ans);
}


Measured memory_bytes: 15432
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x=0,x1=0,max1=0;
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++) {if(s[i]=='I') x++;
	else x--;
	if(x>max1)max1=x;
	} 
	cout<<max1<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];

        int max = Integer.MIN_VALUE;
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] cnt = new int[max + 3];
        for (int i = 0; i < N; i++) {
            cnt[a[i] + -1 + 1]++;
            cnt[a[i] +  0 + 1]++;
            cnt[a[i] +  1 + 1]++;
        }

        int ans = Integer.MIN_VALUE;
        for (int i = 0; i < max + 2; i++) {
            ans = Math.max(ans, cnt[i]);
        }

        System.out.println(ans);
        return;
    }

}

Measured memory_bytes: 51504
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define m 1000000007
#define MAXN 1000001
#define satya ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cil(a,b) (((a-1)/b)+1)
//#define init int t;cin>>t;while(t--)
#define in(a) ll a;scanf("%lld",&a)
#define ine(a,b) ll a,b;scanf("%lld lld",&a,&b)



ll spf[MAXN]; 

void sieve1() 
{ 
	spf[1] = 1; 
	for (int i=2; i<MAXN; i++) 

		spf[i] = i; 

	for (int i=4; i<MAXN; i+=2) 
		spf[i] = 2; 

	for (int i=3; i*i<MAXN; i++) 
	{ 
		if (spf[i] == i) 
		{ 
			for (int j=i*i; j<MAXN; j+=i) 

				if (spf[j]==j) 
					spf[j] = i; 
		} 
	} 
} 

ll  getFactorization(int x) 
{ 
	vector<int> ret; 
	long long int p=0;
	while (x != 1) 
	{ 
		ret.push_back(spf[x]); 
		x = x / spf[x]; 
	} 
	sort(ret.begin(),ret.end());
	for(int i=0;i<ret.size()-1;i++) 
	{
	    if(ret[i]!=ret[i+1])
	    p=p+ret[i];
	}
	p=p+ret[ret.size()-1];
	return p;
} 

ll d[1000055],u=0;
	bool prime[100001]; 
void Sieve(int n) 
{ 
// 	bool prime[n+1]; 
//	ll u=0;
	memset(prime, true, sizeof(prime)); 

	for (int p=2; p*p<=n; p++) 
	{ 
		if (prime[p] == true) 
		{ 
			for (int i=p*2; i<=n; i += p) 
				prime[i] = false; 
		} 
	} 

	for (int p=2; p<=n; p++) 
	if (prime[p]) 
	{
	    d[u]=p;
	    u++;
	}
} 

ll minverse(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return minverse((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*minverse((x*x)%M,(n-1)/2,M))%M;

}
// ll prime(ll n){
//     ll i;
//     if(n==1||n==0)
//     return 0;
//     for(i=2;i<sqrt(n);i++)
//     {
//         if(n%i==0)
//         return 0;
//     }
//     return 1;
// }
int ftemp(int d)
{
    if(d==1)
    return 1;
   ll  temp=0;
   for(ll i=2;i<=d;i++)
   {
       if(d%i==0){
           if(prime[i]){
       if(d%(i*i)==0)
       {
           return 0;
       }
       temp++;
       }
       }
   }
   if(temp%2==0)
   return 1;
   return -1;
}
int main() {
       satya;
     //sieve1(); 
     Sieve(100000);
  double n;
  cin>>n;
  int  p=(n+1)/2;
 
  cout<<fixed<<setprecision(8)<<p/n<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AApplePie solver = new AApplePie();
        solver.solve(1, in, out);
        out.close();
    }

    static class AApplePie {
        private InputReader in;
        private PrintWriter out;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
            int n = in.nextInt();
            int p = in.nextInt();
            int tmp = n * 3 + p;
            out.println(tmp / 2);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 20436
#include<iostream>

using namespace std;

main(){
  int A,B;
  cin>>A>>B;
  if(A==1){
    if(B ==2)cout<<3<<endl;
    else cout<<2<<endl;
  }
  else if(A==2){
    if(B ==1)cout<<3<<endl;
    else cout<<1<<endl;
  }
  else{
    if(B ==2)cout<<1<<endl;
    else cout<<2<<endl;
  }
  return 0;
}

Measured memory_bytes: 3524
#include <stdio.h>
int main(){

    int n;
    int i,j;
    int row,col;
    int num;

    scanf("%d",&n);

    int matrix[n+1][n+1];

    for( i = 0 ; i <= n ; i++ ){
        for( j = 0 ; j <= n ; j++ ){
            matrix[i][j] = 0;
        }
    }

    for( i = 1 ; i <= n ; i++ ){

        scanf("%d",&row);
        scanf("%d",&col);

        for( j = 0 ; j < col ; j++ ){
            scanf("%d",&num);
            matrix[row][num] = 1;
        }

    }

    for( i = 1 ; i <= n ; i++ ){
        for( j = 1 ; j <= n ; j++ ){
            printf("%d",matrix[i][j]);

            if( j != n ){
                printf(" ");
            }

        }
    
       printf("\n");
    
    }


    return 0;

}

Measured memory_bytes: 636
N = int(input())

import math
Nq = int(math.sqrt(N+1))
#print ( Nq )

so = 0
for i in range(1,Nq+1):
  if (N%i != 0):
    continue
  if (N//i < i):
    continue
  
  m,r = (N//i)-1,i
  if ( r<m ):
    so += m
  
  m,r = i-1,(N//i)
  if (N//i != i):
    if (r<m):
      so += m

print ( so)

Measured memory_bytes: 40300
// https://atcoder.jp/contests/nomura2020/tasks/nomura2020_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int t1 = H1 * 60 + M1;
    int t2 = H2 * 60 + M2;
    cout << max(0LL, t2 - t1 - K) << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;

int main()
{
	int x;
	cin >> x;
	int cont = 0;
	if(x % 10 == 1)	cont++;
	if(x / 10 % 10 == 1)	cont++;
	if(x / 100 == 1)	cont++;
	cout << cont << endl;
	return 0;
}

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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        //int n; cin>>n; int arr[n]; for(int i = 0; i<n; i++) cin>>arr[i];
		int a,b,c; cin >> a >>b >> c;
		cout<< c << " " <<a << " "<< b;

		
		cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

sa = 0
min_v = float('inf')
minus_count = 0
for aa in a:
    if aa < 0:
        minus_count += 1
        aa = abs(aa)
    min_v = min(min_v, aa)
    sa += aa

if minus_count % 2 == 0:
    print(sa)
else:
    print(sa - min_v * 2)


Measured memory_bytes: 14412
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, T, A;
	cin >> N >> T >> A;
	double a = INF/2;
	int ans;
	for (int i = 0; i < N; i++) {
		double H;
		cin >> H;
		if (a > abs((double(T) - (0.006*double(H)) - A))) {
			a = abs((double(T) - (0.006*double(H)) - A));
			ans = i;
		}
	}

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

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int n = 0;
  int a = 0;
  int amin = 0;
  long int count = 0;
  
  scanf("%d",&n);
  while(n--){
    scanf("%d",&a);
    if(a > amin) amin = a;
    else count += amin - a;
      //printf("n=%d, a=%d, amin=%d, count=%ld\n", n, a, amin, count);
  }
  printf("%ld\n",count);
  return 0;
}


Measured memory_bytes: 2156
n = gets.chomp.to_i

h = Hash.new()
1.upto(n) do |i|
  a = gets.chomp.to_i
  h[i] = a
end

current = 1

1.upto(n) do |i|
  current = h[current]
  next unless current == 2

  puts i
  exit
end

puts -1





Measured memory_bytes: 10492
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    string s[10000];
    int i;
    for(i=0;i<N;i++){
        cin >> s[i];
    }
    int c0=0,j,c1=0,c2=0,c3=0;
    for(i=0;i<N;i++){
        for(j=0;j<(int(s[i].size()))-1;j++){
            if(s[i][j]=='A' && s[i][j+1]=='B'){
                c0 += 1;
            }
        }

        if(s[i][0]=='B' && s[i][(int(s[i].size()))-1]=='A'){
                c1 += 1;
        }
        else{
            if(s[i][0]=='B'){
                c2 += 1;
            }
            if(s[i][(int(s[i].size()))-1]=='A'){
                c3 += 1;
            }
        }
    }
    if(c2 + c3 == 0){
        if(c1==0){
            cout << c0<<endl;
        }
        else{
        cout << c0+c1-1<<endl;
        }
    }
    else{
        cout << c0+c1+min(c2,c3) <<endl;
    }
return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;

int main(){
    int N,T;cin>>N>>T;
    ll ans=0;
    ll last=0;
    REP(i,N){
        int t;cin>>t;
        if(t<last){
            ans+=t+T-last;
            last=t+T;
        }
        else{
            ans+=T;
            last=t+T;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      int sum = x + y;
      int z = S - sum;
      if (z <= K && z >= 0) {
	ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int weeks = s.nextInt();
        double debt = 100;
        while(weeks>0){
            debt = debt*1.05;
            debt = (int)Math.ceil(debt);
            weeks--;
        }
        System.out.println((int)debt*1000);
    }
}

Measured memory_bytes: 11000
// https://atcoder.jp/contests/abc084/tasks/abc084_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// constexprな素数列挙(エラトステネスの篩)
// https://259-momone.hatenablog.com/entry/2018/05/06/015026
template <int_fast64_t max_N> struct Prime {
    bool b[max_N];
    constexpr Prime() : b() {
        for (int_fast64_t i = 0; i < max_N; ++i)
            b[i] = true;
        b[0] = b[1] = false;
        for (int_fast64_t i = 2; i < max_N; ++i) {
            for (int_fast64_t j = i * i; j < max_N; j += i)
                b[j] = false;
        }
    }
};

// BIT(Binary-Indexed-Tree) 別名：Fenwick Tree
template <typename T> struct BIT {
    int n;
    vector<T> d;
    BIT(int n = 0) : n(n), d(n + 1) {}
    // 要素iにxを加算
    void add(int i, T x = 1) {
        for (i++; i <= n; i += i & -i) {
            d[i] += x;
        }
    }
    // 区間[0, i]の合計を求める（閉区間）
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i & -i) {
            x += d[i];
        }
        return x;
    }
};

const int SZ = 1e5 + 1;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    BIT<int> bit(SZ);
    constexpr auto prime = Prime<SZ>();
    for (int i = 1; i < SZ; i += 2) {
        if (prime.b[i] && prime.b[(i + 1) / 2]) {
            bit.add(i, 1);
        }
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << bit.sum(r) - bit.sum(l - 1) << "\n";
    }

    return 0;
}


Measured memory_bytes: 4280
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll W, a, b;
    cin >> W >> a >> b;

    if(W + a >= b){
        cout << max(0LL, (a-W) - b) << endl;
    }else{
        cout << max(0LL, b - (W + a)) << endl;
    }

}

Measured memory_bytes: 256
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll dp[100][100];
ll ncr(ll n,ll k)
{
	if(n==k || k==0)
	{
		return 1;
	}
	if(dp[n][k]!=-1)
	{
		return dp[n][k];
	}
	dp[n][k]=ncr(n-1,k)+ncr(n-1,k-1);
	return dp[n][k];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    // for (int i = 0; i <=54; ++i)
    // {
    // 	for (int j = 0; j<=54; ++j)
    // 	{
    // 		dp[i][j]=-1;
    // 	}
    // }
    // cout<<ncr(n,k);
    cout<<n-(k-1)<<'\n';
    // cout<<dp[n][k];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  string ans="No";
  rep(i,k){
    if(a>=b) b*=2;
    else if(b>=c) c*=2;
    if(a<b && b<c) ans="Yes";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;

int main()
{
    while (scanf("%d",&n)!=EOF)
    {
        if (n%4==0 || n%7==0) puts("Yes");
        else
        {
            int tt=n;
            while (tt>0)
            {
                if (tt%7==0) break;
                tt-=4;
            }
            if (tt%7==0) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}


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

using namespace std;


int main(){
  int K, X;
  cin >> K >> X;
  
  if(K==1){
    cout << X << endl;
    return 0;
  }else{
    for(int i=X-(K-1); i<=X+(K-1); i++){
      cout << i << " ";
    }
    cout << endl;
  }
  

  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n%1000==0)
	{
		cout<<"0"<<endl;
	}
	else
	{
		int x=n%1000;
		cout<<1000-x<<endl;
	}
	
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
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> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int n;cin >> n;
    vi p(n);
    cin >> p;

    vi ref(n);
    iota(all(ref), 1);

    if(ref == p){
        cout << "YES\n";
        return 0;
    }

    rep(i,n){
        for(int j=i+1;j<n;++j){
            swap(p[i], p[j]);
            if(p == ref){
                cout << "YES\n";
                return 0;
            }
            swap(p[i], p[j]);
        }
    }
    cout << "NO\n";
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  double A, B;
  double i;
  cin >> A >> B;
 

  for (i = 1; i < 13000; i++){
    if(floor(i * 0.08) == A && floor(i * 0.1) == B){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	char s[100]; cin >> s;
	cout << s[0] << s[1] << s[2] << "\n";
	
	return 0;
}


Measured memory_bytes: 3608
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K = MI()
LR = [tuple(MI()) for i in range(K)]
mod = 998244353

dp = [0]*(N+1)  # dp[i] = マス1に行く方法の個数 + マス2に行く方法の個数 + … + マスiに行く方法の個数
dp[1] = 1

for i in range(2,N+1):
    dp[i] = dp[i-1]
    for j in range(K):
        l,r = LR[j]
        dp[i] += dp[max(i-l,0)]-dp[max(i-r-1,0)]
        dp[i] %= mod

print((dp[N]-dp[N-1]) % mod)


Measured memory_bytes: 69748
#pragma GCC target ("arch=ivybridge,tune=ivybridge")
#include <cstdio>
#include <vector>
#include <utility>
#include <map>

/*
\cap_{u,v} \cup_{i\in (u,v) path} E_i

g(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} = N}|
G(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} \subseteq N}|
     = |{E | {u,v\in M-N | \cap_{i\in (u,v) path} !E_i}}|
*/

int n, m;
std::vector<int> E[50];

long long int M[20];
long long int A[1<<20];
std::map<std::pair<int, int>, int> edges;

long long int dfs(int u, int v, int p){
  if(u == v) return 0;
  for(int x: E[u]){
    if(x == p) continue;
    long long int b = dfs(x, v, u);
    if(b != -1) return (1LL << edges[{u, x}]) | b;
  }
  return -1;
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n-1; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    E[a-1].push_back(b-1);
    E[b-1].push_back(a-1);
    edges[{a-1,b-1}] = i;
    edges[{b-1,a-1}] = i;
  }
  scanf("%d", &m);
  for(int i = 0; i < m; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    M[i] = dfs(a-1, b-1, -1);   
  }
  long long int ans = 1LL << (n-1);
  for(int i = 0; i < m; i++){
    for(int j = 0; j < (1<<i); j++){
      int k = (1<<i) + j;
      A[k] = A[j] | M[i];
      long long int x = 1LL << (n-1-__builtin_popcountll(A[k]));
      ans += (1-2*__builtin_parity(k))*x;
    }
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 8448
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

use std::cmp::*;
const INI: i64 = 0;

fn main() {
    input! {
        n: usize,
        w: usize,
        wv: [(i64,i64);n],
    }

    let mut ws = vec![];
    let mut vs = vec![];
    for (e1, e2) in wv {
        ws.push(e1);
        vs.push(e2);
    }

    let mut dp = vec![vec![INI; w + 1]; n + 1];

    for i in 0..n {
        for j in 0..w + 1 {
            dp[i + 1][j] = if ws[i] <= j as i64 {
                max(dp[i][j], dp[i][j - ws[i] as usize] + vs[i])
            } else {
                dp[i][j]
            }
        }
    }

    println!("{}", dp[n][w]);
}


Measured memory_bytes: 106748
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	torikumi := nextLine()
	if strings.Count(torikumi, "o")+15-len(torikumi) >= 8 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

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

using namespace std;

int main() {
    int n, m = 0, tmp = 0;
    cin >> n;
    vector<int> a(n+1, 0), b(n+1, 0);

    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = n; i >= 1; i--) {
        tmp = 0;
        for (int j = 1; i * j <= n; j++) {
            tmp += b[i * j];
        }  
        if (tmp % 2 == 0) {
            a[i] == 0 ? b[i] = 0 : b[i] = 1;
        } else {
            if (a[i] == 0) {
                if (b[i] == 0) b[i] = 1;
                else b[i] = 0; 
            } 
        }
    }
    for (int i = 1; i <= n; i++) {
        m += b[i];
    }
    cout << m << endl;
    for (int i = 1; i <= n; i++) { 
        if (b[i] != 0) {
            cout << i;
            if (i != n) cout << " ";
        }
    }
    cout << endl;

}

Measured memory_bytes: 2432
package main

import (
	"fmt"
)

type ll int64

func main() {

	var N int
	fmt.Scan(&N)

	if ( N % 2 == 0) {
		fmt.Println(N*N/4)
	} else {
		var a = (N - 1) / 2
		fmt.Println(a*a + a)
	}

}





Measured memory_bytes: 512
import scala.io.StdIn
import java.io.{BufferedReader,InputStreamReader}

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val Array(n, t) = in.readLine.split(" ").map(_.toInt)
  val a = in.readLine.split(" ")

  val ans = a./:(t.toLong,0)((acc,e) => {
    val ti = e.toInt
    val dur = ti - acc._2
    if(dur < t) (acc._1 + dur, ti)
    else (acc._1 + t, ti)
  })._1

  println(ans)
}

Measured memory_bytes: 77304
#include <stdio.h>

int n,M[100][100];
void diks(){
  int minv,i,v,u;
  int d[100],col[100];

  for(i=0;i<n;i++){
    d[i]=999999;
    col[i]=0;
  }

  d[0]=0;
  col[0]=1;
  while(1){
    minv=999999;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && col[i]!=2){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1) break;
    col[u]=2;
    for(v=0;v<n;v++){
      if(col[v]!=2 && M[u][v]!=999999){
        if(d[v] > d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          col[v]=1;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==999999){printf("1\n");}
    else{printf("%d\n",d[i]);}
  }
}

int main(){
  int i,j,u,k,v,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=999999;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v]=c;
    }
  }
  diks();
  return 0;
}


Measured memory_bytes: 2088
#include <iostream>

using namespace std;

int main() {
    int m, d;
    cin >> m >> d;
    int answer;
    for (int i = 4; i <= m; ++i) {
        for (int j = 22; j <= d; ++j) {
            int d1 = j / 10, d2 = j % 10;
            if (d2 >= 2 && d1 * d2 == i) {
                ++answer;
            }
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 256