akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  int a, b;
  char op;

  cin >> a >> op >> b;

  if(op == '+') FINA(a+b);
  else FINA(a-b);

 return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

char c;
void input()
{
    cin>>c;
    return;
}

void solve()
{
    cout<<(char)((int)c+1)<<endl;
    return;
}

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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
static const int lim = 1000001;
vector<int> dp(lim,0);
int main() {

	for (int s = 1; s < lim; s *= 2) {
		for (int t = s; t < lim; t *= 3) {
			for (int u = t; u < lim; u *= 5) {
				dp[u] = 1;
			}
		}
	}
	for (int i = 1; i < lim; i++)dp[i] += dp[i - 1];


	int m, n;
	while (cin >> m >> n, m) {
		cout << dp[n] - dp[m - 1] << endl;
	}


	return 0;
}

Measured memory_bytes: 6532
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  vector<int> x(N);
  rep(i,N){
    cin>>x[i];
  }
  
  int P=1;
  int M=10000000;
  
  while(P<=100){
    int c=0;
    for(int i=0;i<N;++i){
      int d=(P-x[i])*(P-x[i]);
      c+=d;
    }
    M=min(M,c);
    ++P;
  }
  
  cout<<M<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using lint = long long int;
using Graph = std::vector<std::vector<lint>>;

template<class T>
struct edge
{
	T dist;
	lint to;
	edge(){}
	edge(const T &a_dist,const lint &a_to) : dist(a_dist), to(a_to) {}
	~edge(){}
};

int main(int argc,char *argv[])
{
	lint n;
	std::cin >> n;

	lint cnt = 0;
	lint left = 1, right = n-1;
	while(left < right)
	{
		if(left + right == n) cnt++;
		++left, --right;
	}

	std::cout << cnt << std::endl;

	return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

char char_to(char c, i32 n) {
    i32 a = c - 'A';
    return (char)('A' + (a + n) % 26);
}

void Main() {
    i32 N;
    cin >> N;
    string S;
    cin >> S;
    for (i32 i = 0; i < S.size(); i++) {
        S[i] = char_to(S[i], N);
    }
    cout << S << endl;

}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static String[] hash = new String[1000005];

	/*
	 * PrintWriterのフラッシュを使わずに毎回コンソールに出力してみる
	 */

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {

			int n = Integer.parseInt(br.readLine());
			br.lines().limit(n).forEach(line -> {

				String[] str = line.split(" ");
				if (str[0].equals("insert")) {
					insert(str[1]);
				} else {
					String ans = find(str[1]) ? "yes" : "no";
					System.out.println(ans);
				}
			});

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// 文字から数値に変換
	static int getChar(char c) {
		switch (c) {
		case 'A':
			return 1;
		case 'C':
			return 2;
		case 'G':
			return 3;
		case 'T':
			return 4;
		default:
			return 0;
		}
	}

	// 文字列から数値に変換してkeyを生成する
	static long getKey(String str) {
		long sum = 0;
		for (int i = 0, p = 1; i < str.length(); i++, p *= 5) {
			sum += p * str.charAt(i);
		}
		return sum;
	}

	// ハッシュ関数
	static int h1(long key) {
		return (int) (key % hash.length);
	}

	static int h2(long key) {
		return (int) (key % hash.length - 1) + 1;
	}

	static boolean find(String str) {
		long key;
		int index;
		key = getKey(str);
		// TODO 配列エラーが起こるかもしれない
		for (int i = 0;; i++) {
			index = (h1(key) + i * h2(key)) % hash.length;
			if (hash[index] == null) {
				return false;
			} else if (hash[index].equals(str)) {
				return true;
			}
		}

	}

	static boolean insert(String str) {
		long key;
		int index;
		key = getKey(str);
		// TODO 配列エラーが起こるかもしれない
		for (int i = 0;; i++) {
			index = (h1(key) + i * h2(key)) % hash.length;
			// TODO 重複した文字列を格納して良いのか？
			if (hash[index] == null) {
				hash[index] = str;
				return true;
			} else if (hash[index].equals(str)) {
				return false;
			}
		}
	}

}



Measured memory_bytes: 210456
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=10000;

int n;
int a[MAXN];
int b[MAXN];

bool solve() {
	ll asum=0; REP(i,n) asum+=a[i];
	ll bsum=0; REP(i,n) bsum+=b[i];
	if(bsum<asum) return false;
	ll have=bsum-asum;
	ll need=0;
	REP(i,n) if(a[i]<b[i]) need+=(b[i]-a[i]+1)/2;
	return need<=have;
}

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]); REP(i,n) scanf("%d",&b[i]);
	printf("%s\n",solve()?"Yes":"No");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 384
