akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0181().doIt();
	}

	class AOJ0181{
		int m,n;
		int[] books;
		
		boolean isPossible(int width){
			int w=0,cnt=1;
			for(int i=0;i<n;i++){
				w+=books[i];
				if(books[i]>width)return false; 
//				System.out.println(books[i]);
				if(w>width){
//					System.out.println("---");
					cnt++;
					w = books[i];
				}
			}
			return cnt>m? false:true;
		}
		
		void doIt(){
			//横幅が可変
			//n = num of book
			//m = 段数
			while(true){
				m = in.nextInt();
				n = in.nextInt();
				if(n+m==0)return;
				books = new int[n];
				for(int i=0;i<n;i++)books[i] = in.nextInt();
//				System.out.println(isPossible(733));
				int left = 1;
				int right = 1500000;
				while(right-left!=1){
					int next = (left+right)/2;
					if(isPossible(next))right = next;
					else left = next;
//					System.out.println(left+" "+right);
				}
				System.out.println(right);
			}
		}
	}

}

Measured memory_bytes: 20968
#include<stdio.h>

int A[2000],q,n;

int solve(int i,int m){
  if(m == 0){
    return 1;
  }else if(m < 0 || i > n){
    return 0;
  }

  if(solve(i + 1, m)){
    return 1;
  }
  if(solve(i + 1, m - A[i])){
    return 1;
  }
}

int main(){
  int i,S[2000];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&S[i]);
  }

  for(i=0; i<q; i++){
    if(solve(0,S[i])==1 ){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}



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

int main() {

	int N,A,B;
  cin>>N>>A>>B;
  if(N>=(B-A)&&B<=A){cout<<"delicious"<<endl;}
  else if(N>=(B-A)){cout<<"safe"<<endl;}
  else{cout<<"dangerous"<<endl;}
	
	
}



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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string[] str = Console.ReadLine().Split(' ');
            var x = Math.Abs(long.Parse(str[0]));  //開始場所、負の場合は
            var k = long.Parse(str[1]);  //移動可能回数
            var d = long.Parse(str[2]);  //1回の移動量
            var result = 0L;

            /*---------
             * 方針
             * →X＞=K＊D　の場合、答えはX-K*D
             * →X＜K×Dの場合、答えは、XをDで割ったあまり。　XをDで割った答えが、移動回数。
             * →割り終わったタイミングで、残り移動回数を見る。（k-x/d)が残り移動回数。
             * 上記、残り移動回数が偶数の場合、答えは、XをDで割ったあまり（の絶対値）、奇数の場合、D-X％D　の絶対値が、答えとなる。
             * 
             ----------*/

            if (x/d >= k)
            {
                //移動回数が小さい場合
                result = x - k * d;
            }
            else
            {
                if ((k - x / d) % 2 == 0)
                {
                    result = x % d;
                }
                else
                {
                    result = d - x % d;
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  
  else if (A+B < C+D) {
    cout << "Right" << endl;
  }
  
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int dp[1001][1001] = {};
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.length() + 1;
  int m = t.length() + 1;
  REP(i, n) { dp[i][0] = i; }
  REP(j, m) { dp[0][j] = j; }
  FOR(i, 1, n) {
    FOR(j, 1, m) {
      dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
      } else {
        dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
      }
    }
  }
  cout << dp[n - 1][m - 1] << endl;
}



Measured memory_bytes: 7092
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    int cur = 0;
    int ans = 0;
    vector <int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        if (i && h[i] <= h[i-1]) {
            cur++;
        } else {
            ans = max(ans, cur);
            cur = 0;
        }
    }

    ans = max(ans, cur);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
int main(void){
   int a[10], b[10], c, n, i;
   scanf("%d %d %d %d %d", &a[1], &a[2], &a[3], &a[4], &a[5]);
   for ( i = 2; i <= 5; i++ ) {
      if ( a[i] >= a[1]) {
         c = a[1];
         a[1] = a[i];
         a[i] = c;
      }
   }
   for ( i = 2; i <= 5; i++ ) {
      if ( a[i] >= a[2]) {
         c = a[2];
         a[2] = a[i];
         a[i] = c;
      }
   }
   for ( i = 3; i <= 5; i++ ) {
      if ( a[i] >= a[3]) {
         c = a[3];
         a[3] = a[i];
         a[i] = c;
      }
   }
   for ( i = 4; i <= 5; i++ ) {
      if ( a[i] >= a[4]) {
         c = a[4];
         a[4] = a[i];
         a[i] = c;
      }
   }
   printf("%d %d %d %d %d\n", a[1], a[2], a[3], a[4], a[5]);
   return 0;
}

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

