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

int main() {
  int t, k;
  cin >> t >> k;
  vector<int> v(t);
  
  for (int i = 0; i < t; ++i)
    cin >> v[i];
  
  int dp[t];
  dp[0] = 0;
  dp[1] = abs(v[1] - v[0]);
  
  for (int i = 2; i < t; ++i) {
    dp[i] = dp[i - 1] + abs(v[i] - v[i - 1]);
    for (int j = 1; j <= k && i - j >= 0; ++j)
      dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j]));
  }
  
  cout << dp[t - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define ll long long int
#define ld long double
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define mod(n) (n) % 1000000007
#define sp << " "
#define precision(n) cout << fixed << setprecision(n);
#define startTime time_t start, end;time(&start);
#define endTime time(&end);double tt = double(end-start);cout<<"Time taken : "<<fixed<<tt<<setprecision(5);cout <<" sec"<< endl;
 
using namespace std;
 
int main() { 
    IOS;
    ll  n;
    cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    }

    ll dp[n][n];
    for (int i = 0; i < n; i++) {
    	for (int j = 0; j < n; j++) {
    		dp[i][j] = LLONG_MIN;
    		if (i == j) dp[i][j] = a[i];
    	}
    }

    for (int i = n - 1; i >= 0; i--) {
    	for (int j = i + 1; j < n; j++) {
    		if (i < n - 1) dp[i][j] = max(dp[i][j], a[i] - dp[i + 1][j]);
    		if (j > 0) dp[i][j] = max(dp[i][j], a[j] - dp[i][j - 1]);
    	}
    }
    cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 73908
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
	int N;
	scanf("%d", &N);
	rep(i, N) {
		double ax, ay, ar, bx ,by, br;
		scanf("%lf %lf %lf %lf %lf %lf", &ax, &ay, &ar, &bx, &by, &br);
		double AB = sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay));
		double ABdis = ar + br;
		if(AB > ABdis) printf("0\n");
		else if(AB + ar < br) printf("-2\n");
		else if(AB + br < ar) printf("2\n");
		else printf("1\n");
	}
	return 0;
}

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

bool is_prime_number(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    
    double sqrtNum = sqrt(n);
    for(int i = 3; i <= sqrtNum; i += 2){
        if (n % i == 0) return false;
    }
    return true;
}

int main(){
    int n;
    int count = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }

    for (int i = 0; i < n; i++){
        if(is_prime_number(a[i])) count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 102;
int N, X;
int L[MAX_N];

void solve()
{
	int d=0;
	int res = 1;
	int idx = 1;
	while(idx <= N){
		if(d > X) break;
		res++;
		d=d+L[idx++];
	}
	if(d <= X) cout << res << '\n';
	else cout << res-1 << '\n';
}

int main()
{
	cin >> N >> X;
	for(int i=1;i<=N;++i) cin >> L[i];
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int x = scan.nextInt();

    int[] c = new int[n];
    int[][] a = new int[n][m];

    for (int i = 0; i < n; i++) {
      c[i] = scan.nextInt();
      for (int j = 0; j < m; j++) {
        a[i][j] = scan.nextInt();
      }
    }

    int[] ability = new int[m];
    int min = Integer.MAX_VALUE;

    for (int bit = 0; bit < Math.pow(2, n); ++bit) {
      
      for (int i = 0; i < m; i++) {
        ability[i] = 0;
      }
      
      boolean flag = true;
      int money = 0;
      
      for (int i = 0; i < n; ++i) {
        if ((1 & (bit >> i)) == 1) { // i が bit に入るかどうか
          for (int j = 0; j < m; j++) {
            ability[j] += a[i][j];
          }
          money += c[i];
        }
      }
      
      for (int j = 0; j < m; j++) {
        if (ability[j] < x) {
          flag = false;
          break;
        }
      }

      if (flag == true) {
        min = Math.min(money, min);
      }

    }
    
    if(min == Integer.MAX_VALUE) {
      System.out.println(-1);
    } else {
      System.out.println(min);
    }
    
  }

}