import java.io.*;
import  java.util.*;

import static java.lang.System.in;

class Main{
    static long mod = 1000000000+7;
    static long[] rest;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt(), W = sc.nextInt(), K = sc.nextInt();
        rest = legalDistribution();
        long ans = help(H,W,K);
        System.out.println(ans);
    }
    static long help(int H, int W, int K){
        if(W==1) return 1;
        long[][] dp = new long[H+2][W];
        dp[0][0] = 1;dp[1][0] = 1;
        for(int row=2;row<=H+1;row++){
            dp[row][0] = (dp[row-1][0]*getRest(W-2)%mod+dp[row-1][1]*getRest(W-3)%mod)%mod;
            for(int col=1;col<W-1;col++){
                dp[row][col] = dp[row-1][col]*getRest(col-1)%mod*getRest(W-col-2)%mod;
                dp[row][col] = (dp[row][col]+dp[row-1][col-1]*getRest(col-2)%mod*getRest(W-col-2)%mod)%mod;
                dp[row][col] = (dp[row][col]+dp[row-1][col+1]*getRest(col-1)%mod*getRest(W-col-3)%mod)%mod;
            }
            dp[row][W-1] = (dp[row-1][W-1]*getRest(W-2)%mod+dp[row-1][W-2]*getRest(W-3)%mod)%mod;
        }
        return dp[H+1][K-1];
    }
    static long getRest(int x){
        if(x<=0) return 1;
        return rest[x];
    }
    static long[] legalDistribution(){
        long[] ans = new long[9];
        ans[0]=1;
        ans[1]=2;
        for(int i=2;i<9;i++) ans[i] = (ans[i-1]+ans[i-2])%mod;
        return ans;
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define N 3005

using namespace std;
typedef pair<int,int> Pair;
typedef long long ll;

const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = mul(res, x);
		x = mul(x, x), y >>= 1;
	} return res;
}

template <class T> inline T	input() {
	T x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T &y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T &y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

int n, m, Q;
char str[N][N];
int sn[N][N], se1[N][N], se2[N][N];

int Query(int xa, int ya, int xb, int yb) {
	return sn[xb][yb] - sn[xb][ya - 1] - sn[xa - 1][yb] + sn[xa - 1][ya - 1] -
	(se1[xb][yb] - se1[xb][ya] - se1[xa - 1][yb] + se1[xa - 1][ya]) -
	(se2[xb][yb] - se2[xb][ya - 1] - se2[xa][yb] + se2[xa][ya - 1]);
}

int main() {
	scanf("%d%d%d", &n, &m, &Q);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", str[i] + 1);
		for (int j = 1; j <= m; ++j)
			sn[i][j] = str[i][j] ^ 48;
	}

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (sn[i][j] == 1) {
				se1[i][j] = sn[i][j - 1];
				se2[i][j] = sn[i - 1][j];
			}

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j)
			sn[i][j] += sn[i][j - 1],
			se1[i][j] += se1[i][j - 1],
			se2[i][j] += se2[i][j - 1];
		for (int j = 1; j <= m; ++j)
			sn[i][j] += sn[i - 1][j],
			se1[i][j] += se1[i - 1][j],
			se2[i][j] += se2[i - 1][j];
	}

	while (Q--) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		printf("%d\n", Query(a, b, c, d));
	}
	return 0;
}


Measured memory_bytes: 83712
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
a0 = as[0]
sum = 0
seki = as.shift
as.each do|a|
   seki *= a
end
as.unshift(a0)
as.each do|a|
  sum += seki/a
end

ans = seki / sum.to_f
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <set>
#include <bitset>
using namespace std;

set<int> graph[200005];
bitset<200005> visited;

int calc(int node) {
    visited[node] = true;
    int counter = 1;

    for (int neighbour : graph[node]) {
        if (!visited[neighbour])
            counter += calc(neighbour);
    }

    return counter;
}

int main() {
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= m; ++i) {
        int x, y;
        cin >> x >> y;

        graph[x].emplace(y);
        graph[y].emplace(x);
    }

    int maxInGroup = 1;
    for (int i = 1; i <= n; ++i) {
        maxInGroup = max(maxInGroup, calc(i));
    }
    cout << maxInGroup;
}


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

typedef pair<int,int> P;

int get(int h,int m){
  return h * 60 + m;
}