int main(){
  string s;
  long long k;
  cin>>s>>k;
  char c = '1';
  for(int i=0; i<min(k,(long long)s.size()); i++){
    if(s[i] != '1'){
      c = s[i];
      break;
    }
  }
  cout<<c<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  fix10;
  int n;
  cin >> n;
  int count;
  for(int i=1;i<=n;i++){
    if(i % 2 == 1) count++;
  }
  double c = (double)count;
  double dn = (double)n;
  cout << c/dn << endl;
}


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

using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for(int i = 0;i < n;++i)
int H,W,K,N,D;
char x [200010];
int main()
{
  int count=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>x[i];
  }
  int i=0,j=N-1;
  while (i<j)
  {
    while(x[i]=='R'){
      i++;
    }
    while(x[j]=='W'){
      j--;
    }
    if(i<j)count++;
    i++;
    j--;
  }
  cout<<count;
  return 0;
}





Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a;cin>>n>>a;
  vector<ll>x(n);
  rep(i,n)cin>>x[i];
  rep(i,n)x[i]-=a;
  ll wei=50*n;
  vector<ll>dp(wei*2);
  dp[wei]=1;
  rep(i,n){
    auto tdp=dp;
    rep(j,wei*2){
      if(0<=j+x[i]&&j+x[i]<2*wei){
        if(dp[j]==0)continue;
        tdp[j+x[i]]+=dp[j];
      }
    }
    dp=tdp;
    //repi(i,wei-10,wei+10)cout<<dp[i]<<" ";
    ///cout<<endl;
  }
  cout<<dp[wei]-1<<endl;

  return 0;

}


Measured memory_bytes: 384
// https://beta.atcoder.jp/contests/abc104

#define SUBMIT

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

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

    if (S[0] != 'A') {
        cout << "WA" << endl;
        exit(0);
    }

    auto c = std::count(S.begin() + 2, S.end() - 1, 'C');
    if (c != 1) {
        cout << "WA" << endl;
        exit(0);
    }

    string u;
    for (size_t i = 0; i < S.length(); ++i) {
        if (i == 0) {
            continue;
        }

        if (2 <= i && i <= S.length() - 1 && S[i] == 'C') {
            continue;
        }

        u += S[i];
    }

    if (!all_of(u.begin(), u.end(), [](char c) { return static_cast<bool>(islower(c)); })) {
        cout << "WA" << endl;
        exit(0);
    }

    cout << "AC" << endl;
    return 0;
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b || (a < b && n == 1)){
        cout << 0 << endl;
    }else if(a == b || (a < b && n == 2)){
        cout << 1 << endl;
    }else if(a < b && n >= 2){
        cout << (n-1)*b+a-(n-1)*a-b+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split())) 
b=[0]*n
c=[]
for i in range(1,n+1):
    if sum(b[n-i:n+1:n+1-i])%2==a[n-i]:
        pass
        
    else:
        b[n-i]=1
        c.append(n-i+1)
print(len(c))
print(*c)

Measured memory_bytes: 14076
fn calc_value(l: usize, r: usize, dispose: usize, vs: &Vec<i64>) -> i64 {
    // println!("l: {}, r: {}, d: {}, len: {}", l, r, dispose, vs.len());

    let mut get_vs = Vec::new();

    if l+r > vs.len() {
        return 0i64;
    }

    for i in 0..l {
        get_vs.push(vs[i]);
    }

    for i in 0..r {
        get_vs.push(vs[vs.len() - i - 1]);
    }

    get_vs.sort();
    let get_vs_len = get_vs.len();
    let mut dispose_start = 0usize;
    for i in 0..dispose {
        if i >= get_vs_len {
            break;
        }
        if get_vs[i] > 0i64 {
            break;
        }
        dispose_start += 1;
    }

    // println!("{:?}, dispose_start: {}", get_vs, dispose_start);

    get_vs[dispose_start..].iter().fold(0i64, |sum, &a| sum + a)
}

fn solve(n: usize, k: usize, vs: &Vec<i64>) -> i64 {
    let mut ans = 0i64;

    for l in 0..(k+1) {
        for r in 0..(k-l+1) {
            ans = std::cmp::max(calc_value(l, r, k-l-r, vs), ans);
        }
    }

    ans
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let vs = buf.split_whitespace()
        .map(|x| x.parse::<i64>().unwrap())
        .collect::<Vec<_>>();

    println!("{}", solve(n, k, &vs));
}


Measured memory_bytes: 4352
string2Ints :: String -> [Int]
string2Ints str = map (\x -> read x :: Int) (words str)

main :: IO ()
main = do
    line <- getLine
    let
        [a, b, c] = string2Ints line
        divisors  = [x | x <- [a..b], c `mod` x == 0]
    print $ length divisors

Measured memory_bytes: 3964
import java.util.Scanner;