Measured memory_bytes: 37160
#include<stdio.h>
typedef long long int LL;
LL x,y;
LL f(LL x,LL z){
  y+=x+z;
  for(LL n=10;n<x;n*=10){
    f(x/n,x%n+z);}
  return y;}
signed main(){
  if(scanf("%lld",&x)==1)
  {printf("%lld\n",f(x,0));}
  return 0;}

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

typedef long long ll;
const int N = (int)1e5 + 500, mod = (int)1e9 + 7;

int n;
ll num[N];
ll fac[N], facinv[N], inv[N];
ll g[N], pg[N];
ll res = 0, cur = 0, sum = 0;

ll fp(ll x, int k){
    if(k == 0) return 1;
    ll hf = fp(x, k/2);
    return k % 2 == 1 ? hf * hf % mod * x % mod : hf * hf % mod;
}

ll per(ll x, ll k){
    return k > x ? 0 : fac[x] * facinv[x-k] % mod;
}

int main(){
    fac[0] = 1;
    for(int i = 1; i < N; i++) fac[i] = fac[i-1] * i % mod;
    facinv[N-1] = fp(fac[N-1], mod-2);
    for(int i = N - 2; i >= 0; i--) facinv[i] = facinv[i+1] * (i+1) % mod;

    for(int i = 1; i < N; i++) inv[i] = fp(i, mod-2);

    cin >> n;
    for(int i = 0; i < n; i++) cin >> num[i];

    g[n-1] = fac[n-1];
    for(int i = n - 2; i >= 0; i--){
        g[i] = per(n-1, i+1) * inv[i+1] + per(n-1, i);
        g[i] %= mod;
    }

    //pg[0] = g[0] * fac[n-1];
    pg[0] = g[0] = 0;

    for(int i = 1; i <= n; i++) pg[i] = (pg[i-1] + g[i] * fac[n-1-(i)]) % mod;

    for(int i = 0; i < n; i++){
        res += (pg[i] + pg[n-1-i] + fac[n]) % mod * num[i] % mod;
        res %= mod;
    }
    cout << res << endl;
//    for(int i = 0; i < n; i++){
//        res = (res + cur * )
//    }

}

Measured memory_bytes: 4992
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
  
int main(){
   int A,B,X;
   cin>>A>>B>>X;
   if(X>=A&&X<=A+B){
       cout<<"YES"<<endl;
   }
   else{
       cout<<"NO"<<endl;
   }
}

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

#define Min(a,b) ((a)<(b)?(a):(b))

#define Max(a,b) ((a)>(b)?(a):(b))

#define ABS(a) ((a)>(0)?(a):-(a))

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

#define Rep2(i,bottom,ceiling) for(int (i)=(bottom);(i)<=(ceiling);(i)++)

void SwapInt(int* v1,int* v2){
	char sw = *v1;
    *v1=*v2;
    *v2=sw;
}

void SwapChar(char* v1,char* v2){
    char sw = *v1;
    *v1=*v2;
    *v2=sw;
}