int K,N,M;
int A[111],B[111];
vector<P> st[111];
vector<P> tt[111];
int main(){

  scanf("%d",&K);
  for(int i=0;i<K;i++){
    int ah,am,bh,bm;
    scanf("%d:%d-%d:%d",&ah,&am,&bh,&bm);
    A[i] = get(ah,am);
    B[i] = get(bh,bm);
  }

  scanf("%d",&N);
  for(int i=0;i<N;i++){
    int k;
    scanf("%d",&k);
    for(int j=0;j<k;j++){
      int ah,am,bh,bm;
      scanf("%d:%d-%d:%d",&ah,&am,&bh,&bm);
      int s = get(ah,am);
      int t = get(bh,bm);
      st[i].push_back( P(s, t) );
    }
  }


  scanf("%d",&M);
  for(int i=0;i<M;i++){
    int k;
    scanf("%d",&k);
    for(int j=0;j<k;j++){
      int ah,am,bh,bm;
      scanf("%d:%d-%d:%d",&ah,&am,&bh,&bm);
      int s = get(ah,am);
      int t = get(bh,bm);
      tt[i].push_back( P(s,t) );
    }
  }

  int res = 0;
  for(int i=0;i<K;i++){
    int am,bm;
    am = bm = 0;
    for(int j=0;j<N;j++){
      for(int k=0;k<(int)st[j].size();k++){
	if( st[j][k].first <= A[i] && B[i] <= st[j][k].second ) {
	  am++; break;
	}
      }
    }
    for(int j=0;j<M;j++){
      for(int k=0;k<(int)tt[j].size();k++){
	if( tt[j][k].first <= A[i] && B[i] <= tt[j][k].second ) {
	  bm++; break;
	}
      }
    }

    res += min(am,bm);
  }
  cout << res << endl;
}

Measured memory_bytes: 1404
#include <iostream>
#include <cassert>
#include <vector>

using namespace std;

void solve(int a, int b, int t){
  int n;

  n = (int)((t + 0.5) / a) * b;

  cout << n;
}