/*

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        // int R = sc.nextInt();
        // int d = sc.nextInt();

        int[] n = new int[N];
        // int[] B = new int[M];

        for (int i = 0; i < N; i++) {
            n[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < N; i++) {
            // A[i] = sc.nextInt();
            if (i % 2 == 0 && n[i] % 2 == 1) {
                count++;
            }
        }
       System.out.println(count);
    }
}

Measured memory_bytes: 35696
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var s = input.ReadLine();

        if (n % 2 != 0) return No;

        for(int i=0; i<n/2; i++) {
            if (s[i] != s[n / 2 + i]) return No;
        }

        return Yes;
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a, b;
  cin >> a >> b;
  if (a.at(0) == b.at(2) && a.at(1) == b.at(1) && a.at(2) == b.at(0)){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
//#define int long long int 
//this is dupe

using namespace std;

int main() {
    int t=1;
   // cin>>t;
    while(t--)
    {
      int n;
       cin>>n;
       int a[n];
   //    int b[n]={0};
       map<int,int> m;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           m[a[i]]++;
       }
      int co=0;
       for(int i=0;i<n;i++)
       {
           int f=0;
           for(int j=2;j*j<=(a[i]);j++)
           {
               if(a[i]%j==0)
               {
                   if(m[j]==0&&m[a[i]/j]==0)
                   {
                       
                   }
                   else
                   {
                       f=123;
                       break;
                   }
               }
           }
           if(f==0&&m[a[i]]==1&&m[1]==0)
           {
               co++;
           }
       }
       if(m[1]>1||m[1]==0)
       cout<<co;
       else
       cout<<co+1;
       
     
     
        
    }
}

Measured memory_bytes: 33072
#126
s = input()

a = int(s[0:2])
b = int(s[2:])

res = ""
if 1 <= a and a <= 12:
    if 1 <= b and b <= 12:
        res = "AMBIGUOUS"
    else:
        res = "MMYY"
else:
    if 1 <= b and b <= 12:
        res = "YYMM"
    else:
        res = "NA"
print(res)

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

int main(){
	int N;
	cin >> N;
	vector<long long> a(N);
	for(int i=0; i<N; i++){
		cin >> a.at(i);
	}
	int cnt = 0;
	int ans = 0;
	for(int i=0; i<N; i++){
		if( a.at(i)%2 != 0 ){
		}
		else{
			for( ; ; ){
				if( a.at(i)%2 == 0 ){
					a.at(i) /= 2;
					ans++;
				}
				else{
					break;
				}
			}
		}	
	}
	cout << ans << endl;
	return 0;
	
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<fstream>

int main() {
	int H = 0;
	int W = 0;
	int N = 0;
	int count = 0;
	std::cin >> N;
	std::cin >> H;
	std::cin >> W;
	if (N > 100 || H > N || W > N) {
		std::cout << "error" << std::endl;
	}
	for (int i = H; i <= N; i++) {
		//std::cout << "aaaa" << std::endl;
		for (int j = W; j <= N; j++) {
			//std::cout << "bbbb" << std::endl;
			count++;
		}
	}

	std::cout << count << std::endl;

}

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

const int N = 1e5 + 5;
int n,m, p[N], connected[N];
stack<int> a,b;

int findset(int x){
    return p[x] == x?x:p[x] = findset(p[x]);
}
void unite(int x,int y){
    x = findset(x);
    y = findset(y);
    
    if(x!=y){
        int total = connected[x] + connected[y];
        connected[y] = total;
        p[x] = y;
    }
    
}


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    
    
 
    cin>>n>>m;
    for(int i = 1; i<= n; i++) p[i] = i, connected[i] = 1;
    int t1, t2;
    for (int i = 0; i < m; i++){
        cin>>t1>>t2;
        a.push(t1);
        b.push(t2);
    }
    
    ll total = (ll) n * (n-1)/2;
    stack<ll> ans;
    ans.push(total);
    ll temp = total;
    for (int i = 1; i < m; i++){
        t1 = a.top();a.pop();
        t2 = b.top();b.pop();
        if(findset(t1) != findset(t2)){
            t1 = findset(t1);
            t2 = findset(t2);
            temp += (ll)connected[t1]*(connected[t1]-1)/2 + (ll)connected[t2]*(connected[t2]-1)/2;
            unite(t1, t2);
            temp -= (ll)connected[t2]*(connected[t2]-1)/2;
        }
        ans.push(temp);
    }

    while (!ans.empty()) {
        cout<<ans.top()<<endl;
        ans.pop();
    }
    
    return 0;
}


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

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int nr;
        cin >> nr;
        if (i % 2 == 1 && nr % 2 == 1)
            cnt++;
    }
    cout << cnt;
    return 0;
}



Measured memory_bytes: 3560
n = int(input())

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

#高さが0でない情報を探す
for i in range(n):
    if xyh[i][2] != 0:
        x_ex, y_ex, h_ex = xyh[i]
        break

for cx in range(101): #Cx 0~100
    for cy in range(101): #Cy 0~100
        h = abs(x_ex - cx) + abs(y_ex - cy) + h_ex #高さHを求める

        #先程出した高さHが他の例にも当てはまるか確認
        flag = 0
        for i in range(n):
            x_i, y_i, h_i = xyh[i]
            if h_i == max(h - abs(x_i - cx) - abs(y_i - cy), 0):
                flag += 1
            else:
                break

        if flag == n:
            print(cx, cy, h)
            exit()


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

int n;

void equiv(string s,int t,int ma){
    if(t==n){
        cout<<s<<endl;
        return;
    }else{
        rep(i,ma+2){
            equiv(s+char(i+int('a')),t+1,max(ma,i));
        }
    }
}


int main(){
    cin>>n;
    equiv("a",1,0);
}


Measured memory_bytes: 1536
use proconio::input;
use std::collections::BTreeMap;


fn main() {
    input! {
        n: usize,
        v: [usize; n], // v_1 v_2 ... v_n
        q: usize,
        mat: [(usize,usize); q], // n*m行列
    }

    let mut map = BTreeMap::new();
    for &x in v.iter() {
        *map.entry(x).or_insert(0) += 1;
    }

    let mut sum = 0;
    for &x in v.iter() {
        sum += x;
    }

    for &(b,c) in mat.iter() {
        if let Some(&kosu) = map.get(&b) {
            if let Some(&kos) = map.get(&c) {
                map.insert(c,kosu+kos);
                map.remove(&b);
                sum += c*kosu;
                sum -= b*kosu;
            } else {
                map.insert(c,kosu);
                map.remove(&b);
                sum += c*kosu;
                sum -= b*kosu;
            }
        }
        println!("{}",sum)
    }

}


Measured memory_bytes: 7972
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <ll, int> P;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n, x;
    cin >> n >> x;

    ll b[n], l[n], u[n];
    ll sm = 0;
    for (int i = 0; i < n; i++) {
        cin >> b[i] >> l[i] >> u[i];
        sm += b[i] * l[i];
    }

    vector <P> benefit(n);
    for (int i = 0; i < n; i++) {
        benefit[i] = P(b[i] * l[i] + (x - b[i]) * u[i], i);
    }

    sort(benefit.begin(), benefit.end(), greater<P>());

    vector <ll> benefit_sm(n);
    for (int i = 0; i < n; i++) {
        benefit_sm[i] = benefit[i].first;
        if (i) benefit_sm[i] += benefit_sm[i-1];
    }

    ll ret = 1LL << 60;
    for (int i = 0; i < n; i++) {
        // 一番最後に除く奴を全探索

        ll mx = b[i] * l[i] + (x - b[i]) * u[i];

        if (sm <= mx) {
            ll tmp = sm;
            ll ans = 0;
            if (tmp <= b[i] * l[i]) {
                ans += tmp / l[i];
                if (tmp % l[i] > 0) ans++;
            } else {
                tmp -= b[i] * l[i];
                ans += b[i];
                ans += tmp / u[i];
                if (tmp % u[i] > 0) ans++;
            }

            ret = min(ret, ans);
        }

        int idx = lower_bound(benefit_sm.begin(), benefit_sm.end(), sm) - benefit_sm.begin();
        idx--;
        if (idx < 0) continue;

        if (benefit[idx].first <= mx) {
            ll tmp = sm - benefit_sm[idx] + mx;
            ll ans = (ll)idx * x;

            while (tmp > mx) {
                idx++;
                tmp -= benefit[idx].first;
                ans += x;
            }

            if (tmp < 0) continue;

            if (tmp <= b[i] * l[i]) {
                ans += tmp / l[i];
                if (tmp % l[i] > 0) ans++;
            } else {
                tmp -= b[i] * l[i];
                ans += b[i];

                ans += tmp / u[i];
                if (tmp % u[i] > 0) ans++;
            }

            ret = min(ret, ans);
        }

        ll tmp = sm - benefit_sm[idx];
        ll ans = (ll)(idx + 1) * x;

        if (tmp < 0) continue;

        if (tmp <= b[i] * l[i]) {
            ans += tmp / l[i];
            if (tmp % l[i] > 0) ans++;
        } else {
            tmp -= b[i] * l[i];
            ans += b[i];

            ans += tmp / u[i];
            if (tmp % u[i] > 0) ans++;
        }

        ret = min(ret, ans);
    }

    cout << ret << "\n";
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  string s;
  rep(i,N){
    cin >> s;
    if(s == "Y"){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;

}




Measured memory_bytes: 3580
import numpy as np
import itertools
n = int(input())
ab = np.array([[int(i) for i in input().split()] for i in range(n)])
ab = ab[ab[:, 1].argsort(), :]

reqtime = list(itertools.accumulate(ab[:, 0]))
dead = ab[:, 1].tolist()
ans = 'Yes'
for d, r in zip(dead, reqtime):
    if d<r:
        ans  = 'No'
        break
print(ans)

Measured memory_bytes: 50052
#include <iostream>
using namespace std;
int main() {
    int n,AC=0,WA=0,TLE=0,RE=0;
    cin >> n;
    string s;
    for (int i = 0; i < n ; i++) {
        cin>>s;
        if (s=="AC")
            AC++;
        else if (s=="WA")
            WA++;
        else if (s=="TLE")
            TLE++;
        else
            RE++;
    }
    cout<<"AC x "<<AC<<endl;
    cout<<"WA x "<<WA<<endl;
    cout<<"TLE x "<<TLE<<endl;
    cout<<"RE x "<<RE<<endl;
    return 0;
}

Measured memory_bytes: 3572
def myAnswer(X1,Y1,X2,Y2):
   X = X2 - X1
   Y = Y2 - Y1
   print(X2 - Y,Y2 + X, X1 - Y, Y1 + X)

def modelAnswer():
   tmp=1
def main():
   X1,Y1,X2,Y2=map(int,input().split())
   myAnswer(X1,Y1,X2,Y2)


if __name__ == '__main__':
   main()

Measured memory_bytes: 2940
#include <iostream>
#include <numeric>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int MOD = 10000;

void solve() {
    int n, k;
    std::cin >> n >> k;

    std::vector<int> xs(n, 0);
    while (k--) {
        int i, x;
        std::cin >> i >> x;
        xs[--i] = x;
    }

    auto dp = vec(4, vec(4, 0));
    dp[0][0] = 1;
    auto ndp = dp;

    for (auto x : xs) {
        for (auto& v : ndp) {
            std::fill(v.begin(), v.end(), 0);
        }

        for (int px1 = 0; px1 <= 3; ++px1) {
            for (int px2 = 0; px2 <= 3; ++px2) {
                for (int nx = 1; nx <= 3; ++nx) {
                    if (x != 0 && x != nx) continue;
                    if (px1 != 0 && px1 == px2 && px2 == nx) continue;

                    (ndp[px2][nx] += dp[px1][px2]) %= MOD;
                }
            }
        }

        std::swap(dp, ndp);
    }

    int ans = 0;
    for (const auto& v : dp) {
        (ans += std::accumulate(v.begin(), v.end(), 0)) %= MOD;
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    char c[5];
    scanf("%s",&c);
    if(c[0]=='S' && c[1]=='A')
        n=1;
    else if(c[0]=='S' && c[1]=='U')
        n=7;
    else if(c[0]=='M')
        n=6;
    else  if(c[0]=='T' && c[1]=='U')
        n=5;
    else if(c[0]=='W')
        n=4;
    else if(c[0]=='T')
        n=3;
    else
        n=2;
    printf("%d",n);
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#define For(i,j,k) for(register int i=j;i<=k;++i)
#define Dow(i,j,k) for(register int i=k;i>=j;--i)
#define max(x,y)	(x>y?x:y)
#define min(x,y)	x>y?y:x
#define no mmp
#define ll long long
#define inf 1e17
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{if(c=='-')	f=-1;c=getchar();}
	while(c<='9'&&c>='0')	t=t*10LL+c-48LL,c=getchar();
	return t*f;
}
inline void write(ll x){if(x>=10)	write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);puts("");}
int main()
{
	int ans=0;
	int n=read(),m=read();
	ans+=1900*m+100*(n-m);
	For(i,1,m)	ans*=2;
	cout<<ans<<endl;
} 

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

int main()
{
  int n,ans=0;
  cin >> n;
  vector<char> c(n);
  rep(i,n) cin >> c[i];
  int i=0,j=n;
  while(i<j){
    if(c[i]!='W'){
      i++;
      continue;
    }
    else if(c[j]!='R'){
      j--;
      continue;
    }
    else{
      swap(c[i],c[j]);
      ans++;
    }
  }
  cout << ans <<endl;
  return 0;
}

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

using namespace std;

int main() {
    while(true) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;

        if(M == 0 && T==0 && P == 0 && R == 0) return 0;

        int m, t, p, j;
        int result[T];
        fill(result, result + T, 0);
        int time[T];
        fill(time, time + T, 0);
        int failure[T][P];
        fill(failure[0], failure[T] + P, 0);
        for (int submit = 0; submit < R; submit++) {
            cin >> m >> t >> p >> j;
            if (j == 0) {
                result[t - 1] += 1;
                time[t - 1] += m + failure[t - 1][p-1] * 20;
            } else {
                ++failure[t - 1][p-1];
            }
        }

        bool done[T];
        fill(done, done + T, false);
        int prevPoint, prevTime;
        for (int count = 0; count < T; count++) {
            int maxPoint = -1;
            int maxTeam = 0;
            int minTime = 100000;
            for (int i = T - 1; i >= 0; i--) {
                if (done[i]) continue;
                if (maxPoint < result[i]) {
                    maxPoint = result[i];
                    maxTeam = i + 1;
                    minTime = time[i];
                } else if (maxPoint == result[i]) {
                    if (minTime > time[i]) {
                        minTime = time[i];
                        maxTeam = i + 1;
                    }
                }
            }
            minTime = time[maxTeam - 1];
            if (count != 0) {
                if (maxPoint == prevPoint && minTime == prevTime) cout << "=";
                else cout << ",";
            }
            cout << maxTeam;
            done[maxTeam - 1] = true;
            prevPoint = maxPoint;
            prevTime = minTime;
        }
        cout << endl;
    }
}


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

int N;
char m;

void solve(){
  int M;
  map<char, char> changer;

  char f, t;
  for (int i = 0; i < N; i++){
    cin >> f;
    cin >> t;
    changer[f] = t;
  }
  cin >> M;
  for (int i = 0; i < M; i++){
    cin >> m;
    if (changer.find(m) != changer.end()) cout << changer[m];
    else cout << m;
  }
  printf("\n");
}

int main(){
  while (cin >> N, N) solve();
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
using namespace std;
int main() {
	int N,Tsum,M;
	scanf("%d", &N);
	vector <int> T(N);
	for (int i = 0;i < N ; i++) {
		scanf("%d", &T[i]); 
		Tsum += T[i];
	}
	scanf("%d", &M);
	vector <int> P(M), X(M);
	for (int i = 0; i < M; i++) scanf("%d%d", &P[i], &X[i]);
	for (int i = 0; i < M; i++) {
		printf("%d\n", Tsum - T[P[i]-1] + X[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n, m, x[100000], y[100000];
int num[100000], red[100000];

int main () {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++) { scanf("%d%d", &x[i], &y[i]); x[i]--; y[i]--; }
	
	red[0] = 1;
	for(int i = 0; i < n; i++) { num[i] = 1; }
	
	for(int i = 0; i < m; i++) {
		if(red[ x[i] ] == 1) { red[ y[i] ] = 1; }
		num[ x[i] ]--;
		num[ y[i] ]++;
		if(num[ x[i] ] == 0) { red[ x[i] ] = 0; }
	}
	
	int ans = 0;
	for(int i = 0; i < n; i++) { if(red[i] == 1) { ans++; } }
	
	printf("%d\n", ans);
	
	return 0;
}


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

int	main()
{
	double	A, B;
	int		H, M;
	cin >> A >> B >> H >> M;
	double	theta = M_PI * (60 * H - 11 * M) / 360;
	double	dist2 = A * A + B * B - 2 * A * B * cos(theta);
	cout << setprecision(16) << sqrt(dist2) << endl;
}


Measured memory_bytes: 4188
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int k, n;
  readf("%s %s\n", &k, &n);
  auto a = readln.chomp.split.to!(int[]);
  auto res = int.max;
  foreach (i; 0..n) {
    auto x = i + n - 1;
    auto y = i - n + 1;
    if (x >= n) {
      x -= n;
    }
    if (y < 0) {
      y += n;
    }

    auto d1 = a[x] - a[i];
    auto d2 = a[i] - a[y] + k;
    if (d1 > k) {
      d1 -= k;
    }
    if (d1 < 0) {
      d1 += k;
    }
    if (d2 > k) {
      d2 -= k;
    }
    if (d2 < 0) {
      d2 += k;
    }

    res = min(res, d1);
    res = min(res, d2);
  }
  res.writeln;
}


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


int main() {
char b;
  cin>>b;
  
  if(b=='A'){cout<<'T'<<endl;}
  if(b=='T'){cout<<'A'<<endl;}
  if(b=='C'){cout<<'G'<<endl;}
  if(b=='G'){cout<<'C'<<endl;}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
int n;
cin >> n;
double a[n];
double che=0,z=0;
for(int i=0;i<n;i++){
   cin >> a[i];
   che+=1/a[i];
}
che = 1/che;
cout << fixed<<setprecision(20);
cout << che<<endl;
}





Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>
#include<stack>
#include<set>

using namespace std;

int main()
{
	string str;
	set<char> s;
	cin >> str;
	for (int i = 0; i < str.size(); i++) {
		s.insert(str[i]);
	}
	if (str.size() == s.size())
		cout << "yes" << endl;
	else
		cout << "no" << endl;
}

Measured memory_bytes: 384
#include <cstdio>

void trace(int *a, int N){
	int i;
	for(i=0; i<N-1; i++){
		std::printf("%d ", a[i]);
	}
	std::printf("%d\n", a[N-1]);
}

void bubbleSort(int *a, int N){
	int i,j,flag,count,x;
	flag = 1;
	count = 0;
	while (flag){
		flag = 0;
		for (j=N-1; j>0; j--){
			if (a[j] < a[j-1]){
				x = a[j];
				a[j] = a[j-1];
				a[j-1] = x;
				flag = 1;
				count ++;
			}
		}
	}
	trace(a, N);
	std::printf("%d\n", count);
}

int main(){
	int N,i;
	int *a;
	std::scanf("%d", &N);
	a = new int[N];
	for (i=0; i<N; i++){
		std::scanf("%d", &a[i]);
	}
	bubbleSort(a, N);
	return 0;
}

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

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

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

  int ans = 1e6;
  rep(bit, 1 << N) {
    int n = 1;
    rep(i, N) {
      if (bit & (1 << i))
        n *= 2;
      else
        n += K;
    }
    ans = min(n, ans);
  }
  printf("%d\n", ans);


  return 0;
}


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

int main(){
	long long L, R;
	cin >> L >> R;

	long long answer = 2018;
	for(long long i = L; i < R; i++){
		for(long long j = i+1; j <= R; j++){
			long long ref = i*j % 2019;
			if(ref == 0){
				cout << 0 << endl;
				return 0;
			}
			if(ref < answer){
				answer = ref;
			}
		}
	}
	
	cout << answer << endl;

	return 0;
}

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

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

int main(){
  using ll=long long;
  ll A,B,C,D;
  cin >> A >> B >> C >> D;
  ll CD=C*D/GCD(C,D);  
  ll ans=(B-(B/C+B/D-B/CD))-(A-1-((A-1)/C+(A-1)/D-(A-1)/CD));
  cout << ans << endl;
  
}


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

int main()
{
	std::string xs[3];
	int cnts[3] = { 0 };

	for (int i = 0; i < 3; i++) {
		std::cin >> xs[i];
	}

	int next = 0;
	while (true) {
		if (cnts[next] == xs[next].size()) {
			std::cout << static_cast<char>(next + 'A') << std::endl;
			return 0;
		}
		int b = next;
		next = xs[next][cnts[next]] - 'a';
		cnts[b]++;
	}


}

Measured memory_bytes: 256
import sys

def solve():
    while 1:
        s = sys.stdin.readline().rstrip()

        if s == '.':
            return

        stack = []

        for ch in s:
            if ch == '(' or ch == '[':
                stack.append(ch)
            elif ch == ')':
                if stack and stack[-1] == '(':
                    stack.pop()
                else:
                    print('no')
                    break
            elif ch == ']':
                if stack and stack[-1] == '[':
                    stack.pop()
                else:
                    print('no')
                    break
        else:
            if not stack:
                print('yes')
            else:
                print('no')
                
if __name__ == '__main__':
    solve()

Measured memory_bytes: 7664
N,T=map(int,input().split())
cost=[]
time=[]
mincost=1000
for i in range(N):
  c,t=map(int,input().split())
  cost.append(c)
  time.append(t)
mintime=min(time)
if mintime>T:
  print("TLE")
else:
  for i in range(N):
    if time[i]<=T:
      if cost[i]<mincost:
        mincost=cost[i]
  print(mincost)

Measured memory_bytes: 3064
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    string s1, s2, s3;
    string ans;

    cin >> s1 >> s2 >> s3;
    ans = "";
    // 小文字→大文字
    ans += s1[0] - 0x20;
    ans += s2[0] - 0x20;
    ans += s3[0] - 0x20;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 2e9

using namespace std;
int connectSize[200000];
int connectPtr[200000];
int connect[400000];
long long dp[200000];
long long a[200000];
int answer[200000];
int N;

void dfs(int current, int parent, long long* dp, int maxL) {
    long long cA = a[current];
    long long* oldPtr = lower_bound(dp, dp+N, cA);
    long long oldV = *oldPtr;
    if (oldV == INF) {
        maxL += 1;
    }
    *oldPtr = cA;
    answer[current] = maxL;
    for (int i=0; i<connectSize[current]; i++) {
        int forward = connect[connectPtr[current] + i];
        if (forward != parent) {
            dfs(forward, current, dp, maxL);
        }
    }
    *oldPtr = oldV;
}
int main() {
    int u[200000], v[200000];
    cin >> N;
    for (int i=0; i<N; i++) cin >> a[i];


    for (int i=0; i<N-1; i++) {
        cin >> u[i] >> v[i];
        connectSize[u[i]-1]++;
        connectSize[v[i]-1]++;
    }
    int ptr = 0;
    for (int i=0; i<N; i++) {
        connectPtr[i] = ptr;
        ptr += connectSize[i];
    }
    {
        int cptr[200000];
        for (int i=0; i<N; i++) cptr[i] = connectPtr[i];
        for (int i=0; i<N-1; i++) {
            connect[cptr[ u[i]-1 ]++] = v[i]-1;
            connect[cptr[ v[i]-1 ]++] = u[i]-1;
        }
    }
    
    for (int i=0; i<N; i++) dp[i] = INF;
    dfs(0, -1, dp, 0);
    for (int i=0; i<N; i++) {
        cout << answer[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 30244
#define ll long long
#define lld long double
#define cn(n)  ll n;cin >> n;
#define tes(t) ll t;cin>>t;while(t--) 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define al(v) v.begin(), v.end()
#define oset(X) tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const long double PI = 3.141592653589793;
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
ll power(ll x, ll y, ll p){ll res = 1;x %= p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}
ll po(ll base, ll powerRaised){if (powerRaised != 0)return (base * po(base, powerRaised - 1));else return 1;}
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a * b) / gcd(a, b);}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif //*
  ll n,k;
  cin>>n>>k;
  vector<ll>v;
  rep(i,0,n-1)
  {
    ll x;
    cin>>x;
    v.pb(x);
  }
  ll start=1;
  ll end=1e9;
  ll res;
  while(start<=end)
  {
    ll mid=(start+end)/2;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
      if(v[i]==mid)
      continue;
      else if(v[i]%mid==0)
      ans+=v[i]/mid-1;
      else 
      ans+=v[i]/mid;
    }
    if(ans<=k)
    {
      end=mid-1;
      res=mid;
    }
    else 
    {
      start=mid+1;
      // res=mid;
    }

    // cout<<mid<<" "<<ans<<endl;

  }

  cout<<res;
  

  
}


Measured memory_bytes: 5320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> l(m),r(m);
    vector<int> pass_num(n,0);
    rep(i,m){
        cin >> l[i] >> r[i];
        l[i]--;r[i]--;
    }
    rep(i,m){
        pass_num[l[i]]++;
        pass_num[r[i]+1]--;
    }
    rep(i,n-1)pass_num[i+1]+=pass_num[i];
    int ans=0;
    rep(i,n){
        if(pass_num[i]==m){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}
unsigned GetDigit(unsigned num) { return log10(num) + 1; }
int main() {
  int cnt = 0, ans = 0;
  string s, t;
  cin >> s >> t;
  int Ss = s.length();
  int Ts = t.length();
  for (int i = 0; i < Ss - Ts + 1; i++) {
    for (int j = 0; j < Ts; j++) {
      // cout << s[i + j] << i + j << " " << t[j] << j << endl;
      if (s[i + j] == t[j]) {
        // cout << s[i + j] << " " << t[j] << endl;
        cnt++;
      }
    }
    if (ans <= cnt) {
      ans = cnt;
      // cout << ans << endl;
    }
    cnt = 0;
  }
  // cout << ans;
  cout << Ts - ans;
}

Measured memory_bytes: 3724
#include <iostream>
#define int long long
using namespace std;
signed main(void){
	int a[100][100]={0},b[100][100]={0},c[100][100]={0},i,j,k,l,m,n;
	cin>>n>>m>>l;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			cin>>b[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l-1;j++){
			cout<<c[i][j]<<' ';
		}
		cout<<c[i][j]<<endl;
	}
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;

using namespace std;

int N;
ll dp[100001][2];

int main() {
  cin >> N;
  vector<ll> A(N);
  REP(i, N) { cin >> A[i]; }
  dp[0][0] = 0;
  dp[0][1] = numeric_limits<ll>::min() / 2;
  FOR(i, 1, N + 1) {
    dp[i][0] = max(dp[i - 1][0] + A[i - 1], dp[i - 1][1] - A[i - 1]);
    dp[i][1] = max(dp[i - 1][0] - A[i - 1], dp[i - 1][1] + A[i - 1]);
  }
  cout << dp[N][0] << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define N 1000005

int main()
{
  FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   
   ll fr[N];
   memset(fr,0,sizeof(fr));
   rep(n)
        fr[arr[i]]++;
   
   ll hold[N];
   memset(hold,0,sizeof(hold));
   
   for(ll i=1;i<N;i++)
        for(ll j=i;j<N;j+=i)
            hold[j]+=fr[i];
   
   ll ans = 0;
   
   rep(n)
       ans+=(hold[arr[i]] == 1);
   
   cout<<ans;
   
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 20800
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007



int main() {
  int N;
  cin >> N;
  vector<ll> a(3 * N);
  rep(i, 3 * N) cin >> a.at(i);

  sort(all(a), greater<ll>());

  ll ans = 0;
  rep(i, N) ans += a.at(2 * i + 1);

  cout << ans << endl;

}


Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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 ll long long 
#define all(v) v.begin(),v.end()

using namespace std;

int main () {
  int n; cin>>n;
  vector<pair<int,int>> p(n);
  rep(i,n)cin>>p[i].first>>p[i].second;
  rep(i,n-2){
    if(p[i].first==p[i].second){
      if(p[i+1].first==p[i+1].second){
        if(p[i+2].first==p[i+2].second){
          cout <<"Yes"<<endl;
          return 0;
        }
      }
    }
  }
    cout <<"No"<<endl;
}
  

Measured memory_bytes: 3636