int main(){ 
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(ABS(a-c)<=d || (ABS(a-b)<=d && ABS(b-c)<=d)) printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll K,A,B,ans;
int main()
{
    ans=1;
    scanf("%lld%lld%lld",&K,&A,&B);
    if(B-A<=2) ans=K+1;
    else
    {
        if(K>=A-1)
        {
            ans=A;K-=(A-1);
            ll moves=K/2;
            ans+=(B-A)*moves;
            if(K&1) ans++;
        }
        else
        {
            ans=K+1;
        }
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 256
h, w = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(10)]


def dfs(now, mp, rest):
    if now == 1:
        return mp
    ret = [
        dfs(p, mp + cost[now][p], rest[:i] + rest[i+1:]) for i, p in enumerate(rest)
    ]
    return min(ret)


r = list(range(10))
magic = [dfs(i, 0, r[:i] + r[i+1:]) for i in range(10)]

ans = 0
for _ in range(h):
    x = list(map(int, input().split()))
    for a_ij in x:
        if a_ij == -1:
            pass
        else:
            ans += magic[a_ij]
print(ans)


Measured memory_bytes: 3064
s = int(input())

num_set = set()
num_set.add(s)
ans = 1
while True:
    if s % 2 == 0:
        s = int(s / 2)
    else:
        s = int((3 * s) + 1)
    ans += 1
    if s not in num_set:
        num_set.add(s)
    else:
        break
print(ans)

Measured memory_bytes: 3060
# 2019-11-16 21:01:15(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    r = int(sys.stdin.readline().rstrip())
    print(r ** 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#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 YN(y, n, b) (b? y : n)
#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;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<i32> a(N + 1);
    for (i32 i = 1; i <= N; i++) cin >> a[i];
    i32 sum = 0;
    for (i32 i = 1; i <= N; i++) {
        if (i % 2 == 1 && a[i] % 2 == 1) sum++;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using ll = long long;
using namespace std;


void solve() {
   int a, b, c, x;
   int ans = 0;
   cin >> a >> b >> c >> x;
   for(int i = 0; i <= a; i++) {
      for(int j = 0; j <= b; j++) {
         for(int k = 0; k <= c; k++) {
            if(i * 500 + j * 100 + k * 50 == x) ans++;
         }
      }
   }
   cout << ans << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  map<int, int> managementMap;
  for(int i=0;i<N;i++){
    managementMap[i+1] = 0;
  }
  for(int i=0;i<N-1;i++){
    int a;
    cin >> a;
    managementMap[a] = managementMap[a] + 1;
  }

  for(pair<int, int> p : managementMap)
    cout << p.second << endl;
}



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

int main(){
  int n,b,x=0,zero=0;
  cin >> n;
  bool ans=true,ok=true;
  map<int,int>f;
  for(int i=0;i<n;i++){
    cin >> b;
    f[b]++;
    x^=b;
    if(b==0)
      zero++;
  }
  if(zero!=n&&!(n%3==0&&n/3==zero)){
  for(auto x:f){
    if(x.second!=n/3)
      ok=false;
  }
  }
  ans=(x==0);
  cout << (ans&&ok?"Yes":"No") << endl;
  return 0;
}

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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

ll dp[3010][3010];
pair<ll, ll> a[3010];
int main() {
  ll n, t;
  cin >> n >> t;
  rep(i, n) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  rep(i, n) {
    rep(j, t) {
      updatemax(dp[i + 1][j], dp[i][j]);
      updatemax(dp[i + 1][min(j + a[i].first, t)], dp[i][j] + a[i].second);
    }
    updatemax(dp[i + 1][t], dp[i][t]);
  }
  cout << dp[n][t] << endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

int main(void) {
	R x[3], y[3];
	rep(i, 3) cin >> x[i] >> y[i];
	R l[3];
	rep(i, 3) l[i] = hypot(x[(i + 1) % 3] - x[i], y[(i + 1) % 3] - y[i]);

	const R lmax = max({l[0], l[1], l[2]});
	const R area = 0.5 * abs((x[2] - x[0]) * (y[1] - y[0]) - (x[1] - x[0]) * (y[2] - y[0]));
	const R r = 2.0 * area / (l[0] + l[1] + l[2]);

	const R coef = (lmax / r + 2.0);
	R ans = lmax / coef;

	cout << setprecision(20) << fixed << ans << endl;
	return 0;
}

Measured memory_bytes: 512
n=int(input())
lst=list(map(int,input().split()))
p=0
for i in range(n):
    p=(p^lst[i]) #全体のxor

ans=[]

for i in range(n):
    q=(p^lst[i]) #自分の数値
    ans.append(str(q))
    
print(" ".join(ans))

Measured memory_bytes: 106236
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <limits>
#include <type_traits>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  int min=0;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
    ll A, B, ans=1;
    cin >> A >> B;
    map< int64_t, int > r1, r2;
    r1 = prime_factor(A);
    r2 = prime_factor(B);

    // cout << A << endl;
    // for(auto p : r1) {
    //     cout << p.first << endl;
    // }
    // cout << B << endl;
    // for(auto p : r1) {
    //     cout << p.first << endl;
    // }
    // cout << endl;

    ll m = min(A, B);
    for(auto p : r1){
        for(auto q : r2){
            if(p.first == q.first){
                ans += 1;
            }
        }
    }

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


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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        
        static void Solve()
        {

            var o = ReadAndParseIntArr();
            int k = o[0];
            int s = o[1];

            int ans = 0;
            for(int x=0;x<=k;++x)
            {
                for(int y=0;y<=k;++y)
                {
                   
                    int z = s - x - y;
                    if( z < 0) { continue; }
                    if( z > k) { continue; }
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
int main(){
	while(1){
	int n, p, i, a;
	int Hozon[50] = {};
		scanf("%d %d", &n, &p);
		if( n == 0 && p == 0 ){
			break;
		}
		a = p;
		for( i = 0 ; ; i = (i + 1) % n ){
			if( a == 0 ){
				a = Hozon[i];
				Hozon[i] = 0;
			}else{
			--a;
			++Hozon[i];
				if( Hozon[i] == p ){
					break;
				}
			}
		}
		printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 
int n;
int a[100001] , b[100001] , c[100001];

int vacation(int ind , int flag, vector<vector<int>>&dp)
{
    if (ind == n )    return 0;

    if (dp[ind][flag] != -1) 
      return dp[ind][flag];
    if (flag == 0) //sob select korte parbe
        return dp[ind][flag] = max( a[ind] + vacation(ind + 1, 1, dp) , max( b[ind] + vacation(ind + 1, 2, dp) , c[ind] + vacation(ind + 1, 3, dp) ));
    else if (flag == 1) //b c choose only
        return dp[ind][flag] = max( b[ind] + vacation(ind + 1 , 2, dp) , c[ind] + vacation(ind + 1, 3, dp) );
    else if (flag == 2) //a c choose only
        return dp[ind][flag] = max( a[ind] + vacation(ind + 1 , 1, dp) , c[ind] + vacation(ind + 1, 3, dp) );
    else if (flag == 3) //b a choose only
        return dp[ind][flag] = max( b[ind] + vacation(ind + 1 , 2, dp) , a[ind] + vacation(ind + 1, 1, dp) );
}




 
 
// Driver code to test above functions
int32_t main()
{
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
	
	 //int n;
    cin >> n;
    //arr(a, n);
    for(int i = 0;i< n;i++) cin >> a[i] >> b[i] >> c[i];

    vector<vector<int>>dp(n + 1, vector<int>(4, -1));
    cout << vacation(0, 0, dp);
    
    return 0; 
}

Measured memory_bytes: 21940
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

void solve() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int x = abs(A - C);
  int y = abs(B - D);
  cout << x + y - __gcd(x, y) << endl;
  return;
}


Measured memory_bytes: 256
H=int(input())+1
A=[0]+list(map(int,input().split()))
def s(x,y):A[x],A[y]=A[y],A[x];h(y)
def h(i):
 l=2*i;r=l+1
 if r<H:
  if A[i]<A[l]:
   if A[l]<A[r]:s(i,r)
   else:s(i,l)
  elif A[i]<A[r]:s(i,r)
 elif l<H and A[i]<A[l]:s(i,l)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64172
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	vector<int>a(m),b(m);
	vector<vector<int> >arrow(n);
	rep(i,m)cin>>a[i]>>b[i];
	rep(i,m){
		arrow[a[i]-1].push_back(b[i]-1);
		arrow[b[i]-1].push_back(a[i]-1);
	}
	vector<int> map(n,-1),times(n,999999999);
	map[0]=0;
	times[0]=0;
	/*
	while(1){
		bool over = true;
		for(int i=1;i<n;i++){
			if(map[i]==-1){
				over = false;
				break;
			}
		}
		if(over)break;
		rep(i,arrow[0].size()){
		*/
	vector<int> list;
	list.push_back(0);
	while(list.size()>0){
		rep(i,arrow[list[0]].size()){
			//cout<<"#"<<list[0]<<" "<<arrow[list[0]].size()<<endl;
			if(times[arrow[list[0]][i]]>times[list[0]]+1){
				times[arrow[list[0]][i]] = times[list[0]]+1;
				map[arrow[list[0]][i]] = list[0];
				list.push_back(arrow[list[0]][i]);
			}
		}
		list.erase(list.begin());
	}
	int enable = true;
	rep(i,n){
		if(map[i]==-1){
			enable =false;
			break;
		}
	}
	if(enable==false){
		cout<<"No\n";
		return 0;
	}

	cout<<"Yes\n";
	for(int i=1;i<n;i++){
		cout<<map[i]+1<<endl;
	}
	/*
	rep(i,n){
		cout<<i<<" "<<times[i]<<endl;
	}
	*/





	return 0;
}

Measured memory_bytes: 12524
#include <iostream>
#include <iomanip>
#include <array>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <cassert>
#include <functional>
using namespace std;

typedef unsigned long long int llui;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
constexpr double pi = 3.141592653589793238462643383279502884L;

// TODO: Mod class

const int sz = 1e5;

int main() {
  ios::sync_with_stdio(false);
  ll k;
  cin >> k;
  cout << 50 << endl;
  ll base = (k + 49) / 50;
  vector<ll> ans(50, 49 + base);
  if (k % 50 != 0) {
    for (int i = 0; i < 50 - k % 50; ++i) {
      ans[i] -= 50 - i;
    }
  }
  for (ll a : ans) {
    cout << a << " ";
    assert(a >= 0);
    assert(a <= 1e16 + 1000);
  }
  cout << endl;
}


Measured memory_bytes: 256
def main():
    s = input().rstrip("\n")
    import re
    parts = re.findall("((>*)(<*))", s)
    total = 0
    whole, left, right = parts[0]
    left_len = len(left)
    left_sum = (left_len * (left_len + 1)) // 2
    right_len = len(right)
    right_sum = (right_len * (right_len - 1)) // 2
    total = left_sum + right_sum
    for whole, left, right in parts[1:-1]:
        left_len = len(left)
        left_sum = (left_len * (left_len - 1)) // 2
        total += left_sum + max(left_len, right_len)
        right_len = len(right)
        right_sum = (right_len * (right_len - 1)) // 2
        total += right_sum
    total += right_len

    print(total)
if __name__ == "__main__":
    main()

Measured memory_bytes: 83016
N,M = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
    A[i] = -A[i]
import heapq
heapq.heapify(A)
for i in range(M):
    a = heapq.heappop(A)
    a = -a
    a = a//2
    a = -a
    heapq.heappush(A,a)
ans = -sum(A)
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n;
pair<int, int> p[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].first, &p[i].second);

	return true;
}

void solve()
{
	llong L = inf, l = inf, R = -inf, r = -inf;

	forn (i, n)
	{
		if (p[i].first > p[i].second)
			swap(p[i].first, p[i].second);

		L = umin(L, p[i].first);
		R = umax(R, p[i].second);
		l = umin(l, p[i].second);
		r = umax(r, p[i].first);
	}

	llong ans = (r - L) * (R - l);
	sort(p, p + n);
	multiset<int> s;

	forn (i, n)
		s.insert(p[i].first);

	ans = min(ans, (R - L) * (*s.rbegin() - *s.begin()));

	forn (i, n)
	{
		s.erase(s.find(p[i].first));
		s.insert(p[i].second);
		ans = min(ans, (R - L) * (*s.rbegin() - *s.begin()));
	}

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

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b;
    char op;
    while(true){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '?') break;
        switch(op){
        case '+':
            printf("%d\n",a+b);
            break;
        case '-':
            printf("%d\n",a-b);
            break;
        case '/':
            printf("%d\n",a/b);
            break;
        case '*':
            printf("%d\n",a*b);
            break;
        }
    }
}


Measured memory_bytes: 2696
#include<iostream>
using namespace std;
int main()
{
    long long k,n,a[200005],b[200005],i,x,y,min;
    cin>>k>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    x=a[n]-a[1];
    y=(k-a[2])+a[1];
    if(x<y)
    {
        b[1]=x;
    }
    else
    {
        b[1]=y;
    }
    min=b[1];
    for(i=2;i<n;i++)
    {
        x=(k-a[i])+a[i-1];
        y=a[i]+(k-a[i+1]);
        if(x<y)
        {
            b[i]=x;
        }
        else
        {
            b[i]=y;
        }
        if(b[i]<min)
        {
            min=b[i];
        }
    }
    x=a[n]-a[1];
    y=(k-a[n])+a[n-1];
    if(x<y)
    {
        b[n]=x;
    }
    else
    {
        b[n]=y;
    }
    if(b[n]<min)
    {
        min=b[n];
    }
    cout<<min<<endl;
    return 0;
}

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

int main() {
  int n[26]={0};
  string s;
  cin >> s;

  bool flg=false;
  for (auto &c:s) {
    n[c-'a']++;

    if (n[c-'a']>=2) flg=true;
  }

  cout << (flg ? "no": "yes") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>=b&&a>=c&&b>=c)
    {
        cout<<(a*10)+b+c;
    }
    else if(a>=b&&a>=c&&c>=b)
    {
        cout<<(a*10)+b+c;
    }
    else if(b>=a&&b>=c&&a>=c)
    {
        cout<<b*10+a+c;
    }
    else if(b>=a&&b>=c&&c>=a)
    {
        cout<<b*10+a+c;
    }
    else if(c>=b&&c>=a&&a>=b)
    {
        cout<<c*10+b+a;
    }
    else if(c>=b&&c>=a&&b>=a)
    {
        cout<<c*10+b+a;
    }
 
 
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> v(20, 0);
	vector<int> c(20, 0);
	for( int i = 0; i < n; ++i ) cin >> v[i];
	for( int i = 0; i < n; ++i ) cin >> c[i];
	int ans = 0;
	for( int i = 0; i < n; ++i ){
		if( v[i] >= c[i] ) ans += (v[i]-c[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;}
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, x, t; cin >> n >> x >> t;

    if(n % x == 0){
        cout << (n/x) * t << endl;
    }else{
        cout << (n/x + 1) * t << endl;
    }

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    priority_queue <int> data;
    
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        data.push(a);
    }

    for (int i = 0; i < M; i++) {
        int temp = data.top() / 2;
        data.pop();
        data.push(temp);
    }

    long long ans = 0;
    while (!data.empty()) {
        ans += data.top();
        data.pop();
    }
    cout << ans << endl;

}

Measured memory_bytes: 892
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//s.find_by_order(index);
//s.order_of_key(value);
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod){
    ll result=1;
    while(power){
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod){
    return fast_power(base,mod-2,mod);
}

void solve() {
    ll n; cin>>n;
    if(n%1000){
        cout<<(n/1000 + 1)*1000 - n;
    } else cout<<0;
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}  

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

long long mod = 1e9 + 7;
int n;
vector<long long> get_val(long long num) {
  vector<long long> v(n);
  v[0] = 0;
  for (int i=1; i<n; i++) {
    v[i] = v[i-1] + num;
    v[i] %= mod;
  }
  return v;
}
int main() {
  cin>>n;
  long long a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  long long ans = 0;
  long long s = 1ll<<60 - 1;

  for (int i=0; i<60; i++) {
    long long cnt1 = 0;
    long long cnt0 = 0;
    long long num = 1ll << i;
    vector<long long> v = get_val(num);
    for (int j=0; j<n; j++) {
      bool flag = (a[j] >> i) & 1;
      if (flag) {
        ans += v[cnt0] % mod;
        ++cnt1;
      } else {
        ans += v[cnt1] % mod;
        ++cnt0;
      }
      ans %= mod;
    }
  }
  cout<<ans<<endl;
}

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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k, h;
    int answer = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) answer++;
    }
    cout << answer;
    return 0;
}

Measured memory_bytes: 256
s = input()
l = [0]*4
y = "Yes"
n = "No"
res = ""

for i in s:
    if i == "S":
        l[0] += 1
    elif i == "E":
        l[1] += 1
    elif i == "N":
        l[2] += 1
    elif i == "W":
        l[3] += 1

if (l[0] == 0 and l[2] >= 1) or (l[0] >= 1 and l[2] == 0) or (l[1] == 0 and l[3] >= 1) or (l[3] == 0 and l[1] >= 1):
    res = n
else:
    res = y

print(res)


Measured memory_bytes: 3064
gets
arr =  STDIN.gets.split.map(&:to_i)

min = arr.inject(1000000) do |cmin, i|
  if cmin < i then
    cmin
  else 
    i
  end
end

max = arr.inject(-1000000) do |cmax, i|
  if cmax > i then
    cmax
  else 
    i
  end
end

sum=(arr).to_a.inject {|sum,n| sum+n}

puts "#{min}\s#{max}\s#{sum}"

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  char  a,b,c,d,e,f,g,h,i;
  cin >> a>>b>>c>>d>>e>>f>>g>>h>>i;
  
  cout << a<< e << i << endl;

  
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import copy

def solve():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    candidates = copy.deepcopy(A[1:])

    for i in range(N-1):
        A = list(map(int, input().split()))
        A = copy.deepcopy(A[1:])

        copied_candidates = copy.deepcopy(candidates)
        for candidate in copied_candidates:
            if candidate in A:
                continue
            else:
                candidates.remove(candidate)
            
    print(len(candidates))



if __name__ == "__main__":
    solve()


Measured memory_bytes: 3444
line = input()

N = int(line.split()[0])
D = int(line.split()[1])

matrix = []
for dim_cnt in range(N):
    line = input()
    vector = []
    for cnt in range(D):
        elm = int(line.split()[cnt])
        vector.append(elm)
    matrix.append(vector)

check_list = []
for i in range(N-1):
    for elm in range(N-i-1):
        j = i + elm + 1
        check_list.append((i, j))

int_cnt = 0
for check_point in check_list:
    i_vector = matrix[check_point[0]]
    j_vector = matrix[check_point[1]]
    sq_sum = 0
    for dim_cnt in range(D):
        sq_elm = (i_vector[dim_cnt] - j_vector[dim_cnt])**2
        sq_sum = sq_sum + sq_elm
    dist = sq_sum**0.5
    if dist.is_integer():
        int_cnt += 1
print(int_cnt)

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

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

  int N;
  cin >> N;
  int A[N];
  map<int, int> mp;
  rep(i, N){
    cin >> A[i];
    mp[A[i]]++;
  }
  int ans = 0;
  for(pair<int, int> P : mp){
    if(P.second % 2 == 1){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  double A, B, X;
  cin >> A >> B >> X;
  double rad = 0;
  if (X >= A * A * B / 2) {
    double bp = 2.0/A*(A*B-X/A);
    rad = atan2(bp, A);
  } else {
    double ap = 2.0 * X / (A * B);
    rad = atan2(B, ap);
  }
  double deg = rad * 180.0 / M_PI;
  printf("%.10lf\n", deg);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using ll = long long;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b+a); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

signed main() {  
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n; cin >> n;
  string s; cin >> s;

  // r,g,b のすべての組み合わせ
  // - r,g,b の組み合わせかつ index の差が等しい

  int ac = 0,gc = 0,bc = 0;

  rep(i,n) {
    if (s[i] == 'R') {
      ac += 1;
    } else if (s[i] == 'G') {
      gc += 1;
    } else if (s[i] == 'B') {
      bc += 1;
    }
  }
  // すべての組み合わせ
  ll sum = ac*gc*bc;

  // index の差が等しい
  ll minus = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      int k = j + j - i;
      if (k >= n) continue;
      if (s[i] == s[j] || s[i] == s[k] || s[j] == s[k]) continue;
      minus++;
    }
  }
  
  cout << sum - minus << endl;

  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m;
    cin>>n>>m;
    int ll=0,rr=100010,l,r;
    rep(i,m){
        cin>>l>>r;
        ll=max(ll,l);
        rr=min(rr,r);
    }
    if(rr-ll+1<=0){
        cout<<0; return 0;
    }
    cout<<rr-ll+1;
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (A, B) = ReadStream<int,int>();
        if (A <= 5) WriteLine(0);
        else if (A <= 12) WriteLine(B/2);
        else WriteLine(B);
    }
}