int main(int argc, char const* argv[])
{
  int t, a, b;

  cin >> a >> b >> t;

  //cout << a << " " << b << " " << t << endl;

  solve(a, b, t);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[105];
int main() {
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for (int i =0; i < n; i++) {
        cin >> a[i];
        ans += a[i];
    }
    sort(a, a + n);
    int index = 0;
    while (index < n && ans % 10 == 0) {
        if (a[index] % 10 != 0) {
            ans -= a[index];
        }
        index++;
    }
    //cout << ans << endl;
    cout << ((ans % 10 == 0) ? 0 : ans) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
#define R register
char s[5];
inline void read(R int &x)
{
	x = 0;R char ch = getchar();R bool f = false;
	for(;ch < 48 || ch > 57;ch = getchar()) f |= (ch == '-');
	for(;ch > 47 && ch < 58;ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
	(f) && (x = -x);
}
int main()
{
	scanf("%s",s);
	if(strlen(s) == 2){printf("%s",s);return 0;}
	else 
	{
		R char ch = s[0];
		s[0] = s[2];
		s[2] = ch;
		printf("%s",s);
		return 0;
	}
}


Measured memory_bytes: 128
import java.util.Scanner;

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

        int A = scan.nextInt();
        int B = scan.nextInt();
        int AB = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();

        int ans = 1000000000;
        for(int i=0; i<2*(x+y)+1; i++){
            int ABpizza = i;
            int Apizza = Math.max(0,x - (i/2));
            int Bpizza = Math.max(0,y - (i/2));
            ans = Math.min(ans,(ABpizza*AB)+(Apizza*A)+(Bpizza*B));
        }
        System.out.println(ans);
    }
}

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

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    int temp;
    cin >> temp;
    a[i] = temp / 2;
  }
  
  int b = 1, a0 = a[0];
  while (a0 % 2 == 0) { b *= 2; a0 /= 2; }
  long long lcm = a[0];
  for (int i = 1; i < n && lcm <= m; ++i)
  {
    if ( !(a[i] % b == 0 && a[i] % (2*b) != 0) )
    {
      cout << "0" << endl;
      return 0;
    }
    
    if (lcm % a[i] != 0)
    {
      int mcd = lcm > a[i] ? f((int)lcm, a[i]) : f(a[i], (int)lcm);
      lcm *= a[i] / mcd;
    }
  }
  
  cout << (m / lcm + 1) / 2 << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b,c;
    int sum = 0;
    scanf("%d %d %d",&a,&b,&c);
    if(a<=c){
        if(b<=c){
            sum = a+b;
        }
        else sum = a+c;
    }
    else if(a>c){
        if(a<=b){
            sum = a+c;
        }
        else sum = c+b;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
h,w,k=map(int,input().split())
s=[]
ans=[[0 for k in range(w)] for _ in range(h)]
for _ in range(h): s.append(input())
temp=0
for i in range(h):
    flag=0
    for j in range(w):
        if flag:
            if s[i][j]=="#": temp+=1
            ans[i][j]=temp
        else:
            if s[i][j]=="#":
                temp+=1
                flag=1
                ans[i][j]=temp
temp=[ans[i].count(0) for i in range(h)]
for i,val in enumerate(temp):
    if 0<val<w:
        j=w-1
        while ans[i][j]!=0: j-=1
        while j>=0:
            ans[i][j]=ans[i][j+1]
            j-=1
for i in range(h):
    if i>0 and ans[i][0]==0: ans[i]=ans[i-1]
for i in range(h-1,-1,-1):
    if i<h-1 and ans[i][0]==0: ans[i]=ans[i+1]
for i in range(h):
    for j in range(w):
        print(ans[i][j],end=" ")
    print()

Measured memory_bytes: 12836
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Double student, avr, a;
        String tmp[];
        Double scores[] = new Double[1000];
        try {
            while ((student = Double.parseDouble(br.readLine())) != 0) {
                avr = 0.0;
                a = 0.0;
                tmp = br.readLine().split(" ");
                for (int i = 0; i < student; i++) {
                    scores[i] = Double.parseDouble(tmp[i]);
                    avr += scores[i];
                }

                avr /= student;

                for (int i = 0; i < student; i++) {
                    a += (Math.pow(avr - scores[i], 2));
                }
                System.out.println(Math.sqrt(a / student));
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  int N; cin >> N;
  vector<int> A(N), B(N);
  rep(i, N) {
    cin >> A[i];
    cin >> B[i];
  }
  sort(all(A));
  sort(all(B));

  if(N%2==1){
    cout << B[N/2]-A[N/2]+1 << endl;
  }
  else{
    cout << (B[N/2]+B[N/2-1]) - (A[N/2]+A[N/2-1]) + 1 << endl;
  }
}

Measured memory_bytes: 6324
import java.util.Scanner;
import java.math.BigDecimal;

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

		// 整数の入力
		int a = sc.nextInt();

		System.out.println(a + a * a + a * a * a);

	}
}

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

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


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("").map(n=>parseInt(n));
    const K = parseInt(arg[1]);
    
    for(let i=0; i<K; i++) {
        if(S[i] !== 1) {
            console.log(S[i]);
            return;
        }
    }
    
    console.log(1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

vector<vector<pair<ll,ll>>> a(15);
vector<ll> l(15, -1);

ll count(ll x, ll n){
    for(auto j : a[x]){
        if(l[j.first-1] != -1 && l[j.first-1] != j.second){
            //cout << "hoge";
            return -1;
        }
        l[j.first-1] = j.second;
    }
    ll ans = 0;
    rep(i, n) if(l[i] == 1) ans++;
    return ans;
}

int main(){
    ll n; cin >> n;
    
    rep(i, n){
        ll b; cin >> b;
        rep(j, b){
            ll x, y; cin >> x >> y;
            a[i].emplace_back(x, y);
        }
    }
    ll ans = 0;
    for(ll i = 0; i < pow(2, n); ++i){
        ll tmp = 0;
        l.assign(15, -1);
        //cout << i << " " << ans << ": ";
        rep(j, n) l[j] = (i & (1 << j)) ? 1 : 0;
        rep(j, n){
            if(!(i & (1 << j))) continue;
            tmp = count(j, n);
            if(tmp == -1) break;
        }
        ans = max(ans, tmp);
        //cout << endl;
        //for(auto x : l) cout << x << " "; cout << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4112
import math
N,H = map(int,input().split())
swing, dagger = 0,[]
for i in range(N):
    a,b = map(int,input().split())
    swing = max(a,swing)
    dagger.append(b)

dagger.sort(reverse= True)

count = 0
while H > 0:
    if count < N and dagger[count] > swing:
        H -= dagger[count]
        count += 1
    else:
        count += math.ceil(H/swing)
        break
print(count)

Measured memory_bytes: 7508
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean v = true;
        for (int i = 0; i < n; ++i) {
            int ai = sc.nextInt();
            if (ai % 2 == 0 && (ai % 3 != 0 && ai % 5 != 0)) {
                v = false;
                break;
            }
        }
        System.out.println(v ? "APPROVED" : "DENIED");
    }
}


Measured memory_bytes: 23124
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD = 1000000007;
lli gcd(lli a, lli b)
{
    return a < b ? gcd(b, a) : (b == 0 ? a : gcd(b, a % b));
}
int main()
{
    lli N, C;
    cin >> N >> C;
    lli dp[405][405] = {};
    lli A[404], B[405];
    lli sum[404][404];
    rep(i, N)
    {
        cin >> A[i];
    }
    rep(i, N) cin >> B[i];
    rep(i, N)
    {
        for (lli j = A[i]; j <= B[i]; j++) {
            lli temp = 1;
            rep(k, 404)
            {
                sum[i][k] = (sum[i][k] + temp) % MOD;
                temp = (temp * j) % MOD;
            }
        }
    }
    dp[0][0] = 1;
    rep(i, N) rep(j, C + 1)
    {
        rep(k, j + 1)
        {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - k] % MOD * (sum[i][k]) % MOD + MOD) % MOD;
        }
    }
    // rep(i, N + 1)
    // {
    //     rep(j, C + 1)
    //     {
    //         cout << dp[N][C] << ' ';
    //         if (j == C)
    //             cout << endl;
    //     }
    // }
    cout << (dp[N][C] + MOD) % MOD << endl;
}


