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

const int INF = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  int v[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> v[i];
  }

  int ans = 0;
  for ( int a = 0; a <= min(n, k); a++ ) {
    for ( int b = 0; a+b <= min(n, k); b++ ) {
      priority_queue<int, vector<int>, greater<int>> q;
      int sm = 0;
      int remk = k-(a+b);
      for ( int i = 0; i < a; i++ ) {
        sm += v[i];
        q.push(v[i]);
      }
      for ( int i = 0; i < b; i++ ) {
        sm += v[n-1-i];
        q.push(v[n-1-i]);
      }
      while ( remk-- > 0 && q.size() > 0 && q.top() < 0 ) {
        sm -= q.top();
        q.pop();
      }
      ans = max(ans, sm);
    }
  }

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

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
 
int main(){
    ll N,T;
    cin >> N >> T;
    ll time = 0;
    ll sum = 0;
    REP(i,N){
        ll t;
        cin >> t;
        if(i != 0){
            ll delta = t - time;
            if(delta < T) sum += delta;
            else sum += T;
            time = t;
            //printf("sum:%lld\n", sum);
        }
    }
    sum += T;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#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 pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;


int main(){
	ll n,a,b;
	std::cin >> n>>a>>b;
	vector<ll>x(n);
	ll ans=0LL;
	rep(i,n)std::cin >> x[i];
	rep(i,n-1){
		if((x[i+1]-x[i])*a>b)ans+=b;
		else ans+=(x[i+1]-x[i])*a;
	}
	std::cout << ans << std::endl;
}



Measured memory_bytes: 1024
class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 0
        s = 0
        step = 1 << self.size.bit_length()
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                print(self.bit[i + step - 1], i, step)
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for i in range(n):
  d[a[i]]=i+1
Bit = BinaryIndexedTree(n+1)
ans=0
for i in range(n):
  j=i+1
  i=d[j]
  x=Bit.sum(i)
  ok=i
  ng=-1
  while ok - ng > 1:
    mid=(ok+ng)//2
    if Bit.sum(mid)==x:
      ok=mid
    else:
      ng=mid
  l=ok+1
  ok=i
  ng=n+1
  while ng - ok > 1:
    mid=(ok+ng)//2
    if Bit.sum(mid)==x:
      ok=mid
    else:
      ng=mid
  r=ok
  ans+=j*(i-l+1)*(r-i+1)
  Bit.add(i,1)
print(ans)
  

Measured memory_bytes: 100724
import numpy as np
n = int(input())
L = [int(i) for i in input().split()]
T = [-1 for i in range(n)]

for i in range(n):
  T[L[i]-1] = i+1

for i in range(n-1):
  print("{0} ".format(T[i]), end="")
print(T[-1])

Measured memory_bytes: 23440
#include<iostream>
#include<string>

using namespace std;

int main(){
   int map[200000];
   string s;
   cin >> s;
   char prev =0;
   int size = 0;
   for(int i=0;i<s.size();i++){
      if(prev == 'B' && s[i] != 'C'){
         map[size] = 2;
         size++;
      }
      if(s[i] == 'A'){
         map[size] = 0;
         size++;
      }else if(s[i] == 'B'){

      }
      else if(s[i] == 'C' && prev == 'B'){
         map[size] = 1;
         size++;
      }else{
         map[size] = 2;
         size++;
      }
      prev = s[i];
   }
   if(prev == 'B'){
      map[size] = 2;
      size++;
   }

   /*
   for(int i=0;i<size;i++){
      cout << map[i];
   }
   cout << endl;
   */

   int cnt_b=0;
   long ans = 0;
   for(int i=size - 1;i>=0;i--){
      if(map[i] == 0){
         ans += cnt_b;
      }else if(map[i] == 1){
         cnt_b++;
      }else{
         cnt_b=0;
      }
   }

   cout << ans << endl;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, T;
    cin >> K >> T;
    vector<int> as(T);
    for(int i=0; i<T; i++) cin >> as.at(i);

    priority_queue<pair<int, int>> q;
    for(int i=0; i<T; i++)
    {
        q.push(make_pair(as.at(i), i));
    }

    int prei = -1;
    int ans = 0;
    while(!q.empty())
    {
        pair<int, int> p = q.top();
        q.pop();
        pair<int, int> temp = p;
        if(!q.empty() && p.second == prei)
        {
            p = q.top();
            q.pop();
            q.push(temp);
        }
        if(p.second == prei) ans++;
        p.first--;
        prei = p.second;
        if(p.first != 0) q.push(p);
    }
    cout << ans << '\n';

    return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif
template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c; return o;
}
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;


int main() {
	#ifdef LOCAL
	auto stTime = clock();
	#endif
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int N, K;
	vi A;
	cin >> N >> K;
	A.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		int L = 0, LR = 0;
		for (int j = 0; j < i; ++j) {
			L += A[j] > A[i];
		}
		for (int j = 0; j < N; ++j) {
			LR += A[j] > A[i];
		}
		ll add = (L * 1LL * K) % 1000000007;
		ans = (ans + add) % 1000000007;
		add = (K * 1LL * (K - 1) / 2) % 1000000007;
		add = (add * LR) % 1000000007;
		ans = (ans + add) % 1000000007;
	}

	cout << ans << '\n';

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int R = 90;
		double x = 0, y = 0;
		while (scanner.hasNext()) {
			String str = scanner.next();
			String[] ab = str.split(",");
			if (Integer.parseInt(ab[0]) == 0 && Integer.parseInt(ab[1]) == 0) {
				System.out.println((int)x);
				System.out.println((int)y);
				break;
			}
			x += Integer.parseInt(ab[0]) * Math.cos(R * Math.PI / 180);
			y += Integer.parseInt(ab[0]) * Math.sin(R * Math.PI / 180);
			R -= Integer.parseInt(ab[1]);


		}
		scanner.close();
	}

}



