akhauriyash/Code-Regression huggingface dataset:
import Data.List
import Data.Char
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [n, k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  fs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine 
  print $ binarySearch k (sort as) (reverse $ sort fs) (-1, 1100000000000000000)

binarySearch :: Int -> [Int] -> [Int] -> (Int, Int) -> Int
binarySearch k as fs (l, r)
  | r - l <= 1 = r
  | otherwise = if check mid
                  then binarySearch k as fs (l, mid)
                  else binarySearch k as fs (mid, r)
                where 
                  mid = (l + r) `div` 2
                  check :: Int -> Bool
                  check x = (sum $ filter (> 0) $ zipWith (\a f -> a - x `div` f) as fs) <= k
                    

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

using namespace std;

using LL = long long;
using vi = vector<int>;
LL INF = 100000000000LL;

// https://scrapbox.io/ganariya/%E9%81%85%E5%BB%B6%E8%A9%95%E4%BE%A1%E3%82%BB%E3%82%B0%E3%83%A1%E3%83%B3%E3%83%88%E6%9C%A8%E3%80%80%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA
struct LazySegmentTree {
private:
  LL n;
  vector <LL> node, lazy;
  vector<bool> lazyFlag;

public:
  LazySegmentTree(vector <LL> v) {
    LL sz = (LL) v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, INF);
    lazyFlag.resize(2 * n - 1, false);

    for (LL i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (LL i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
  }

  void lazyEvaluate(LL k, LL l, LL r) {
    if (lazyFlag[k]) {
      node[k] = min(node[k], lazy[k]);
      if (r - l > 1) {
        lazy[k * 2 + 1] = min(lazy[k * 2 + 1], lazy[k]);
        lazy[k * 2 + 2] = min(lazy[k * 2 + 2], lazy[k]);
        lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
      }
      lazyFlag[k] = false;
    }
  }

  void update(LL a, LL b, LL x, LL k = 0, LL l = 0, LL r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = min(lazy[k], x);
      lazyFlag[k] = true;
      lazyEvaluate(k, l, r);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }

  LL find(LL a, LL b, LL k = 0, LL l = 0, LL r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return INF;
    if (a <= l && r <= b) return node[k];
    LL vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
    LL vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  LL n, q;
  cin >> n >> q;
  vector <pair<int, int>> pr(q);
  for (int i = 0; i < q; i++) cin >> pr[i].first >> pr[i].second;
  vector <LL> v(1 << 19, n - 2), v2(1 << 19, n - 2);
  LazySegmentTree r(v), u(v2);
  LL ans = (n - 2) * (n - 2);
  for (int i = 0; i < q; i++) {
    if (pr[i].first == 1) {
      int g = r.find(pr[i].second - 2, pr[i].second - 1);
      ans -= g;
      u.update(0, g + 1, pr[i].second - 2);
    } else {
      int g = u.find(pr[i].second - 2, pr[i].second - 1);
      ans -= g;
      r.update(0, g + 1, pr[i].second - 2);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

map<pair<int,int>, int> a;

pair<int,int> HighLow(int n)
{
    pii p;
    p.second = n % 10;
    while(n / 10) {
        n /= 10;
    }
    p.first = n;
    return p;
}

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

    int n;
    cin >> n;

    FOR(i, 1, n + 1) a[HighLow(i)]++;

    ll ans = 0;
    FOR(i, 1, 10) FOR(j, 1, 10) {
        ans += a[make_pair(i,j)] * a[make_pair(j,i)];
    } 
    cout << ans << endl;

    return 0;
}

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

int main() {
	int n, t, e;
	cin >> n >> t >> e;

	int ans = -1;
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		for (int j = t - e;j <= t + e;j++) {
			if (j%a == 0) {
				ans = i + 1;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {
	
	int n;
	while( cin >> n) {
		
		int sum = 0;
		
		if( n == 0)
			break;
			
		sum = sum + n / 5 + n / 25 + n / 125 + n / 625 + n / 3125 + n / 15625;
		cout << sum << "\n";
			
	}
	
	return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    string s; cin >> s;
    int ans = 0;
    if(s == "RRR")
        ans = 3;
    else if((s[0] == 'R' && s[1] =='R') || (s[1] == 'R' && s[2] =='R'))
        ans = 2;
    else if(s[0] =='R' || s[1] == 'R' || s[2] =='R')
        ans = 1;
    cout << ans << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;


bool dp[100100];

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    
    rep(i,k+1){ //小さい方から見ていく
        rep(j,n){
            if (i-a[j]>=0) {
                //勝つ手があるならそれを優先->orをとる
                dp[i]|=!dp[i-a[j]];
            }
        }
    }
    
    if (dp[k]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
   
}


Measured memory_bytes: 384
input()
a = list(map(int, input().split()))
b = [0] * 9
for i in a:
    if i < 3200:
        b[int(i / 400)] = 1
    else:
        b[8] = b[8] + 1
mini = sum(b[0:8])
if mini == 0:
    mini = 1
maxi = sum(b[0:8]) + b[8]
print(str(mini) + ' ' + str(maxi))


Measured memory_bytes: 3060
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);
ll n, k;
string s;
ll can(ll xx) {
  ll prev = 1;
  ll tot = 0;
  for(ll i = 0; i < xx; i++) {
    if(prev == 0) {
      if(s[i] == '1') {
        prev = 1;
      }
      else prev = 0;
    } if(prev == 1) {
      if(s[i] == '0') {
        tot++;
        prev = 0;
      } 
    }
  }
  if(tot <= k) return true;
  char last = s[0];
  ll st = 1;
  for(ll i = xx; i < n; i++) {
    if(prev == 0) {
      if(s[i] == '1') {
        prev = 1;
      }
      else prev = 0;
    } if(prev == 1) {
      if(s[i] == '0') {
        tot++;
        prev = 0;
      } 
    }
    // cout<< last << " " << s[st] << " ";
    if(last == '0' and s[st] == '1') {
      tot--;
    }
    last = s[st];
    st++;
    // cout << tot << endl;
    if(tot <= k) return true;
  }
  return false;
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  cin >> n >> k;
  
  cin >> s;
  // for(ll i = 0; i < n; i++) {
  //   if(s[i] == '1') s[i] = '0';
  //   else s[i] = '1';
  // }
  ll low = 0, high = n, ans = 0, mid;
  can(8);
  while(low <= high) {
    mid = (low + high)/2;
    if(can(mid)) {
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  cout << ans << endl;
  return 0;
} //good night.

Measured memory_bytes: 512
import math

inputs = input().split(" ")
H = int(inputs[0])
W = int(inputs[1])

inf = W * 10

# case 1.
ret1 = 0 if H % 3 == 0 else  W
if H == 2:
	ret1 = inf

# case 2.
ret2 = 0 if W % 3 == 0 else H
if W == 2:
	ret2 = inf

# case 3.
ret3 = 0
idealx = W / 3
smallx = math.floor(idealx)
bigx = math.ceil(idealx)

def getDelta(h, w, x):
	if x == 0:
		return inf
	areas = [h * x, (w - x) * (h // 2), (w - x) * (h - h // 2)]
	return max(areas) - min(areas)

ret3_small = getDelta(H, W, smallx)
ret3_big = getDelta(H, W, bigx)

ret3 = min(ret3_small, ret3_big)

# case 4.
ret4 = 0
idealy = H / 3
smally = math.floor(idealy)
bigy = math.ceil(idealy)

ret4_small = getDelta(W, H, smally)
ret4_big = getDelta(W, H, bigy)

ret4 = min(ret4_small, ret4_big)

# print minof ret1-ret4s

print(min([ret1, ret2, ret3, ret4]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q,year;
  int y[1000],b[1000];
  string s,era[1000];
  while(1){
    cin>>n>>q;
    if(n==0 && q==0) break;
    for(int i=0;i<n;i++){
      cin>>era[i]>>b[i]>>y[i];
    }
    for(int i=0;i<q;i++){
      cin>>year;
      for(int j=0;j<n;j++){
	if(year<=y[j] && year>y[j]-b[j]){
	  cout<<era[j]<<" "<<year-y[j]+b[j]<<endl;
	  break;
	}
	else if(j==n-1) cout<<"Unknown"<<endl;
      }
    }
  }
  return 0;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
        cout << b + a << endl;
    } else {
        cout << b - a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int A, B, K;
  cin >> A >> B >> K;
  for (int i = A; i <= min(A+K-1, B); i++) {
    cout << i << endl;
  }
  for (int i = max(A+K, B-K+1); i <= B; i++) {
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 3524
k=int(input())
l=[1 ,1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[k-1])

Measured memory_bytes: 38256
import sys
import math
sys.setrecursionlimit(1000000)

N,blue = map(int,input().split())
red = N-blue
MOD = 10**9+7

def cmb(n, r):
    ans = (math.factorial(n) // math.factorial(n-r)) // math.factorial(r)
    return ans

# 操作回数
for i in range(1, blue+1):
    if red +1 -i >= 0: # 赤の隙間と両端
        # 青の差し込み箇所（操作回数）
        ins_ptn = cmb(red+1, i) % MOD
        # 青の配置方法
        layout_ptn = cmb(blue-1, i-1) % MOD
        print(ins_ptn * layout_ptn % MOD)
    else:
        print(0)

Measured memory_bytes: 66264
s=input()
a=0
b=0
for i in range(len(s)):
  if i % 2 ==0 :
    if s[i] == 'L':
      a+=1
  if i % 2 ==1 :
    if s[i] == 'R':
      b+=1
if a == 0 and b == 0:
  print('Yes')
else :
  print('No')


Measured memory_bytes: 3060
import sys; from collections import deque ; readline = sys.stdin.readline

N, K = map(int, readline().split())
S = readline().rstrip()

nhappy = 0
nseg = 0

state = None
for c in S:
    if c == state:
        nhappy += 1
    else:
        nseg += 1
        state = c

k = K
while k > 0:
    k -= 1
    if nseg >= 3:
        nseg -= 2
        nhappy += 2
    elif nseg == 2:
        nseg -= 1
        nhappy += 1
    else:
        break

print(nhappy)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string s;
    cin >> s;

    ll N = s.length();

    REP(i, N-1){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }

    REP(i, N-2){
        if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 3720
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        sys.exit()
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print("-1")
            break
    else:
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 82680
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n, m; cin >> n >> m;
    vector<int> vec[m];
    for(int i = 0; i < m; i++) {
        int k; cin >> k;
        for(int j = 0; j < k; j++) {
            int s; cin >> s;
            vec[i].push_back(s);
        }
    }
    vector<int> p(m);
    for(int i = 0; i < m; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for(int i = 0; i < (1 << n); i++) {
        int sum = 0;
        for(int j = 0; j < m; j++) {
            int cnt = 0;
            for(int k = 0; k < vec[j].size(); k++) {
                if(i & (1 << (vec[j][k] - 1))) cnt++;
            }
            if(cnt % 2 == p[j]) sum++;
        }
        if(sum == m) ans++;
    }

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


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $n);

$result = [
  'AC' => 0,
  'WA' => 0,
  'TLE' => 0,
  'RE' => 0,
];

for ($i = 0; $i < $n; $i++) {
  fscanf(STDIN, '%s', $s);
  $result[$s] += 1;
}

foreach ($result as $judge => $count) {
  printf('%s x %d%s', $judge, $count, PHP_EOL);
}

Measured memory_bytes: 16188
import fractions
from functools import reduce
N,M= map(int,input().split())
A=[int(x) for x in input().split()]
def lcmpair(a,b):
    return (a*b)// fractions.gcd(a,b)
def lcm(List):
    return reduce(lcmpair,List,1)
lcmB = lcm(A) //2

crit = 0
pena = 0
num = A[0]
while num%2 == 0:
    crit +=1
    num = num//2
count = 0
for i in A:
    count = 0
    while i%2 == 0 :
        count +=1
        i = i//2
    if count != crit:
        pena = 1

if lcmB > M:
    print(0)
elif pena ==1:
    print(0)
else:
    print(((M//lcmB)+1)//2)    

Measured memory_bytes: 16308
n, m = gets.strip.split.map(&:to_i)
ary = []
m.times do
  ary << gets.split.map(&:to_i)
end
ans = []
ary.each do |ele|
  ans << ele[0]
  ans << ele[1]
end

n.times do |i|
  puts ans.count(i + 1)
end

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

int n, d, x, a[200];
int res = 0;

int main(){
  cin >> n >> d >> x;
  rep(i, n) cin >> a[i];
  rep(i, n){
    int num = a[i];
    res += (d + num - 1) / num;
  }
  res += x;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

double a[100];

int main(){
  int N;
  cin >> N;
  rep(i,N){
    cin >> a[i];
  }
  sort(a,a+N);
  double ans = a[0];
  rep(i,N-1){
    ans += a[i+1];
    ans /= 2;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
#define ll long long
map<string, ll>mp;

int main() {

	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++){
		string x; cin >> x;
		sort(x.begin(), x.end());

		if (mp[x] == NULL){
			mp[x] = 1;
		}
		else{
			mp[x]++;
		}
	}
	ll ans = 0;
	for (auto &it : mp){
		ans += it.second*(it.second-1) / 2;
	}
	printf("%lld\n", ans);
	//system("pause");
	return 0;
}

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

bool check[10] = {false};

bool Disassembly(int input) {
    while (input){
        if (check[input % 10]) return true;
        input /= 10;
    }

    return false;
}

int main() {
    int N, K;
    cin >> N >> K;
    int temp;
    for (int i = 0; i < K; ++i) {
        cin >> temp;
        check[temp] = true;
    }
    while (true) {
        if(Disassembly(N)) {
            ++N;
        } else break;
    }

    cout << N << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int a, b, z, i;
   
  
   for(int i=1; i<=3000; i++)
   {
   cin >> a >> b;
   if (b<a)
   { 
     z=a;
   
     a=b;
   
     b=z;
   }
   if (a==0 && b==0)
  
    break ;
  
    else
      cout << a << " " << b << endl;
   
  }

}



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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
int main(){
	int N,K;
	cin >> N >> K;
	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}

	cout << N - K << endl;



	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    scanf("%d",&n);
    if(n<=10)
        printf("Yes");
    else{
        for(m=2;m<=9;m++){
            if(n%m==0 && n/m<=9){
                printf("Yes");
                return 0;
            }
        }
        printf("No");
    }
}


Measured memory_bytes: 256
function main(arg) {
	var tmp = arg.split("\n")[0];
	var t = false;
	do {
        t = /keyence$/.test(tmp);
        if (t) break;
        t = /^keyence/.test(tmp);
        if (t) break;
        t = /^k.*eyence$/.test(tmp);
        if (t) break;
        t = /^ke.*yence$/.test(tmp);
        if (t) break;
        t = /^key.*ence$/.test(tmp);
        if (t) break;
        t = /^keye.*nce$/.test(tmp);
        if (t) break;
        t = /^keyen.*ce$/.test(tmp);
        if (t) break;
        t = /^keyenc.*e$/.test(tmp);
        if (t) break;
        t = /^keyence$/.test(tmp);
        if (t) break;
	} while (0);
	if (t) {
		console.log("YES");
	} else {
		console.log("NO");
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
    var h = parseInt(input[2], 10);
    var ans=(a+b)*h/2;
	//出力
    console.log('%d',ans);
    

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
#define umap unordered_map
#define all(x) x.begin(), x.end()
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M ;
    }
    return res%M;
}
lli solve(){
    lli n;
    cin>>n;
    vll A(n);
    loop(i, 0, n)
        cin>>A[i];
    lli cnt = 0;
    loop(i, 0, n){
        if(i%2 == 0 && A[i] %2 == 1)
            cnt++;
    }
    cout<<cnt<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
	// cin>>t;
    t = 1;
    while(t>0){ 
        t--;
        solve();
    }
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long 

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

const int mod = 1e9+7;

int dp[2][55][3];

signed main()
{
    int N; cin >> N;
    string S[2];
    rep(i,2)cin>>S[i];
    
    int cur = 1;

    int ans;

    rep(i, N) {
        if (i == 0) {
            if (S[0][i] == S[1][i]) {
                ans = 3;
                cur = 1;
            } else {
                ans = 6;
                cur = 2;
                i++;
            }
        } else {
            if (S[0][i] == S[1][i]) {
                if (cur == 1) {
                    ans *= 2;
                    ans %= mod;
                }
                cur = 1;
            } else {
                if (cur == 1) {
                    ans *= 2;
                    ans %= mod;
                } else {
                    ans *= 3;
                    ans %= mod;
                }
                cur = 2;
                i++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, m, a, b, onecount=0;
    bool flag = false;
    cin >> n >> m;
    pair<long long, long long> A[m];
    bool check[n] = {};
    for(int i=0;i<m;i++){
        cin >> a >> b;
        if(a==1){
            A[i] = make_pair(a, b);
        }else if(b==n){
            check[a-1] = true;
        }
        
    }
    for(int i=0;i<m;i++){
        if(A[i].first==1){
            if(check[A[i].second-1]){
                flag = true;
            }
        }
        if(flag==true){
            break;
        }
    }
    if(flag){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
 
}


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


int main()
{
  int x;
  cin >> x;
  if (x == 2)
  {
    puts("2");
    return 0;
  }
  vector<bool> prime(1e6, true);
  for (int i=3; i<1e6; i+=2)
  {
    if (!prime[i])
      continue;
    if (i >= x)
    {
      cout << i << endl;
      return 0;
    }
    int j = i * 3;
    while (j < 1e6)
    {
      prime[j] = false;
      j += i * 2;
    }
  }
  return 0;
}

Measured memory_bytes: 384
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    n = int(input())
    a = wi()

    nums = defaultdict(int)
    ans = 0
    for i in range(n):
        nums[a[i]] += 1
    for i in nums:
        ans += nums[i] * (nums[i]-1)//2
    """
    for v in a:
        ans += nums[v]
        nums[v] += 1
    """

    for v in a:
        print(ans - (nums[v]-1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 82680
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
int main(void){
	ll x,ans=0,y;
	scanf("%lld",&x);
	y=x/11;
	ans=y*2;
	x%=11;
	if(x!=0){
		if(x<7)ans++;
		else ans+=2;
	}
	
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
use std::io;
fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned();
    let mut ws = s.split_whitespace();
    let a: i32 = ws.next().unwrap().parse().unwrap();
    let b: i32 = ws.next().unwrap().parse().unwrap();

    if (a * b) % 2 == 0 {
        println!("Even");
    }
    else {
        println!("Odd");
    }
}


Measured memory_bytes: 2104
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.Monad

solve :: Int -> Int -> [(Int,Int)] -> [String]
solve n m pys = answer where

  perPref = V.create $ do
    vec <- VM.replicate (n+1) []
    forM_ (zip [0..] pys) $ \(i,(p,y)) -> VM.modify vec ((y,i):) p
    return vec

  answer = map snd $ sort $ concat [label p (perPref V.! p) | p <- [1..n]]

label p yis = zipWith f [1..] (sort yis) where
  f j (_,i) = (i, fmt p ++ fmt j)

fmt x = let s = "00000" ++ (show x)
        in drop (length s - 6) s

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> [String]
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_m]:remLines1 = remLines0
      n = readBInt bs_n
      m = readBInt bs_m
      pys = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve n m pys

outAnswer :: [String] -> IO ()
outAnswer = putStrLn . unlines

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 58876
#include <iostream>
#include <cstring>
#include <cstdio>

#define LL long long

using namespace std;

inline LL read() {
    LL x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

LL x, pw[8000];

int main() {
    x = read();
    for(LL i = -3000; i <= 3000; ++i) {
        for(LL j = -3000; j <= 3000; ++j) {
            LL pwi = i * i * i * i * i;
            LL pwj = j * j * j * j * j;
            if(pwi - pwj == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
char ca[8005];
bool dp[4005][8005];
vector<int> v1[2];

void check(int p,int q,int t,int n){
	int i,j,k;
	memset(dp,false,sizeof(dp));
	dp[0][0]=true;
	for(i=0;i<v1[p].size();i++){
		for(j=0;j<=n;j++){
			if(!dp[i][j])continue;
			dp[i+1][abs(j-v1[p][i])]=true;
			dp[i+1][j+v1[p][i]]=true;
		}
	}
}

int main(){
	int x,y;
	int i,j,k;
	int fir=-1;
	bool s1,s2;
	cin>>ca;
	cin>>x>>y;
	for(i=0,j=0,k=0;i<strlen(ca);i++){
		if(ca[i]=='T'){
			if(fir==-1)fir=k;
			else if(k!=0)v1[j].push_back(k);
			j=1-j,k=0;
		}else k++;
	}
	if(fir==-1)fir=k;
	else if(k!=0)v1[j].push_back(k);
	check(0,fir,x,strlen(ca));
	s1=dp[v1[0].size()][abs(fir-x)];
	check(1,0,y,strlen(ca));
	s2=dp[v1[1].size()][abs(y)];
	if(s1 && s2){
		cout<<"Yes"<<endl;
	}else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 31744
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...

    
    string s;
    
    cin >> s;
    
    string t[4];
    
    t[0] = "dream";
    t[1] = "dreamer";
    t[2] = "erase";
    t[3] = "eraser";
    
    reverse(s.begin(),s.end());
    
    
    for(int i=0; i<4; i++){
        reverse(t[i].begin(),t[i].end());
    }

    
    int cnt = 0;
    bool flg = true;
    
    for(int i=0; i<s.size(); ){
        bool flg2 = false;
        for(int j=0; j<4; j++){
            string tmp = t[j];
            if(s.substr(i,tmp.size())==tmp){
                flg2 = true;
                i += t[j].size();
                break;
            }
        }
        
        if(flg2 == false){
            flg = false;
            break;
        }
       
    }


    if(flg)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    
    return 0;
    
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();

		int ans = 0;
		for (int i = 0; i < a + 1; i++) {
			for (int j = 0; j < b + 1; j++) {
				for (int k = 0; k < c + 1; k++) {
					if (500 * i + 100 * j + 50 * k == x) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<stdio.h>

int func(int a){
    if(a==1){
        return 1;
    }else{
        return func(a-1)+a;
    }
}

int main(void){
    int num,ans;
    scanf("%d",&num);
    ans = func(num);
    printf("%d", ans);
    return 0;
}

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            List<int> results = new List<int>();

            //  全部白にする場合の個数→黒の数
            int black = s.Count(c => c == '#');
            results.Add(black);

            //  全部黒にする場合の個数→白の数
            int white = n - black;
            results.Add(white);

            //  白／黒にする場合
            int[] counts = new int[n];
            int leftb = 0;
            int rightW = white;
            int min = int.MaxValue;
            for(int pivot = 0; pivot < n; ++pivot)
            {
                if(s[pivot] == '.')
                {
                    rightW--;
                }
                else
                {
                    leftb++;
                }
                int ans = rightW + leftb;
                if (ans < min) min = ans;
            }
            results.Add(min);

            Console.WriteLine(results.Min());

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    double sum=0.0;
    for (int i=0; i<N; i++) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
            sum += x;
        else
            sum += x * 380000.0;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import copy

n=int(input())
s=input().split(' ')
s1=[]
s2=[]
s1=copy.deepcopy(s)
s2=copy.deepcopy(s)

def Bubble_Sort(n,s1):
	m=0
	flag=1
	while flag:
		flag=0
		for i in range(1,n):
			j=n-i
			if int(s1[j][1])<int(s1[j-1][1]):
				a=s1[j]
				s1[j]=s1[j-1]
				s1[j-1]=a
				m+=1
				flag=1
	b=s1
	return(b)

def Selection_Sort(n,s2):
	m=0
	for i in range(n):
		minj=i
		for j in range(i,n):
			if int(s2[j][1])<int(s2[minj][1]):
				minj=j
		if i!=minj:
			a=s2[minj]
			s2[minj]=s2[i]
			s2[i]=a
			m+=1
	b=s2
	return(b)

s1=Bubble_Sort(n,s1)
s2=Selection_Sort(n,s2)

print(' '.join(s1))
print('Stable')
print(' '.join(s2))
if s1==s2:
	print('Stable')
else:
	print('Not stable')


Measured memory_bytes: 6344
n=int(input())
h=list(map(int,input().split()))
dp=[]
dp.append(0)
dp.append(abs(h[1]-h[0]))
for i in range(1,n-1):
    dp.append(min(dp[i-1]+abs(h[i+1]-h[i-1]),dp[i]+abs(h[i+1]-h[i])))


print(dp[-1])

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


int main()
{
  int a,b;
  cin >> a >> b;
  if((a*b)%2 == 0) cout << "Even" << endl;
  else if((a*b)%2 == 1) cout << "Odd" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};


priority_queue<P,vector<P>,greater<P> >q;

signed main(){
	int n,now=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int l,r;
		cin>>l>>r;
		q.push(P(r,l));
	}
	r(i,n){
		P p=q.top();q.pop();
		if(now+p.second > p.first){
			cout<<"No"<<endl;
			return 0;
		}
		now += p.second;
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 6256
#include <iostream>
#include <math.h>
using namespace std;

int isPrimeNum(int target) {
  for (int i = 2; i <= sqrt(target); i++) {
    if (target % i == 0) {
      return 0;
    }
  }
  return 1;
}

int main() {
  int n;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n; i++) {
    int target;
    cin >> target;
    res += isPrimeNum(target);
  }
  cout << res << endl;
}



Measured memory_bytes: 3088
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var low = 0
    var high = n / 2 + 1
    while (high - low > 1) {
        val mid = low + (high - low) / 2
        if (solve(s, mid)) {
            low = mid
        } else {
            high = mid
        }
    }
    println(low)
}

fun solve(s: String, divide: Int): Boolean {
    fun String.chunk(size: Int): List<String> {
        val nChunks = length / size
        return (0 until nChunks).map { substring(it * size, (it + 1) * size) }
    }

    fun String.window(windowSize: Int, step: Int = 1): List<String> {
        val n = (length - windowSize) / step + 1
        return (0 until n).map { substring(step * it, step * it + windowSize) }
    }

    val windowed = s.window(divide)
        .groupBy { it }
        .mapValues { it.value.size }
        .filterValues { it > 1 }
        .map { it.key }
    windowed.forEach {
        val i = s.indexOf(it)
        val ii = s.indexOf(it, i + it.length)
        if(ii != -1) return true
    }
    return false
}


Measured memory_bytes: 126900
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int s = Integer.parseInt(scan.next());
		int h = s / 3600;
		s = s % 3600;
		int m = s / 60;
		System.out.println(h + ":" + m + ":" + s % 60);
		scan.close();
	}
}


Measured memory_bytes: 26124
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>
#include<float.h>

#define N 100001

int main(){
	char c[N];
	int n, q, arr[N], sum=0, i=0, l, r;
	scanf("%d%d\n", &n, &q);
	scanf("%s\n", c);
	for(i=0; i<n; i++){
		arr[i] = 0;
	}
	for(i=0; c[i]; i++){
		if(c[i] == 'A' && c[i+1] == 'C') {
			++sum;
		}
		arr[i+1] = sum;
	}
	for(int i=0; i<q; i++){
		scanf("%d%d\n", &l, &r);
		printf("%d\n", arr[r - 1] - arr[l - 1]);
	}
	return 0;
}


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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  
  bool pc = true;
  for(int i=0; i<s.size(); i++) {
    if(i!=a && !isdigit(s[i])) pc = false;
    if(i==a && s[i]!='-') pc = false;
  }
  if(pc) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	int A;
	int cnt=0;
	
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> A;
		if(A%2==1)
			cnt++;
	}
	
	if(cnt%2==0)
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
a=[]
for x in range(m):
  s=list(map(int,input().split()))
  a.append(s)
  
min1=1
max1=n

for y in range(m):
  l=a[y][0]
  r=a[y][1]
  if min1<l:
    min1=l
  if max1>r:
    max1=r
    
if max1-min1>=0:
  print(max1-min1+1)
  
else:
  print(0)

Measured memory_bytes: 27180
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long N, K;
    cin >> N >> K;
    long am1 = N-(N/K)*K;
    long am2 = N-((N/K)+1)*K;
    if (am1<0) am1 = -am1;
    if (am2<0) am2 = -am2;
    cout << min(am1,am2) << endl;
}


Measured memory_bytes: 256
import re
(A,B),S = map(int,input().split()),input()


if (len(S) == (A+B+1)) and (S[A] == '-') and (S.count('-') == 1) and len(re.findall('[0-9]', S)) == (A+B):
    print("Yes")
else:
    print("No")


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

using namespace std;

int main() {
  unsigned int n;
  scanf("%u", &n);

  vector<int> v1(n), v2(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &v1[i]);
    v2[i] = v1[i];
  }

  sort(v1.begin(), v1.end());

  auto len = v1.size();
  auto c1 = len / 2 - 1;
  auto c2 = len / 2;
  int center1 = v1[c1];
  int center2 = v1[c2];

  for (int i = 0; i < n; ++i) {
    if (v2[i] <= center1) printf("%d\n", center2);
    else printf("%d\n", center1);
  }
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        int i=1;
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        while(x != 0){
            System.out.println("Case " + i +": " + x);
            x = sc.nextInt();
            i++;
        }
    }
}


Measured memory_bytes: 41504
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = 1 ; i <= 1000000 ; i++) {
        int aa = i * 8 / 100;
        int bb = i * 10 / 100;
        if (aa == a && bb == b) {
            cout << i << endl;
            exit(0);
        }
    }
    cout << -1 << endl;
}

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

using namespace std;

vector<int> pri;

//素数かどうか判定
bool isprime(long long int x){

	if(x%2==0 && x!=2) return false;

	int sqrtn;
	sqrtn=(int)sqrt(x)+1;

	for(int i=0;i<pri.size();i++){
		if(x%pri[i]==0) return false;
		if(sqrtn<pri[i]) return true;
	}
	return true;
}

//n以下の素数を配列に
void list_prime(long long int n){
	//int flag, sqrtn;
	pri.emplace_back(2);

	for(int i=3;i<=n;i+=2){
		if(isprime(i)) pri.emplace_back(i);
	}
}

//nを素因数分解
vector<long long int> prime_fac(long long int n){
	int lmt=0;
	long long int tmp;
	while(1){
		tmp=pri[lmt];
		tmp*=pri[lmt];
		if(n<=tmp) break;
		lmt++;
		//if(pri.size()<=lmt) list_prime(n);
		//cout<< lmt << " " << pri[lmt] << endl;
	}

	vector<long long int> fac(lmt+10, 0);

	for(int i=0;i<pri.size();i++){
		while(n%pri[i]==0){
			n/=pri[i];
			fac[i]++;
//cout<< pri[i] <<endl;
		}
		if(n==1) break;
		if(lmt<=i) break;
	}
	
	if(n!=1) fac.emplace_back(-n);
//cout<< n <<endl;

	return fac;

}

void print_defac(long long int m){
	if(isprime(m)){
		cout<< m << " is prime number." << endl;
		return;
	}

	vector<long long int> v=prime_fac(m);
	int flag=0;

//cout<< v.size() << "#" << pri[v.size()-2] << "# " << pri[v.size()-1] << "# " <<endl;
	cout<< m << "=";

	for(int i=0;i<v.size();i++){
		for(int j=0;j<v[i];j++){
			if(flag) cout<< "*";
			cout<< pri[i];
			flag=1;
		}
	}
	cout<< endl;
}

int main(){

	long long int a, b, ans=1, lim, ae, be;
	vector<long long int> af, bf;

	cin>> a >> b;

	lim=sqrt(max(a, b))+100;

	list_prime((int)lim);

	af=prime_fac(a);
	bf=prime_fac(b);

	lim=min(af.size(), bf.size());

	for(int i=0;i<lim;i++){
		if(af[i]>0 && bf[i]>0) ans++;
	}

	ae=af[af.size()-1];
	be=bf[bf.size()-1];
	if(ae<0 && be<0 && ae==be) ans++;
	else{
		if(ae<0){
			if(b%(-1*ae)==0) ans++;
		}
		if(be<0){
			if(a%(-1*be)==0) ans++;
		}
	}

	//print_defac(a);
	//print_defac(b);

//cout<< ae << " " << be <<endl;

	cout<< ans <<endl;

}


Measured memory_bytes: 2348
<?php
list($n) = ints();
$a = ints();
$avg = array_sum($a) / $n;
$mind = PHP_INT_MAX;
for ($i = 0; $i < $n; ++$i) {
    if ($mind > abs($avg - $a[$i])) {
        $mind = abs($avg - $a[$i]);
        $mini = $i;
    }
}
echo $mini;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16120
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=100+5;

int main(){
    GO();
    ll x,k,d;
    cin>>x>>k>>d;
    if(x==0){
        if(k%2==0){
            cout<<x<<"\n";
        }
        else{
            cout<<d<<"\n";
        }
        return 0;
    }
    ll mi;
    if(x>0){
      if(k%2==0)
      mi=x;
      else
        mi=llabs(x-d);
      ll F= x/d;
      if(k>F){
        k-=F;
        x= x%d;
        if(k%2==0){
        mi=min(mi,x);
        x-=d;
        x-=d;
        mi=min(mi,llabs(x));
        }
        else{
        x-=d;
        mi=min(mi,llabs(x));
        }
      }
      else if(k==F){
        k-=F;
        x%=d;
        mi=min(mi,x);
      }
      else{
        x= x- k*d;
        mi=min(mi,x);
      }
    }
    else{
        if(k%2==0)
        mi=llabs(x);
        else
        mi=llabs(x+d);

        ll F= llabs(x/d);
        if(k>F){
            x%=d;
            k-=F;
            if(k%2==0){
                mi=min(mi,llabs(x));
                x+=d;
                x+=d;
                mi=min(mi,llabs(x));
            }
            else{
                x+=d;
                mi=min(mi,llabs(x));
            }

        }
        else if(k==F){
            x%=d;
            mi=min(mi,llabs(x));
        }
        else{
            x= x+k*d;
            mi=min(mi,llabs(x));
        }

    }
    cout<<mi<<"\n";

}








Measured memory_bytes: 3648
import sys

input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    S = input()
    
    count = [0] * N
    
    for i in range(1, N):
        if S[i-1:i+1] == 'AC': count[i] = count[i-1] + 1
        else: count[i] = count[i-1]
    
    for i in range(Q):
        l, r = map(int, input().split())
        
        print(count[r-1] - count[l-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 6436