akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;
int N, M;
int s, c;
int main(void){
    cin >> N >> M;
    int res[N];
    REP(i,N) res[i] = -1;
    REP(i,M){
        cin >> s >> c;
        if(res[s-1] == -1 or res[s-1] == c){
            res[s-1] = c;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    if(N >= 2 and res[0] == 0){
        cout << -1 << endl;
        return 0;
    }

    if(N == 1 and res[0] == 0){
        cout << 0 << endl;
        return 0;
    }
    if(N == 1 and M == 0){
        cout << 0 << endl;
        return 0;
    }


    if(res[0] == -1) cout << 1;
    else cout << res[0];

    for(int t=1;t<N;t++){
        if(res[t] == -1) cout << 0;
        else cout << res[t];
    }
    cout << endl;
    return 0;
}



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

class Main{
    private static int[] d, f;
    private static int[][] g;
    private static int t = 0;
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        d = new int[n+1];
        f = new int[n+1];
        g = new int[n+1][n+1];
        for(int i = 0; i<n; i++){
            final StringTokenizer st = new StringTokenizer(br.readLine(), " ");
            final int u = Integer.parseInt(st.nextToken());
            final int k = Integer.parseInt(st.nextToken());
            g[u][0] = k;
            for(int j = 1; j<=k; j++){
                g[u][j] = Integer.parseInt(st.nextToken());
            }
        }
        for(int i = 1; i<=n; i++)
            if(d[i]==0) dfs(i);
        final StringBuilder sb = new StringBuilder();
        for(int i = 1; i<=n; i++){
            sb.append(i).append(' ').append(d[i]).append(' ').append(f[i]).append('\n');
        }
        System.out.print(sb);
    }
    private static void dfs(int e){
        if(d[e]!=0) return;
        d[e] = ++t;
        for(int i = 1, n = g[e][0]; i<=n; i++)
            dfs(g[e][i]);
        f[e] = ++t;
    }
}

Measured memory_bytes: 24884
import java.math.*;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();

        if (400<=n && n<=599) {
            System.out.print(8);
        } else if (600<=n && n<=799) {
            System.out.print(7);
        } else if (800<=n && n<=999) {
            System.out.print(6);
        } else if (1000<=n && n<=1199) {
            System.out.print(5);
        } else if (1200<=n && n<=1399) {
            System.out.print(4);
        } else if (1400<=n && n<=1599) {
            System.out.print(3);
        } else if (1600<=n && n<=1799) {
            System.out.print(2);
        } else if (1800<=n && n<=1999) {
            System.out.print(1);
        }
    }

}



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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef char* String;

int main(void){
    int N;
    scanf("%d",&N);

    String S;
    NEW(S,N+1);
    scanf("%s",S);

    int d=0;
    int x=0;
    int l=0;
    int r=0;
    for(int i=0;i<N;i++){
        if(S[i]=='(') l++;
        else r++;
        d=l-r;
        x=MIN(d,x);
    }

    for(int i=1;i<=(-x);i++) printf("(");
    printf("%s",S);
    for(int i=1;i<=(d-x);i++) printf(")");
    printf("\n");

    return 0;
}

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

int main() {
  int n,q;
  long long sum = 0;
  vector<int> x(pow(10,5)+1,0); // カウント用
  
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  cin >> q;
  vector<int> b(q), c(q);
  for(int i = 0; i < q; i++) cin >> b.at(i) >> c.at(i);
  
  for(int i = 0; i < n; i++) x.at(a.at(i)) += 1; // デフォルトカウント
  for(int i = 0; i < x.size(); i++) sum += x.at(i) * i; //デフォ合計
  
  for(int i = 0; i < q; i++) {
    sum += (c.at(i) - b.at(i)) * x.at(b.at(i));
    x.at(c.at(i)) += x.at(b.at(i)); // CiにBiを追加
    x.at(b.at(i)) = 0; // Biを削除
    cout << sum << endl; }
}

Measured memory_bytes: 4824
#include <iostream>

int main()
{
    int org_a;
    int ang = 0;
    std::cin >> org_a;
    int k = 0;
    while (1) {
        k++;
        ang += org_a;
        if (ang % 360 == 0) {
            std::cout << k << std::endl;
            break;
        }

    }
}


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

count = 0
for i in range(N):
    divisor_count = 0
    for j in range(i + 1):
        # 偶数は対象外
        if (j + 1) % 2 == 0:
            continue
        if (i + 1) % (j + 1) == 0:
            divisor_count += 1
    if divisor_count == 8:
        count += 1
