akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int Left;
    int Right;
    int Gokei = 0;
    for (int i = 0; i < N; i++){
        cin >> Left >> Right;
        Gokei += Right - Left + 1;
    }
    cout << Gokei << endl;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
inf=float("inf")
dp=[inf for i in range(n)]
dp[0]=0
dp[1]=abs(A[1]-A[0])
for i in range(2,n):
	dp[i]=min(dp[i],abs(A[i-1]-A[i])+dp[i-1],abs(A[i-2]-A[i])+dp[i-2])
print(dp[n-1])

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

int main(int argc, char *argv[]){
    int n,m;
    cin >> n >> m;
    int a=(n+1)/2;
    int c=0;
    for(int i=0;i<m;i++){
        cout << 1+i << " " << n-i << endl;
        c++;
        if(c==m) break;
        cout << a-1-i << " " << a+1+i << endl;
        c++;
        if(c==m) break;
    }
    return 0;
}

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

typedef long long ll;
const int maxn = 200005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int n, m;
char S[maxn];

struct edge
{
	int to, next;
} e[maxn * 2];
int h[maxn], deg[maxn][2], vis[maxn], tot;
int s, t, q[maxn];

void add(int u, int v)
{
	e[++tot] = (edge) {v, h[u]}; h[u] = tot;
	e[++tot] = (edge) {u, h[v]}; h[v] = tot;
	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];
}

int topo()
{
	for (int i = 1; i <= n; ++i)
		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;
	int cnt = 0;
	while (s < t) {
		int u = q[++s];
		++cnt;
		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;
	}
	return cnt;
}

int main()
{
	scanf("%d%d%s", &n, &m, S + 1);
	for (int i = 1; i <= m; ++i) add(gi(), gi());
	
	puts(topo() == n ? "No" : "Yes");
	
	return 0;
}


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

int main() {
 
  string s;
  cin >> s;
  
  string ans = "Yes";
  for(int i = 0; i < s.size(); i++) {
    int t = i + 1;
    if(t % 2 == 0) {
      if(s.at(i) =='R') {
        ans = "No";
      }
    } else {
      if(s.at(i) == 'L') {
        ans = "No";
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val S = scala.io.StdIn.readLine().toInt
  val K = scala.io.StdIn.readLine().split(" ").toList.map(_.toInt)

  val ans = K.zipWithIndex.filter( v => (K.dropRight(K.length - v._2 - 1)).max == v._1 ).map(v => v._1)
  println(ans.length)
}

Measured memory_bytes: 25388
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K,T,a[100],ans=0;
  cin>>K>>T;
  for(int i=0;i<T;i++){
    cin>>a[i];
    ans=max(ans,a[i]);
  }
  int t=ans-(K+1)/2;
  ans=0;
  if(K%2==0)ans++,t--;
  /*  
  K=(K-1)/2;
  while(K){
    if(t>0)ans+=t;
    t-=(K+1)/2;
    K=(K-1)/2;
    }*/
  cout<<max(ans+t*2,0)<<endl;
  return 0;
}


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

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n = 0, a = 0, b = 0;
    cin >> n >> a >> b;
    char temp;

    ll a_temp = 0, b_temp = 0, all_temp = 0;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp == 'a') {
            if(all_temp < (a + b)) {
                cout << "Yes\n";
                all_temp++;
            }
            else {
                cout << "No\n";
            }
        }
        else if(temp == 'b') {
            if(all_temp < (a + b)) {
                if(b_temp < b) {
                    cout << "Yes\n";
                    b_temp++;
                    all_temp++;
                }
                else {
                    cout << "No\n";
                }
            }
            else {
                cout << "No\n";
            }
        }
        else {
            cout << "No\n";
        }
    }
    
    return 0;
}

Measured memory_bytes: 640
S=list(input())

alphabet=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','None']

S.sort()

for s in alphabet:
  if s in S:
    pass
  else:
    print(s)
    break


Measured memory_bytes: 4208
import sys

h, w = map(int, input().split())
a = [[i for i in input()] for j in range(h)]

board = [[-1 for i in range(w)] for j in range(h)]
board[0][0] = 0

movecol = [1, 0]
moverow = [0, 1]
count = 0

# #の数を数える
for i in range(w):
    for j in range(h):
        if(a[j][i] == "#"):
            count += 1

def dfs(x, y, n):
    #これ以上進めない
    if(x >= w or y >= h or a[y][x] == "."):
        flag = -1
        return
    #右下についた
    if(x == w-1 and y == h-1):
        if(n == count):
            print("Possible")
            sys.exit()
        else:
            flag = -1

    for i in range(2):
        nextx = x + movecol[i]
        nexty = y + moverow[i]
        dfs(nextx, nexty, n+1)

dfs(0, 0, 1)
print("Impossible")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define MOD 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";
    cout<<endl;
}


Measured memory_bytes: 256
def get_prime_nums(max_p)
  primes = (0..max_p).map{true}
  primes[0] = primes[1] = false

  smp = Math::sqrt(0.5 + max_p).to_i
  count = 0

  for p in (2..smp)
    if (primes[p])
      count += 1
      (p * p).step(max_p, p){|q| primes[q] = false}
    end
  end

  #puts "#{count} primes"

  return primes
