akhauriyash/Code-Regression huggingface dataset:
kuri_now = False
cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]
kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1]
result = 0
for digit in input():
    digit = int(digit)
    if kuri_now == 0:
        result += cost[digit]
        kuri_now = kuri[digit]
    elif kuri_now == 1:
        result += cost[digit + 1]
        kuri_now = kuri[digit + 1]
    else:
        if cost[digit] <= cost[digit + 1]:
            result += cost[digit]
            kuri_now = kuri[digit]
        else:
            result += cost[digit + 1]
            kuri_now = kuri[digit + 1]
if kuri_now == 1:
    result += 1
print(result)

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int64_t x,y;
    cin >> x >> y;
    int64_t ans=inf64;
    for(int i=-1; i<=1; i+=2){
        for(int j=-1; j<=1; j+=2){
            if(x*i>y*j) continue;
            ans=min(ans,y*j-x*i+(i==-1)+(j==-1));
        }   
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

typedef long long ll;

int main() {
	int H[2], ans = 1e5;
	cin >> H[0] >> H[1];
	for (int i = 0; i < 2; i++) {
		if (H[i] % 3 == 0) {
			cout << 0 << endl;
			return 0;
		}
		ans = min(ans, H[1 - i]);
		int H1 = H[i] / 3;
		int S_max = (H1 + 1) * H[1 - i];
		int S_min = (H[i] - H1 - 1) * (H[1 - i] / 2);
		ans = min(ans, S_max - S_min);
		S_min = H1 * H[1 - i]; S_max = (H[i] - H1) * ((H[1 - i] + 1) / 2);
		ans = min(ans, S_max - S_min);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

using ll = long long;

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> hs(N);
    for (auto && i: irange(0LL, N)){
        cin >> hs.at(i);
    }
    sort(hs.begin(), hs.end(), greater<>());

    ll attack_number_max = hs.front() + 1;
    ll attack_number_min = 0;

    while (true){
        ll attack_number = (attack_number_max + attack_number_min) / 2;
        vector<ll> hp = hs;
        for (auto && i: irange(0LL, N)){
            hp.at(i) -= attack_number * B;
            if (hp.at(i) < 0) hp.at(i) = 0;
        }
        ll physic_number = 0;
        for (auto && i: irange(0LL, N)){
            physic_number += (hp.at(i) % (A - B) == 0) ? (hp.at(i) / (A-B)) : (hp.at(i) / (A-B) + 1);
        }
        if (physic_number > attack_number){ // could not kill
            attack_number_min = attack_number;
        } else { // could kill
            attack_number_max = attack_number;
        }
        if (attack_number_max - attack_number_min <= 1) break;
    }
    cout << attack_number_max << endl;


  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define pb push_back

#define INF int(1e9)
#define EPS 1e-9
#define MOD int(1e9 + 7)

template<typename T>
struct SegmentTree {     // One-based except Input Array
	int N;
	vector<T> stree;

	inline T f(T a, T b) { return max(a, b); }

	SegmentTree(int n) {
		N = n;
		int sz = 1;
		while(sz < N)
			sz <<= 1;
		stree.assign(sz << 1, 0);
	}

	void updatePoint(int v, int l, int r, int idx, T val) {
		if(l == r) {
			stree[v] += val;
			return;
		}
		int mid = (l + r) >> 1;
		if(idx <= mid)
			updatePoint(v << 1, l, mid, idx, val);
		else
			updatePoint(v << 1 | 1, mid + 1, r, idx, val);
		stree[v] = f(stree[v << 1], stree[v << 1 | 1]);
	}

	void updatePoint(int idx, T val) {  //Input index 1-based
		updatePoint(1, 1, N, idx, val);
	}


	T query(int v, int l, int r, int queryStart, int queryEnd) {
		if(r < queryStart || l > queryEnd)
			return 0; //dummy variable
		if(l >= queryStart && r <= queryEnd)
			return stree[v];
		int mid = (l + r) >> 1;
		T q1 = query(v << 1, l, mid, queryStart, queryEnd);
		T q2 = query(v << 1 | 1, mid + 1, r, queryStart, queryEnd);
		return f(q1, q2);
	}

	T query(int l, int r) {
		return query(1, 1, N, l, r);
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, x;
	cin >> n;
	ii arr[n];
	for(int i = 0; i < n; i++) {
		cin >> x;
		arr[i] = {x, i + 1};
	}
	sort(arr, arr + n, [](ii& a, ii& b) {
		if(a.first == b.first)
			return a.second > b.second;
		return a.first < b.first;
	});
	int ans = 0;
	SegmentTree<int> tree(n);
	for(int i = 0; i < n; i++) {
		int idx = arr[i].second;
		int q = tree.query(1, idx);
		if(q == 0) {
			ans++;
		} else {
			tree.updatePoint(q, -q);
		}
		tree.updatePoint(idx, idx);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int allday = in.nextInt();
		int pasta = in.nextInt();
		int sum = 0;
		int[][]A = new int [3][2];
		int[]B = new int [3];
		int[]C = new int [allday+1];
		for(int i = 1;i <= allday;i++)C[i] = 0;
		for(int i = 0;i < pasta;i++){
			int day = in.nextInt();
			C[day] = in.nextInt();
		}
		for(int i = 0;i < 3;i++)A[i][0]=1;
		switch(C[1] % 4){
		case 0:
			break;
		case 1:
			A[1][0] = 0;
			A[2][0] = 0;
			break;
		case 2:
			A[0][0] = 0;
			A[2][0] = 0;
			break;
		case 3:
			A[0][0] = 0;
			A[1][0] = 0;
			break;
		}
		for(int i = 2;i <= allday;i++){
			B[0]=A[1][0]+A[2][0]+A[1][1]+A[2][1];
			B[1]=A[0][0]+A[2][0]+A[0][1]+A[2][1];
			B[2]=A[0][0]+A[1][0]+A[0][1]+A[1][1];
			switch(C[i] % 4){
			case 0:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
				}
				break;
			case 1:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
					if(j != 0){
						A[j][0] = 0;
						A[j][1] = 0;
					}
				}
				break;
			case 2:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
					if(j != 1){
						A[j][0] = 0;
						A[j][1] = 0;
					}
				}
				break;
			case 3:
				for(int j = 0;j < 3;j++){
					A[j][1]=A[j][0] % 10000;
					A[j][0]=B[j] % 10000;
					if(j != 2){
						A[j][0] = 0;
						A[j][1] = 0;
					}
				}
			}
		}
		for(int i = 0;i < 3;i++){
			sum = sum + A[i][0] + A[i][1];
		}
		sum = sum % 10000;
		System.out.println(sum);
	}
}

Measured memory_bytes: 18092
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int mapp[52][52]; 
int main()
{ 
    int m,n;
    char tmp;
    cin>>m>>n; 
    for(int i=1;i<=m;i++)
     for(int j=1;j<=n;j++) 
        {
            cin>>tmp; 
            if(tmp=='#') 
			mapp[i][j]=1;
        }
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(mapp[i][j]) 
			cout<<"#"; 
            else
            cout<<mapp[i+1][j+1]+mapp[i+1][j-1]+mapp[i+1][j]+mapp[i][j+1]+mapp[i][j-1]+mapp[i-1][j+1]+mapp[i-1][j]+mapp[i-1][j-1];
        }
        cout<<endl;
    }
    cout<<endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  //スペード1 ハート2 クラブ3 ダイヤ4
  int real[4][13];
  for(int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      real[i][j] = 0;
    }
  }

  char mark;
  int number;

  for (int count = 0; count < n; count++){
    cin >> mark >> number;
      if(mark == 'S') {
        real[0][number-1] = 1;
      } else if(mark == 'H') {
        real[1][number-1] = 1;
      } else if(mark == 'C') {
        real[2][number-1] = 1;
      } else if(mark == 'D') { 
        real[3][number-1] = 1;
      }
  }

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      if (real[i][j] == 0) {
        if(i == 0) {
          cout << 'S' << " " << j+1 << endl;
        } else if(i == 1) {
          cout << 'H' << " " << j+1 << endl;
        } else if(i == 2) {
          cout << 'C' << " " << j+1 << endl;
        } else if(i == 3) {
          cout << 'D' << " " << j+1 << endl;
        }
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
int main()
{
    fast;
   ll n;
   std::cin >> n;
   ll a[100],j=0;
   for(;;)
   {
       n--;
       a[j++]=n%26;
       n/=26;
       if(n==0)
       break;
   }
   rf(i,j-1,0)
   {
       char c='a'+a[i];
       cout<<c;
   }
   cout<<"\n";
}

Measured memory_bytes: 3648
n,d=map(int,input().split())
xs=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i,y in enumerate(xs):
    for z in xs[i+1:]:
        s=sum([(a-b)**2 for a,b in zip(y,z)])**(1/2)
        if s==s//1:
            ans+=1
print(ans)


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

int main()
{
    long long int n,k,a,b,s;
    cin>>n>>k>>a>>b;
    if(k>=n)
    {
        s=n*a;
    }
    else
    {
        s=k*a+(n-k)*b;
    }
    cout<<s<<endl;
    return 0;
}


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

typedef long long ll;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //Älä käytä, jos tehtävä on interaktiivinen!
    ll n, d;
    int ans=0;
    cin >> n >> d;
    for (int i=1; i<=n; ++i){
        ll a, b;
        cin >> a >> b;
        if ((a*a+b*b)<=d*d) ans++;
    }
    cout << ans << "\n";
}