print(count)


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll H, N;
vector<ll> As;
vector<ll> Bs;


ll solve_fast(ll N, vector<ll>& As, vector<ll>& Bs) {
    vector<vector<ll>> dp(N + 1, vector<ll>(H + 10010, 1e18));
    dp[0][0] = 0;
    REP(i, N) {
        ll a = As[i];
        ll b = Bs[i];

        dp[i + 1][0] = 0;
        REP(k, 1e9) {
            if (a * k >= H * 2 + 10) break;
            dp[i + 1][a * k] = b * k;
        }

        // 本番時はこれでWA
        // 魔力1で体力10000減らせる魔法があり、
        // かつH = 100のときに失敗
        // REP(j, H * 2 + 10) {

        // 正しくは以下
        REP(j, H + 10000) {
            dp[i + 1][j] = min(dp[i + 1][j],
                               dp[i][j]);
            if (j - a >= 0) {
                if (dp[i][j - a] != 1e18) {
                    dp[i + 1][j] = min(dp[i + 1][j],
                                       dp[i][j - a] + b);
                }
                if (dp[i + 1][j - a] != 1e18) {
                    dp[i + 1][j] = min(dp[i + 1][j],
                                       dp[i + 1][j - a] + b);
                }
            }
        }
    }

    ll ans = 1e18;

    // 本番時は以下
    // FOR(h, H, H * 2 + 10) {

    // 正しくは以下
    FOR(h, H, H + 10000) {
        ans = min(ans, dp[N][h]);
    }
    return ans;
}

int main(void)
{
    cin.sync_with_stdio(false);
    cin >> H >> N;
    As.resize(N);
    Bs.resize(N);
    REP(n, N) {
        cin >> As[n] >> Bs[n];
    }
    cout << solve_fast(N, As, Bs) << endl;

    return 0;
}