Measured memory_bytes: 2816
using System;
using System.Collections.Generic;
using System.Linq;

class E
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var map = new List<int>[1001000];
		for (var i = 1; i <= n; i++)
			for (var j = i + 1; j <= n; j++)
				map[1000 * j + i] = new List<int>();
		for (var i = 1; i <= n; i++)
		{
			var a = Console.ReadLine().Split().Select(int.Parse).Select(j => i > j ? 1000 * i + j : 1000 * j + i).ToArray();
			var m = n - 2;
			for (int j = 0, k = 1; j < m; j++, k++)
			{
				map[a[j]].Add(a[k]);
			}
		}

		var cs = new int[1001000];
		var rs = new bool[1001000];
		for (var id = 0; id < map.Length; id++) if (map[id] != null) Find(map, id, cs, rs);
		Console.WriteLine(cs.Max());
	}

	static void Find(List<int>[] map, int id, int[] cs, bool[] rs)
	{
		if (cs[id] > 0) return;
		if (map[id].Count == 0) { cs[id] = 1; return; }
		if (rs[id]) { Console.WriteLine(-1); Environment.Exit(0); }
		rs[id] = true;
		foreach (var pid in map[id]) Find(map, pid, cs, rs);
		cs[id] = map[id].Max(i => cs[i]) + 1;
		rs[id] = false;
	}
}


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

bool G[100][100];