Measured memory_bytes: 3612
N = int(input().rstrip())
l = []
flag = True
for i in range(1,int(N**0.5)+1):
    if N % i == 0:
        l.append(i)
num = len(l)
if num==1:
    print(N-1)
else:
    ans=N-1
    for a in l:
        b=N/a
        ans = min([ans, a+b-2])
    print(int(ans))

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



int main() {
 int N;
 cin >> N;
  
  vector<int> a(N);
  
  for(int i=0; i<N; i++)
    cin >> a.at(i);
  
 
  sort(a.begin(),a.end(), greater<int>());
  int ans = 0;

  for(int i=0; i<N; i+=2)
    ans += a.at(i);
  for(int i=1; i<N; i+=2)
    ans -= a.at(i);
  
  
  cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin
input = stdin.readline
import copy as cp
from collections import deque

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Decimal(x):
  print("{0:.10f}".format(x))

class Pair:
  def __init__(self, x=0, y=0):
    self.first = x
    self.second = y

  def __repr__(self):
    return '{0} {1}'.format(self.first, self.second)

  def __lt__(self, pi):
    return self.first < pi.second

def POW(x, n):
  ret = 1
  while n:
    if n&1:
      ret *= x
    x *= x
    n >>= 1
  return ret

a = list(map(int, input().rstrip().split()))
a.sort()
if a[0] + a[1] == a[2]:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 38384
#include <stdio.h>
#include <algorithm>
using namespace std;

int a[1111];

int main(void)
{
 	int n, k, i;
  
  	scanf("%d %d" ,&n, &k);
  
	for (i = 1; i <= n; i++)
      	scanf("%d" ,&a[i]);
  
  	sort (a + 1, a + n + 1);
  
  	int ans = 0;
 	for (i = 1; i <= k; i++)
      	ans += a[i];
  
  	printf("%d" ,ans);
  	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;

    // データ長
    cin >> n;
    
    // 動的配列
    unsigned int *b = new unsigned int[n+1];

    // データセット
    for(int i=1; i<=n - 1; i++) cin >> b[i];

    // ダミーデータ
    b[0] = 100000;
    b[n] = 100000;

    unsigned long ans = 0;

    for(int i=1; i<=n; i++){
        ans += min(b[i-1],b[i]);
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    n_usable_child_list = [0 for _ in range(N + 1)]
    n_usable_child = 1 - A[0]
    for d in range(N):
        n_usable_child_list[d] = n_usable_child
        if n_usable_child < 0:
            print(-1)
            return
        n_usable_child = 2 * n_usable_child - A[d + 1]
    n_usable_child_list[-1] = n_usable_child
    if n_usable_child < 0:
        print(-1)
        return
    ans, cur = 0, 0
    for d in reversed(range(N + 1)):
        cur = min([cur, n_usable_child_list[d]]) + A[d]
        ans += cur
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 668596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int a,b,k;
  cin >> k >> a >> b;
  bool ok = false;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) ok = true;
  }
  cout << (ok ? "OK" : "NG") << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using f32 = float;
using f64 = double;
using LL = long long;
using ULL = unsigned long long;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()

signed main()
{
    long long N;
  cin >> N;
    vector<long long> a(N);
    vector<long long> b(N);
    REP(i, N){
        cin >> a[i] >> b[i];
    }
    SORT(a);
    SORT(b);
    if (N % 2 == 0) {
        long long mi = a[N/2-1] + a[N/2];
        long long ma = b[N/2-1] + b[N/2];
        cout << ma - mi + 1 << endl;
    } else {
        long long mi = a[N/2], ma = b[N/2];
        cout << ma - mi + 1 << endl;
    }
}


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

using namespace std;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


typedef long long ll;

int cnt(ll a) {
	ll ans = 0;
	while(a % 2 == 0) {
		ans++;
		a = a/2;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	ll array[n+2];
	for(int i = 0; i < n; i++) {
		cin >> array[i];
	}
	ll ans = 0;
	for(int i = 0; i < n ;i++) {
		ans = ans+cnt(array[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
/*
AOJ 0033 Ball

?¢???????????§??????????????????¢???????§???§?\?????????????A??£?????\???????????????????????????????????????DE?????¶??????B?£???????C?£??????????
??°??????1-10??????????????????????????????A??£?????\???????????????????§???§??¶??????????????\?????\???B?£???????C?£???????????????????????????????????¢????

?????\????¬¬???????????\??°????????°N?????\?????\N??????N???????????°??????????????°?????????10?????´??°?????£??¨???????????\?????????

???????????????????????°????????\?????\?????¨?????????YES?????\????????¨?????????NO
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

int main(int argc, char *argv[]) {
  int n, x;
  for (scanf("%d", &n); n; --n) {
    int l1 = 0, l2 = 0;
    bool ret = true;
    REP(i, 10) {
      scanf("%d", &x);
      if (x > l2) l2 = x;
      else if (x > l1) {
        l1 = x;
      } else {
        ret = false;
      }
    }
    puts(ret? "YES" : "NO");
  }
}

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

using namespace std;

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

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (a[i] - 1);
    }

    cout << ans << endl;

    return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int A,B;
    cin >> A >> B;
    vector<int> t(3);
    t[0] = A + B;
    t[1] = A - B;
    t[2] = A * B;

    cout << *max_element(all(t)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main()
{
    int N, result;
    cin >> N >> result;
    
    int X = -1;
    int Y = -1;
    int Z = -1;
    
    int sum = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            for (int k = 0; k <= N - i - j; k++) {
                if (i+k+j == N) {
                    sum = 10000 * i + 5000 * j + 1000 * k;
                    if (sum == result) {
                        X = i;
                        Y = j;
                        Z = k;
                        break;
                    }
                }
                
            }
        }
    }
    cout << X << " " << Y << " " << Z << endl;
    
    return 0;   
}

Measured memory_bytes: 256
import sys
from collections import deque

while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        sys.exit()

    grid = [[0] * w for _ in range(h)]
    grid[0][0] = 1

    wall_tate = []
    wall_yoko = []

    for i in range(h * 2 - 1):
        if i % 2 == 0:
            wall_yoko.append(list(map(int, input().split())))
        else:
            wall_tate.append(list(map(int, input().split())))

    moves = [1, -1]

    q = deque([[0, 0]])

    while q:
        curr = q.popleft()

        # 縦移動
        for m in moves:
            nx, ny = curr[0] + m, curr[1]
            if 0 <= nx < h and 0 <= ny < w and grid[nx][ny] == 0:
                if wall_tate[min(curr[0], nx)][ny] == 0:
                    grid[nx][ny] = grid[curr[0]][curr[1]] + 1
                    q.append([nx, ny])

        # 横移動
        for m in moves:
            nx, ny = curr[0], curr[1] + m
            if 0 <= nx < h and 0 <= ny < w and grid[nx][ny] == 0:
                if wall_yoko[nx][min(curr[1], ny)] == 0:
                    grid[nx][ny] = grid[curr[0]][curr[1]] + 1
                    q.append([nx, ny])

    print(grid[-1][-1])


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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> vll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

void update(ll* f, ll* s, ll val){
  if(val > *f){
    *s = *f;
    *f = val;
  }
  else if(val > *s){
    *s = val;
  }
}

int main(){
  ll N; cin >> N;
  ll A[1 << N];
  rep(i, 1 << N) cin >> A[i];

  vll ans(1, A[0] + A[1]);
  vector<P> or12;
  or12.emplace_back(0, -1);
  if(A[0] > A[1]) or12.emplace_back(0, 1);
  else or12.emplace_back(1, 0);
  repi(n, 2, 1 << N){
    ll f = n, s = 0;
    if(A[s] > A[f]) swap(f, s);
    rep(i, N){
      ll mask = 1 << i;
      if(n & mask){
        if(A[or12[n-mask].first] >  A[f]){
          s = f;
          f = or12[n-mask].first;
          if(A[or12[n-mask].second] > A[s])
            s = or12[n-mask].second;
        }
        else if(A[or12[n-mask].first] >  A[s] && f != or12[n-mask].first){
          s = or12[n-mask].first;
        }
      }
    }
    ans.push_back(max(ans.back(), A[f] + A[s]));
    or12.emplace_back(f, s);
    // printf("%lld : %lld %lld\n", n, f, s);
  }
  for(ll a : ans) cout << a << endl;
  return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(),a.end());

	bool flag = true;
	int ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (flag) {
			ans += a[i];
		}
		else {
			ans -= a[i];
		}
		flag = !flag;
	}
	cout << ans << endl;

	return 0;
}


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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
const ll inf = 1e15;

// Reference: http://mmxsrup.hatenablog.com/category/%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
// with a little modification (add, min)
//(1)区間に一様加算 (2)区間の合計値
struct segtree{
public:
    const int SIZE = 1 << 18;
    //seg:区間の合計値 lazy:区間に対して、加える値でまだ遅延しているもの
    vector<ll> seg, lazy;//segは欲しい情報 lazyは区間に対する一様な処理を示すもの
    segtree():seg(SIZE * 2), lazy(SIZE * 2){}
    void lazy_evaluate(int k, int l, int r){//遅延情報の適用方法
        if(lazy[k] != 0){
            seg[k] += lazy[k];//区間[l,r)にすべて同じ値を追加することになっていて、segには合計値が入っているので、加える値を足す
            if(r  - l > 1){
                lazy[k * 2 + 1] += lazy[k];//遅延を左の子に伝搬
                lazy[k * 2 + 2] += lazy[k];//遅延を右の子に伝搬
            }
            lazy[k] = 0;//ノードkは伝搬完了
        }
    }
    void update(int a, int b, int k, int l, int r, int x){
        lazy_evaluate(k, l, r);
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            lazy[k] += x; //加える
            lazy_evaluate(k, l, r);
        }else{
            update(a, b, k * 2 + 1, l, (l + r) / 2, x);
            update(a, b, k * 2 + 2, (l + r) / 2, r, x);
            seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]); //区間の合計
        }
    }  
    ll query(int a, int b, int k, int l, int r){
        lazy_evaluate(k, l, r);
        if(r <= a || b <= l) return -inf;//合計に影響のないもの
        if(a <= l && r <= b) return seg[k];
        ll x = query(a, b, k * 2 + 1, l, (l + r) / 2);
        ll y = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(x, y); //左右の合計を
    }
    //update(a,b,x) := [a,b)を全てxを加える
    void update(int a, int b, int x){update(a, b, 0, 0, SIZE, x);}
    //query(a,b) := [a,b)に対する合計値を求める
    ll query(int a, int b){return query(a, b, 0, 0, SIZE);}
};


int main(void){
  int n, m;
  cin >> n >> m;
  vector<PI> lr;
  vector<PI> pool;
  REP(i, 0, n) {
    int l, r;
    cin >> l >> r;
    lr.push_back(PI(l, r));
    
  }
  sort(lr.begin(), lr.end());
  segtree st;
  ll ma = 0;
  REP(i, 0, m + 2) {
    st.update(i, i + 1, i);
  }
  REP(i, 0, n) {
    int l = lr[i].first;
    int r = lr[i].second;
    st.update(l, r + 1, 1);
    ma = max(ma, st.query(l, m + 2) - m - l - 1);
    if (0) {
      cerr << "st:";
      REP(j, 0, m + 1) {
	cerr << " " << st.query(j, j + 1);
      }
      cerr << endl;
    }
  }
  ma = max(ma, (ll) n - m);
  cout << ma << endl;
}


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

int main(){
    int N,count,m,a,tmp;
    cin >> N;
    m = 0;
    for(int i=1;i<=N;i++){
        count = 0;
        tmp = i;
        while(tmp%2 == 0){
            count++;
            tmp/=2;
        }
        if(count > m){
            m = count;
            a = i;
        }
        if(N == 1) a = 1;
    }
    cout << a << endl;
}


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


using ld=long double;
int v[4];
ld n;
ld EPS=1e-10;
ld dp[301][301][301];
ld f(int a,int b,int c){
  if(dp[a][b][c]>=0)return dp[a][b][c];
  ld res=0;
  if(a)res+=(ld)a/(a+b+c)*f(a-1,b,c);
  if(b)res+=(ld)b/(a+b+c)*f(a+1,b-1,c);
  if(c)res+=(ld)c/(a+b+c)*f(a,b+1,c-1);
  ld z=n-a-b-c;
  res+=(1-z/n)/((1-z/n)*(1-z/n));
  return dp[a][b][c]=res;
}

signed main(){
  cin>>n;
  for(int i=0;i<n-(EPS);i++){
    int x;cin>>x;
    v[x]++;
  }
  for(int i=0;i<301;i++)for(int j=0;j<301;j++)for(int k=0;k<301;k++)dp[i][j][k]=-1;
  dp[0][0][0]=0;
  cout<<fixed<<setprecision(12)<<f(v[1],v[2],v[3])<<endl;
}


Measured memory_bytes: 426496
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// head

int t;
const int MAXN = 1000000+5;

int n;

struct Node{
    int lbit;
};

Node nodes[2*MAXN-1];

void init(int n_){
    //为了简单起见，将元素扩大到2的幂
    n = 1;
    while(n<n_) n*=2;

/*    for(int i=0;i<2*n-1;++i){*/
        //nodes[i].letters.clear();
    /*}*/
}

inline int getbit(char a) {
    return 1<<(a-'a');
}
//将第k个值更新为a
void update(int k, char a){
    //叶子节点
    k+=n-1;
    nodes[k].lbit = 0;
    nodes[k].lbit |= getbit(a);
    //向上更新
    while(k>0){
        k = (k-1)/2;
        nodes[k].lbit=0;
        auto& par = nodes[k].lbit;
        auto& chl = nodes[k*2+1].lbit;
        auto& chr = nodes[k*2+2].lbit;
        par = chl | chr;
    }
}

//求[a,b)的最大prefix_max
//后面的参数是为了计算方便传入的
//k是节点的编号，l,r表示这个节点代表区间[l,r)
//外部调用时，使用query(a,b,0,0,n);

int query(int a,int b,int k,int l,int r){
    //如果[a,b)和[l,r)不相交，返回0
    if(r<=a||b<=l) return 0;
    //如果[a,b)完全包含[l,r)，返回当前节点值
    if(a<=l && r<=b) return nodes[k].lbit;
    else{
        auto v1 = query(a, b, k*2+1, l, (l+r)/2);
        auto v2 = query(a, b, k*2+2, (l+r)/2, r);
        return v1|v2;
    }
}

int main()
{
    ios::sync_with_stdio(false);
#ifdef RG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
#endif
    int nn;
    string s;
    cin>>nn;
    cin>>s;
    init(nn);
    rep(i,0,nn) {
        update(i,s[i]);
    }
    int q;
    cin>>q;
    int l,r;
    char c;
    int ty;
    rep(i,0,q) {
        cin>>ty;
        if(ty==1) {
            cin>>l>>c;
            update(l-1,c);
        }
        else {
            cin>>l>>r;
            auto ans = query(l-1,r,0,0,n);
            int aaa = 0;
            for(int i=0;i<30;++i) {
                if(ans&(1<<i)) aaa++;
            }
            cout<<aaa<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5020
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#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 llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

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

void chmax(int prev_max, int new_max){
    if (new_max > prev_max){
        prev_max = new_max;
    }
    return;
}

void chmin(int prev_min, int new_min){
    if (new_min > prev_min){
        prev_min = new_min;
    }
    return;
}

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }


int main(){
    int N;
    cin >> N;
    cout << 180 * (N-2) << endl;

    return 0;
}


Measured memory_bytes: 256
import itertools

N, M = map(int, input().split())
edges = {tuple(sorted(map(int, input().split()))) for _ in range(M)}

answer = 0
for i in itertools.permutations(range(2, N+1), N-1):
    l = [1] + list(i)
    answer += sum(1 for edge in zip(l, l[1:]) if tuple(sorted(edge)) in edges) == N-1
print(answer)

Measured memory_bytes: 3064
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=1e5+10;
int N,K,W; 
int t[MX];
int memo[100][MX];
int w[MX],v[MX];


int solve(int i, int r){
	if(i==N && r==0) return 0;
	if(i==N) return INF;
	if(memo[i][r]!=-1)return memo[i][r];
	int ans=solve(i+1,r);
	if(r>=v[i]) ans=min(ans,solve(i+1,r-v[i])+w[i]);
	return memo[i][r]=ans;
}

int32_t main(){
   boost;
   IO();

   memset(memo,-1,sizeof(memo));
   cin>>N>>W;
   for(int i=0; i<N;i++) cin>>w[i]>>v[i];

   for(int i=100000; i>=0; i--) if(solve(0,i)<=W){cout << i << endl; return 0;}
	


   return 0;
}



Measured memory_bytes: 81724
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e1 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	int cur = 1;
	cin >> n >> k;
	while (n--)
	{
		cur = min(cur * 2, cur + k);
	}
	cout << cur << endl;
	return 0;
}


Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int maxn = 1e5 + 10 ;

int q , ps [ maxn ] ; 
bool isPrime [ maxn ] ; 

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> q;  
	fill ( isPrime , isPrime + maxn , 1 ) ;
	for ( int i = 2 ; i < maxn ; ++ i )
		if ( isPrime [ i ] )
			for ( int j = 2 * i ; j < maxn ; j += i )
				isPrime [ j ] = 0 ;
	isPrime [ 0 ] = isPrime [ 1 ] = 0 ; 
	for ( int i = 1 ; i < maxn ; ++ i )
		ps [ i ] = ps [ i - 1 ] + ( isPrime [ i ] && isPrime [ ( i + 1 ) / 2 ] ) ;
	while ( q -- ) {
		int l , r ;
		cin >> l >> r ;
		cout << ps [ r ] - ps [ l - 1 ] << '\n' ; 
	}
}


Measured memory_bytes: 1536
#include<cstdio>

int DP[31];
int w,n;


int main()
{
	for(int i=0;i<31;i++)
	{
		DP[i]=i;
	}
	scanf("%d%d",&w,&n);
	int a,b,c;
	for(int i=0;i<n;i++)
	{
		scanf("%d,%d",&a,&b);
		c= DP[a];
		DP[a]=DP[b];
		DP[b]=c;
	}
	for(int i=1;i<w+1;i++)
	{
		printf("%d\n",DP[i]);
	}
}

Measured memory_bytes: 0
package main

import "fmt"

func main() {
        left := true
        var n, prefixNum, suffixNum int
        var s string
        fmt.Scan(&n)
        fmt.Scan(&s)
        nested := 0
        for i := 0; i < n; {
                if left {
                        for ; i < n; i++ {
                                cur := s[i]
                                if cur == '(' {
                                        nested++
                                } else if cur == ')' {
                                        break
                                }
                        }
                        for ; i < n; i++ {
                                cur := s[i]
                                if cur == ')' {
                                        nested--
                                } else if cur == '(' {
                                        break
                                }
                        }
                        if nested < 0 {
                                prefixNum -= nested
                                nested = 0
                        }
                }
        }
        if nested > 0 {
                suffixNum += nested
        }
        for i := 0; i < prefixNum; i++ {
                fmt.Print("(")
        }
        fmt.Printf("%s", s)
        for i := 0; i < suffixNum; i++ {
                fmt.Print(")")
        }
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll N; cin >> N;
    frep(i, 1, 3500) {
        frep(j, 1, 3500) {
            ll a = N*i*j, b = 4*i*j - N*i - N*j ; // w = a/b
            if(b <= 0) continue;
            else if((a%b) == 0) {
                ll k = a/b;
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 256
/************************************Tufaan************************************/
#include<bits/stdc++.h>
#define pi acos(-1.0)
#define pb push_back
#define LL long long
#define LIM 50000
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
using namespace std;
int _I(){int x; scanf("%d",&x); return x;}
LL _L(){LL x; scanf("%lld",&x); return x;}
LL gcd(LL a, LL b){ while(b) b ^= a ^= b ^= a %= b; return a; }
LL lcm(LL x,LL y){x/=gcd(x,y); return x*y;}
int kdx[8]={-2,-2,-1,-1,1,1,2,2};
int kdy[8]={-1,1,-2,2,-2,2,-1,1};
bool prime[LIM+7];
long long _pow(long long a, long long b){
        if(b == 0) return 1;
        long long ret = 1;
        ret *= _pow(a, b/2);
        ret = ret*ret;
        if(b&1){
                ret *= a;
        }
        return ret;
}
bool inrng(LL x, LL y, LL c){
        return (x <= c && c <= y);
}
bool inRng(int a, int b, int x, int y){
        return ( inrng(a,b,x) || inrng(a,b,y) || inrng(x,y,a) || inrng(x,y,b) );
}
vector<int> v;
map<int, int> mp;
void sieve(){
    int i,j; prime[1]=1; v.pb(2);
    for(i=4;i<=LIM;i+=2) prime[i]=1;
    for(i=3;i<=LIM;i+=2) if(!prime[i]){ v.pb(i); for(j=i+i+i;j<=LIM;j+=i+i) prime[j]=1;}
}

/********************************************************************************/
/********************************************************************************/
int cases;

void fun(){
        int n,k,mn,mx;
        n = _I();
        k = _I();
        if(k == 1) puts("0");
        else {
                printf("%d\n",n-k);
        }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //sieve();
    //int t = _I();
    //while(t--)
        fun();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int i, n;
  scanf("%d", &n);
  int array[n];
  int max;
  int second_max;
  int ith_max[n];
  for(i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }

  max = array[0];
  second_max = array[1];
  for(i = 1; i < n; i++) {
    if(max < array[i]) {
      second_max = max;
      max = array[i];
    }
    else if(second_max < array[i]) {
      second_max = array[i];
    }
  }

  for(i = 0; i < n; i++) {
    if(array[i] < max) {
      ith_max[i] = max;
    }
    else {
      ith_max[i] = second_max;
    }
  }

  for(i = 0; i < n; i++) {
    printf("%d\n", ith_max[i]);
  }

  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long int lli;

long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
typedef pair<lli,lli> pii;
typedef vector<int> vi;


void facs(lli n,vector<pii>& val){
  for(lli i = 2;i*i<=n;i++){
    if(n%i==0){
      int cnt = 0;
      while(n%i==0){
        cnt++;
        n/=i;
      }
      val.push_back({i,cnt});
    }
  }
  if(n>1) val.push_back({n,1});
}


void solve(){
  lli n;
  cin>>n;
  vector<pii> vals;
  facs(n, vals);
  lli cnt = 0;

  for(int i = 0;i<vals.size();i++){
    lli curr = vals[i].second;
    //cout<<vals[i].first<<" "<<vals[i].second<<endl;
    lli j = 1;
    while(curr-j>=0){
      curr-=j;
      cnt+=1;
      j++;
    }
  }
  cout<<cnt;



}


int main(){
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll a[2005];
ll dp[2005][2005];

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

	int n; cin >> n;
	vector<pair<int, int>> v;
	rep(i, 1, n + 1) {
		int t; cin >> t;
		v.push_back({ t, i });
	}
	sort(all(v));
	reverse(all(v));

	for (int sum = 0; sum < n; sum++) {
		ll act = v[sum].first, pos = v[sum].second;
		//printf("%d %d\n", act, pos);
		for (int i = 0; i <= sum; i++) {
			int j = sum - i;

			// put on left
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + act * abs((i + 1) - pos));
			//printf("%d %d -> %d\n", i + 1, j, dp[i + 1][j]);
			// put on right
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + act * abs((n - j) - pos));
			//printf("%d %d -> %d\n", i, j + 1, dp[i][j + 1]);
		}
	}
	
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ans = max(ans, dp[i][n - i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 26324
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A)
if len(c) <= K:
    print(0)
else:
    n = len(c)
    c = sorted(c.items(), key=lambda x: x[1])
    ans = 0
    cnt = 0
    for k, v in c:
        cnt += 1
        ans += v
        if cnt == n - K:
            break
    print(ans)


Measured memory_bytes: 39344
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i;
	string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(i=0;i<a.size();i++){
    if(a[i]=='b'){
	a[i]='d';
	}
    else if(a[i]=='d'){
	a[i]='b';
	}
    else if(a[i]=='p'){
	a[i]='q';
	}
    else if(a[i]=='q'){
	a[i]='p';
    }}
    if(a==b){
	cout<<"Yes";
	}
    else{
	cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 512
MOD = 10**9 + 7

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


n = int(input())
temp = [None]*(n+2)

for i,a in enumerate(map(int,input().split())):
  if temp[a-1] is None:
    temp[a-1] = i
  else:
    m = n - i + temp[a-1]
    break


b = 1
for i in range(2,m+1):
  b *= i
  b %= MOD

a = b
for i in range(m+1, n+2):
  a *= i
  a %= MOD

ik = modinv(a,MOD)

for i in reversed(range(n+2)):
  temp[i] = ik
  ik *= i
  ik %= MOD


# C(n+1,k) - C(m,k-1)
# C(n,k) = n!/(k!(n-k)!)

for k in range(1, m+2):
  s = a*temp[k]*temp[n+1-k]
  t = b*temp[k-1]*temp[m+1-k]
  print((s-t)%MOD)

for k in range(m+2,n+2):
  s = a*temp[k]*temp[n+1-k]
  print(s%MOD)

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

const int mod=1e9+7;

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

	if(s.size()<t.size()){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}

	for (int i = s.size() - t.size(); i >= 0; i--){
		bool flag=true;
		
		for (int j = 0; j < t.size(); ++j){
			if(s[i+j]!=t[j]&&s[i+j]!='?'){
				flag=false;
				break;
			}
		}
		if(flag){
			for (int j = 0; j < t.size(); ++j){
				s[i+j]=t[j];
			}
			for (int j = 0; j < s.size(); ++j){
				if(s[j]=='?')s[j]='a';
			}
			cout<<s<<endl;
			return 0;
		}
	}

	cout<<"UNRESTORABLE"<<endl;

}


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

int main() {
  int K;
  cin >> K;

  // メモを作る
  vector<vector<int>> g(201, vector<int>(201));
  for (int i = 0; i <= 200; i++) {
    for (int j = 0; j <= 200; j++) {
      if (i == 0 || j == 0) {
        g.at(i).at(j) = 0;
      } else {
        g.at(i).at(j) = __gcd(i, j);
      }
    }
  }

  // 和を求める
  ll ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int x = g.at(i).at(j);
      for (int k = 0; k <= K; k++) {
        ans += g.at(x).at(k);
      }
    }
  }

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

Measured memory_bytes: 3776
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var arr=Arr[0].split(" ").map(Number);
var a=Math.pow(arr[2]-arr[0],2)+Math.pow(arr[3]-arr[1],2)
var b=Math.sqrt(a,2);
var c=b.toFixed(4);
console.log(c);

Measured memory_bytes: 7648