end

### main

primes = get_prime_nums(60000)

while (line = gets)
  n = line.chomp.to_i

  n0 = n - 1
  while (! primes[n0]) do
    n0 -= 1
  end

  n1 = n + 1
  while (! primes[n1]) do
    n1 += 1
  end

  puts "#{n0} #{n1}"
end

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

int main(){
  long double a, b, c;
  cin >> a >> b >> c;
  
  if (c - a - b >= 0){
    
    if (a * b < (c - a - b) * (c - a - b) / 4.0){
    cout << "Yes" << endl;
    }
    else{
    cout << "No" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
int main() {
	int a;
	std::cin >> a;
	if(a % 10 == 9 || a / 10 == 9) std::cout <<  "Yes"  << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,k,dem=0;

void nhap()
{
    scanf("%d %d",&n,&k);
    for (int i=1;i<=n;++i)
    {
        int x;
        scanf("%d",&x);
        dem+=(x>=k);
    }
    cout<<dem;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long temp = n;
		long x = sc.nextLong();
		n-=x;
//		System.out.println(n + " "+ x);
		long gcd = gcd(n,x);
		n/=gcd;
		x/=gcd;
		long a = n/x;
		long b = n%x;
		long ans = (2*a+2)*x+2*b-3;
		ans*=gcd;
		System.out.println(ans+temp);
	}
	static long gcd(long a, long b) {
		if(b==0) return a;
		return gcd(b,a%b);
	}
}


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

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

    if (n >= 10) cout << r << endl;
    else cout << r + (100 * (10 - n)) << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
bool f; 
int lps[N], g[N], dis[N];
 
int calc(int cur, int org){
    if(cur == org)  {
        f = 1;
        return -1;
    }
    if(dis[cur] != -1)
        return dis[cur];
    if(g[cur] == -1)
        return dis[cur] = 0;
    dis[cur] = 1 + calc(g[cur], org);
    return dis[cur];
}
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s, t;
    cin >> s >> t;
    int tl = t.length();
    /*for(int i = 1, l = 0; i < tl; i++){
        while(l > 0 && t[i] != t[l])
            l = lps[l-1];
        if(t[i] == t[l])
            lps[i] = lps[l] + 1, l++;
    }  */ 
    int i = 1, l = 0;
    while(i < tl){
        if(t[i] == t[l]){
            l++;
            lps[i] = l;
            i++;
        }
        else{
            if(l != 0)
                l = lps[l-1];
            else
                lps[i] = 0, i++;
        }
    }  
    string tmp = s;
    while(tmp.length() < tl)
        tmp += s;
    s = tmp + tmp;
    int sl = (s.length());
    i = 0; l = 0;
    for(int i = 0; i < sl; i++)
        g[i] = dis[i] = -1;
    while(i < sl){
        if(s[i] == t[l])
            i++, l++;
        if(l == tl){
            int u = (i-l)%sl;
            int v = (i)%(sl>>1);
            if(u < (sl >> 1)){
                g[u] = v;
            }
            l = lps[l-1];
        }
        else if(i < sl && t[l] != s[i]){
            if(l != 0)
                l = lps[l-1];
            else
                i += 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < (sl >> 1); i++){
        if(g[i] != -1){
            f = 0;
            int x = calc(g[i], i);
            if(f)
                return cout << -1, 0;
            dis[i] = 1 + x;
            ans = max(ans, dis[i]);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 30896
#include<bits/stdc++.h>
using namespace std;
string s;
int ans;
int main()
{
	cin>>s;
	int n=s.size();
	for(int i=1;i<n;i++)
	{
		if(s[i]!=s[i-1])
		{
			ans++;
		}
			
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
 
#define PI 3.1415926535897932384626433832795
 
double d; int a;
double vcos[6], vsin[6];
double x, y;
 
void koch_curve(int k)
{
    if (k == 0) {
        x += d*vcos[a % 6], y += d*vsin[a%6];
        printf("%.8lf %.8lf\n", x, y);
    } else {
        d /= 3;
        koch_curve(k-1), a++, koch_curve(k-1);
        a += 4;
        koch_curve(k-1), a++, koch_curve(k-1);
        d *= 3;
    }
}
 
int main()
{
    int n, i;
     
    for (i = 0; i < 6; i++) vcos[i] = cos(i*PI/3), vsin[i] = sin(i*PI/3);
 
    scanf("%d", &n);
 
    d = 100;        // (0,0) - (100,0);
 
    a = 0, x = 0, y = 0; puts("0.00000000 0.00000000");
    koch_curve(n);
    return 0;
}


Measured memory_bytes: 2096
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define INF (1<<21)
int dp[1001][1001];
pair<int,int> solve(vector<int> value , vector<int> weight , int W , int N){
	for(int i=0;i<1001;i++)
		for(int j=0;j<1001;j++)
			dp[i][j] = 0;
	for(int num=1;num<=N;num++){
		for(int w=0;w <= W;w++){
			if(w >= weight[num])dp[num][w] = max( dp[num-1][w] , dp[num-1][w-weight[num]] + value[num]);
			else dp[num][w] = dp[num-1][w];
		}
	}	
	int ans1 = *max_element(dp[N],dp[N]+W+1);
	int ans2 = find(dp[N],dp[N]+W+1,ans1)-dp[N];
	return make_pair(ans1,ans2);
}

int main(){
	int n,w,CaseNum=0;
	while(cin >> w && w){
		cout << "Case " << ++CaseNum << ":" << endl;
		cin >> n;
		vector<int> value(1+n) , weight(1+n);
		for(int i=1;i<=n;i++){
			scanf("%d,%d\n",&value[i],&weight[i]);
		}
		pair<int,int> ans = solve(value,weight,w,n);
		cout << ans.first << endl << ans.second << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=7777;
const int mod=998244353;

ll dp[mx];

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,S; cin>>N>>S;
	dp[0]=1;
	for (int i=0; i<N; i++) {
		int A; cin>>A;
		for (int j=S; j>=0; j--)
			dp[j+A]=(dp[j+A]+dp[j])%mod, dp[j]=(dp[j]<<1)%mod;
	}
	cout<<dp[S]<<"\n";
	return 0;
}

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

uint_fast64_t N, M;
vector<size_t> v({0});
bool cond[50505], p;
string s;

int main(){
    cin >> s;
    N = s.size();
    for(size_t i = 1; i <= N; ++i){
        p = s[i - 1] == '1';
        if(i * 2 <= N){
            cond[i] = p;
        }else{
            if(cond[N - i] != p)return 0 & puts("-1");
        }
        if(p)v.push_back(i);
    }
    if(!cond[1])return 0 & puts("-1");
    size_t j(0);
    M = v.size();
    v.push_back(N);
    for(size_t i = 1; i < M; ++i){
        printf("%lu %lu\n", v[i - 1] + 1, v[i] + 1);
        for(size_t j = v[i] + 1; j < v[i + 1]; ++j){
            printf("%lu %lu\n", v[i] + 1, j + 1);
        }
    }
    return 0;
}


Measured memory_bytes: 2548
N, A = map(int, input().split())
X = list(map(int, input().split()))
x_max = max(X)
Y = [x-A for x in X]

dp = [[0]*(2*N*x_max+1) for i in range(N+1)]
dp[0][N*x_max] = 1

for j in range(N+1):
    for t in range(2*N*x_max+1):
        if j >= 1 and 0 <= t - Y[j-1] <= 2*N*x_max:
            dp[j][t] = dp[j-1][t] + dp[j-1][t-Y[j-1]]
        elif j >= 1:
            dp[j][t] = dp[j-1][t]

print(dp[N][N*x_max]-1)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

void solve(long long N, long long X, std::vector<long long> L){
    ll ans=1;
    ll cur=0;
    rep(i,N){
        cur+=L[i];
        if(cur<=X)ans++;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, X, std::move(L));
}


Measured memory_bytes: 256
///supercalifragilisticexpialidocious.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef long double ld;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef pair<pii , int> piii;
typedef map<string , int> msi;
const int MAXN = 2e3 + 10;
int n , m , ans , dp[3 * MAXN][3 * MAXN];
int32_t main()
{
	cin >> n >> m;
	///base
	dp[0][0] = 1;
	///update
	for(int i = 1 ; i <= 3 * n ; i ++)
		for(int j = 0 ; j <= i / 2 ; j ++)
		{
			dp[i][j] += dp[i - 1][j] , dp[i][j] %= m;
			if(!j)
				continue;
			if(1 < i)
				dp[i][j] += (((i - 1) * dp[i - 2][j - 1]) % m) , dp[i][j] %= m;
			if(2 < i)
				dp[i][j] += (((i - 2) * (((i - 1) * dp[i - 3][j - 1]) % m)) % m) , dp[i][j] %= m;
		}
	///ans
	for(int i = 0 ; i <= n ; i ++)
		ans += dp[3 * n][i] , ans %= m;
	return cout << ans << endl , 0;
}


Measured memory_bytes: 281088
def main():
    l, r = map(int, input().split())
    mi = 2019
    c = 0

    for i in range(l, r):
        a = (i*i) % 2019
        for _ in range(min(r-l-c, 2019)):
            a = (a+i) % 2019

            if a < mi:
                mi = a
                if a == 0:
                    print(0)
                    return 
        c += 1

    print(mi)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9084
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

struct Data {
    ll h, a, d, s;
    
    Data() {}
    Data(ll h, ll a, ll d, ll s) :
        h{h}, a{a}, d{d}, s{s} {}

    bool operator < (const Data& d) const {
        return s < d.s;
    }
};

istream& operator >> (istream& is, Data& d)
{
    return is >> d.h >> d.a >> d.d >> d.s;
}

ll solve(Data& M, vector<Data>& ene)
{
    vector<pair<double, Data>> v;
    for (const Data& e : ene) {
        if (M.a <= e.d && M.d < e.a) return -1;
        ll turn = ceil((double)e.h / (M.a - e.d));
        if (e.a - M.d <= 0) continue;
        v.emplace_back((double)(e.a - M.d) / turn, e);
    }

    sort(v.rbegin(), v.rend());
    
    ll res = 0, total_turn = 0;
    for (const auto& d : v) {
        Data e = d.second;
        ll turn = ceil((double)e.h / (M.a - e.d));
        total_turn += turn;
        
        ll damage = (total_turn - (M.s > e.s)) * max(0LL, e.a - M.d);
        M.h -= damage;
        if (M.h <= 0) return -1;
        res += damage;
    }        
    return res;
}

int main()
{
    int N;
    cin >> N;
    Data M;
    cin >> M;
    vector<Data> ene(N);
    for (int i = 0; i < N; i++) {
        cin >> ene[i];        
    }
    cout << solve(M, ene) << endl;
    return 0;
}

Measured memory_bytes: 6628
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int j = 0;

	for(int i = a;i <= b;i++){
		if(c%i == 0){
			j++;
		}
	}
	System.out.println(j);
	}
}

Measured memory_bytes: 26380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> maze;
  rep(i, h){
    string str;
    cin >> str;
    maze.push_back(str);
  }
  int biggest = 0;
  rep(i, h){
    rep(j, w){
      if(maze[i][j] == '#') continue;
      vector<string> mazeCopy = maze;
      queue<vector<int>> que;
      vector<int> tmp = {j, i, 0};
      mazeCopy[i][j] = '#';
      que.push(tmp);
      int biggestInThisPattern = 0;
      while(!que.empty()){
        int x = que.front()[0];
        int y = que.front()[1];
        int cnt = que.front()[2];
        biggestInThisPattern = max(cnt, biggestInThisPattern);
        que.pop();
        for (int dx = -1, dy = 0, i = 0; i < 4; dx += dy, dy = dx - dy, dx = dy - dx, ++i) {
          if(0 <= x+dx && x+dx < w && 0 <= y+dy && y+dy < h && mazeCopy[y+dy][x+dx] == '.'){
            mazeCopy[y+dy][x+dx] = '#';
            vector<int> vec = {x+dx, y+dy, cnt+1};
            que.push(vec);
          }
        }
      }
      biggest = max(biggest, biggestInThisPattern);
    }
  }
  cout << biggest << endl;
  return 0;
}
  
  
  
  
  

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	n   uint64
	tmp uint64
	ans uint64
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ = strconv.ParseUint(sc.Text(), 10, 64)
	ts := make([]uint64, 0, n)

	for sc.Scan() {
		tmp, _ = strconv.ParseUint(sc.Text(), 10, 64)
		ts = append(ts, tmp)
	}

	ans = lcm(ts[0], ts[1:])
	fmt.Println(ans)
}

func lcm(a uint64, l []uint64) uint64 {
	if len(l) == 0 {
		return a
	}

	b := l[0]
	n := a / gcd(a, b) * b

	return lcm(n, l[1:])
}

func gcd(x, y uint64) uint64 {
	r := x % y

	if r == 0 {
		return y
	}

	return gcd(y, r)
}


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

int p[8];
int c[8] = { 4, 1, 4, 1, 2, 1, 2, 1 };

int main()
{
	while( std::cin >> p[0] )
	{
		for( int i = 1; i != 8; ++i )
			std::cin >> p[i];

		std::vector<int> ans( 8, 0 );
		int mi = 1 << 30;
		for( int r = 0; r != 8; ++r )
		{
			int rest = 0;
			std::vector<int> mem( 8, 0 );

			for( int i = 0; i != 8; ++i )
			{
				mem[i] = c[( i + r ) % 8];
				rest += std::max( 0, p[i] - mem[i] );
			}

			if( mi > rest || ( mi == rest && ans > mem ) )
			{
				mi = rest;
				std::copy( mem.begin(), mem.end(), ans.begin() );
			}
		}

		for( int i = 0; i != 8; ++i )
			std::cout << ans[i] << ( i == 7 ? '\n' : ' ' );
	}

	return 0;
}

Measured memory_bytes: 1208
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	string s, t, u;
  	int a, b;
  	cin >> s >> t >> a >> b >> u;
  	if(u==s){
    	cout << a-1 << " " << b << endl;
    }
  	else if (u==t){
    	cout << a << " " << b-1 << endl;
  	}
	return;
}

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


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

public static class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var gusu = 0;
        var kisu = 0;

        for (var i = 1; i<= n; i++)
        {
            if (i % 2 == 0)
            {
                gusu++;
            }
            else
            {
                kisu++;
            }
        }
        Console.WriteLine(((double)kisu / (double)(gusu + kisu)).ToString());
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;
vii data;
int n;
int cnt[(int)2e5 + 5];
int add(int i){
    cnt[data[i].second]++;
    if(cnt[data[i].second] == 1)return 1;
    return 0;
}
int remove(int i){
    cnt[data[i].second]--;
    if(cnt[data[i].second] == 0)return -1;
    return 0;
}
int check(){
    memset(cnt, 0, sizeof cnt);
    int ans = 0;
    int i = 1;
    ans += add(i);
    int j = 1;
    i++;
    int len = 1e18;
    if(ans == n)len= min(len, data[i-1].first - data[j].first);
    while(i < data.size() -1){
        ans += add(i);
        while(ans > n){
            ans += remove(j);
            j++;
        }
        while(ans == n && i > j && cnt[data[j].second] > 1){
           ans += remove(j); 
           j++;
        }
        i++;
        if(ans == n)len= min(len, data[i-1].first - data[j].first);
    }
//    debug(len);
    return len;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    int x, y;
    FOR(i, n){
        cin >> x >> y;
        if(y < x)swap(x, y);
        data.pb(mp(x, i));
        data.pb(mp(y, i));
    }
    sort(data.rbegin(), data.rend());
    map<int, bool> found;
    int ans = 1e18;
    int start =-1;
    FOR(i, data.size()){
        //debug(data[i].first);
        if(found[data[i].second] && start == -1){
            start = data[i].first;
        } 
        found[data[i].second] = true;
        if(found.size() == n){
            ans =min(ans, (data[0].first - data[i].first)*((start == -1 ? data[i+1].first : start)- data.back().first)); 
            break;
        }
    }
    if(data[0].second == data.back().second){
        cout << ans;
        return 0;
    }
    int len = data[0].first - data.back().first;

    //debug("here");
//    debug(len);
    reverse(data.begin(), data.end());
    //debug(len);
    ans = min(ans, len * check());
    cout << ans;

}




Measured memory_bytes: 22376
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a;
    cin >> a;
    cout << a + a * a + a * a * a;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
# define MAX_N 1000010 // 10^6 + 10

// UnionFindTree
// 使い方(インスタンス名 : tree)
// インスタンス生成 : UnionFind tree;
// tree.init(要素数)
// uniteしたりsameかどうか判定したり

class UnionFind{
    private:
        int par_[MAX_N];
        int rank_[MAX_N];
        int size[MAX_N];
        int groups_;
    
    public:
        void init(int n){ // initializes the tree 
            for(int i=0; i<n; i++){
                par_[i] = i;
                rank_[i] = 0;
                size[i] = 1;
            }
            groups_ = n;
        } 
        int rootOf(int x){ // returns the root of x 
            if(par_[x] == x){
                return x;
            }
            else{
                return par_[x] = rootOf(par_[x]);
            }
        } 
        void unite(int x, int y){ // unites x and y 
            x = rootOf(x);
            y = rootOf(y);
            if(x == y) return;
            if(rank_[x] < rank_[y]){
                par_[x] = y;
                groups_--;
                size[y] += size[x];
            }
            else{
                par_[y] = x;
                groups_--;
                size[x] += size[y];
                if(rank_[x] == rank_[y]) rank_[x]++;
            }
        }
        bool isSameGroupe(int x, int y){ // whether x and y are united
            return rootOf(x) == rootOf(y);
        }
        int countGroups(){ // returns the number of groups
            return groups_;
        }
        // 6 / 19 Updated!! (連結成分のサイズを返す)
        int sizeOf(int x){
            return size[rootOf(x)];
        }
};

int main(void){
    int n, q;
    cin >> n >> q;
    UnionFind tree;
    tree.init(n);
    for(int i = 0; i < q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0){
            tree.unite(u, v);
        }
        else if(t == 1){
            if(tree.isSameGroupe(u, v)){
                cout << 1 << endl;
            }
            else{
                cout << 0 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 5632
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int a[110]; 
bool check(int a,int b,int c ){
	if(a!=b&&b!=c&&a!=c) return true; 
	return false;
}
int main()
{
	int n;
	cin>>n ;
	for(int i=1;i<=n;i++){
		cin>>a[i]; 
	}
	int ans=0;
	sort(a+1,a+n+1);
	for(int i=1;i<=n-2;i++)
		for(int j=i+1;j<=n-1;j++)
			for(int k=j+1;k<=n;k++){
				if(a[i]+a[j]>a[k]&&a[i]-a[j]<a[k]&&check(a[i],a[j],a[k])){
					ans++;
				}
			}
	cout<<ans<<endl;	
	return 0;
 } 

Measured memory_bytes: 3620
N, K = map(int, input().split())
P = list(map(int, input().split()))
acc = [0]

def calc(n):
  num =  n * (n+1) / 2
  return num / n

tmp = 0
for p in P:
  num = calc(p)
  tmp += num
  acc.append(tmp)

left = 0
right = K 
ans = 0

while right <= N:
  ans = max(ans, acc[right] - acc[left])
  left += 1
  right += 1

print(ans)

Measured memory_bytes: 76040
import java.util.Scanner;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			System.out.println(((double) w) * h / 2.0d + " " + (((x + x == w) && (y + y == h)) ? 1 : 0));
		}
	}
}


Measured memory_bytes: 23636
function Main(input) {
    var N = parseInt(input[0].split(/\s/)[0], 10);
    var D = parseInt(input[0].split(/\s/)[1], 10);
    var X = input.slice(1).map(x => {
        return x.split(/\s/).map(num => parseInt(num, 10));
    });

    var result = 0;

    for (var i = 0; i < N - 1; i++) {
        for (var j = i + 1; j < N; j++) {
            var dist = 0;
            var distSum = 0;
            for (var d = 0; d < D; d++) {
                distSum += Math.pow((X[j][d] - X[i][d]), 2);
            }
            dist = Math.sqrt(distSum);
            if (Number.isInteger(dist)) {
                result++;
            }
        }
    }
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

Measured memory_bytes: 21192
from heapq import heappush, heappop, heapify
from itertools import product

def solve():
    hq = [(0, y, x) for y, x in product(xrange(m), xrange(n)) 
          if not(0 < y < m - 1 and 0 < x < n - 1)]
    heapify(hq)
    while len(hq) != 0:
        cost, cy, cx = heappop(hq)
        if field[cy][cx] == "&":
            return cost
        if memo[cy][cx] <= cost:
            continue
        memo[cy][cx] = cost
        for dx, dy in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            ny, nx = cy + dy, cx + dx
            if 0 <= ny < m and 0 <= nx < n:
                if field[ny][nx] != "#" and field[cy][cx] == "#": 
                    heappush(hq, (cost + 1, ny, nx))
                else:
                    heappush(hq, (cost, ny, nx))
    return None

while True:
    n, m = map(int, raw_input().split())
    if n | m == 0:
        break
    memo = [[1 << 20] * n for _ in xrange(m)]
    field = [raw_input() for _ in xrange(m)]    
    print solve()

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

int main () {
    ll N, K; cin >> N >> K;
    ll neg = 0, zer = 0, pos = 0;
    vector<ll> negative;
    vector<ll> positive;
    for (ll i = 0; i < N; i++) {
        ll a; cin >> a;
        if (a < 0) {
            negative.push_back(a);
            neg++;
        } else if (a == 0) {
            zer++;
        } else {
            positive.push_back(a);
            pos++;
        }
    }
    ll minus = neg * pos;
    ll zero = zer * (pos + neg) + zer * (zer-1) / 2;
    ll plus = pos * (pos-1) / 2 + neg * (neg-1) / 2;
    sort(negative.begin(), negative.end());
    sort(positive.begin(), positive.end());

    if (K <= minus) {
        ll ng = (ll)-1e18 - 1, ok = -1;
        while (ok - ng != 1) {
            ll c = (ok + ng) / 2;
            ll k = 0;
            for (ll i = 0; i < neg; i++) {
                if (negative[i] * positive[pos-1] <= c) {
                    ll ngi = -1, oki = pos-1;
                    while (oki - ngi != 1) {
                        ll ci = (oki + ngi) / 2;
                        if (negative[i] * positive[ci] <= c) {
                            oki = ci;
                        } else {
                            ngi = ci;
                        }
                    }
                    k += pos - oki;
                }
            }
            if (K <= k) {
                ok = c;
            } else {
                ng = c;
            }
        }
        cout << ok << endl;
    } else if (K <= zero + minus) {
        cout << 0 << endl;
    } else {
        K -= (zero + minus);
        ll ng = 0, ok = 1e18;
        while (ok - ng != 1) {
            ll c = (ok + ng) / 2;
            ll k = 0;
            for (ll i = 0; i < pos; i++) {
                if (positive[i] * positive[i] > c) break;
                ll oki = i, ngi = pos;
                while (ngi - oki != 1) {
                    ll ci = (oki + ngi) / 2;
                    if (positive[i] * positive[ci] <= c) {
                        oki = ci;
                    } else {
                        ngi = ci;
                    }
                }
                k += oki - i;
            }
            sort(negative.begin(), negative.end(), greater<ll>());
            for (ll i = 0; i < neg; i++) {
                if (negative[i] * negative[i] > c) break;
                ll oki = i, ngi = neg;
                while (ngi - oki != 1) {
                    ll ci = (oki + ngi) / 2;
                    if (negative[ci] * negative[i] <= c) {
                        oki = ci;
                    } else {
                        ngi = ci;
                    }
                }
                k += oki - i;
            }
            if (k >= K) {
                ok = c;
            } else {
                ng = c;
            }
        }
        cout << ok << endl;
    }
}


Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	vector<double>l;
	double x, h;
	while (cin >> x >> h){
		if (x == 0 && h == 0)break;
		double sqr = x*x;
		double tri = sqrt(x/4*x + h*h)*x / 2;
		l.push_back(sqr + tri * 4);
	}
	for (double i : l) {
		printf("%.6f\n", i);
	}
	char ch;
	cin >> ch;
}

Measured memory_bytes: 3088
n = int(input())
a = list(map(int, input().split()))

min_ind = a.index(min(a))

while True:
    min_num = min(a)
    min_ind = a.index(min_num) 
    a = [n % min_num for n in (a[:min_ind] + a[min_ind+1:]) if n % min_num != 0]
    if a == []:
        print(min_num)
        exit()
    a.append(min_num)

Measured memory_bytes: 14252
#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <cmath>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <sstream>

// short keywords

#define ipow(a,b) (int)pow(a,b)
#define pi(a,b) pair<int,int>(a,b)
#define pis(a,b) pair<int,string>(a,b)
#define pc(c,d) pair<int,pair<int,string>>(c,d)
#define pp(a,b,c) pair<pair<int,int>,int>(pi(a,b),c)
#define ps(a,b,c) pair<string,pair<int,int>>(a,pi(b,c))
#define pic(c,d) pair<char,int>(c,d)
#define pii(a,b,c) pair<int,pair<int,int>>(a,pi(b,c))

// for loops

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
using namespace std;

// short keywords2
typedef long long ll;
typedef set<int>::iterator sit;
typedef vector <int> ::iterator vit;
typedef map<int,int>::iterator mit;
typedef multimap<int,int>::iterator mmit;

class Task
{
public:
    const int k=1000000;
    void solve(istream& in,ostream& out)
    {
        string s;
        in>>s;
        int a=0,z=0;
        int n=s.length();
        for(int i=0;i<n;i++)
        {
            if(s[i]=='A')
            {
                a=i;
                break;
            }
        }

        for(int i=0;i<n;i++)
        {
            if(s[i]=='Z')
            {
                z=i;
            }
        }

        out<<z-a+1<<endl;
    }

    int c(int a,int b)
    {
        int res=0;
        reps(i,1,15)
        {
            if(a/(int)pow(b,i)!=0)
            {
                res+=a/(int)pow(b,i);
            }
            else
            break;
        }

        return res;
    }

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

    bool isprime(int n)
    {
        if(n==1 || (n%2==0 && n!=2))
        {
            return false;
        }
        else if(n==2 || n==3)
        {
            return true;
        }
        else
        {
            int res=0;
            for(int i=3 ;i<=(int)sqrt(n) ;i+=2)
            {
                if(n%i==0)
                {
                    res++;
                    break;
                }
            }

            if(res==0)
            {
                return true;
            }
            else
            return false;
        }
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}



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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// 標準入力
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int x = Integer.parseInt(br.readLine());

		int ans = 1;

		for (int i = 1; i <= 1000; i++) {
			for (int j = 2; j < 1000; j++) {
				int anstemp = (int) Math.pow(i, j);
				if (x < anstemp) {
					break;
				}
				if (ans < anstemp) {
					ans = anstemp;
				}
			}
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 21204
W, H, N = map(int, input().split())

xl, xr = 0, W
yl, yh = 0, H

for i in range(N):
    xi, yi, ai = map(int, input().split())

    if ai == 1:
        xl = max(xi, xl)
    elif ai == 2:
        xr = min(xi, xr)
    elif ai == 3:
        yl = max(yi, yl)
    else:
        yh = min(yi, yh)

if xr - xl > 0 and yh - yl > 0:
    ans = (xr - xl) * (yh - yl)
else:
    ans = 0

print(ans)


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

int main() {
  int N;
  int M;
  int a[100002];
  int b[100001];
  cin >> M >> N;
  for(int i=0;i!=N;i++){
    cin >> a[i];
  }
  sort(a,a+N);
  int ans=0;
  for(int i=0;i!=N-1;i++){
    b[i]=a[i+1]-a[i];
  }
  sort(b,b+N-1,greater<int>());
  for(int i=0;i!=M-1;i++){
    ans+=b[i];
  }
  cout << a[N-1]-a[0]-ans << endl;
}


Measured memory_bytes: 1024
n=gets.to_i
ac=0
wa=0
tle=0
re=0
n.times.each do
    v=gets.chomp.to_s
    if v=="AC"
        ac+=1
    elsif v=="TLE"
        tle+=1
    elsif v=="WA"
     wa+=1
     else
     re+=1
     end
end


puts "AC x #{ac}"
puts "WA x #{wa}"
puts "TLE x #{tle}"
puts "RE x #{re}"

Measured memory_bytes: 14272
from bisect import bisect


def solve(l, r):
    if l > r:
        return l
    m = (l + r) // 2
    j = bisect(flowers, (m, float('inf')))
    t = sum((m - w) // d + 1 for w, d in flowers[:j])
    if t < k:
        l = m + 1
    else:
        r = m - 1
    return solve(l, r)


n, k = map(int, input().split())
flowers = [tuple(map(int, input().split())) for _ in range(n)]
flowers.sort()
print(solve(1, flowers[0][0] + flowers[0][1] * k))


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int q;
string x, y;
int dp[1111][1111];

void print() {
   for (int i = 0; i <= x.size(); i++) {
      for (int j = 0; j <= y.size(); j++) {
         cout << dp[i][j];
      }
      puts("");
   }
}

void solve() {
   int n = x.size() - 1, m = y.size() - 1;
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         if (x[i] == y[j]) {
            dp[i][j] = dp[i-1][j-1] + 1;
         } else {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
         }
      }
   }
   cout << dp[n][m] << endl;
}

int main() {
   cin >> q;
   while (q--) {
      fill(dp[0], dp[1111], 0);
      cin >> x >> y;
      x = "#" + x, y = "#" + y;
      solve();
   }

   return 0;
}


Measured memory_bytes: 8004
//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int lMax = 1;
        int rMin = 100000;

        for(int i=0;i<m;i++) {
            int lCur = sc.nextInt();
            int rCur = sc.nextInt();
            lMax = Math.max(lMax, lCur);
            rMin = Math.min(rMin, rCur);
        }

        pw.println((rMin >= lMax) ? rMin - lMax + 1 : 0);

        pw.close();
    }
}


Measured memory_bytes: 39920
import sys
n,m=map(int,input().split())
x =list(map(int,input().split()))

ans=0
if n>=m:
    ans=0
else:
    x.sort()
    diff=[0]*(m-1)

    for i in range(m-1):
        diff[i]=x[i+1]-x[i]

    diff.sort()

    ans=0
    
    for i in range(m-n):
        ans+=diff[i]

print(ans)


Measured memory_bytes: 85344
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <functional>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); //cinの高速化

  int N;
  int M;
  cin >> N >> M;
  vector<ll> A(N);
  for(int i=0; i<N; ++i) cin >> A[i];
  sort(A.begin(), A.end());
  vector<pair<ll,ll>> X(M);
  REP(i,M){
    int B, C;
    cin >> B >> C;
    X[i] = make_pair(-C,-B);
  }
  sort(X.begin(), X.end());
//  REP(i,M) OUT(-X[i].first <<"," << -X[i].second);
  
  int cnt=-1;
  for(int i=0; i<M; ++i){
    for(int j=0; j<-X[i].second; ++j){
      ++cnt;
      if(A[cnt] < -X[i].first){
        A[cnt] = -X[i].first;
      }
      else goto for_exit;
      if(cnt == N-1) goto for_exit;
    }
  }
  for_exit:
  
  ll ans=0;
  REP(i,N) ans += A[i];
  OUT(ans);
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
string S;
int len;
int bin[10];
int idx = 0, cnt = 0;
long long sum = 0;


long long stringTolong(string S){
    int len_ = S.size();
    long long digit, D = 0;
    for(int i = 0; i < len_; i++){
        digit = S[i] - 48;
        D += digit * pow(10, len_-i-1);
    }
    return D;
}

void calcSum(int Bit[10], string S_){
    long long sum_ = 0;
    int point = 0;
    string sub;
    for(int i = 0; i < len-1; i++){
        if(Bit[i] == 1){
            sub = S_.substr(point, i-point+1);
            sum += stringTolong(sub);
            point = i+1;
        }
    }
    sub = S_.substr(point, len-point);
    sum += stringTolong(sub);
}

int bitserch(int idx, int BitY[10], int BitN[10]){
    if(idx == len-1){
        calcSum(BitY, S);
        return 0;
    }
    BitY[idx] = 1;
    BitN[idx] = 0;
    
    int BitY_[10], BitN_[10];
    for(int i = 0; i < 10; i++){
        if(i == idx){
          BitY_[i] = 1;
          BitN_[i] = 0;
        }
        else{
          BitY_[i] = BitY[i];
          BitN_[i] = BitN[i];
        }
    }
    idx++;
    bitserch(idx, BitY_, BitY_);
    bitserch(idx, BitN_, BitN_);   

}

int main(){
    cin >> S;
    len = S.size();
    int init[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    bitserch(idx, init, init);
    cout << setprecision(10) << sum << endl;    
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

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


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int data[200]={};
        rep(i,n){
            cin>>data[i];
        }
        int k;
        cin>>k;
        
        int sum=0;
        
        int left=0,right=n-1;
        int cent;
        while(1){
            cent=( left+right )/2;
            sum++;
            if(data[cent]==k)break;
            if(data[cent]>k){
                right=cent-1;
            }
            if(data[cent]<k){
                left=cent+1;
            }
            
            if( left>right )break;
        }
        cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 1160
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e6 + 20 , mod = 998244353 ;
int n , a[N] , ans ;
int sum[N] , val[N] ;
vector <int> dv[N] ;

inline int pw (int a , int b) {
	int res = 1 ;
	while (b) {
		if (b & 1) res = 1ll * res * a % mod ;
		a = 1ll * a * a % mod ;
		b >>= 1 ;
	}
	return res ;
}

int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
	
	for (int i = 1 ; i < N ; i ++)
		for (int j = i ; j < N ; j += i)
			dv[j].pb(i) ;

	cin >> n ;

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

		for (int x : dv[a[i]]) {
			val[x] = (val[x] + 1ll * sum[x] * a[i]) % mod ;
			sum[x] = (sum[x] + a[i]) % mod ;
		}
	}

	for (int i = N - 1 ; i > 0 ; i --) {
		ans = (ans + 1ll * val[i] * pw(i , mod - 2)) % mod ;
		for (int j : dv[i]) {
			if (i == j) continue ;
			val[j] = (val[j] - val[i] + mod) % mod ;
		}
	}

	cout << ans << '\n' ;
}


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

using namespace std;

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

int main() {
	int k;
	cin >> k;
    long long sum = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
            long long f = gcd(i, j);
			for (int c = 1; c <= k; c++) {
				long long temp = gcd(f, c);
                sum += temp;
			}
		}
	}
    cout << sum;
}

Measured memory_bytes: 3584