class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 27268
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define SPACE " "
#define pff first.first
#define pfs first.second
#define psf second.first
#define pss second.second

int main(){

	ll N, M;
	cin >> N >> M;
	vector<ll> A;
	map<ll, ll> mp;
	A.pb(0);
	mp[0] ++;
	for(int i = 1; i <= N; i ++){
		ll a;
		cin >> a;
		A.pb(A[i - 1] + a);
		mp[A[i] % M] ++;
	}
	ll ans = 0;
	for(auto itr = mp.begin(); itr != mp.end(); itr ++){
		ans += itr->second * (itr->second - 1) / 2;
		//cout << "key = " << itr->first << ", val = " << itr->second << endl;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {

            String S = Console.ReadLine();
            String[] L = S.Split(' ');
            double W = int.Parse(L[0]);
            double H = int.Parse(L[1]);
            double x = int.Parse(L[2]);
            double y = int.Parse(L[3]);

            int center;

            if(W / 2 == x && H / 2 == y)
            {
                center = 1;
            }
            else
            {
                center = 0;
            }

            Console.WriteLine((W * H / 2) + " " + center);

        }
    }
}

Measured memory_bytes: 11092
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
win_hand = { "r": P, "s": R, "p": S }
prev_hand = {}
LOST,WON = -1,1