int main() {
  int a,b; cin>>a>>b;
  rep(i, 0, 100) {
    rep(j, 0, 100) {
      if (i<50) G[j][i]=true;
      else G[j][i]=false;
    }
  }

  int cnt=1;
  rep(i, 0, 26) {
    rep(j, 0, 50) {
      if (cnt==a) break;
      G[2*j+1][2*i+1]=false;
      cnt++;
    }
  }
  cnt=1;
  rep(i, 28, 49) {
    rep(j, 0, 50) {
      if (cnt==b) break;
      G[2*j+1][2*i]=true;
      cnt++;
    }
  }
  cout<<100<<" "<<100<<endl;
  rep(i, 0, 100) {
    rep(j, 0, 100) {
      if (G[j][i]) cout<<'#';
      else cout<<'.';
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int MAX = 200005;
/* global variables */
vector<vector<int> > G(MAX, vector<int>());
vector<int> counter;
int N;
/* function */
void bfs() {
    vector<int> visited(N, 0);
    queue<int> q;
    q.push(0);
    visited[0] = 1;
    while (!q.empty()) {
        int from = q.front(); q.pop();
        for (int to : G[from]) {
            if (visited[to]) continue;
            counter[to] += counter[from];
            visited[to] = 1;
            q.push(to);
        }
    }
}

/* main */
int main(){
    int Q, a, b, p, x;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    counter.assign(N, 0);
    for (int i = 0; i < Q; i++) {
        cin >> p >> x;
        p--;
        counter[p] += x;
    }
    bfs();
    for (int c : counter) cout << c << ' ';
    cout << '\n';
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(K % 2) {
        cout << B - A << endl;
    } else {
        cout << A - B << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = tuple(map(int, input().split()))

ct = Counter(A)
d = dict()
for k, v in ct.items():
    d[k] = v * (v - 1) // 2

s = sum(d.values())

for i in range(N):
    print(s - (ct[A[i]] - 1))


Measured memory_bytes: 32020
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char str[200005];
int main() {
	scanf("%s", str);
	int n = strlen(str);
	vector<char> st;
	for (int i = 0; i < n; ++i) {
		if (!st.empty() && st.back() == 'S' && str[i] == 'T') st.pop_back();
		else st.push_back(str[i]);
	}
	printf("%d\n", st.size());
}


Measured memory_bytes: 768
#include<cstdio>
#include<algorithm>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define orz return printf("-1\n"),0;
#define f(i,a,b) for(register int i=(a),i##end=(b);i<=i##end;i=-(~i))
__gnu_pbds::gp_hash_table<int,int>ht;
const int N=100010;
int n,sum,ans,a[N],b[N],c[N],d[N],fa[N],cnt;
using namespace std;
int find(int x){return fa[x]^x?fa[x]=find(fa[x]):x;}
int merge(int x,int y)
{
	x=find(x),y=find(y);
	if(x^y)fa[y]=x;
}
int main()
{
	scanf("%d",&n);
	f(i,1,n)scanf("%d",&a[i]),c[i]=a[i],sum^=a[i];c[n+1]=a[n+1]=sum;
	sum=0;
	f(i,1,n)scanf("%d",&b[i]),d[i]=b[i],sum^=b[i];d[++n]=b[n]=sum;
	sort(c+1,c+n+1),sort(d+1,d+n+1);
	f(i,1,n)if(c[i]^d[i])if(i<n)orz;
	f(i,1,n)if(a[i]^b[i]||i==n)
	{
		ans+=(i<n);
		if(!ht[a[i]])ht[a[i]]=++cnt;
		if(!ht[b[i]])ht[b[i]]=++cnt;
	}f(i,1,cnt)fa[i]=i;
	f(i,1,n)if(a[i]^b[i])merge(ht[a[i]],ht[b[i]]);
	f(i,1,cnt)if(fa[i]==i)++ans;
	printf("%d\n",ans-1);
}

Measured memory_bytes: 6768
#include <iostream>
#include <algorithm>

int main() {
        std::string s;
        int k;
        std::cin >> s >> k;

        auto length = std::min(static_cast<int>(s.size()), k);
        auto find = std::find_if(std::begin(s), std::begin(s) + length,
                [](const auto& c) {
                        return c != '1';
                }
        );
        if (find == std::begin(s) + length) {
                std::cout << "1" << std::endl;
        }
        else {
                std::cout << *find << std::endl;
        }

        return 0;
}

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

using namespace std;

int main()
{
	int N, M;
	int ans = 0;
	cin >> N >> M;

	vector<vector<int>> nodes(N);

	for (int i = 0;i < M;i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		nodes[a].push_back(b);
		nodes[b].push_back(a);
	}

	vector<int> p(N);
	for (int i = 0;i < N;i++)
		p[i] = i;

	do
	{
		//スタートは頂点1番から
		if (p[0] != 0)
			continue;

		//すべての頂点に道があるか
		bool all_found = true;
		for (int i = 1;i < N;i++)
		{
			//次の頂点への道があるか
			bool found = false;
			for (int j = 0;j < nodes[p[i - 1]].size();j++)
			{
				if (nodes[p[i - 1]][j] == p[i])
				{
					found = true;
					break;
				}
			}

			//行くことができない場合
			if (!found)
			{
				all_found = false;
				break;
			}
		}

		//すべて通ることができる場合
		if (all_found)
			ans++;

	} while (next_permutation(p.begin(), p.end()));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

n,*a=map(int,sys.stdin.read().split())

a.sort(reverse=True)
c=0
f=0
ans=[]
for i in range(n-1):
  if a[i]==a[i+1]:
    c+=1
    f+=1
    ans.append(a[i])
  else:
    f=0
  if (c>1 and f==1) or (c>2 and f==3):
    print(ans[0]*ans[-1])
    sys.exit()
print(0)
  
  


Measured memory_bytes: 20080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int s,fr[2000000];
int f(int x){
    if(x%2==0){return x/2;}
    else return 3*x + 1;
}
int main(){
    cin>>s;
    int idx = 0;
    while(fr[s]==0){
        fr[s]++;
        s = f(s);
        idx++;
    }
    idx++;
    cout<<idx<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;cin>>a>>b;
    int ans=0;

    for(int i=a;i<=b;i++){
        int right1 = i%10;
        int left1 = (i/10000)%10;
        int right2 = (i/10)%10;
        int left2 = (i/1000)%10;
        if(right1==left1&&right2==left2) ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

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

	int kuji[n], a[n], b[n];
	for (int i = 1; i <= w; i++) kuji[i] = i;

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

	for (int i = 1; i <= w; ++i) {
		cout << kuji[i] << endl;
	}
}

Measured memory_bytes: 1240
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	string s;
	while(getline(cin, s), s != "."){
		vi v;
		bool ok = 1;
		rep(i, s.size()){
			if(s[i] == '(') v.pb(1);
			if(s[i] == ')'){
				if(!v.size() || v.back() != 1) ok = 0;
				else v.pop_back();
			}
			if(s[i] == '[') v.pb(2);
			if(s[i] == ']'){
				if(!v.size() || v.back() != 2) ok = 0;
				else v.pop_back();
			}
			if(!ok) break;
		}
		cout << (ok && !v.size() ? "yes" : "no") << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,cnt;
  cin >> n >> cnt;
  vec v(n);
  for(ll i=0;i<n;i++) cin >> v[i];
  ll ans=-inf;
  for(ll i=0;i<=n;i++) {
    for(ll j=0;j<=n-i;j++) {
      if(i+j>min(n,cnt)) continue;
      ll tans=0;
      priority_queue<ll,vector<ll>,greater<ll>> q;
      for(ll k=0;k<i;k++) {
        tans+=v[k];
        q.push(v[k]);
      }
      for(ll k=n-1;k>n-1-j;k--) {
        tans+=v[k];
        q.push(v[k]);
      }
      ll tcnt=0;
      while(q.size()&&tcnt<cnt-i-j) {
        ll p=q.top();
        q.pop();
        if(p<0) tans-=p;
        tcnt++;
      }
      ans=max(ans,tans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import bisect

a,b,q = map(int, input().split())
S = [-float('inf')]+[int(input()) for _ in range(a)]+[float('inf')]
T = [-float('inf')]+[int(input()) for _ in range(b)]+[float('inf')]
X = [int(input()) for _ in range(q)]


for q_i in range(q):
  x_pos_s = bisect.bisect_left(S, X[q_i])
  x_pos_t = bisect.bisect_left(T, X[q_i])
  
  s_1 = S[x_pos_s-1]
  t_1 = T[x_pos_t-1]
  s_2 = S[x_pos_s]
  t_2 = T[x_pos_t]
  
  ans = min(abs(X[q_i]-min(s_1,t_1)),
            abs(X[q_i]-max(s_2,t_2)),
            abs(s_2-t_1)+min(abs(X[q_i]-s_2),abs(X[q_i]-t_1)),
            abs(t_2-s_1)+min(abs(X[q_i]-t_2),abs(X[q_i]-s_1)))
  
  print(ans)

Measured memory_bytes: 16144
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,m,l[200000],r[200000],x,y;
  cin >> n >> m;
  rep(i,m)cin >> l[i] >> r[i];
  x=1;
  y=n;
  rep(i,m){
    x=max(l[i],x);
    y=min(r[i],y);
  }
  if(x>y)printf("0");
  else printf("%lld",y-x+1);
}

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

#include <iostream>
#include <fstream>

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

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void vpd(vector<pair<int, int>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

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

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

template<typename T> void debug::vpd(vector<pair<int, int>> vec) {
    for(auto const& vv : vec) {
        cout << vv.first << " " << vv.second << endl;
    }
    cout << endl;
}

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

class ARemainingBalls {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string s, t, u;
	    int a, b;
	    in >> s >> t >> a >> b >> u;

	    if(s == u) out << a-1 sp b << endl;
	    else out << a sp b-1 << endl;
	}
};


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


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
typedef long long ll;

int main()
{
    ll n;   scanf("%lld", &n);
    ll sq = sqrt(n);
    ll a, b;
    for(ll i=sq; i>=1; i--)
    {
        if(n%i==0)
        {
            a = i;
            b = n/i;
            break;
        }
    }
    printf("%lld\n", a+b-2);
    return 0;
}

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

N,A,B,C = [int(x) for x in input().split()]
ln = tuple([int(input()) for _ in range(N)])

def dp(A, B, C, a, b, c, n):
    global ln
    if n == N:
        if len(a) == 0 or len(b) == 0 or len(c) == 0:
            return float('INF')
        cost = (len(a) + len(b) + len(c) - 3) * 10
        return cost + abs(A - sum(a)) + abs(B - sum(b)) + abs(C - sum(c))
    ans = float('INF')
    ans = min(ans, dp(A, B, C, a[:], b[:], c[:], n+1))
    ans = min(ans, dp(A, B, C, a[:]+[ln[n]], b[:], c[:], n+1))
    ans = min(ans, dp(A, B, C, a[:], b[:]+[ln[n]], c[:], n+1))
    ans = min(ans, dp(A, B, C, a[:], b[:], c[:]+[ln[n]], n+1))
    return ans
print(dp(A, B, C, [], [], [], 0))    

Measured memory_bytes: 3064
INF=float('inf')
mod=10**9+7

h,w=map(int,input().split())
G=[]
for _ in range(h):
  s=input()
  G.append(s)
  
dp=[[-INF for i in range(w+1)] for j in range(h+1)]
dp[1][1]=1

for i in range(1,h+1):
  for j in range(1,w+1):
    if G[i-1][j-1]=='#':
      continue
    if i==1 and j==1:
      continue
    dp[i][j]=max(0,dp[i-1][j])+max(0,dp[i][j-1])
    dp[i][j]%=mod
print(dp[h][w])

Measured memory_bytes: 91000
n = gets.to_i
arr = []

n.times do |i|
  arr << gets.chomp.split.push(i)
end

arr.group_by{|e| e[0]}.sort_by{|e| e[0]}.each{|e|
  e[1].sort_by{|i| -i[1].to_i}.each{|f| puts f[2]+1}
}


Measured memory_bytes: 1788
def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    ans = 0
    for i in range(N):
        for j in range(N):
            if i < j and A[i] > A[j]:
                ans += K*(K-1) // 2 + K
                ans %= mod
            elif i > j and A[i] > A[j]:
                ans += K*(K-1) // 2
                ans %= mod
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 40560
#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long int ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back


int main(){
    string s;
    while(getline(cin,s)){
        stack<char> data;
        while(data.size())data.pop();
        if(s==".")break;

        rep(i,s.size()){
            if(s[i]=='[')data.push('[');
            if(s[i]=='(')data.push('(');
            if(s[i]==']'){
                if(data.size() && data.top()=='[')data.pop();
                else{
                    cout<<"no"<<endl;
                    break;
                }
            }
            if(s[i]==')'){
                if(data.size() && data.top()=='(')data.pop();
                else{
                    cout<<"no"<<endl;
                    break;
                }
            }
            if(i==s.size()-1)
                if(data.empty()) cout<<"yes"<<endl;
                else cout<<"no"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>
#include <algorithm>
#include <tuple>
#include <functional>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

ll n, a[2100];
pii s[2100];
ll dp[2100][2100];
int main() {
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", a + i);
	for (int i = 0; i < n; i++)
		s[i] = pii(a[i], i);
	sort(s, s + n, greater<>());

	for (int i = 0; i < n; i++) {
		ll index, ac;
		tie(ac, index) = s[i];
		for (int j = 0; j <= i; j++) {//j 前に置いた数
			dp[j + 1][i - j] = max(dp[j + 1][i - j], dp[j][i - j] + ac * abs(index - j));
			dp[j][i - j + 1] = max(dp[j][i - j + 1], dp[j][i - j] + ac * abs(index - ((n - 1) - (i - j))));
		}
	}
	ll max_c = 0;
	for (int i = 0; i <= n; i++)
		max_c = max(max_c, dp[i][n - i]);
	printf("%lld\n", max_c);
}

Measured memory_bytes: 24736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,k;cin>>a>>b>>c>>k;ll sum=0;
  if(a>=k)  cout<<k<<endl;
  else if(a+b>=k)cout<<a<<endl;
   else if(a+b+c>=k)
   {
     cout<<(b-k)+2*a<<endl;
   }
}


Measured memory_bytes: 3632
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if 4*n*h-N*h-N*n>0 and N*h*n%(4*n*h-N*h-N*n)==0:print(h,n,N*h*n//(4*n*h-N*h-N*n));exit()

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int n,m,k;
	cin >> n >> m >> k;
	if(k % n == 0 || k % m == 0) {
		cout <<"Yes";
		return 0;
	}
	for(int i= 0;i<n;i++)
		for(int j = 0;j<m;j++){
			if((m-j)*i+(n-i)*j == k){
				cout <<"Yes";
				return 0;
			}
		}
		
	cout <<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    int N = s.size();
    if(s[N-1] == '0' && s[0] == '1' && s[N-2] == '1'){
        for(int i = 1; i < N-2; i++){
            if(s[i] != s[N-2-i]) {
                cout << -1 << '\n';
                return 0;
            }
        }
        int ch = 1;
        int p = 2;
        cout << ch << ' ' << p << '\n';
        for(int i = 1; i < N-1; i++){
            cout << i+2 << ' ' << p << '\n';
            if(s[i] == '0'){
                
            }else{
                p = i+2;
            }
        }
    }else{
        cout << -1 << '\n';
        return 0;
    }
}

Measured memory_bytes: 1664