akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
  int e;
  while(cin >> e, e){
    int ans = e+1;
    for(int i = 0 ; i*i*i <= e ; i++){
      for(int j = 0 ; j*j <= e-i*i*i ; j++){
	int k = e-i*i*i-j*j;
	ans = min(ans, i+j+k);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

struct Dice {
  int f[6];
  Dice() {
    f[0] = 1; f[1] = 4; f[2] = 2;
    f[3] = 3; f[4] = 5; f[5] = 6;
  }
  // a -> b, b -> c, c -> d, d -> a;
  void rot(int a, int b, int c, int d) {
    int tmp = f[d];
    f[d] = f[c]; f[c] = f[b]; f[b] = f[a]; f[a] = tmp;
  }
  void rot1() {
    rot(0, 1, 5, 3);
  }
  void rot2() {
    rot(0, 2, 5, 4);
  }
  void rot3() {
    rot(0, 3, 5, 1);
  }
  void rot4() {
    rot(0, 4, 5, 2);
  }
  void rot_v() {
    rot(1, 2, 3, 4);
  }
  void set(int top, int front) {
    while(true) {
      if(f[0] == top) break;
      rot2();
      if(f[0] == top) break;
      rot1();
      if(f[0] == top) break;
      rot2();
      if(f[0] == top) break;
      rot1();
      if(f[0] == top) break;
      rot2();
      if(f[0] == top) break;
      rot1();
    }
    while(true) {
      if(f[3] == front) break;
      rot_v();
    }
  }
};

int level[201][201];
int number[201][201];

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    for(int i = 0; i < 201; i++) {
      for(int j = 0; j < 201; j++) {
        level[i][j] = 0;
        number[i][j] = 0;
      }
    }
    while(N--) {
      int top, front; cin >> top >> front;
      Dice dice;
      dice.set(top, front);
      int Y = 100, X = 100;
      while(true) {
        int mov = -1;
        for(int i = 0; i < 4; i++) {
          bool ok_face = false;
          for(int k = 4; k <= 6; k++) {
            if(dice.f[i+1] == k) ok_face = true;
          }
          if(ok_face == false) continue;
          const int dy[4] = { -1, 0, 1, 0 };
          const int dx[4] = { 0, -1, 0, 1 };
          int ny = Y + dy[i], nx = X + dx[i];
          if(level[ny][nx] < level[Y][X] && (mov == -1 || dice.f[mov] < dice.f[i+1])) mov = i + 1;
        }
        if(mov == -1) break;
        switch(mov) {
          case 1:
            dice.rot1();
            Y -= 1;
            break;
          case 2:
            X -= 1;
            dice.rot2();
            break;
          case 3:
            Y += 1;
            dice.rot3();
            break;
          case 4:
            X += 1;
            dice.rot4();
            break;
        }
      }
      level[Y][X]++;
      number[Y][X] = dice.f[0];
      // cerr << "PUT: X = " << X << ", Y = " << Y << ", F = " << dice.f[0] << endl;
    }

    int count_[7] = { 0 };
    for(int i = 0; i < 201; i++) {
      for(int j = 0; j < 201; j++) {
        count_[number[i][j]]++;
      }
    }
    for(int i = 1; i <= 6; i++) {
      if(i != 1) cout << " ";
      cout << count_[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1476
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;

signed main()
{
    fast;
    int a,b,c;
    map<int,int> mp;
    cin>>a>>b>>c;
    mp[a]++;
    mp[b]++;
    mp[c]++;

    if ( mp.size() == 2 )
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  int x;
  cin >> x;
  x = x - 400;
  if(x%200 == 0){}
  x = x / 200;
  if(8-x < 1) cout << "1";
  else
    cout << 8 - x;
  return 0;
}


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

int main(){
    int sum = 700;
    char c;
    rep(i,3){
        cin >> c;
        if(c=='o') sum += 100;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
local N,M,X,Y = io.read("*n","*n","*n","*n")
local cityN = {}
local cityM = {}
for i=1,N do
    table.insert(cityN,io.read("*n"))
end
for i=1,M do
    table.insert(cityM,io.read("*n"))
end

function test(X,Y,cityN,cityM)
    local minN,maxN = X,X
    for i,v in ipairs(cityN) do
        minN = math.min(v,minN)
        maxN = math.max(v,maxN)
    end
    local minM,maxM = Y,Y
    for i,v in ipairs(cityM) do
        minM = math.min(v,minM)
        maxM = math.max(v,maxM)
    end
    if minM>maxN or minN >maxM then
        print("No War")
    else
        print("War")
    end
end

test(X,Y,cityN,cityM)

Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    x = li()
    amin = 100000000000
    
    for i in range(101):
        tmp = 0
        for j in x:
            tmp+=(i-j)**2
        amin = min(amin,tmp)
    print(amin)



main()



Measured memory_bytes: 5628
#include <stdio.h>

int main (){
	int n, a, b;
	scanf ("%d %d %d", &n, &a, &b);
	int sum = 0;
	
	// cth
	// i == 123
	// memecah ambil tiap digit jd 3 + 2 + 1 = 6;
	// 123 % 10 == 3; 123 / 10 = 3
	// 12 % 10 == 2; 12 / 10 == 1
	// 1 %  10 == 1; 1 / 10 == 0
	
	for (int i = 1; i <= n; i++){
		int digitSum = 0;
		int temp = i; // i ditampung ke temp biar ga infinite loop
		while (temp != 0){
			digitSum = digitSum + temp % 10;
			temp /= 10;
		}
		// temp = 0; makanya jadi sum += i;
		if (digitSum >= a && digitSum <= b){
			sum += i;
		}
	}
	printf ("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 1732
n = int(input()) #time
m = int(input()) 
a = [] #input
s = [m] #result

for i in range(n):
    b = input().split( )
    a.append(b)

for i in range(n):
    m = m + int(a[i][0]) - int(a[i][1])
    s.append(m)

if(min(s) < 0): 
    print(0)
else:
    print(max(s))


Measured memory_bytes: 8552
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned LL
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector< PII >
#define VVI vector< VI >
#define MP make_pair
#define PB push_back
#define F first
#define S second
const int INF=1e9;
const int MOD=1e9+7;
// >.<
int n,m;
LL x=1,y=1;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)x=(x*i)%MOD;
    for(int i=1;i<=m;i++)y=(y*i)%MOD;
    if(n==m){
        cout<<(((x*y)%MOD)+((x*y)%MOD))%MOD<<"\n";
    }
    else if(abs(n-m)==1){
        cout<<(x*y)%MOD<<"\n";
    }
    else{
        cout<<"0\n";
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	cout << n*(n-1)/2 - n/2 << "\n";
	if (n%2 == 0){
		rep(i, n){
			for(int j=i+1; j<n; j++){
				if (i+j+1 != n)
					cout << i+1 << " " << j+1 << "\n";
			}
		}
	}else{
		rep(i, n){
			for(int j=i+1; j<n; j++){
				if (i+j+2 != n)
					cout << i+1 << " " << j+1 << "\n";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
while True:
    data = input().split()
    m = int(data[0])
    f = int(data[1])
    r = int(data[2])
    ans = ""

    if m==-1 and f==-1 and r==-1:
        break

    if m==-1 or f==-1:
        ans = "F"
    elif m+f >= 80:
        ans = "A"
    elif m+f >= 65:
        ans="B"
    elif m+f >= 50:
        ans="C"
    elif m+f >= 30:
        if r >= 50:
            ans="C"
        else:
            ans="D"
    else:
        ans = "F"

    print(ans)


Measured memory_bytes: 5592
n = int(input())
list_n = list((map(int, input().split())))
count = 0
ans = 0
while count < n-1:
    if list_n[count] == list_n[count+1]:
        if count == n-2:
            if list_n[count] != 1:
                list_n[count+1] = 1
            else:
                list_n[count+1] = 2
        else:
            if list_n[count] != 1 and list_n[count+2] != 1:
                list_n[count+1] = 1
            elif list_n[count] != 2 and list_n[count+2] != 2:
                list_n[count+1] = 2
            else:
                list_n[count+1] = 3
        ans += 1
    count += 1
print(ans)


Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
long long a,b;
int main(){
	scanf("%lld%lld",&a,&b);
	if(a<=0 && b>=0) printf("Zero");
	else if(a>0) printf("Positive");
	else if(a<0 && (b-a)&1) printf("Positive");
	else printf("Negative");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int next_prime(int x)
{
    int prime = 1;
    for(int i = 2; i*i <= x; i++){
        if(x % i == 0) {
            prime = 0;
            break;
        }
    }
    if(prime) return x;
    else      return next_prime(x+1);
}

int main()
{
    int x;
    cin >> x;
    cout << next_prime(x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<string> ans_vec(N+2);
  
  for (int i=0;i<M+2;i++){
    ans_vec.at(0) += '#';
    ans_vec.at(N+1) += '#';
  }
  
  for(int i = 0;i<N;i++){
   cin >> ans_vec.at(i+1); 
    ans_vec.at(i+1) = '#' + ans_vec.at(i+1) +'#';
  }

  
   for (int i = 0; i < ans_vec.size(); i ++){
   cout << ans_vec.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def bogosort(l):
  import random
  while 1:
    random.shuffle(l)
    for i in range(1,len(l)):
      if l[i]<l[i-1]:
        break
    else:
      return l
l=input().split()
a,b,c=bogosort(l)
print(eval(c+b+'+'+a))

Measured memory_bytes: 4592
#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>;

ll gcd(ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}

int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> vec(n);
  rep(i,n) cin >> vec.at(i);
  ll ans = abs(x-vec.at(0));
  rep(i,n) ans = gcd(ans, abs(x-vec.at(i)));
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;
    vector<ll> num;
    vector<pair<ll,ll>> city;
    REP(i,N){
        ll x, y;
        cin >> x >> y;
        city.push_back(make_pair(x,y));
        num.push_back(i);
    }

    ll count=0;
    double sum = 0.0;
    do{
       count++;
       for(int i = 0; i < N-1; i++ ){
          sum += sqrt( pow((city[num[i]].first - city[num[i+1]].first), 2) +
                       pow((city[num[i]].second- city[num[i+1]].second), 2) );
       }
    }while(next_permutation(num.begin(), num.end()));


    cout << sum/(double)count << endl;
}


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


int main(void)
{
    
    int n;
    scanf("%d", &n);
    int h[n];
    for (int i=0; i < n; i++)
        scanf("%d", &h[i]);

    int max = 0;
    int sum;
    int index = 0;
    while(1){
        sum = 0;
        while(1){
            if (index == n-1)
                break;
            else if(h[index] >= h[index+1]){
                index++;
                sum++;
            }
            else{
                index++;
                break;
            }
            if (max < sum)
                max = sum;
        }
        if(index == n-1)
            break;
    }

    printf("%d\n", max);






    return 0;
} 



Measured memory_bytes: 512
import collections

n = int(input())
data_list = [input() for i in range(n)]
data_list.sort()

count_dict = collections.Counter(data_list)

max_val = max(count_dict.values())
max_keys = [key for key in count_dict if count_dict[key] == max_val]

max_keys.sort()

for i in range(len(max_keys)):
    print(max_keys[i])

Measured memory_bytes: 35572
N, D = gets.split.map &:to_i
X = $<.map{|s|
  s.split.map &:to_i
}

p X.combination(2).count{|a, b|
  sq = a.zip(b).map{|y, z|
    (y - z) ** 2
  }.inject:+
  sqrt = sq ** 0.5
  sqrt.floor ** 2 == sq
}

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int cnt = 0;
			int n = sc.nextInt();
			int x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(int i=1; i<=n-2; i++){
				for(int j=i+1; j<=n-1; j++){
					for(int k=j+1; k<=n; k++){
						if(i + j + k == x){
							cnt++;
						}
					}
				}
			}
			
			System.out.println(cnt);
		}
	}

}

Measured memory_bytes: 26472
// Bismillaahirrahmaanirrahiim
/* Author	: Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define jehian using
#define mau namespace
#define libur std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

jehian mau libur;
/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n");
#define sp printf(" ");

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)
#define special pair<ll,pll>

int main(){
	ll A, B;
	cin >> A >> B;
	cout << 2 * B - A << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	float i = 0;
	int N,t = 0;
	cin >> N;
	while (1) {
		if (N < pow(10, 2 * i + 1)) {
			if (N < pow(10, 2 * i))break;
			t += N - pow(10, 2 * i)+1;
			break;
		}
		else {
			t += pow(10, 2 * i + 1) - pow(10, 2 * i);
		}
		++i;
	}
	cout << t << "\n";
	return 0;
}

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

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int ans = (h2 - h1) * 60 + m2 - m1 - k;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<iostream>

#include<algorithm>
#include<cstdlib>
#include<queue>
#include<stack>
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<iomanip>
#include <string.h>
using namespace std;

int pos[22][22];
int main(){
    while(true){
        int N;
        cin>>N;
        if(N==0)
            break;
        memset (pos,0,sizeof(pos));
        for(int i=0;i<N;i++){
            int x,y;
            cin>>x>>y;
            pos[20-y][x]=1;
        }
        int M;
        cin>>M;
        int x=10,y=10;
        for(int i=0;i<M;i++){
            char d;
            int l;
            cin>>d>>l;
            switch(d){
                case'N':
                    for(int i=0;i<=l;i++){
                        pos[y-i][x]=0;
                    }
                    y-=l;
                    break;
                case'S':
                    for(int i=0;i<=l;i++){
                        pos[y+i][x]=0;
                    }
                    y+=l;
                    break;
                case'W':
                    for(int i=0;i<=l;i++){
                        pos[y][x-i]=0;
                    }
                    x-=l;
                    break;
                case'E':
                    for(int i=0;i<=l;i++){
                        pos[y][x+i]=0;
                    }
                    x+=l;
                    break;
            }
            //cout<<x<<"    "<<y<<endl;
        }
        int a=1;
        
        for(int i=0;i<=20;i++){
//            cout<<setw(2) << setfill('.')<<20-i<<": ";
           for(int j=0;j<=20;j++){
//                cout<<setw(2) << setfill('.')<<pos[i][j];
                if(pos[i][j]==1)
                    a=0;
            }
//            cout<<endl;
        }
//        cout<<"    ";
//        for(int i=0;i<=20;i++)
//            cout<<setw(2) << setfill('.')<<i;
//        cout<<endl;
        cout<<(a==1?"Yes":"No")<<endl;
    }
}

Measured memory_bytes: 1152
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define PI 3.14159265358979323846264338327950288
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define testP	 cout << "------------------ test ------------------" << endl;	// 動作確認テスト
#define testX(x) cout << "testout : " << x << endl;	// テストアウト
typedef long long ll;
using namespace std;
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	int H, W;
	cin >> H >> W;

	queue<pair<int, int>> que;
	pair<int, int> end_pair;

	static char maze[1000][1000];
	fill(maze[0], maze[1000], '-');
	rep(y, H) {
		rep(x, W) {
			cin >> maze[y][x];
			if (maze[y][x] == '#') {
				que.push(make_pair(y, x));
				end_pair = que.back();
			}
		}
	}

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

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

	while (!que.empty()) {
		pair<int,int> tmp = que.front();
		que.pop();

		rep(i, 4) {
			int nextY = tmp.first + dy[i],
				nextX = tmp.second + dx[i];

			if (nextY < 0 || nextY >= H || nextX < 0 || nextX >= W) continue;
			if (maze[nextY][nextX] == '#') continue;
			
			maze[nextY][nextX] = '#';
			que.push(make_pair(nextY, nextX));
		}

		if (tmp == end_pair) {
			ans++;
			if (!que.empty()) end_pair = que.back();
		}
	}
	
	cout << ans - 1 << endl;
	return 0;
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];
    sort(ALL(A));
    UNIQUE(A);
    int ans = A.size();
    if(ans % 2 == 0) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 3740
#include<stdio.h>
#include<string.h>
#define M 100005
char s1[M],s2[M],s[M],d[M],x[M];
int  a[M],b[M],c[M];
void ss(char s1[],char s2[],int n,int m)
{
    int i,j,a[M],b[M];
    for(i=0; i<n; i++)
        a[i]=s1[n-i-1]-'0';
    for(i=0; i<m; i++)
        b[i]=s2[m-i-1]-'0';
    for(i=0; i<n; i++)
        c[i]=a[i]-b[i];
    for(i=0;i<n;i++)
      if(c[i]<0)
        {
            while(c[i]<0)
            {
              c[i+1]=c[i+1]-1;
              c[i]+=10;
            }
        }
}
int main()
{
    int n,m,i,j,k,kk;
    memset(s1,0,sizeof(s1));
    memset(s2,0,sizeof(s2));
    scanf("%s %s %s",x,s2,s1);
    {
        n=strlen(s1);
        m=strlen(s2);
        if(n>m)
            ss(s1,s2,n,m);
        else if(n<m)
        {
            printf("delicious\n");
            return 0;
        }
        else
        {
            k=strcmp(s1,s2);
            if(k<=0)
            {
                printf("delicious\n");
                return 0;
            }
            else if(k>0)
                ss(s1,s2,n,m);
        }
        if(n>m) kk=n;
        else kk=m;
        while(c[kk]==0) kk--;
        for(i=kk,j=0;i>=0;i--,j++)
        {

            d[j]=(c[i]+'0');
        }
        n=strlen(d);
        m=strlen(x);
        if(n>m)
        {
            printf("dangerous\n");
            return 0;
        }
        else if(n<m)
        {
            printf("safe\n");
            return 0;
        }
        else
        {
            k=strcmp(d,x);
            if(k<=0)
            {
                printf("safe\n");
                return 0;
            }
            else if(k>0)
            {
                printf("dangerous\n");
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M;

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

	cin >> N >> M;
	int a = 1, b = N;
	bool F[200010] = { false };
	int m = N;
	while (M--) {
		if (F[b - a - 1] || F[a + N - b - 1]  || a + N - b - 1 == b-a-1)b--;
		F[b- a - 1] = F[a + N - b - 1] = 1;
		cout << a << " " << b << endl;
		a++;
		b--;
		
	}

	return 0;
}



Measured memory_bytes: 3864
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        int sw = Integer.parseInt(str.split(" ")[0]);
        int lbnum = Integer.parseInt(str.split(" ")[1]);
        List<String> swStates = new ArrayList<String>((int)Math.pow(2, sw));
        List<List<Integer>> lbConnected = new ArrayList<List<Integer>>();

        for (int i = 0; i < lbnum; i++) {
            List<Integer> ls = new ArrayList<Integer>();
          	int lbConum = in.nextInt();
            for (int j = 0; j < lbConum; j++) {
                ls.add(in.nextInt());
            }
            lbConnected.add(ls);
        }
        int[] zoo = new int[lbnum];
      	int hld = 0;
        for (int i = 0; i < lbnum; i++) {
            zoo[i] = in.nextInt();
        }
        in.close();

        StringBuilder sb = new StringBuilder();
        String bins;
        for (int i = 0; i < Math.pow(2, sw); i++) {
            sb.delete(0, sb.length());
            bins = Integer.toBinaryString(i);
            for (int j = 0; j <= sw - bins.length(); j++) {
                sb.append("0");
            }
            sb.append(bins);
            swStates.add(sb.toString());
        }

        List<String> ignoreCase = new ArrayList<String>();
        for(int i = 0; i < lbnum; i++) {
            ignoreCase.clear();
            int count;
            for (String a : swStates) {
                count = 0;
                for (Integer idx : lbConnected.get(i)) {
                    if (a.charAt(sw + 1 - idx) == '1') {
                        count++;
                    }
                }
                if (count % 2 != zoo[i]) {
                    ignoreCase.add(a);
                }
            }
            swStates.removeAll(ignoreCase);
            if (swStates.size() == 0) {
                break;
            }
        }

        System.out.println(swStates.size());

    }

}


Measured memory_bytes: 24020
def main():
    import sys
    input = sys.stdin.readline


    #Union Find

    #xの根を求める
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    #xとyの属する集合の併合
    def unite(x,y):
        x = find(x)
        y = find(y)
        
        if x == y:
            return False
        else:
            #sizeの大きいほうがx
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True

    #xとyが同じ集合に属するかの判定
    def same(x,y):
        return find(x) == find(y)

    #xが属する集合の個数
    def size(x):
        return -par[find(x)]

    n,m = map(int,input().split())
    #初期化
    #根なら-size,子なら親の頂点
    par = [-1]*n

    for i in range(m):
        X,Y,Z = map(int,input().split())
        unite(X-1,Y-1)
    
    tank = set([])
    for i in range(n):
        tank.add(find(i))
    print(len(tank))

if __name__ == '__main__':
    main()

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

#define int long long
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; }

signed main(){
	int n, k;
	cin >> n >> k;

	int a[200010];
	for(int i = 0;i < n;i++){
		cin >> a[i];
		a[i]--;
	}
	int v[200010];
	memset(v, -1, sizeof(v));
	int now = 0;
	int cnt = 0;
	while(1){
		v[now] = cnt;
		if(k == 0){
			cout << now+1 << endl;
			return 0;
		}
		cnt++;
		if(v[a[now]] != -1){
			k %= (cnt-v[a[now]]);
			break; 
		}
		k--;
		now = a[now];
	}
	while(1){
		if(k == 0){
			cout << now+1 << endl;
			return 0;
		}
		k--;
		now = a[now];
	}
	return 0;
}


Measured memory_bytes: 6760
#include <cstdio>
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <string>
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;

// 移動元と行先と辺のコストを記録する構造体
template <typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int s, T d) : to(s), cost(d) {}
    Edge(int f, int s, T d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};

template <typename T>
using Graph = vector< vector< Edge<T> > >;

template <typename T>
vector<int> tpsort_Kahn(const vector< vector< Edge<T> > > &g) {
    const int V = g.size();
    vector<int> indeg(V, 0);
    stack<int> S;

    rep(i,0,V) rep(j,0,g[i].size())
        indeg[ g[i][j].to ]++;
    rep(i,0,V) if(indeg[i] == 0) S.push(i);

    vector<int> ans;
    while(S.size() > 0) {
        int u = S.top(); S.pop();
        ans.push_back(u);
        rep(i,0,g[u].size()) {
            indeg[ g[u][i].to ]--;
            if(indeg[ g[u][i].to ] ==  0)
                S.push( g[u][i].to );
        }
    }
    return ans;
}

const int INF = 1 << 28;
int lb[110][110], ub[110][110];

int main() {
    int M, N; cin >> M >> N;
    for(int i=0; i<M; i++) {
        fill(lb[i], lb[i] + N,  -1);
        fill(ub[i], ub[i] + N, INF);
    }

    Graph<int> G(M);
    bool ok = true;
    for(int i=0; i<M; i++) {
        int K; cin >> K;
        for(int k=0; k<K; k++) {
            int s, t;
            string cond;
            cin >> s >> cond >> t; s--;
            if(cond == "<=") ub[i][s] = min(ub[i][s], t);
            if(cond == ">=") lb[i][s] = max(lb[i][s], t);
        }
        for(int k=0; k<N; k++) {
            if(lb[i][k] > ub[i][k]) ok = false;
        }
    }

    for(int i=0; i<M; i++) {
        for(int j=0; j<M; j++) {
            if(i == j) continue;
            for(int k=0; k<N; k++) {
                // i より j の方が後でなければならない条件
                if(ub[i][k] == INF || lb[j][k] == -1) continue;
                if(ub[i][k] < lb[j][k]) {
                    G[i].push_back(Edge<int>(j, 1));
                }
            }
        }
    }

    if(tpsort_Kahn(G).size() != M) ok = false;
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 5008
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;
ll N;
ll M;
string s;
vector<ll > input1;  
vector<vector <ll > > input2;
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
int main(){
    
    //cin >> N;
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll LCM = lcm(C, D);
    //cout << LCM << endl;

    ll ansA = B / C - A / C;
    if(A % C == 0){
        ansA += 1;
    }

    //cout << ansA << endl;

    ll ansB = B / D - A / D;
    if(A % D == 0){
        ansB += 1;
    }

    ll anslcm = B / LCM - A / LCM;
    if(A % LCM == 0){
        anslcm += 1;
    }
    //cout << anslcm << endl;
    ll ryouhou = ansA + ansB - anslcm;

    ll ans = (B - A + 1) - ryouhou;

    cout << ans << endl;
} 

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

int main() {
  int n;
  char c;
  string res = "Three";
  cin >> n;
  rep(i, n) {
    cin >> c;
    if (c == 'Y') {
      res = "Four";
      break;
    }
  }
  cout << res;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int number,dp[100100][3];
int main(){
	cin>>number;
	for(int i=1;i<=number;i++){
		int a,b,c;
		cin>>a>>b>>c;
		int p=a+max(dp[i-1][1],dp[i-1][2]);
		int q=b+max(dp[i-1][0],dp[i-1][2]);
		int r=c+max(dp[i-1][0],dp[i-1][1]);
		dp[i][0]=p;
		dp[i][1]=q;
		dp[i][2]=r;
	}
	cout<<max(max(dp[number][0],dp[number][1]),dp[number][2])<<endl;
	return 0;
}

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

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

  double T = 1;
  rep(i, M) { T *= 0.5; }
  int64_t ANS = (M * 1900 + ((N - M) * 100)) / T;
  cout << ANS << endl;
}

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


#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
// vector<int> A;
vector<int> C,D;
int input(){
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    fast_io();
    cin >> N;
    C.assign(N,0);
    D.assign(N+1,0);
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;--a;
        C[a]++;
    }
    for (int i = 0; i < N; i++)
    {
        D[C[i]]++;
    }

    
    return 0;
}

int solve(){
    // vector<int> C(N+1,0);
    // map<int,int> Cnt;
    vector<int> kD,sumD;
    // for (int i = 0; i < N; i++) Cnt[A[i]]++;
    // for(auto cnt:Cnt) C.push_back(cnt.second);
    // sort(C.begin(),C.end());
    // for (int i = 0; i < N; i++) D[C[i]]++;
    sumD.assign(N+1,0),kD.assign(N+1,0);
    for (int i = 0; i < N; i++) {
        sumD[i+1] = sumD[i]+D[i];
        kD[i+1] = kD[i]+i*D[i];
    }
    auto f = [&](int x){
        return (kD[x]+x*(sumD[N]-sumD[x]))/x;
    };
    DBG(C)
    DBG(D)
    DBG(kD)
    DBG(sumD)
    int L = C.size();
    for (int k = 1; k <= N; k++)
    {
        if(k==1) {cout << N << "\n"; continue;}
        if(k>L) {cout << 0 << "\n"; continue;}

        int ok=0,ng=N+1;
        while(ng-ok>1){
            int mid=(ok+ng)/2;
            if(f(mid)>=k) ok=mid;
            else ng=mid;
        }        
        cout << ok << "\n";
    }
    
    return 0;
}

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 5632
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(i64, a, b);
    if ((a + b) % 2) {
        print("IMPOSSIBLE");
    } else {
        print((a + b) / 2);
    }

    return 0;
}


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

int main() {
    
    int n, t, minc = 10001, ci, ti;
    cin >> n >> t;
    for (int i = n; i--;) {
        cin >> ci >> ti;
        if (ti <= t) minc = min(ci, minc);
    }

    if (minc == 10001)
        cout << "TLE" << endl;
    else
        cout << minc << endl;
    
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int i, j;
	int sosu = 0;
	int flag = 0;
	int X;
	cin >> X;
	for (i = X; i < 110000; ++i) {
		sosu=i;

		for (j = 2; j < sosu; ++j) {
			if (sosu%j == 0) {
				//cout << "test" << endl;
				flag = 1;
			}
		}
		if (flag == 0) {
			//cout << "test" << endl;
			break;
		}
		flag = 0;

	}
	cout << sosu << endl;



}



Measured memory_bytes: 256
n = gets.to_s.to_i
a = gets.to_s.split.map(&:to_i)

c = Hash.new(0)
a.each{ |k| c[k] += 1 }
cnt = 1
c.values.each{ |k| cnt += k * (k-1)/2 }

a.each{ |k| puts cnt - c[k] }

Measured memory_bytes: 31620
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var X = input[0];
        var Y = input[1];

        for (int i = 0; i <= X; i++)
        {
            if (2 * i + 4 * (X - i) == Y)
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }
}


Measured memory_bytes: 28196
#include <stdio.h>

char map[102][102];

int main()
{
	int n, m, d, r, c, w, ans;

	scanf("%d%d%d", &m, &n, &d);
	for (r = 0; r < m; r++) scanf("%s", map[r]);
	for (ans = 0, r = 0; r < m; r++) {
		for (w = c = 0; c < n; c++) {
			if (map[r][c] == '.') w++;
			else if (w > 0) {
				if (w >= d) ans += w-d+1;
				w = 0;
			}
		}
		if (w >= d) ans += w-d+1;
	}
	for (c = 0; c < n; c++) {
		for (w = r = 0; r < m; r++) {
			if (map[r][c] == '.') w++;
			else if (w > 0) {
				if (w >= d) ans += w-d+1;
				w = 0;
			}
		}
		if (w >= d) ans += w-d+1;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int a, b; cin >> a >> b;
    vector<string> field(100);
    rep(i,50) {
        string s(100,'#');
        field[i] = s;
    }
    for (int i = 50; i < 100; i++) {
        string s(100,'.');
        field[i] = s;
    }
    int ct = 0;
    for (int h = 0; h <= 48; h += 2) {
        for (int w = 0; w < 100; w += 2) {
            if (ct >= a-1) break;
            field[h][w] = '.';
            ct++;
        }
    }
    ct = 0;
    for (int h = 51; h < 100; h += 2) {
        for (int w = 0; w < 100; w += 2) {
            if (ct >= b-1) break;
            field[h][w] = '#';
            ct++;
        }
    }
    cout << 100 << " " << 100 << endl;
    rep(i,100) {
        rep(j,100) cout << field[i][j];
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

int n, k, m;

int main(void)
{
	while (cin >> n >> k >> m, n|k|m) {
		m--;
		vector<int> rem;
		rep(i, n)
			rem.push_back(i);

		int cnt = 0;
		for (;;) {
			vector<int>::iterator it;
			it = remove(ALL(rem), m);
			rem.erase(it, rem.end());

			if (++cnt == n)
				break;
		
			int idx = lower_bound(ALL(rem), m)-rem.begin();
			m = rem[(idx+k-1)%rem.size()];
		}
		printf("%d\n", m+1);
	}
	return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl



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

    return 0;
}


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

#define ll long long
#define ld long double

#define pii pair<int, int>
#define pci pair<char, int>
#define pcc pair<char, char>

#define vi vector <int>
#define vll vector<long long>
#define vld vector<long double>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>

#define vvi vector<vi>
#define vvll vector<vll>
#define vvld vector<vld>
#define vvb vector<vb>
#define vvc vector<vc>
#define vvs vector<vs>

#define vpii vector<pii>
#define vpci vector<pci>
#define vpcc vector<pcc>

#define all(v) (v).begin(), (v).end()
#define allrev(v) (v).rbegin(), (v).rend()
#define allcomp(v) (v).begin(), (v).end(), comp
#define allrevcomp(v) (v).rbegin(), (v).rend(), comp

const int MOD = 1e9 + 7;
const ld pi = 3.1415926535897932384626433832;

#define line cout<<"\n";
#define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);


void solve(int test_case){

    int a, b , c ,d;
    cin >>  a >> b >> c >> d;

    while(a > 0 || c > 0){
        c -= b ;
        if(c <= 0) {cout << "Yes"; break;}
        a -= d;
        if(a <= 0) {cout << "No"; break;}
    }
}

int main(){
    fast
    int test = 1;
    //cin>>test;
    for(int i = 1; i <= test; i++){
        solve(i);
    }
    return 0;
}


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

namespace Sum_of_4_Integers
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();

                if (input == null)
                {
                    break;
                }

               
                int num = int.Parse(input);
                int count = 0;

                for (int i = 0; i < 10; ++i)
                {
                    for (int j = 0; j < 10; ++j)
                    {
                        for (int k = 0; k < 10; ++k)
                        {
                            for (int l = 0; l < 10; ++l)
                            {
                                if (i + j + k + l == num)
                                {
                                    ++count;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}



Measured memory_bytes: 13912
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&m);
  if(n <= m) printf("unsafe");
  else printf("safe");
  
  return 0;
}



Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int n;
    cin >> n;
    vector<Pii> p;
    rep(i, n) {
      int a, b;
      cin >> a >> b;
      p.emplace_back(a, b);
    }

    vvi dp(n, vi(n, inf));
    rep(i, n) dp[i][i] = 0;
    rep2(len, 2, n + 1) {
      rep(l, n) {
        int r = l + len - 1;
        if (r >= n) break;
        rep2(c, l, r) {
          chmin(dp[l][r], dp[l][c] + dp[c+1][r] +
            p[l].first * p[c].second * p[c+1].first * p[r].second);
        }
      }
    }

    cout << dp[0][n-1] << endl;
}



Measured memory_bytes: 3072