points = 0
for i in range(N):
  if i-K >= 0:
    if T[i] != T[i-K]:
      prev_hand[i] = WON
      points += win_hand[T[i]]
    else:
      if prev_hand[i-K] == WON:
        prev_hand[i] = LOST
      else:
        points += win_hand[T[i]]
        prev_hand[i] = WON
  else:
    prev_hand[i] = WON
    points += win_hand[T[i]]

print(points)

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, q;
    cin >> n >> q;
    vector<vector<ll>> g(n);
    REP(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll> val(n);
    REP(i, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        val[p] += x;
    }

    function<void(ll,ll)> dfs = [&](ll v, ll p) {
        for(auto to: g[v]) {
            if(to == p) continue;
            val[to] += val[v];
            dfs(to, v);
        }
    };
    dfs(0, -1);

    REP(i, n) cout << val[i] << (i==n-1?'\n':' ');

    return 0;
}


Measured memory_bytes: 30592
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;
    cin>>n;
    char s[100+5];
    scanf("%s",s);
    int sum=0,minsum=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='(')
        {
            sum+=1;
        }
        else
        {
            sum-=1;
            minsum=min(minsum,sum);
        }
    }
    for(int i=1;i<=-minsum;i++)
        cout<<"(";
    cout<<s;
    for(int i=1;i<=sum-minsum;i++)
        cout<<")";
    return 0;
}

Measured memory_bytes: 256