Measured memory_bytes: 25884
#!/usr/bin/env python3
import collections
n = int(input()) 
S = [input() for _ in range(n)]
c = collections.Counter(S)
print("AC x " + str(c["AC"]))
print("WA x " + str(c["WA"]))
print("TLE x " + str(c["TLE"]))
print("RE x " + str(c["RE"]))

Measured memory_bytes: 16544
input_KN = list(map(int, input().split()))
K = input_KN[0] 
N = input_KN[1] 
ienokyori= list(map(int, input().split()))
ienokyori.append(K)
if(ienokyori[0]==0):
    max_ienokyori = 0 
else:
    max_ienokyori = ienokyori[0]+abs(ienokyori[-1]-ienokyori[-2])
for i in range(N):
    if(max_ienokyori < abs(ienokyori[i]-ienokyori[i+1])):
        max_ienokyori = abs(ienokyori[i]-ienokyori[i+1])

print(K-max_ienokyori)


Measured memory_bytes: 26444
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int k, n;
	cin >> k >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	int max_d = a[0] - a[n-1] + k;
	rep(i, n-1) chmax(max_d, a[i+1] - a[i]);
	cout << k - max_d << endl;
}


Measured memory_bytes: 1024
import math
import itertools

n = int(input())

fac = math.factorial(n)

p = []
for i in range(n):
   x, y = list(map(int, input().split()))
   p.append([x, y])

# print(fac)
# print(p)
# print()

################

term = 0
for c in list(itertools.permutations(p)):
    t = 0
    for i in range(len(c)-1):
        t += math.sqrt((c[i][0] - c[i+1][0]) ** 2 + (c[i][1] - c[i+1][1]) ** 2)
        # print("x=%d y=%d and x=%d y=%d" % (c[i][0], c[i][1], c[i+1][0], c[i+1][1]))
        # print(t)
    term += t
    # print(term)
print(term / fac)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    ll n,m;cin>>n>>m;
    vll a(n);rep(i,n)cin>>a[i];
    sort(all(a));reverse(all(a));
    ll l=0,r=2e5+1,mid,sum,al,ar,am;
    while(r-l>1){
        mid=(l+r)/2;//mid以上の組み合わせの個数
        sum=(ll)0;
        rep(i,n){
            al=-1;ar=n;
            while(ar-al>1){
                am=(al+ar)/2;
                if(a[i]+a[am]<mid)ar=am;
                else al=am;
            }
            sum+=al+1;
        }
        if(sum<m)r=mid;
        else l=mid;
    }
    ll ans=(ll)0;sum=(ll)0;
    vll b(n+1);
    rep(i,n)b[i+1]=b[i]+a[i];
    rep(i,n){
        al=-1;ar=n;
        while(ar-al>1){
            am=(al+ar)/2;
            if(a[i]+a[am]<l)ar=am;
            else al=am;
        }
        ans+=(al+1)*a[i]+b[al+1];
        sum+=al+1;
    }
    ans-=(sum-m)*l;
    cout<<ans<<endl;
    //cout<<sum<<" "<<l<<endl;
}

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

int n,c,a[410],b[410];
const long long mod=1e9+7;
long long dp[410][410],s[410][410];
inline long long ksm(long long x,long long y,long long mod)
{
	long long res=1;
	while(y)
	{
		if(y&1)
		res=(res*x)%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;++i)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
	scanf("%d",&b[i]);
	for(int i=1;i<=400;++i)
	{
		for(int j=0;j<=400;++j)
		s[i][j]=(s[i-1][j]+ksm(i,j,mod))%mod;
	}
	for(int i=0;i<=c;++i)
	dp[1][c-i]=(s[b[1]][i]-s[a[1]-1][i]+mod)%mod;	
	for(int i=2;i<=n;++i)
	{
		for(int j=0;j<=c;++j)
		{
			for(int k=0;k<=j;++k)
			{
				dp[i][j-k]=(dp[i][j-k]+dp[i-1][j]*((s[b[i]][k]-s[a[i]-1][k]+mod)%mod))%mod;
			}
		}
	}
	printf("%lld\n",dp[n][0]);
	return 0;
}

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