Measured memory_bytes: 160640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int ans = 700;
    for(int i=0; i<3; i++){
        char c; cin >> c;
        if(c == 'o') ans += 100;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#!/usr/bin/env python

def main():
    S = input()

    S1 = int(S[:2])
    S2 = int(S[2:])
    
    if 0 < S1 and S1 < 13 and 0 < S2 and S2 < 13:
        return 'AMBIGUOUS'
    elif 0 < S1 and S1 < 13:
        return 'MMYY'
    elif 0 < S2 and S2 < 13:
        return 'YYMM'
    else:
        return 'NA'

if __name__ == '__main__':
    print(main())

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

int main() {
    int A, B;
    std::cin >> A >> B;
    if ((A - B) % 2 == 0) {
        std::cout << (A + B) / 2 << std::endl;
    } else {
        std::cout << "IMPOSSIBLE" << std::endl;
    }
}


Measured memory_bytes: 3620
def modinv2(a,m):
    return pow(a,m-2,m)

def modcomn(n,r,m):
    modcom = [0 for _ in range(n)]
    for i in range(n):
        if i < r-1:
            continue
        if i == r-1:
            modcom[i] = 1
        elif i == r:
            modcom[i] = (i+1)%m
        else:
            div = modinv2(i-r+1,m)
            modcom[i] = (modcom[i-1]*div%m)*(i+1)%m
    return modcom

N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
P = 10**9+7

com = modcomn(N-1,K-1,P)

#print(com)
ans = 0

for i in range(N):
    if i >= K-1:
        ans = (ans+A[i]*com[i-1]%P)%P

A.sort(reverse=True)
for i in range(N):
    if i >= K-1:
        ans = (ans-A[i]*com[i-1]%P+P)%P

print(ans)


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

int main() {
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    for (auto& e : a) cin >> e;

    cout << (n == 1 ? abs(a[0] - w) : max(abs(a[n-2] - a[n-1]), abs(a[n-1] - w))) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int min_of_common(int a0, int a1, int b0, int b1) {
  if (a0 > a1 || b0 > b1) return -1;
  if (a0 >= b0 && a0 <= b1) return a0;
  if (b0 >= a0 && b0 <= a1) return b0;
  return -1;
}

int modify(int current, int target, double tax) {
  while ((int)(current * tax) < target) current++;
  while ((int)(current * tax) > target) current--;
  return current;
}

int main() {
  int A, B;
  const double tax_a = 0.08, tax_b = 0.1;
  scanf("%d %d", &A, &B);
  const int
    A0 = modify(A / tax_a, A, tax_a),
    A1 = modify((A + 1) / tax_a, A, tax_a),
    B0 = modify(B / tax_b, B, tax_b),
    B1 = modify((B + 1) / tax_b, B, tax_b);
  printf("%d\n", min_of_common(A0, A1, B0, B1));
  return 0;
}


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

int main(){
  int A,B,K;cin>>A>>B>>K;
  int X=B-A+1;
  if(X<=2*K){
    for(int i=A;i<=B;i++) cout<<i<<endl;
  }
  else{
    for(int i=A;i<A+K;i++) cout<<i<<endl;
    for(int i=B-K+1;i<=B;i++) cout<<i<<endl;
  }
}


Measured memory_bytes: 3568
a = raw_input().strip().split()
[n,m,X,Y] = [int(i) for i in a]
x = raw_input().strip().split()
x = [int(i) for i in x] + [X]
y = raw_input().strip().split()
y = [int(i) for i in y] + [Y]
x_m = max(x)
y_m = min(y)
if (x_m < y_m):
	print("No War")
else:
	print("War")

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if(a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }
  
  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

int main() {
  std::cout << std::setprecision(9);
  int k;
  cin >> k;

  if(k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
  }
  else {
    int r = 7 % k;
    int count = 1;
    while(r != 0 && count < 2 * k) {
      r *= 10;
      r += 7;
      r %= k;
      count++;
    }

    if(count <= k) {
      cout << count << endl;
    }
    else {
      cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 3640
import java.util.Scanner;

/**
 * Created by wild on 16/08/13.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            num[i] = scan.nextInt();
        }

        int resultMin = Integer.MAX_VALUE;

        for (int i = -100; i <= 100; i++) {
            int resultTmp = 0;
            for (int j = 0; j < num.length; j++) {
                resultTmp += Math.pow(num[j] - i, 2);
            }
            if (resultTmp < resultMin) {
                resultMin = resultTmp;
            }
        }

        System.out.println(resultMin);
    }
}

Measured memory_bytes: 9552
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    
    ll int cnt = 0;
    
    for(ll int i=0; i<3; i++)
        if(s[i] == t[i])
            cnt++;
        
    cout<<cnt;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N, X[100], P = 0, ave, ans[100], an = 0,a=0;

	scanf("%d",&N);
	for (int i = 0; i < N;i++) {
		scanf("%d",&X[i]);
		P = P + X[i];
		ans[i]=0;
	}
	ave = P / N;

	for (int i = 1; i <= 100;i++) {
		for (int j = 0; j < N; j++) {
			a = a + (X[j] - i) * (X[j] - i);
		}
		if (i==1|| an > a) {
			an = a;
		}
		a = 0;
	}
	printf("%d",an);

	return 0;
}

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

int main() {
	char TAP[100];
	int x=0;
	cin >> TAP;
	
	for (int i = 1; TAP[i - 1] != '\0'; i++) {
		if (i % 2 == 1) {
			if (TAP[i-1] == 'R' || TAP[i-1] == 'U' || TAP[i-1] == 'D') {
			}
			else {
				x += 1;
			}
		}
		else {
			if (TAP[i-1] == 'L' || TAP[i-1] == 'U' || TAP[i-1] == 'D') {
			}
			else {
				x += 1;
			}
		}
	}

	if (x == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

#[macro_use]
mod _input {
    use std::fmt;
    use std::io::{self, Read};
    use std::str::{self, FromStr};

    macro_rules! input {
        ($($name:ident : $t:tt),*,) => {
            input!($($name: $t),*)
        };
        ($($name:ident : $t:tt),*) => {
            let mut _scanned = ::_input::Scanned::new(::std::io::stdin(), 1024);
            $(
                let $name = unsafe { _read_value!(_scanned, $t) };
            )*
        };
    }

    macro_rules! _read_value {
        ($scanned:expr, ($($t:tt),*)) => {
            ($(_read_value!($scanned, $t)),*)
        };
        ($scanned:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| _read_value!($scanned, $t)).collect::<Vec<_>>()
        };
        ($scanned:expr, _bytes) => {
            _read_value!($scanned, String).into_bytes()
        };
        ($scanned:expr, _1based) => {
            _read_value!($scanned, usize) - 1
        };
        ($scanned:expr, $t:ty) => {
            $scanned.next::<$t>()
        };
    }

    pub struct Scanned {
        buf: Vec<u8>,
        pos: usize,
    }

    impl Scanned {
        pub fn new<R: Read>(mut input: R, estimated: usize) -> Self {
            let mut buf_ = Vec::with_capacity(estimated);
            let _ = io::copy(&mut input, &mut buf_).unwrap();
            debug_assert!(str::from_utf8(&buf_).is_ok());
            debug_assert!(buf_.iter().all(|&c| u32::from(c) <= 0x7F));
            Scanned { buf: buf_, pos: 0 }
        }

        #[inline]
        pub unsafe fn next<T: FromStr>(&mut self) -> T
        where
            T::Err: fmt::Debug,
        {
            let mut start = None;
            loop {
                match (self.buf[self.pos], start.is_some()) {
                    (b' ', true) | (b'\n', true) => break,
                    (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                    (_, false) => start = Some(self.pos),
                }
            }
            let target = &self.buf[start.unwrap()..self.pos];
            str::from_utf8_unchecked(target).parse().unwrap()
        }
    }
}

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Stderr, StderrLock, Stdout, StdoutLock, Write};
use std::iter::{self, Product, Sum};
use std::num::{ParseFloatError, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Deref,
    DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, mem, thread, u16, u32, u64, u8};

fn main() {
    input! {
        r: u64,
        g: u64,
        b: u64,
        n: u64,
    }
    let mut a = 0;
    for s in 0..n / b + 1 {
        for t in 0..n / g + 1 {
            let k = b * s + g * t;
            if n >= k && (n - k) % r == 0 {
                a += 1;
            }
        }
    }
    println!("{}", a);
}


Measured memory_bytes: 4352
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int n;
	string s[1000];
	while (cin >> n&&n) {
		int ans = 0;
		string s,ss;
		for (int i = 0; i < n; i++) {
			cin >> s;
			if (s == "lu"&&ss == "ru")ans++;
			if (s == "ru"&&ss == "lu")ans++;
			if (s == "ld"&&ss == "rd")ans++;
			if (s == "rd"&&ss == "ld")ans++;
			ss = s;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n,k,i;
    cin>>n>>k;
    vector<int> v;
    for(i=0;i<n;i++)
    {
    	int x;
    	cin>>x;
    	v.pb(x);
	}
	int c=0;
	for(i=k;i<n;i++)
	{
		if(v[i]>v[i-k])
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
    
	return 0;
}

Measured memory_bytes: 5304
#include<cstdio>
#include<iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++ )
#define MAX 1000
#define INFTY (1<<21)
struct Point {int x, y;};
int H, W, sy, sx, gy, gx, cnt[5];
Point P[5][MAX];
int D[5][MAX];
inline int mdist(int x1, int y1, int x2, int y2) {
	//??????????????????????????????????????????max min??§??????????????°?????????
	return max(x1, x2) - min(x1, x2) + max(y1, y2) - min(y1, y2);
}
void compute() {
	int opts, optc = INFTY;
	int t;
	//s???start????????????
	rep(s, 5){
		rep(i, 5)
			rep(j, cnt[i])
				D[i][j] = INFTY;//??????D???int??????????????§?????????DP??????D????????????????????????
		t = (s + 1) % 5;
		rep(j, cnt[t])
			D[t][j] = mdist(sx, sy, P[t][j].x, P[t][j].y);
		//D[t]?????????????????¨??????t?????????????°´??¨????????§j???????????????
		//start???st??¨??¨??????st????????????????????¢???mdsit??§.st??¨sx??§??¨????????????
		for (int i = s + 1; i < s + 5; i++) {
			int b = (i) % 5;
			int e = (i + 1) % 5;
			rep(k, cnt[b])
				rep(l, cnt[e]){
			//DP
			D[e][l] = min(D[e][l],D[b][k]	+ mdist(P[b][k].x, P[b][k].y, P[e][l].x,P[e][l].y));
			}
		}
		t = (s + 4) % 5;
		rep(j, cnt[t] )	{
			//??????????????????(????????????)if(?????§????????§????????£??????????????§????????§???????????????)
			if (D[t][j] + mdist(gx, gy, P[t][j].x, P[t][j].y) < optc) {
				optc = D[t][j] + mdist(gx, gy, P[t][j].x, P[t][j].y);
				//s??????????????§???????????????
				opts = s;
			}
		}
	}
	if (optc == INFTY)
		cout << "NA" << endl;
	else
		cout << opts + 1 << " " << optc << endl;
}
int main() {
	char ch;
	while(cin >> W >> H && W) {
		rep(i, 5) cnt[i] = 0;
		rep(y, H) rep(x, W) {cin >> ch;if ( ch == '.' ) continue;if ( ch == 'S' ) {sy = y; sx = x;} else if ( ch == 'G' ) {gy = y; gx = x;} else {int p = ch -'0' - 1;P[p][cnt[p]].x = x;P[p][cnt[p]++].y = y;}}
		compute();
	}
	return 0;
}


//rep(y, H) rep(x, W) {cin >> ch;if ( ch == '.' ) continue;
//if ( ch == 'S' ) {sy = y; sx = x;}
//else if ( ch == 'G' ) {gy = y; gx = x;}
//else {int p = ch -'0' - 1;
//P[p][cnt[p]].x = x;P[p][cnt[p]++].y = y;}}

Measured memory_bytes: 3024
d = int(input())
cl = list(map(int, input().split()))
sl = []
for _ in range(d):
    sl.append(list(map(int, input().split())))

tl = []
for _ in range(d):
    tl.append(int(input()))

last_di = [-1]*26
ans = 0
for day, t in enumerate(tl):
    ans += sl[day][t-1]
    last_di[t-1] = day
    for ld, c in zip(last_di, cl):
        # if ld == -1: continue
        ans -= (day-ld)*c
    print(ans)

Measured memory_bytes: 68696
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	var t string
	for i := 0; i < len(s); i++ {
		if i%2 == 0 {
			t = t + s[i:(i+1)]
		}
	}
	fmt.Println(t)
}


Measured memory_bytes: 7680
#include <stdio.h>
#include <math.h>
int main()
{
    int a,b,k,i,j,l;
    scanf("%d%d",&a,&b);
    if(a>b)
    {
       k=a-b;
       if(k%2==0)
       {
           i=k/2;
           b=b+i;
           printf("%d",b);
       } 
       else
       {
           printf("IMPOSSIBLE");
       }
    }
    else if(a<b)
    {
        j=b-a;
        if(j%2==0)
        {
            l=j/2;
            a=a+l;
            printf("%d",a);
        }
        else
        {
            printf("IMPOSSIBLE");
        }
    }
    else
    {
        printf("%d",a);
    }
    
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

string s;

int main() {
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

namespace ConsoleApp69 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            int pow = 0;

            while(N != 1) {
                N /= 2;
                pow++;
            }

            Console.WriteLine(Math.Pow(2, pow));
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	string s;
	cin>>s;
	bool all9 = 1;
	int K = s.size();
	rep1(i,K-1){
		if(s[i]!='9') all9 = 0;
	}
	if(all9){
		cout<<(K-1)*9+s[0]-'0'<<endl;
	}else{
		cout<<(K-1)*9+s[0]-'0'-1<<endl;
	}
}


Measured memory_bytes: 256
s = input()
t = input()
s_prime = ''.join(sorted(list(s)))
t_prime = ''.join(reversed(sorted(list(t))))
# print(s_prime,t_prime)
box1 = [s_prime,t_prime]
box2 = sorted(box1)
# print(box1,box2)
if box1 != box2 or s_prime == t_prime:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
# include<bits/stdc++.h>
using namespace std;
int main (){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b and b==c){
        cout<<1;
    }
    else if (a!=b and b!=c and a!=c){
        cout<<3;
    }
    else {
        cout<<2;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int w,h,x,y; cin >> w >> h >> x >> y;
  double ans = (double)w*h/2;
  printf("%.10f", ans); cout << " ";
  if(w == x*2 && h == y*2) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np


n, a = map(int, input().split())
X = np.array(list(map(int, input().split())))
X -= a

plus = X[X > 0]
zero = X[X == 0]
minus = abs(X[X < 0])

num_count = np.zeros(2551, dtype=np.int64)
num_count[0] = 1

for num in plus:
    num_count[num:] = num_count[:-num] + num_count[num:]

for num in minus:
    num_count[:-num] = num_count[:-num] + num_count[num:]

ans = 2 ** len(zero) * (num_count[0])

print(ans-1)


Measured memory_bytes: 12504
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{
  int D, G;
  cin >> D >> G;

  int p[D + 1], c[D + 1];

  repd(h, 1, D + 1)
  {
    cin >> p[h] >> c[h];
  }

  int ans = 1001;
  repd(i, 1, pow(2, D) + 1)
  {
    int score = 0;
    int cnt = 0;

    rep(j, D)
    {
      if (i & 1 << j)
      {
        // j番目の問をComplete
        cnt += p[j + 1];
        score += 100 * (j + 1) * p[j + 1] + c[j + 1];
      }
    }
    // 足りない点数分の問を解く
    if (G > score)
    {
      repdm(k, D, 0)
      {
        if ((i & 1 << (k - 1)) == 0)
        {
          int remain = ceil((float)(G - score) / (float)(100 * k));
          if (remain <= p[k])
          {
            cnt += remain;
            score += remain * 100 * k;
          }
          else
          {
            cnt += p[k];
            score += p[k] * 100 * k;
          }
        }
        if (score >= G)
          break;
      }
    }

    if (ans > cnt)
    {
      ans = cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll a;
    cin >> a;
    prt(a+a*a+a*a*a);

    return 0;
}



Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 22 11:38:11 2015

@author: hirose
"""

# -*- coding: utf-8 -*-

from random import *
import copy

def command(hougaku, label):
    temp = {}
    temp = copy.deepcopy(label)
    if(hougaku == 'E'):
        label[1] = temp[4]
        label[3] = temp[1]
        label[4] = temp[6]
        label[6] = temp[3]
    elif(hougaku == 'W'):
        label[1] = temp[3]
        label[3] = temp[6]
        label[4] = temp[1]
        label[6] = temp[4]
    elif(hougaku == 'N'):
        label[1] = temp[2]
        label[2] = temp[6]
        label[5] = temp[1]
        label[6] = temp[5]
    elif(hougaku == 'S'):
        label[1] = temp[5]
        label[2] = temp[1]
        label[5] = temp[6]
        label[6] = temp[2]

if __name__=="__main__":
    n = input()
    label = {}
    for i in range(n):
        label[i] = {}
        temp = map(int, raw_input().split())
        for j in range(6):
            label[i][j+1] = temp[j]
        #print label[i]
    flag = 0
    for i in range(n-1):
        #print label[i]
        for j in range(i+1,n):
            count = 0
            #print label[j]
            while True:
                if(label[i] == label[j]):
                    flag = 1
                    break
                x = random()
                if(x < 0.25):
                    command('E', label[j])
                elif(x < 0.50):
                    command('W', label[j])
                elif(x < 0.75):
                    command('N', label[j])
                else:
                    command('S', label[j])
                count += 1
                if(count > 50):
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if(flag == 0):
        print 'Yes'
    else:
        print 'No'

Measured memory_bytes: 5628
import math

A,B,H,M=map(int,input().split())
sital=30*H+0.5*M
sitas=6*M
sita=min(abs(sital-sitas),360-abs(sital-sitas))
co=math.cos(math.radians(sita))
L=A*A+B*B-2*A*B*co
l=L**0.5
print(l)

Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x; cin>>x;
    cout<<(x>=30 ?  "Yes\n" : "No\n");
    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >>c;
  if (c>=a && c <=b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] sort = new int[3];
        sort[0] = sc.nextInt();
        sort[1] = sc.nextInt();
        sort[2] = sc.nextInt();
        Arrays.sort(sort);
        System.out.println(sort[0] + " " + sort[1] + " " + sort[2]);
        sc.close();
        
    }
    
}


Measured memory_bytes: 26212
import java.util.Scanner;

/**
 * ABC043B
 */
public class Main {

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

        String S = sc.nextLine();
        StringBuilder ans = new StringBuilder();

        for (int i = 0; i < S.length(); i++) {
            char c = S.charAt(i);

            if (c == '0') {
                ans.append('0');
            } else if (c == '1') {
                ans.append('1');
            } else if (c == 'B') {
                if (ans.length() != 0) {
                    ans.deleteCharAt(ans.length() - 1);                    
                }
            }
        }

        System.out.println(ans.toString());
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

int main() {
	int n;
	std::cin >> n;

	const int INF = (int)1e9 + 10;

	std::vector<long long> x(n), y(n);
	long long rmax = -INF;
	long long rmin = INF;
	long long bmax = -INF;
	long long bmin = INF;
	for (int i = 0; i < n; i++) {
		std::cin >> x[i] >> y[i];
		if (x[i] > y[i]) {
			std::swap(x[i], y[i]);
		}
		rmax = std::max(rmax, y[i]);
		rmin = std::min(rmin, y[i]);
		bmax = std::max(bmax, x[i]);
		bmin = std::min(bmin, x[i]);
	}
	auto max = std::max_element(y.begin(), y.end()) - y.begin();
	auto min = std::min_element(x.begin(), x.end()) - x.begin();

	long long ans = (rmax - rmin) * (bmax - bmin);

	if (max == min) {
		std::cout << ans << std::endl;
		return 0;
	}

	long long R = rmax - bmin;

	bmax = std::max(x[max], y[min]);
	bmin = std::min(x[max], y[min]);
	if (max < min) {
		std::swap(min, max);
	}
	x.erase(x.begin() + max);
	y.erase(y.begin() + max);
	x.erase(x.begin() + min);
	y.erase(y.begin() + min);
	n -= 2;

	for (int i = 0; i < n; i++) {
		if (x[i] > bmax) {
			bmax = x[i];
		}
		if (y[i] < bmin) {
			bmin = y[i];
		}
	}
	std::vector<long long> X, Y;
	for (int i = 0; i < n; i++) {
		if (x[i] < bmin && bmax < y[i]) {
			X.push_back(x[i]);
			Y.push_back(y[i]);
		}
	}

	std::vector<std::pair<long long, long long>> XY(X.size());
	for (int i = 0; i < X.size(); i++) {
		XY[i] = std::make_pair(X[i], Y[i]);
	}
	std::sort(XY.begin(), XY.end());
	for (int i = 0; i < XY.size(); i++) {
		std::tie(X[i], Y[i]) = XY[i];
	}

	for (int i = 0; i < X.size(); i++) {
		ans = std::min(ans, R * (bmax - X[i]));
		bmax = std::max(bmax, Y[i]);
	}
	ans = std::min(ans, R * (bmax - bmin));
	std::cout << ans << std::endl;
}

Measured memory_bytes: 3328
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)


def solve(h, w, matrix):
    dp = [[[0, False] for x in range(w)] for y in range(h)]
    for row in range(h):
        for col in range(w):
            dp[row][col][1] = matrix[row][col] == "#"
            prev = False
            if row > 0 and col > 0:
                if dp[row-1][col][0] < dp[row][col-1][0]:
                    prev = dp[row-1][col][1]
                    dp[row][col][0] = dp[row-1][col][0]
                elif dp[row-1][col][0] > dp[row][col-1][0]:
                    prev = dp[row][col-1][1]
                    dp[row][col][0] = dp[row][col-1][0]
                else:
                    prev = dp[row-1][col][1] or dp[row][col-1][1]
                    dp[row][col][0] = dp[row][col-1][0]
            elif row > 0:
                prev = dp[row-1][col][1]
                dp[row][col][0] = dp[row-1][col][0]
            elif col > 0:
                prev = dp[row][col-1][1]
                dp[row][col][0] = dp[row][col-1][0]
            if dp[row][col][1] and not prev:
                dp[row][col][0] += 1
    return dp[h-1][w-1][0]


if __name__ == "__main__":
    h, w = arr_in()
    matrix = [str_in() for x in range(h)]
    out(solve(h, w, matrix))

Measured memory_bytes: 43760
#include<cstdio>
#include<iostream>

using namespace std;

const int maxn = 1e5+5;
int pa[maxn];
int Mrk[maxn];

int qt[maxn],qv[maxn];
int Qt;
int fdst(int x)
{
    return Mrk[x] < Qt ? x :pa[x] = fdst(pa[x]);
}


int main()
{
    int N, Q;
    while(scanf("%d%d",&N,&Q),N){
        for(int i = 2; i <= N; i++){
            scanf("%d",pa+i);
            Mrk[i] = Q+1;
        }
        int c = 0;
        for(int i = 1; i <= Q; i++){
            char op[2];
            int v;
            scanf("%s%d",op,&v);
            if(*op == 'Q'){
                qt[c] = i;
                qv[c++] = v;
            }else {
                Mrk[v] = min(Mrk[v],i);//取最早生效的??
            }
        }
        long long ans = 0;
        while(c--){
            Qt = qt[c];
            ans += fdst(qv[c]);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#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 REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int a,b,c;cin>>a>>b>>c;
    cout<<a*b/2<<endl;
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class ECountMedian {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<lint> A(N), B(N);
        REP(i, N){
            in>>A[i]>>B[i];
            if(N%2==0) A[i] *= 2, B[i] *= 2;
        }
        sort(ALL(A));
        sort(ALL(B));
        if(N%2) out<<B[N/2]-A[N/2]+1<<'\n';
        else out<<(B[N/2-1]+B[N/2])/2-(A[N/2-1]+A[N/2])/2+1<<'\n';
    }
};


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


Measured memory_bytes: 6344
#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 ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, x, t;
    cin >> n >> x >> t;
    ll div = n / x;
    ll ans = div * t;
    if(n % x) {
    	ans += t;
    }
    cout << ans << "\n";
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
 
const ll MOD = 1000000007;

int main() {
   int n; scanf("%d", &n);
   vector<int> a(n);
   for (int &i : a)
      scanf("%d", &i);
   vector<int> pre = {a[0]};
   for (int i = 1; i < n; i++)
      pre.pb(max(pre.back(), a[i]));
   ll ans = 0;
   for (int i = 0; i < n; i++)
      ans += pre[i] - a[i];
   printf("%lld", ans);
   return 0;
}

Measured memory_bytes: 5116
k=int(input())
if k&1==0 or k%5==0:
  print(-1)
  exit()
elif 7%k==0:
  print(1)
  exit()
m=7
a=b=1
while(m>0):
  a=a*10%k
  m=(m+7*a)%k
  b+=1
print(b)

Measured memory_bytes: 9084
class Combination():  # nCr(mod p) #n<=10**6
    def __init__(self, N, MOD):  # cmbの前処理
        self.mod = MOD
        self.FACT = [1, 1]  # 階乗
        self.INV = [0, 1]  # 各iの逆元
        self.FACTINV = [1, 1]  # 階乗の逆元
        for i in range(2, N + 1):
            self.FACT.append((self.FACT[-1] * i) % self.mod)
            self.INV.append(pow(i, self.mod - 2, self.mod))
            self.FACTINV.append((self.FACTINV[-1] * self.INV[-1]) % self.mod)

    def count(self, N, R):  # nCr(mod p) #前処理必要
        if (R < 0) or (N < R):
            return 0
        R = min(R, N - R)
        return self.FACT[N] * self.FACTINV[R] * self.FACTINV[N-R] % self.mod


n, k = map(int, input().split())
r = n - k
mod = 10 ** 9 + 7

cmb = Combination(n, mod)
for i in range(1, k + 1):
    ans = cmb.count(r + 1, i) * cmb.count(k - 1, i - 1)
    print(ans % mod)


Measured memory_bytes: 68516
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    ll a, b, c; cin >> a >> b >> c;
    if (c - a - b < 0) cout << "No" << endl;
    else {
        if (4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes" << endl; 
        else cout << "No" << endl;
    }
}



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



int main(){
    int N; cin >> N;
    vector<int> a(N);
    map<int, int> cnt;
    for(int i=0; i<N; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    int ans=0;
    for(auto itr=cnt.begin(); itr!=cnt.end(); itr++){
        //cout << itr->first <<" "<< itr->second << endl;
        if(itr->first != itr->second){
            if(itr->first < itr->second){
                ans += itr->second-itr->first;
            }
            else {
                ans += itr->second;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define inf 2000000000
#define INF 1e18
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll a[100005];
int main()
{
    fastread;
     ll i,j,k,n,m,y,t;
    cin>>n;
   // m=(ll)(pow(n,1/5));
    //cout<<m;
    ll res;
   for(i=-1000;i<=1000;i++){
   // k=(ll)(pow(i,5));
   for(j=-1000;j<=1000;j++){
    res=(i*i*i*i*i)-(j*j*j*j*j);
    if(res==n){
        cout<<i<<" "<<j;
        return 0;
              }
         }
     }
   return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5+10;
#define ll long long
#define F first
#define S second

int dx[2]={+1,-1};
char ch[2]={'+','-'};
main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	char a,b,c,d;cin>>a>>b>>c>>d;
	int aa=a-'0',bb=b-'0',cc=c-'0',dd=d-'0';
//	cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<endl;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<2;k++)
				if(aa+bb*dx[i]+cc*dx[j]+dd*dx[k]==7){
					cout<<aa<<ch[i]<<bb<<ch[j]<<cc<<ch[k]<<dd<<"=7";
					return 0;
				}
}

Measured memory_bytes: 256