akhauriyash/Code-Regression huggingface dataset:
use std::collections::HashSet;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn factors(x: usize) -> HashSet<usize> {
    let mut x = x;
    let mut result = HashSet::new();
    result.insert(1);
    let target = (x as f64).sqrt() as usize;
    let mut d = 2;
    while d < target {
        while x % d == 0 {
            result.insert(d);
            x /= d;
        }
        d += 1;
    }
    if x > 1 {
        result.insert(x);
    }
    result
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }

    let a_factors = factors(a);
    let b_factors = factors(b);

    // println!(" {:?}", a_factors);
    // println!(" {:?}", b_factors);

    let mut result = 0;
    for f in a_factors {
        if b_factors.contains(&f) {
            result += 1;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 100010;
const int maxD = 400;
const int maxH = 100; 
const int MOD = 1000000007;

int a[maxN];
ll ps[maxN];
ll ss[maxN];
ll sum[maxN];
int main()
{
	
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=b)
		puts("0");
	else
		printf("%d\n",a-b);
	return 0;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 993244853
#define ll long long
#define debug(x) printf("\n'x is: %lld'\n\n",x);
#define lp(i,l,r) for(ll i=l;i<r;i++)
//VECTOR
#define pb push_back
#define pop pop_back
//PAIR
#define fst first
#define snd second
#define mp make_pair

ll invmod(ll a,ll b)
{
  ll i=1, m=b-2;

  while(m)
  {
    if(m&1)(i=i*a)%b;

    m>>=1;
    a=(a*a)%b;
  }
return i;
}

ll n=0,a[4000]={0},dp[4000][4000],cum[4000]={0};

ll diff(ll l, ll r)
{
 if(l==0)
   return cum[r];
 else
   return cum[r]-cum[l-1];
}

ll rec(ll l,ll r)
{
 if(l>r)
   return 0;
  
 if(dp[l][r]==-1)
   dp[l][r] = max(diff(l,r)-rec(l+1,r) , diff(l,r)-rec(l,r-1));

 return dp[l][r];
}

int main()
{
  ios::sync_with_stdio(false);

  cin>>n;

  lp(i,0,n)
  {
    cin>>a[i];
    
    if(i>0)
      cum[i]=cum[i-1]+a[i];
    else
      cum[i]=a[i];
  }

  lp(i,0,4000)
    lp(j,0,4000)
     dp[i][j]=-1;

  cout<<(2*rec(0,n-1) - cum[n-1])<<endl;

return 0;
}


Measured memory_bytes: 125440
s = list(input())
t = list(input())
tmp = 0
ans = len(t)
# j_tmp = 0
for i in range(len(s) - len(t) + 1):
    tmp = 0
    for j in range(len(t)):
        if s[i + j] != t[j]:
            tmp += 1
    if tmp < ans:
        ans = tmp
print(ans)


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

int n, k, q;
int a[2010];
#define rep(i,n) for(int i=0;i<(n);i++)

int main(int argc, char const *argv[])
{
	cin >> n >> k >> q;
	rep(i, n) cin >> a[i];

	int ans = 1e9;

	rep(l, n) {
		// printf("l %d\n", l);
		vector<int> v[2010];
		int idx = 0;
		rep(i, n) {
			if (a[i] < a[l]) {
				idx++;
				continue;
			}
			v[idx].push_back(a[i]);
		}

		rep(i, 2010) sort(v[i].begin(), v[i].end());
		vector<int> u;

		rep(i, 2010) {
			// printf("i %d\n", i);
			if ((int)v[i].size() < k) continue;
			// printf("size %d\n", (int)v[i].size());
			rep(j, v[i].size() - k + 1) {
				u.push_back(v[i][j]);
			}
		}
		sort(u.begin(), u.end());

		if (u.size() < q) continue;
		ans = min(ans, u[q - 1] - u[0]);
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
  string n;
  //3桁の整数を入力
  cin >> n;
  string ans;
  //入力された文字列の長さ分のforループ
  for(int i=0;i<n.length();i++){
    //substr1文字切り出して「1」か「9」か判定
    if(n.substr(i,1)=="1"){
      //「1」なら「9」をansに格納
      ans += "9";
    }else if(n.substr(i,1)=="9"){
      //「9」なら「1」をansに格納
      ans += "1";
    }
  }
  //置換された文字列を出力
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    num_list = i_list()

    num_list.sort()

    diff = num_list[2] * 2 - num_list[1] - num_list[0]

    ans = diff / 2

    if diff % 2 == 1:
        ans += 2
    
    print(int(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 10460
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef vector<ll> vl;
typedef vector<vl> vv;
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define endl '\n'
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }

int main(){
    
    fast();
   // #ifndef ONLINE_JUDGE
	//freopen("F:\\Codes\\input.txt", "r", stdin);
	//freopen("F:\\Codes\\output.txt", "w", stdout);
	//#endif
	
	ll n,i,a,b,c,da=0,db=0,dc=0,da1,da2,da3;
	cin>>n;

	for(i=0;i<n;i++){
		
		cin>>a>>b>>c;
		da1=da;da2=db;da3=dc;
		da=a+max(da2,da3);
		db=b+max(da1,da3);
		dc=c+max(da1,da2);
	}
	cout<<max(da,max(db,dc))<<endl;

    
	return 0;
}

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

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> x(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long result = max(max(x[n - 1] - x[0], max(abs(x[0]), abs(x[k - 1])) * 2 + max(abs(x[0]), abs(x[k - 1]))), max(abs(x[n - 1]), abs(x[0])));
  for (i = k - 1; i < n; i++) {
    if (x[i - k + 1] <= 0 && x[i] <= 0) {
      result = min(result, (long long)(abs(x[i - k + 1])));
    } else if (0 <= x[i - k + 1] && 0 <= x[i]) {
      result = min(result, (long long)(x[i]));
    } else {
      result = min(result, min(abs(x[i - k + 1]), abs(x[i])) * 2 + max(abs(x[i - k + 1]), abs(x[i])));
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
 
const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
const int INF = INT_MAX / 2;
 
int main() {
	vector<int> a(100);
	int N; cin >> N;
	while (N--) {
		int x; cin >> x;
		a[x / 400]++;
	}
	int cnt = 0;
	rep(k, 8) if (a[k]) cnt++;
	int pro = 0;
	for (int k = 8; k < 100; k++) pro += a[k];
	cout << max(1, cnt) << ' ' << cnt + pro << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size()<=k)
        cout << s;
    else{
        cout << s.substr(0, k) + "...";
    }
    return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
 int main(void)
 {
     int N,K;
     int i=0;

     scanf("%d%d",&N,&K);

     if(N<K) printf("1\n");
     else if(N%K==0) printf("%d\n",N%K);
     else if(N%K<K) printf("1\n");
     return 0;
 }



Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k, d, snuke;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    int arr[n + 1] = {0};
    while (k--)
    {
        cin >> d;
        while (d--)
        {
            cin >> snuke;
            arr[snuke] = 1;
        }
    }
    int count = 0;
    for (int i = 1; i <= n; i++)
    {
        if (arr[i] == 0)
        {
            count++;
        }
    }
    cout << count;
}

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

typedef pair<int,int> P;
const int INF =1e+8;

// 2 テァツつケテゥツ鳴禿」ツ?ョテ」ツδ榲」ツδウテ」ツδ湘」ツδε」ツつソテ」ツδウティツキツ敕ゥツ崢「, d = |x1-x2| + |y1-y2|
int dist( P p , P p_ ){
	return abs(p.first-p_.first)+abs(p.second-p_.second);
}

int to_i(string s){
	int n=0;
	for(int i=0 ; i < s.size() ; i++ ){
		n = n*10 + s[i]-'0';
	}
	return n;
}

int main(){
	int w, h;
	while( cin >> w >> h , w || h ){
		string s;
		map<int,vector<P> > f;
		vector< vector<int> > dp;
		int gx, gy, t=0;
		
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				cin >> s;
				if( s == "S" ){
					vector<int> v;
					v.push_back( 0 );
					dp.push_back( v );
					f[0].push_back( P(x,y) );
				}else if( s == "G" ){
					gx = x;
					gy = y;
				}else if( s != "." ){
					int n = to_i(s);
					t = max( t , n );
					f[n].push_back( P(x,y) );
				}
			}
		}
		f[t+1].push_back( P(gx,gy) );
		for(int i=1 ; i <= t+1 ; i++ ){
			vector<int> v;
			for(int j=0 ; j < f[i].size() ; j++ ){
				v.push_back( INF );
			}
			dp.push_back( v );
		}
		for(int i=0 ; i <= t ; i++ ){
			for(int j=0 ; j < f[i].size() ; j++ ){
				for(int k=0 ; k < f[i+1].size() ; k++ ){
					int d = dist( f[i+1][k] , f[i][j] );
					dp[i+1][k] = min( dp[i+1][k] , dp[i][j] + d );
				}
			}
		}
		cout << dp[t+1][0] << endl;
	}
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	string s1, s2;
	cin >> s1 >> s2;

	ll res;
	ll i;
	bool is_t = (s1[0] == s2[0]);

	if (is_t)
	{
		res = 3;
		i = 1;
	}
	else
	{
		res = 6;
		i = 2;
	}
	
	for (; i < N;)
	{
		// std::cout << "i : " << i << "\tres : " << res << std::endl;
		if (is_t)
		{
			(res *= 2) %= MOD;
			if (s1[i] == s1[i+1])
			{
				i+=2;
				is_t = false;
			}
			else
			{
				++i;
				is_t = true;
			}
		}
		else
		{
			if (s1[i] == s2[i])
			{
				++i;
				is_t = true;
			}
			else
			{
				(res *= 3) %= MOD;
				i+=2;
				is_t = false;
			}
			
		}
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 256
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

ans = 0
for m in b:
    l_idx = bisect.bisect_left(a, m)
    u_idx = bisect.bisect_right(c, m)
    ans += l_idx * (n - u_idx)

print(ans)


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

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

    int result=1;
    for(int i=0;i<n-1;i++){
        if(vec.at(i)==vec.at(i+1)){
            result=0;
            
            break;
        }else{
            continue;
        }
    }
    if(result){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 2000005;
const int mod = 1000000007;
vector<int>vv[maxn];
int siz[maxn];
void dfs(int u,int fa){
    siz[u]=1;
    for(auto v:vv[u]){
        if(!siz[v]){
            dfs(v,u);
            siz[u]+=siz[v];
        }
    }
}
int main()
{
    int n,m;
    cin >> n >> m ;
    int u,v;
    for(int i=0;i<m;i++){
        cin >> u >>v;
        vv[u].push_back(v);
        vv[v].push_back(u);
    }
    int ans =0 ;
    for(int i=1;i<=n;i++){
        if(!siz[i])
            dfs(i,i);
        ans = max(ans,siz[i]);
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 69976
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
string s;
int len;
int ans;
int main(){
	cin>>s;
	len=s.size();
	for (int i=0;i<len-1;i++){
	//	cout<<s[i]<<" "<<s[i+1]<<endl;
		if (s[i]!=s[i+1]){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
signed main()
{
	int n, p[8], q[8], ans = 1, same = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; scanf("%d", &p[i++]));
	for(int i = 0; i < n; scanf("%d", &q[i++]));
	for(int i = 0; i < n; ++i)
	{
		if(q[i] < p[i])
		{
			break;
		}
		if(q[i] > p[i])
		{	
			for(int j = 0; j < n; ++j)
			{
				swap(p[j], q[j]);
			}
			break;
		}
		if(q[i] == p[i])
		{
			same++;
		}
	}
	if(same == n)
	{
		printf("0\n");
		return 0;
	}
	for(; next_permutation(q, q + n); ++ans)
	{
		int issame = true;
		for(int i = 0; i < n; ++i)
		{
			issame &= p[i] == q[i];
		}
		if(issame)
		{
			break;
		}
	}
	printf("%d\n", ans);
}

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

int main()
{
	ll n,W;
    cin>>n>>W;
    ll w[n],v[n];
    for(ll i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
  	ll dp[n+1][W+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=W;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=W;j++)
        {
            if(w[i-1]<=j)
            dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]] , dp[i-1][j]);
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][W];
}

Measured memory_bytes: 79104
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        h: usize, w: usize,
        c: [[i64; 10]; 10],
        a: [[i64; w]; h],
    }
    let mut ans = 0;

    let mut heap = BinaryHeap::new();

    heap.push((0, 1));
    let mut cost = vec![1 << 30; 10];
    while !heap.is_empty() {
        let s = heap.pop().unwrap();
        if cost[s.1] < -s.0 {
            continue;
        }
        cost[s.1] = -s.0;
        for i in 0..10 {
            let ns = (-(-s.0 + c[i][s.1]), i);
            if cost[ns.1] <= -ns.0 {
                continue;
            }
            heap.push(ns);
        }
    }
    for i in 0..h {
        for j in 0..w {
            if a[i][j] >= 0 {
                ans += cost[a[i][j] as usize];
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;
import java.lang.*;
import java.math.*;

class Main {

	Scanner sc = new Scanner(System.in);

	void run() {
		
		int[] mt = new int [10];
		
		for (int i = 0; i < 10; i++) {
			mt[i] = sc.nextInt();
		}
		
		Arrays.sort(mt);
		
		System.out.println(mt[9] + "\n" + mt[8] + "\n" + mt[7] );
		

	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 11000
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, M; cin >> N >> M;
    vector<int> p(M);
    for(int i=0; i<M; i++) {
        cin >> p[i];
    }
    sort(p.begin(), p.end());

    vector<int> itrs;
    for(int i=1; i<M; i++) {
        itrs.push_back(p[i] - p[i-1]);
    }
    sort(itrs.rbegin(), itrs.rend());

    int ans = 0;
    for(int i=N-1; i<(int)itrs.size(); i++) {
        ans += itrs[i];
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    size_t H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (auto&& s : S)
    {
        cin >> s;
    }

    // grid[y][x]
    vector<vector<int>> grid(H + 2);
    for (auto&& row : grid)
    {
        row = vector<int>(W + 2);
    }

    for (size_t y = 0; y < H + 2; ++y)
    {
        auto& row = grid[y];
        if (y == 0 || y == H + 1)
        {
            for (auto&& cell : row)
            {
                cell = 0;
            }
            continue;
        }
        const auto& row_s = S[y - 1];
        for (size_t x = 0; x < W + 2; ++x)
        {
            if (x == 0 || x == W + 1)
            {
                row[x] = 0;
                continue;
            }
            const auto cell_char = row_s[x - 1];
            if (cell_char == '.')
            {
                row[x] = 0;
            }
            else
            {
                row[x] = -1;
            }
        }
    }

    for (size_t y = 1; y < H + 1; ++y)
    {
        for (size_t x = 1; x < W + 1; ++x)
        {
            if (grid[y][x] == -1)
            {
                continue;
            }

            int N = grid[y - 1][x] == -1;
            int S = grid[y + 1][x] == -1;
            int E = grid[y][x + 1] == -1;
            int W = grid[y][x - 1] == -1;
            int NE = grid[y - 1][x + 1] == -1;
            int NW = grid[y - 1][x - 1] == -1;
            int SE = grid[y + 1][x + 1] == -1;
            int SW = grid[y + 1][x - 1] == -1;

            grid[y][x] = N + S + E + W + NE + NW + SE + SW;
        }
    }

    for (size_t y = 1; y < H + 1; ++y)
    {
        for (size_t x = 1; x < W + 1; ++x)
        {
            auto cell = grid[y][x];
            if (cell == -1)
            {
                cout << '#';
            }
            else
            {
                cout << cell;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int n; cin >> n;
	rep(i, 0, n) {
		string s; cin >> s;
		bool b[256] = {};
		string ans ="";
		ans += s[0];
		b[s[0]] = true;
		for (int i = 1; i < s.size(); i += 3) {
			if (b[s[i + 2]])continue;
			b[s[i + 2]] = true;
			if (s[i] == '<') {
				ans = s[i + 2] + ans;
			}
			else {
				ans = ans + s[i + 2];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
x, y = map(int,input().split())
group1 = {1,3,5,7,8,10,12}
group2 = {4,6,9,11}
group3 = {2}
if (x in group1) and (y in group1) :
    print("Yes")
elif (x in group2) and (y in group2) :
    print("Yes")
elif (x in group3) and (y in group3) :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
string answer;
char ret[MAX_N];

char nextchr(char center, char ans, char left){

	if ((center == 'S' && ans == 'o') || (center == 'W' && ans == 'x')){
		return left;
	}
	else{
		return (left == 'S' ? 'W' : 'S');
	}
}

bool check(char center, char ans, char left, char right){
	return right == nextchr(center, ans, left);
}

bool run(char first, char second){

	ret[0] = first;
	ret[1] = second;
	for (int i = 2; i < N; i++){
		ret[i] = nextchr(ret[i - 1], answer[i - 1], ret[i - 2]);
	}

	return (check(ret[0], answer[0], ret[N - 1], ret[1]) &&
		check(ret[N - 1], answer[N - 1], ret[0], ret[N - 2]));
}

int main() {

	cin >> N;
	cin >> answer;

	bool success = false;

	if (!success){
		success = run('S', 'S');
	}
	if (!success){
		success = run('S', 'W');
	}
	if (!success){
		success = run('W', 'S');
	}
	if (!success){
		success = run('W', 'W');
	}

	if (success){
		rep(i, N){
			cout << ret[i];
		}
		cout << endl;
	}
	else{
		cout << -1 << endl;
	}
	
}

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

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

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
    int N, A;
    cin >> N >> A;
    cout << N * N - A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool vis[200005];
vector<int>v[200005];
int k;
void bfs(int i)
{
	queue<int>q;
	q.push(i);
	vis[i]=true;
	k=1;
	while(!q.empty())
	{
		int p=q.front();
		q.pop();
		for(int j=0;j<v[p].size();j++)
		{
			if(vis[v[p][j]]==false)
			{
				k++;
				q.push(v[p][j]);
				vis[v[p][j]]=true;
			}
		}
	}
}
int main()
{
	ll t,n,i,m,x,y,mx;
	map<pair<int,int>,bool>mp;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		if(mp.find(make_pair(x,y))!=mp.end())
		continue;
		mp[make_pair(x,y)]=true;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(i=0;i<n+3;i++)vis[i]=false;
	mx=INT_MIN;
	for(i=1;i<=n;i++)
	{
		if(vis[i]==false)
		{
			k=0;
			bfs(i);
			if(k>mx)
			{
				mx=k;
			}
			//cout<<k<<"**"<<i<<endl;
		}
	}
	cout<<mx<<endl;
	return 0;
}

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

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int[] abc = new int[3];
		    abc[0] = scanner.nextInt();
		    abc[1] = scanner.nextInt();
		    abc[2] = scanner.nextInt();
		    int k = scanner.nextInt();
		    
		    Arrays.sort(abc);
		    
		    System.out.println(abc[0] + abc[1] + abc[2] * (int)Math.pow(2, k));
		    
		    scanner.close(); }
		  }

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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int transition = 0;
    char prev = 'A';
    for (int i = 0; i < N; i++) {
        if (prev != S[i]) {
            ++transition;
        }
        prev = S[i];
    }
    int minus = max(1, transition - 2*K);
    cout << N - minus << endl;
    return 0;
}

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

#ifdef _LOCAL_DEBUG
#include "templates/debug.h"
#else
#define debug(...) 
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int cnt = 0;
    for (char c : s)
        cnt += c == 'R';
    if (cnt == 3 || cnt == 0 || cnt == 1)
        cout << cnt;
    else
        cout << (s[1] == 'S' ? 1 : 2);
    
    return 0;
}

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

int main(void)
{
    int N,K;
    cin >> N >> K;
    int p[N],price=0;

    for(int i=0;i<N;i++)
    {
        cin >> p[i];
    }
    sort(p,p+N);
    for(int i=0;i<K;i++)
    {
        price+=p[i];
    }
    cout << price << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <algorithm>
#include <cstdlib>
#include <math.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  int INF = pow(10, 9);

  vector<int> dp(N, INF);
  dp[0] = 0;
  
  for (int j = 1; j < N; j++) {
  	for (int i = max(0, j - K); i < j; i++) {
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
    }
  }
  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  REP(i,1,n + 1){
    if((i % 15 != 0) && i % 3 != 0 && i % 5 != 0)ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672
def yoko():
    for h, line in enumerate(L):
        if line[q-1:q-1+p] != [' ']*p:
            h = h-1
            break
    for i in range(q-1, (q-1+p-1)+1):
        L[h][i] = '#'
    check(h, 1)
    
def tate():
    for h, line in enumerate(L):
        if line[q-1] != ' ':
            h = h-1
            break
    for i in range(h-p+1, h-p+1+p):
        L[i][q-1] = '#'
    check(h-p+1, p)

def check(h, c):
    while 0 < c:
        if L[h] == ['#']*5:
            del L[h]
        else:
            h += 1
        c -= 1
     
def add():
    c = 0
    for line in L:
        if line == [' ']*5:
            c += 1
        else:
            break
    for i in range(5-c):
        L.insert(0, [' ']*5)
        
def result():
    ans = 0
    for line in L:
        for v in line:
            if v == '#':
                ans += 1
    else:
        print ans

while True:
    n = input()
    if n == 0: break
    L = [[' ']*5 for i in range(5)]
    for i in range(n):
        d, p, q = map(int, raw_input().split())
        if d == 1:
            yoko()
        else:
            tate()
        add()
    else:
        result()

Measured memory_bytes: 4796
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ar[10000],br[10000],i,j,t,t1,d,sum=0;

    for(i=0;i<5;i++)
    {
        cin>>ar[i];
        if(ar[i]%10!=0)
        br[i]=10-ar[i]%10;

    }

    for(i=0;i<5;i++)
    {
        for(j=i;j<5;j++)
        {
            if(br[i]!=0 && br[i]>=br[j])
            {
                t1=ar[i];
                ar[i]=ar[j];
                ar[j]=t1;



                t=br[i];
                br[i]=br[j];
                br[j]=t;
                d=j;
            }
        }
    }


    for(i=0;i<5;i++)
    {
        if(ar[i]%10!=0 && i!=d)
        {
            ar[i]=ar[i]+(10-ar[i]%10);
        }
    }

    for(i=0;i<5;i++)
    {
        sum=sum+ar[i];
    }

    cout<<sum<<endl;














    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		int a[] = new int[n]; 
		
		for(int i= 0; i < n -1 ; i++) {
			int temp = scan.nextInt()-1;
			a[temp]++;
		}
		
		for(int i= 0; i < n; i++) {
			System.out.println(a[i]);
		}
	}
}

Measured memory_bytes: 57088
#include <iostream>

using namespace std;

int main() {
    int grid[50][50], h, w;
    string str;

    cin >> h >> w;

    for (int i=0; i<h; i++) {
        cin >> str;
        for (int j=0; j<w; j++) {
            if (str[j] == '#') {
                grid[i][j] = -10;
            }
            else {
                grid[i][j] = 0;
            }
        }
    }

    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (grid[i][j] < 0) {
                for (int k=i-1; k<=i+1; k++) {
                    for (int l=j-1; l<=j+1; l++) {
                        if (k >= 0 && k < h && l >= 0 && l < w) {
                            grid[k][l]++;
                        }
                    }
                }
            }
        }
    }

    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (grid[i][j] < 0) {
                cout << "#";
            }
            else {
                cout << grid[i][j];
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int a,b;
  string s;
  cin>>a>>b;
  if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int n;
    int i;
    
    cin >> n;
    
    int a[n-1];
    int b[n];
    
    for(i = 0; i < n; i++) {
        b[i] = 0;
    }
    
    for(i = 0; i < n-1; i++) {
        cin >> a[i];
        b[a[i]-1] += 1;
    }
    
    for(i = 0; i < n; i++) {
        cout << b[i] << endl;
    }
    
    return 0;
}


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

using namespace std;

int main(){
  long long n;
  cin >> n;
  
  long long ans = 0;
  for(long long i = 1; i * i <= n; i++){
    if(n % i == 0) ans = i - 2 + n / i;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main(void){
    // Here your code !
   int h, w;
   while (1){
       scanf("%d %d", &h, &w);
       if (h == 0 && w == 0) break;
       for (int i = 0; i < h; i++){
           for (int j = 0; j < w; j++){
               printf("#");
           }
           printf("\n");
       }
       printf("\n");
   }
    return 0;
}

Measured memory_bytes: 2592
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def bleft(fn, x, lo, hi):
    """
    (memo) いっぱい呼ぶなら np.searchsorted のほうがベクトル化されててはやそう
    lo から hi-1 のうち、fn の結果が x 以上となる、最も左の値
    bisect.bisect_left と同じ
    https://docs.python.org/ja/3/library/bisect.html
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if fn(mid) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


N, Q = list(map(int, sys.stdin.readline().split()))
S = sys.stdin.readline().rstrip()
TD = [sys.stdin.readline().rstrip().split() for _ in range(Q)]


def check(i):
    if i < 0:
        return -1
    if i >= N:
        return 1

    # i 番目のゴーレムが左に落ちるなら -1、右に落ちるなら 1
    for t, d in TD:
        if t == S[i]:
            i += 1 if d == 'R' else -1
        if i < 0:
            return -1
        if i >= N:
            return 1
    return 0


l = bleft(check, 0, -1, N + 1)
r = bleft(check, 1, -1, N + 1)
print(r - l)


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

int s[200010], a[200010];
int main()
{
    int n, k; cin>>n>>k;
    for(int i=1; i<=n; ++i) cin>>a[i];

    while (k--) {
        fill(s, s+n+1, 0);
        for(int i=1; i<=n; ++i) {
            s[max(i-a[i], 0)]++;
            s[min(i+a[i]+1, n+1)]--;
        }
        int mina=n;
        for(int i=1; i<=n; ++i)
            mina=min(mina, s[i]+=s[i-1]);
        for(int i=1; i<=n; ++i) a[i]=s[i];
        if (mina==n) break;
    }
    for(int i=1; i<=n; ++i) cout<<a[i]<<' ';
    cout<<endl;
}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define ALL(v) (v).begin(),(v).end()
#define REP(i, x, n) for(ll (i)=(x); (i)<(n); (i)++)
#define RREP(i, x, n) for(ll (i)=(n)-1; (i)>=x; (i)--)
#define FOR(i, n) for(ll (i)=0; (i)<(n); (i)++)
#define RFOR(i, n) for(ll (i)=(n)-1; (i)>=0; (i)--)

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

        ll X, N;
        cin >> X >> N;
        vector<ll> p(N);
        FOR(i, N) cin >> p[i];
        bool inc = false;
        FOR(i, N) {
                if (p[i] == X) {
                        inc = true;
                        break;
                }
        }
        if (N == 0 || !inc) {
                cout << X << endl;
        }
        else {
                REP(i, 1, 200) {
                        bool bm = false, bp = false;
                        FOR(j, N) {
                                if (p[j] == X - i) bm = true;
                                else if (p[j] == X + i) bp = true;
                        }
                        if (!bm) {
                                cout << X - i << endl;
                                break;
                        }
                        else if (!bp) {
                                cout << X + i << endl;
                                break;
                        }
                }
        }

        return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

int main()
{
    // input
    int K;
    char S[101];
    scanf( "%d", &K );
    scanf( "%s", S );

    // process

    // output
    if ( std::strlen(S) <= K ) {
        printf( "%s\n", S );
    } else {
        for ( int i=0; i<K; i++ ) {
            printf( "%c", S[i] );
        }
        printf( "...\n" );
    }

    return 0;
}


Measured memory_bytes: 1648
#include <iostream>
#include <cmath>
#include <vector>
#define EPS (1.0e-3)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;


class Point {
public:
  double x, y, z;
  Point(double x=0, double y=0, double z=0) : x(x), y(y), z(z) {}
  Point operator - (Point p) { return Point(x-p.x, y-p.y, z-p.z); }
  bool operator == (const Point &p) const {
    return equals(x, p.x) && equals(y, p.y) && equals(z, p.z);
  }
};
typedef Point Vector;

double norm(Vector a) { return a.x*a.x + a.y*a.y + a.z*a.z; }
double abs(Vector a) { return sqrt(norm(a)); }

int N;
double QR, RP, PQ;
vector<Point> V;


void solve() {
  for(int p = 0; p < V.size(); ++p) {
    for(int q = 0; q < V.size(); ++q) {
      for(int r = 0; r < V.size(); ++r) {
	if(V[p] == V[q] || V[q] == V[r] || V[r] == V[p]) continue;
	if(equals(abs(V[r]-V[q])/QR, abs(V[p]-V[r])/RP) &&
	   equals(abs(V[q]-V[p])/PQ, abs(V[p]-V[r])/RP)) {
	  cout << p+1 << " " << q+1 << " " << r+1 << endl;
	  return;
	}
      }
    }
  }
  cout << -1 << endl;
}

main() {
  int T;
  cin >> T;
  for(int t = 0; t < T; ++t) {
    V.clear();
    cin >> QR >> RP >> PQ;
    cin >> N;
    for(int i = 0; i < N; ++i) {
      Point p;
      cin >> p.x >> p.y >> p.z;
      V.push_back(p);
    }
    solve();
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

int main(){
    int N, K;
    cin >> N >> K;
    if(K==1){
        cout << 0 << endl;
    }else{
        cout << N - K << endl;
    }
    return 0;
}


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

const ll INF = 1e16;

struct edge{ll from,to,cost;};
vector<edge> es;

ll d[3000];
ll V,E;

// 頂点sからの最小距離(sに影響する負閉路があるかを返す)
bool BellmanFord(ll s){
    for(int i = 0;i < V;i ++) d[i] = INF;
    d[s] = 0;
    for(int i = 0;i < V-1;i ++) {
        for(int j = 0;j < E;j ++){
            edge e = es[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    for(int i = 0;i < V;i ++) {
        for(int j = 0;j < E;j ++){
            edge e = es[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = -INF;
                if(e.to==V-1){
                    return 0;
                }
            }
        }
    }
    return 1;
}

int main(){
    ll P;
    cin >> V >> E >> P;
    for(int i = 0;i < E;i ++){
        ll a,b,c;
        cin >> a >> b >> c;
        a --,b --;
        c = -(c-P);
        es.push_back({a,b,c});
    }
    if(BellmanFord(0))  cout << max(0ll,-d[V-1]) << endl;
    else                cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct P {
  int y, xl, xr, x, k;
  int cost;
  P(int y, int xl, int xr, int x, int k, int cost) : y(y),xl(xl),xr(xr),x(x),k(k),cost(cost) {}
  bool operator<(const P &b) const {
    return cost > b.cost;
  }
};

int ba[11][10];
int dist[11][10][10][10][51];
int f, m, o;

void func(int y, int x, int &k, int &cost) {
  if (k == 0) return;
  if (ba[y][x] < 0) {
    cost += -ba[y][x];
  } else {
    k = min(m,k+ba[y][x]);
  }
}

int main() {
  int w,h;
  while(cin>>w>>h,w||h) {
    cin >> f >> m >> o;
    REP(i,h)REP(j,w)cin>>ba[i][j];
    REP(i,w) ba[h][i] = 0;
    priority_queue<P> Q;
    REP(i,h+1)REP(j,w)REP(k,w)REP(l,w)REP(ll,m+1)dist[i][j][k][l][ll] = INF;
    REP(i,w) {
      int k=o-1, cost=0;
      func(0,i,k,cost);
      Q.push(P(0,i,i,i,k,cost));
      dist[0][i][i][i][k] = cost;
    }
    int ans = -1;
    while(!Q.empty()) {
      P p = Q.top(); Q.pop();
      int d = dist[p.y][p.xl][p.xr][p.x][p.k];
      if (d < p.cost) continue;
      if (p.k == 0) continue;
      if (d > f) break;
      if (p.y == h-1) {
        ans = d;
        break;
      }

      // left, right
      REP(i,2) {
        int xx = p.x + (i?-1:1);
        if (xx<0||xx>=w) continue;
        int xl = p.xl;
        int xr = p.xr;
        int k = p.k-1;
        int cost = d;
        if (xx < xl) {
          xl = xx;
          func(p.y,xx,k,cost);
        }
        if (xx > xr) {
          xr = xx;
          func(p.y,xx,k,cost);
        }
        if (dist[p.y][xl][xr][xx][k] > cost) {
          dist[p.y][xl][xr][xx][k] = cost;
          Q.push(P(p.y,xl,xr,xx,k,cost));
        }
      }
      // down
      int x = p.x;
      int k = p.k-1;
      int cost = d;
      func(p.y+1,p.x,k,cost);
      // if (p.y == 2 && p.xl == 3 && p.xr == 3) {
      //   cout << p.y << " " << p.xl << " " << p.xr << " " << p.x << " " << p.k << " " << p.cost << endl;
      //   cout << d << endl;

      //   cout << k << " " << cost << endl;
      //   cout << p.y+1 << endl;
      //   cout << dist[p.y+1][x][x][x][k] << endl;
      // }
      if (dist[p.y+1][x][x][x][k] > cost) {
        dist[p.y+1][x][x][x][k] = cost;
        Q.push(P(p.y+1,x,x,x,k,cost));
      }
    }
    if (ans == -1) puts("NA");
    else cout << ans << endl;
  }
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;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())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll x,a,b,flag;
int main()
{
    //IOS;
    cin>>x;
    for(int i=-2000; i<=2000; i++)
    {
        for(int j=-2000; j<=2000; j++)
        {
            if(qpow(i,5)-qpow(j,5)==x)
            {
                flag=1;
                a=i;
                b=j;
                break;
            }
        }
        if(flag==1)
        {
            break;
        }
    }
    cout<<a<<' '<<b;
    return 0;
}
/*

*/


Measured memory_bytes: 3636