void put4(int x,int y)
{
	string s[4];
	s[0]="aaca",
	s[1]="bbca",
	s[2]="acbb",
	s[3]="acaa";
	for(int i=0;i<4;i++,puts(""))
	{
		for(int j=1;j<=x;j++) putchar('.');
		for(int j=0;j<4;j++) putchar(s[i][j]);
		for(int j=1;j<=y;j++) putchar('.');
	}
}
void put3(int x)
{
	string s[3];
	s[0]="aab",
	s[1]="b.b",
	s[2]="baa";
	for(int i=0;i<3;i++,puts(""))
	{
		for(int j=1;j<=x;j++) putchar('.');
		for(int j=0;j<3;j++) putchar(s[i][j]);
	}

}
void put5(int x)
{
	string s[5];
	s[0]="aabbc",
	s[1]="bcc.c",
	s[2]="b..ca",
	s[3]="a..ca",
	s[4]="accbb";
	for(int i=0;i<5;i++,puts(""))
	{
		for(int j=1;j<=x;j++) putchar('.');
		for(int j=0;j<5;j++) putchar(s[i][j]);
	}
}
void put6(int x)
{
	string s[6];
	s[0]="aabb.c",
	s[1]="bc...c",
	s[2]="bc..aa",
	s[3]=".aacb.",
	s[4]="a..cb.",
	s[5]="a.aacc";
	for(int i=0;i<6;i++,puts(""))
	{
		for(int j=1;j<=x;j++) putchar('.');
		for(int j=0;j<6;j++) putchar(s[i][j]);
	}
}
void put7(int x)
{
	string s[7];
	s[0]="aab.aa.",
	s[1]="b.b..bb",
	s[2]="bcaa...",
	s[3]=".cb..cc",
	s[4]="a.bcc..",
	s[5]="ab....a",
	s[6]=".b.aa.a";
	for(int i=0;i<7;i++,puts(""))
	{
		for(int j=1;j<=x;j++) putchar('.');
		for(int j=0;j<7;j++) putchar(s[i][j]);
	}

}
int main()
{
	int n;
	cin >> n;
	if(n<=2){puts("-1");}
	else if(n==3)put3(0);
	else if(n==5)put5(0);
	else 
	{
		for(int i=1;i<=n/4-1;i++)
			put4(4*i-4,n-4*i);
		if(n%4==0) put4(n-4,0);
		if(n%4==1) put5(n-5);
		if(n%4==2) put6(n-6);
		if(n%4==3) put7(n-7);
	}
	return 0;
}

Measured memory_bytes: 1280
// AOJ 2185

#include <iostream>
using namespace std;

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		int x, y, w, h, m, cx, cy;
		int ret = 0;
		cin >> x >> y >> w >> h >> m;
		for (int i = 0; i < m; i++){
			cin >> cx >> cy;
			if (x <= cx && cx <= x + w){
				if (y <= cy && cy <= y + h){
					ret++;
				}
			}
		}
		cout << ret << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
import sys
import math

N = input()
a = map(int, raw_input().split())

X = long(sum(a))

ans = long(sys.maxint + sys.maxint)

x = 0
for i in range(N - 1):
    x += a[i]
    ans = min(ans, math.fabs(X - 2*x))

print long(ans)


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){
    
    int N;cin>>N;
    vector<int> S(N),T;
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    bool check=true;
    for(int i=0;i<N;i++){
        int change,cnt=0;
        int now=1;
        for(int j=0;j<N;j++){
            if(S[j]==now){
                cnt++;
                change=j;
                now++;
            }else if(S[j]!=0) now++;
        }
        if(cnt==0){
            check=false;
        }
        else{
            T.push_back(S[change]);
            S[change]=0;
        }
    }
    if(!check){
        cout<<-1<<endl;
    }else{
        for(int i=N-1;i>=0;i--){
            cout<<T[i]<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> a, b;
  REP(i, n) {
    ll h;
    cin >> h;
    a.pb(h);
  }
  REP(i, n) {
    ll h;
    cin >> h;
    b.pb(h);
  }
  ll cnt = 0;
  ll odd = 0;
  REP(i, n) {
    if (a[i] < b[i]) {
      cnt += (b[i] - a[i] - 1) / 2 + 1;
      if ((b[i] - a[i]) % 2 == 1)
        odd++;
    } else {
      odd += a[i] - b[i];
    }
  }
  cout << (cnt >= odd ? "Yes" : "No") << endl;
}


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

int main() {
  int n,k;
  k = 0;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);}
  for(int i=0;i<n;i++){
    if(p.at(i) != i+1){k++;}
  }
  if(k == 2 || k == 0){cout << "YES" << endl;}
  else {cout << "NO" << endl;}
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		String s = in.next();
		char[] cs = s.toCharArray();
		int n = s.length();
		int k = in.nextInt();
		for (int i=0; i<n; i++) {
			if (cs[i] == 'a') continue;
			if ('z' - cs[i] + 1 <= k) {
				k -= 'z' - cs[i] + 1;
				cs[i] = 'a';
			}
		}

		if (k > 0) {
			k %= 26;
			cs[n-1] = (char)((cs[n-1] - 'a' + k)%26 + 'a');
		}

		for (int i=0; i<n; i++) {
			out.print(cs[i]);
		}
		out.println();
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 14104
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_ll.hpp>
// using namespace boost::multiprecision; // cpp_ll

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

signed main(){
    VC1(3,a);
    sort(ALL(a));
    COUT(a[2] - a[0]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int h[110];
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    int count = 1;
    for(int i=1; i<n; i++){
        bool isOk = true;
        for(int j=0; j<i; j++){
            if(h[j]>h[i]){
                isOk = false;
            }
        }
        if(isOk){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M = map(int,input().split(' '))
l = [list(map(int,input().split())) for _ in range(M)]

def ok_or_not(i):
    k = list(str(i))
    for j_0,j_1 in l:
        if not int(k[j_0-1])==j_1:
            break
    else:
        print(i)
        exit()

if N==1:
    for i in range(10):
        ok_or_not(i)
elif N==2:
    for i in range(10,100):
        ok_or_not(i)
else:
    for i in range(100,1000):
        ok_or_not(i)
print(-1)

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

using namespace std;

const int mod = 1007050321;
const int base = 521;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int inf = 2e9;

int main() {
    ios_base :: sync_with_stdio(0),cin.tie(0),cout.tie(0);

    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
<?php
$input = STDIN;

while (true) {
    list($n, $x) = explode(' ', trim(fgets($input)));

    if ($n == 0 && $x == 0) break;

    $min_a = max(intval($x / 3) + 1, 3);
    $max_a = min($n, $x - 3);
    $cnt = 0;

    for ($a = $min_a; $a <= $max_a; $a++) {
        $rest = $x - $a;
        $min_b = max(intval($rest / 2) + 1, 2);
        $max_b = min($rest - 1, $a - 1);

        $cnt += ($max_b - $min_b + 1);
    }

    print "{$cnt}\n";
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e5+1;
int F[N], G[N];
string S, T;

int main()
{
	fastio;
	cin >> S >> T;
	for (int i = 0; i < S.size(); i++){
		F[i + 1] = F[i] + S[i] - 'A' + 1;
	}
	for (int i = 0; i < T.size(); i++){
		G[i + 1] = G[i] + T[i] - 'A' + 1;
	}
	int n; cin >> n;
	while (n--){
		int a, b, c, d; 
		cin >> a >> b >> c >> d;
		int x = F[b] - F[a - 1];
		int y = G[d] - G[c - 1];
		if ((x % 3) == (y % 3)) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i <= _##i; ++i)
#define repd(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i >= _##i; --i)
#define debug(x...) printf("["#x"]="),print(x);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fcout cout<<setprecision(4)<<fixed
using namespace std;
typedef long long ll;
//======================================
namespace FastIO{
char print_f[105];void read() {}void print() {putchar('\n');}
template <typename T, typename... T2>
inline void read(T &x, T2 &... oth){x = 0;char ch = getchar();ll f = 1;while (!isdigit(ch)){if (ch == '-')f *= -1;ch = getchar();}while (isdigit(ch)){x = x * 10 + ch - 48;ch = getchar();}x *= f;read(oth...);}
template <typename T, typename... T2>
inline void print(T x, T2... oth){ll p3=-1;if(x<0) putchar('-'),x=-x;do{print_f[++p3] = x%10 + 48;}while(x/=10);while(p3>=0) putchar(print_f[p3--]);if(sizeof...(T2)) putchar(' ');print(oth...);}} // namespace FastIO

using FastIO::print;
using FastIO::read;
//======================================
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const int mod=998244353;
const int maxn = 1e6+5;
ll sum[maxn],a[maxn];
ll get(int l,int r){
    if(r<=0) return 0;
    if(l<=0) l=1;
    return ((sum[r]-sum[l-1])%mod+mod)%mod;
}
int l[maxn],r[maxn];
int main() {
#ifndef ONLINE_JUDGE
    freopen("H:\\code\\in.in", "r", stdin);
    freopen("H:\\code\\out.out", "w", stdout);
    clock_t c1 = clock();
#endif
//**************************************
    int n,m;
    read(n,m);
    rep(i,1,m){
        read(l[i],r[i]);
    }
    a[1]=1;
    sum[1]=1;
    rep(i,2,n){
        rep(j,1,m){
            a[i]=(a[i]+get(i-r[j],i-l[j]))%mod;
        }
        sum[i]=(sum[i-1]+a[i])%mod;
    }
    print(a[n]);
//**************************************
    
#ifndef ONLINE_JUDGE
    cerr << "Time:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}


Measured memory_bytes: 6764
#include<iostream>
using namespace std;
int n,d,cnt=0;
int main(){
	cin>>n>>d;
	for(int i=1,x,y;i<=n;i++)cin>>x>>y,cnt+=(1ll*x*x+1ll*y*y<=1ll*d*d);
	cout<<cnt;
    return 0;
}


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

using namespace std;
#define int long long
const int mod = 1e9+7;
const int N = 200010;

int n, m;
int p[N], cnt[N];

int find(int x)
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}
long long sum[N];
int a[N];
signed main()
{
   //a0*a1 + a0*a2 * a0 *a3 + a1*a2 + a2*a3
    cin >> n;
  for(int i = 1; i <= n; i++)
  {
  	int t;
    cin >> t;
    a[i] = t;
    
  }

  for(int i = 1; i <=n;i++)
  {
  	sum[i] = a[i] + sum[i-1];
  }
  int ans = 0;
  for(int i = 1; i <= n; i++)
  {
  	ans = (ans +a[i]*((sum[n]-sum[i])%mod))%mod % mod;
  }
  
  cout << ans << endl;
     
    return 0;
}


Measured memory_bytes: 6672
#include <stdio.h>

int main(void) {
	int a,b,c,d,s,p,x,y,z;
	while(scanf("%d",&s) != EOF){
		if(s > 36){
			printf("0\n");
		}
		else{
			p = 0;
			for(a = 0;a <= 9;a++){
				x = s - a;
				if(x < 0 || x > 27){continue;}
				for(b = 0;b <= 9;b++){
					y = s - a - b;
					if(y < 0 || y > 18){continue;}
					for(c = 0;c <= 9;c++){
						z = s - a - b - c;
						if(z < 0 || z > 9){continue;}
						for(d = 0;d <= 9;d++){
							if(s == a + b + c + d){p++;}
						}
					}
				}
			}
			printf("%d\n",p);
		}
	}
	return 0;
}

Measured memory_bytes: 608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
int main(void)
{
    ll i, x, st = 100;
    scanf("%lld", &x);
    i = 0;
    while (1)
    {
        if (st >= x)
            break;
        st = st * 1.01;
        i++;
    }
    printf("%lld\n", i);
    return 0;
}

Measured memory_bytes: 1732
include Math
def prime_judge(num)
  judge = 0
  i = 2
  while i <= sqrt(num)
    if num % i == 0
      judge =  1
      break
    end
    i += 1
  end
  return judge
end

n = gets.to_i
count = 0
n.times do
  if prime_judge(gets.to_i) == 0
    count += 1
  end
end
puts count

Measured memory_bytes: 8668
X,Y=map(int, input().split())
a=0
MAX_NUM = 7*10**5
pr = 10**9+7
fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]
fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % pr
    inv[i] = pr - inv[pr%i] * (pr // i) % pr
    finv[i] = finv[i-1] * inv[i] % pr
def c(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % pr) % pr
if (X+Y)%3==0:
    a=c((X+Y)//3,(X-Y+(X+Y)//3)//2)
print(a)

Measured memory_bytes: 86232
/*
  Warn - Don't change next line else you will get WA verdict. Online Judge is configured to give WA if next line is not present.
  Author - Aryan Choudhary (@aryanc403)
 
  const short DEBUG { 0 };
  #define debug(x) if (DEBUG) cout << #x << " = " << x << '\n'
*/

#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"
#define PI 3.1415926535897932384626433832795
typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

//const lli [3] ={ 999119999L,1000000007L,1000992299L};
//const lli [3] ={ 97L,101L,103L};
//const lli  = chrono::high_resolution_clock::now().time_since_epoch().count();
clock_t time_p=clock();
void aryanc403()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

class CMP
{
public:
    bool operator()(lli a , lli b) //For min priority_queue .
    {
        return ! ( a <= b );
    }
};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    map<lli,lli> ::iterator jt;
    jt=m.find(x);
    if(jt==m.end())         m.insert(mp(x,cnt));
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    map<lli,lli> ::iterator jt;
    jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}
const lli INF = 0xFFFFFFFFFFFFFFFL;
const lli mod = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,ans;
    lli m;
    string s;
    vi a;
    vi :: iterator it;
    //priority_queue < lli , vector < lli > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n>>m;
    ans=(1LL<<m)-1;// 0based
    fo(i,n)
    {
        cin>>k;
        cnt=0;
        while(k--)
        {
            cin>>in;
            in--;
            cnt|=(1LL<<in);
        }
        ans&=cnt;
    }
    cnt=0;
    fo(i,m)
    {
        if(ans&(1LL<<i))
            cnt++;
    }
    cout<<cnt<<endl;
}   aryanc403();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a,b;
    
    scanf("%d\n",&a);
    scanf("%d\n",&b);
    
    if(a < b){
        puts("a < b");
    }
    else if(a > b){
        puts("a > b");
    }
    else{
        puts("a == b");
    }
    return 0;
}



Measured memory_bytes: 2604
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m = map(int,input().split())
d = {}
invalid = False
for _ in range(m):
    s,c = map(int,input().split())
    if n != 1 and s == 1 and c == 0:
        invalid = True
    if s in d:
        if d[s] != c:
            invalid = True
    else:
        d[s] = c

if invalid:
    print (-1)
    exit ()

for i in range(1,n+1):
    if i in d:
        print (d[i],end="")
    else:
        if n == 1:
            print (0)
            exit ()
        else:
            print (1,end="") if i == 1 else print (0,end="")
print ()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;







public class Main{
	public static int n;
	public static boolean[] vis;
	public static int[] nums;
	public static void main(String[] args) throws IOException, InterruptedException {
		
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int t = n*sc.nextInt();
		int T = sc.nextInt();
		out.println(Math.min(t, T));
		
		out.flush();

	}


	
	

	
}
class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

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

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

	public char nextChar() throws IOException {
		return next().charAt(0);
	}

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

	public boolean ready() throws IOException {
		return br.ready();
	}

	public void waitForInput() throws InterruptedException {
		Thread.sleep(3000);
	}


}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int m[n + 1] = {};
    m[0] = 0;
    reverse(all(s));
    int p = 1;
    rep(i, 0, n) {
        m[i + 1] = (m[i] + (s[i] - '0') * p) % 2019;
        p *= 10;
        p %= 2019;
    }
    map<int, int> mp;
    rep(i, 0, n + 1) mp[m[i]]++;
    ll ans = 0;
    for (auto i : mp) {
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  rep(i,n)cin>>a[i];
  sort(rng(a));
  vi s(n);
  rep(i,n) s[i] = a[i]<0;
  s[0] = 1; s.back() = 0;
  int ans = 0;
  rep(i,n) ans += s[i]?-a[i]:a[i];
  cout<<ans<<endl;
  for (int i = 1; s[i]; ++i) {
    cout<<a.back()<<" "<<a[i]<<endl;
    a.back() -= a[i];
  }
  for (int i = n-2; !s[i]; --i) {
    cout<<a[0]<<" "<<a[i]<<endl;
    a[0] -= a[i];
  }
  cout<<a.back()<<" "<<a[0]<<endl;
  return 0;
}

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

int main(){
  string s;
  cin >> s;

  long long ans = 0, bnum = 0;
  for(long long i=0; i<s.length(); ++i){
    if(s[i] == 'W'){
      ans += bnum;
    }else{
      bnum++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
    if((1<=A && A<=9)&&(1<=B && B<=9))
    {
        printf("%d",A*B);
    }
    else
    {
        printf("-1");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;

   int Ans;
   if(N>K) {
     Ans = K*X + (N-K)*Y;
   }else {
     Ans = N*X;
   } 
  cout << Ans << endl;

  return 0;
}

Measured memory_bytes: 256
//AOJ 0528
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

const int NMAX = 20000;

int n, k;
int Rank[NMAX + 1];
int tmp[NMAX + 1];

bool compare_sa(int i, int j) {
  if (Rank[i] != Rank[j]) return Rank[i] < Rank[j];
  else {
    int ri = i + k <= n ? Rank[i + k] : -1;
    int rj = j + k <= n ? Rank[j + k] : -1;
    return ri < rj;
  }
}

void construct_sa(string S, int *sa) {
  n = S.length();

  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    Rank[i] = i < n ? S[i] : -1;
  }

  for (k = 1; k <= n; k *= 2) {
    sort(sa, sa + n + 1, compare_sa);

    tmp[sa[0]] = 0;
    for (int i = 1; i <= n; i++) {
      tmp[sa[i]] = tmp[sa[i - 1]] + 
        (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
    }

    for (int i = 0; i <= n; i++) {
      Rank[i] = tmp[i];
    }
  }
}

void construct_lcp(string S, int *sa, int *lcp) {
  int n = S.length();
  for (int i = 0; i <= n; i++) Rank[sa[i]] = i;

  int h = 0;
  lcp[0] = 0;
  for (int i = 0; i < n; i++) {
    int j = sa[Rank[i] - 1];

    if (h > 0) h--;
    for (; j + h < n and i + h < n; h++) {
      if (S[j + h] != S[i + h]) break;
    }

    lcp[Rank[i] - 1] = h;
  }
}

string S, T;

const int LMAX = 20000;
int sa[LMAX], lcp[LMAX];

int solve() {
  int sl = S.length();
  S += '_' + T;

  construct_sa(S, sa);
  construct_lcp(S, sa, lcp);

  int ans = 0;
  for (int i = 0; i < S.length(); i++) {
    if ((sa[i] < sl) != (sa[i + 1] < sl)) {
      ans = max(ans,lcp[i]);
    }
  }
  return ans;
}

int main() {
  while (cin >> S >> T) {
    cout << solve() << endl;
  }
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n , m ; 
  cin >> n >> m  ;
  int l=0 , r = INF ;
  rep(i,n){
    int a,b ; 
    cin >> a >> b ; 
    l = max(l,a) ; 
    r = min(r,b);
  }
  
  if(r-l+1 < 0 ) cout << 0  <<endl ;
  else           cout << r- l + 1 <<endl ;
    


}


Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> k(M);
	vector<vector<int>> s(M);
	for (int ii = 0; ii < M; ++ii){
		cin >> k[ii];
		for (int jj = 0; jj < k[ii]; ++jj){
			int tmp;
			cin >> tmp;
			tmp--;
			s[ii].push_back(tmp);
		}
	}

	vector <int> p(M);
	for (int ii = 0; ii < M; ++ii){
		cin >> p[ii];
	}

	int ans = 0;
	for (int n = 0; n < (1<<N); ++n){
		//スイッチの状態
		vector <int> t(N);
		for (int ii = 0; ii < N; ++ii){
			t[ii] = (n>>ii)&1;
		}

		// printf("n = %i\n", n);
		// for (int ii = 0; ii < N; ++ii){
		// 	printf(" %i ", t[ii]);
		// }
		// printf("\n");

		//つくかチェック
		bool ok = true;
		for (int ii = 0; ii < M; ++ii){
			int val = 0;
			for (int jj = 0; jj < k[ii]; ++jj){
				int idx = s[ii][jj];
				// printf("  idx[%i] %i\n", jj, idx);
				val += t[idx];
			}
			// printf("   ii %i, val %i\n", ii, val);
			if (val%2 != p[ii]){
				ok = false;
				break;
			}
		}

		if (ok){
			ans++;
		}
	}

	cout << ans << "\n";

	return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool A = (a==b && b==c);
    bool B = (a!=b && b!=c && c!=a);
    if (A || B) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

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

using LL = long long;

LL solve(LL X, LL Y) {
  auto q=X/Y;
  auto r=X%Y;
  if(r==0) return X+2*q*Y-Y;
  return X+2*q*Y-Y+solve(Y,r);
}

int main() {
  LL N, X;
  cin >> N >> X;
  if(2*X==N)  cout << 3*X << endl;
  if(2*X < N) cout << X+solve(N-X,X) << endl;
  if(2*X > N) cout << N-X+solve(X, N-X) <<endl;
}


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

int main() {
  string s; cin >> s;
  int a, b; a = b = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A') {
      a = i;
      break;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s.at(s.size() - 1 - i) == 'Z') {
      b = i;
      break;
    }
  }
  cout << s.size() - a - b << endl;
  
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <map>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

ll p, q, a, n;

ll calc(ll depth, ll prev, ll s, ll sum) {
  if (s * p == q * sum) { return 1; }
  if (depth == n) { return 0; }
  if (s * p < q * sum) { return 0; }
  ll ret = 0;
  FOREQ(i, prev, a) {
    ll ns = i * s;
    if (ns > a) { break; }
    ll nsum = sum * ns / s + ns / i;
    if (ns * p > q * (nsum + (n - depth - 1) * ns / i)) { break; }
    ret += calc(depth + 1, i, ns, nsum);
  }
  return ret;
}

int main() {
  while (scanf("%lld %lld %lld %lld", &p, &q, &a, &n), p|q|a|n) {
    printf("%lld\n", calc(0, 1, 1, 0));
  }
}

Measured memory_bytes: 880
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define gpf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

char st[100];
int len;
ll ans;

void dfs(int pos, ll nows, ll t){
	if (pos == len + 1){
		ans = ans + nows + t;
		return;
	}
	dfs(pos + 1, nows, t * 10 + st[pos] - '0');
	nows = nows + t;
	t = st[pos] - '0';
	dfs(pos + 1, nows, t);
}

int main(){
	scanf("%s", st + 1);
	len = strlen(st + 1);
	ans = 0;
	dfs(2, 0, st[1] - '0');
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    S = []
    for _ in range(N):
        S.append(II())
    ans = sum(S)
    if ans % 10 == 0:
        m = INF
        for s in S:
            if s % 10:
                m = min(m, s)
        if m == INF:
            ans = 0
        else:
            ans -= m
    return ans

print(main())

Measured memory_bytes: 3444
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    VS = list(map(int, input().split()))
    CS = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        if VS[i] - CS[i] > 0:
            ans += VS[i] - CS[i]
    print(ans)

if __name__ == '__main__':
    main()

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


int main() {
  int n;
  cin >> n;
  vector<long>t(n),a(n);
  rep(i,n){
    cin>>t.at(i)>>a.at(i);
  }
  long ans=t.at(0)+a.at(0);
  rep2(i,1,n){
    long ch=(ans/(t.at(i-1)+a.at(i-1))*a.at(i-1)-1)/a.at(i)+1LL;
    if(ch<(ans/(t.at(i-1)+a.at(i-1))*t.at(i-1)-1LL)/t.at(i)+1LL){
      ch=(ans/(t.at(i-1)+a.at(i-1))*t.at(i-1)-1LL)/t.at(i)+1LL;
    }
    if(ch<((ans-1LL)/(t.at(i)+a.at(i))+1LL)){
      ch=((ans-1LL)/(t.at(i)+a.at(i))+1LL);
    }
    ans=ch*(t.at(i)+a.at(i));
  }
  
    cout<<ans<<endl;
  
}





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

using IV = std::vector<int>;
IV ToFixedIntArray(std::istream& is, int n) {
	IV ret(n);
	auto* dst = ret.data();
	while(n > 0) {
		--n;
		is >> *dst++;
	}
	return ret;
}

#define _For(idx, from, to, inc, cmp) \
	for(auto idx=(from) ; idx cmp (to) ; inc idx)
#define ForLE(idx, from, to) \
	_For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) \
	_For(idx, from, to, --, >=)
#define ForLT(idx, from, to) \
	_For(idx, from, to, ++, <)
#define ForGT(idx, from, to) \
	_For(idx, from, to, --, >)
#define For(idx, from, to) \
	_For(idx, from, to, ++, <)

void DisableIOSync() {
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios::sync_with_stdio(false);
}
#include <map>
#include <algorithm>
int main() {
	DisableIOSync();
	const int N = ToFixedIntArray(std::cin, 1)[0];
	const auto bar = ToFixedIntArray(std::cin, N);
	std::map<int, int, std::greater<>> m;
	for(auto& n : bar) {
		++m[n];
	}

	int cur = 0;
	int len[2] = {};
	for(auto itr=m.begin() ; itr!=m.end() ; ++itr) {
		while(itr->second >= 2) {
			itr->second -= 2;
			len[cur++] = itr->first;
			if(cur == 2)
				goto END;
		}
		if(itr == m.end())
			break;
	}
	END:
	std::cout << uint64_t(len[0]) * uint64_t(len[1]) << std::endl;
	return 0;
}


Measured memory_bytes: 5376
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();

		int a[] = new int[N];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		int happychild = 0;

		for (int i = 0; i < a.length; i++) {
			x -= a[i];
			if(x < 0) {
				break;
			}
			happychild++;
		}
		if (x > 0) {
			happychild -= 1;
		}
		System.out.println(happychild);
	}
}


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


#define dhai_machli ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)



using namespace std;

int main()
{



    dhai_machli;


    int x, y;

    cin >> x >> y;




    for (int i = 0; i <= x; i++)
    {
        for (int j = 0; j <=x; j++)

        {


            if (i + j == x && 2 * i + 4 * j == y)
            {


                cout << "Yes" << endl;
                return 0;


            }

        }
    }

    cout << "No" << endl;



    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 305;
string S;
int K;
int dp[MC][MC][MC];

int main(){
	cin >> S;
	int n = S.size();
	int m = n/2;
	cin >> K;
	repp(i,0,n) repm(j,n-1,i) repp(k,0,K+1){
		if(S[i] == S[j]){
			dp[i+1][j-1][k] = max(dp[i+1][j-1][k] , dp[i][j][k]+1);
		} else {
			dp[i+1][j][k] = max(dp[i+1][j][k] , dp[i][j][k]);
			dp[i][j-1][k] = max(dp[i][j-1][k] , dp[i][j][k]);
			if(k < K){
				dp[i+1][j-1][k+1] = max(dp[i+1][j-1][k+1] , dp[i][j][k]+1);
			}
		}
	}
	int ans = 0;
	repp(i,0,n) repp(k,0,K+1){
		ans = max(ans , dp[i][i][k]*2 + 1);
		ans = max(ans , dp[i+1][i][k]*2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 110848