akhauriyash/Code-Regression huggingface dataset:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

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

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n,a,b = map(int,input().split())
    if (b-a)%2==0:
        print((b-a)//2)
    else:
        print(min(a-1,n-b)+1+(b-a-1)//2)
    return

if __name__=='__main__':
    main()


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

#define MAX_N 50

typedef long long ll;

using namespace std;

ll comb(ll n, ll k) {
  ll w = min(n - k, k);
  if (n <= 1 || w == 0) {
    return 1;
  }
  ll a = n;
  for (int i = n - 1; i > n - w; --i) {
    a *= i;
  }
  ll b = 1;
  for (int i = 2; i <= w; ++i) {
    b *= i;
  }
  return a / b;
}

int main() {
  int N, P;
  cin >> N >> P;
  ll NO = 0;
  ll NE = 0;
  for (int i = 0; i < N; ++i) {
    int a = 0;
    cin >> a;
    if (a % 2 == 0) {
      ++NE;
    } else {
      ++NO;
    }
  }
  ll e = (ll)pow(2, NE);
  ll o = 0;
  for (int i = P; i <= NO; i += 2) {
    o += comb(NO, i);
  }
  ll res = e * o;
  if (P == 0) {
    res = o > 0 ? e * o : e;
  } else {
    res = e > 0 ? o * e : o;
  }
  printf("%lld\n", res);
}

Measured memory_bytes: 3360
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <string>
#define SIZE 1000005

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

char str[SIZE];
int A[SIZE],B[SIZE];
P pos[5];
int cnt[5];

int main()
{
	scanf("%s",&str);
	string S=str;
	S.erase(unique(S.begin(),S.end()),S.end());
	int n=S.size();
	for(int i=0;i<n;i++)
	{
		A[i]=S[i]-'A';
		cnt[A[i]]++;
	}
	for(int i=0;i<3;i++) pos[i]=P(cnt[i],i);
	sort(pos,pos+3,greater <P>());
	int a=pos[0].second,d=pos[0].first-pos[1].first;
	int sz=0;
	for(int i=0;i<n;i++)
	{
		B[sz++]=A[i];
		if(sz>=3&&d>0&&B[sz-2]==a&&B[sz-1]!=B[sz-3])
		{
			d--;
			B[sz-2]=B[sz-1];
			sz--;
		}
		if(sz==1&&d>0&&B[sz-1]==a)
		{
			d--;
			sz--;
		}
	}
	while(1)
	{
		if(d>0&&sz>=1&&B[sz-1]==a)
		{
			d--;
			sz--;
		}
		else
		{
			break;
		}
	}
	n=sz;
	memset(cnt,0,sizeof(cnt));
	for(int i=0;i<n;i++)
	{
		A[i]=B[i];
		cnt[A[i]]++;
	}
	for(int i=0;i<3;i++) pos[i]=P(cnt[i],i);
	sort(pos,pos+3,greater <P>());
	a=pos[0].second;
	int b=pos[1].second,c=pos[2].second;
	int db=pos[0].first-pos[1].first,dc=pos[0].first-pos[2].first;
	//printf("%d %d %d : %d : %d %d\n",a,b,c,pos[0].first,db,dc);
	sz=0;
	for(int i=0;i<n;i++)
	{
		B[sz++]=A[i];
		if(sz>=3&&db>0)
		{
			if(B[sz-3]==c&&B[sz-2]==a&&B[sz-1]==c)
			{
				db--;
				sz-=2;
			}
			else if(B[sz-3]==a&&B[sz-2]==c&&B[sz-1]==a)
			{
				db--;
				sz-=2;
			}
		}
		else if(sz==2&&db>0)
		{
			if(B[sz-2]==a&&B[sz-1]==c)
			{
				db--;
				sz-=2;
			}
			else if(B[sz-2]==c&&B[sz-1]==a)
			{
				db--;
				sz-=2;
			}
		}
		if(sz>=3&&dc>0)
		{
			if(B[sz-3]==b&&B[sz-2]==a&&B[sz-1]==b)
			{
				dc--;
				sz-=2;
			}
			else if(B[sz-3]==a&&B[sz-2]==b&&B[sz-1]==a)
			{
				dc--;
				sz-=2;
			}
		}
		else if(sz==2&&dc>0)
		{
			if(B[sz-2]==a&&B[sz-1]==b)
			{
				dc--;
				sz-=2;
			}
			else if(B[sz-2]==b&&B[sz-1]==a)
			{
				dc--;
				sz-=2;
			}
		}
	}
	while(1)
	{
		bool up=false;
		if(db>0&&sz>=2)
		{
			if(B[sz-2]==a&&B[sz-1]==c)
			{
				db--;
				sz-=2;
				up=true;
			}
			else if(B[sz-2]==c&&B[sz-1]==a)
			{
				db--;
				sz-=2;
				up=true;
			}
		}
		else if(dc>0&&sz>=2)
		{
			if(B[sz-2]==a&&B[sz-1]==b)
			{
				dc--;
				sz-=2;
				up=true;
			}
			else if(B[sz-2]==b&&B[sz-1]==a)
			{
				dc--;
				sz-=2;
				up=true;
			}
		}
		if(!up) break;
	}
	for(int i=0;i<sz;i++) printf("%c",'A'+B[i]);puts("");
	return 0;
}


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

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N+1);
  vector<int> y(M+1);
  x.at(0)=X; y.at(0)=Y;
  for(int i=1; i<=N; i++) cin >> x.at(i);
  for(int i=1; i<=M; i++) cin >> y.at(i);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  if(y.at(0)-x.at(N)>0) cout << "No War" << endl;
  else cout << "War" << endl;
}

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;

    int x[n] = {};
    int y[n] = {};
    int a[n] = {};

    rep(i, n) cin >> x[i] >> y[i] >> a[i];

    int xr = w;
    int xl = 0;
  	int yb = 0;
    int yc = h;

    rep(i, n) {
        if(a[i] == 1) xl = max(x[i], xl);
        else if(a[i] == 2) xr = min(x[i], xr);
        else if(a[i] == 3) yb = max(yb, y[i]);
        else if(a[i] == 4) yc = min(yc, y[i]);
    }
  
  	int W = xr-xl;
  	int H = yc-yb;
  
  	if(W >= 0 && H >= 0) cout << W*H << endl;
  	else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
H,W,A,B = map(int,input().split())
grid = [[1]*W for i in range(H)]
for i in range(B):
    for j in range(A):
        grid[i][j] = 0
for i in range(B,H):
    for j in range(A,W):
        grid[i][j] = 0
#print(grid)
for col in range(H):
    a = grid[col]
    anscol = ''
    for e in a:
        anscol += str(e)
    print(anscol)


Measured memory_bytes: 11892
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	long double d;
	cin >> d;
	d/=3;
	cout << fixed << setprecision(9);
	cout << d*d*d;
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

class UF {
public:
    vector<int> p, sz;
    UF(size_t n) : p(n), sz(n) {
        for(size_t i=0; i<n; i++)
            p[i] = i, sz[i] = 1;
    };
    int find(int x) {
        if(p[x] == x) return x;
        return p[x] = find(p[x]);
    };
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        sz[y] += sz[x];
        p[x] = y;
    };
};


int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;

    UF uf(n);

    while(m--) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    ll res = 0;
    for(ll i=0; i<n; i++)
        res = max(res, (ll)uf.sz[i]);
    cout << res << endl;
}

Measured memory_bytes: 4764
<?php
fscanf(STDIN,"%d %d",$n,$m);
$h = explode(" ",trim(fgets(STDIN)));
$j = [];
$bad = [];
for ($i = 0;$i < $m;++$i) {
    fscanf(STDIN,"%d %d",$a,$b);
    if ($h[$a - 1] < $h[$b - 1]) {
        $bad[] = $a;
    } else if ($h[$a - 1] > $h[$b - 1]) {
        $bad[] = $b;
    } else {
        $bad[] = $a;
        $bad[] = $b;
    }
}
$bad = array_unique($bad);
foreach ($bad as $val) {
    unset($h[$val - 1]);
}


echo count($h).PHP_EOL;

Measured memory_bytes: 34112
max_len = 0
tmp = 0

S = input()
acgt = {'A': 0, 'C': 0, 'G': 0, 'T': 0}

for i in range(len(S)):
    if S[i] in acgt:
        tmp += 1
    else:
        max_len = max(max_len, tmp)
        tmp = 0

max_len = max(max_len, tmp)
print(max_len)


Measured memory_bytes: 9028
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <ccomplex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n, r; cin >> n >> r;
	if (n >= 10) cout << r << endl;
	else cout << r + 100 * (10 - n) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double[] a = new double[n];
		double ans = 1;
		double div = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextDouble();
			ans *= a[i];
		}
		for(int i = 0; i < n; i++) {
			div += ans / a[i];
		}
		ans /= div;
		System.out.println(ans);
	}

}


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

int main() {
	int a, b, c;
  	cin >> a >>b;
  	c = a + b;
    if (c % 2 == 0) {
    	cout << c/2 << endl;
    }
    if (c % 2 == 1) {
    	cout << c/2 + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1e18;
int main()
{
    int n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    ll dp[n];
    for(int i=1;i<n;i++) dp[i]=N;
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)dp[i]=min(dp[i],abs(arr[i-j]-arr[i])+dp[i-j]);
        }
        
    }
    cout<<dp[n-1]<<endl;

    
}

Measured memory_bytes: 1792
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi dp(1000001);
  dp[1] = 1;
  loop(i, 2, dp.size()) {
    if (i % 2 == 0) dp[i] |= dp[i / 2];
    if (i % 3 == 0) dp[i] |= dp[i / 3];
    if (i % 5 == 0) dp[i] |= dp[i / 5];
  }
  int m, n;
  while (cin >> m >> n, m) {
    int c = 0;
    for (int i = m; i <= n; i++) c += dp[i];
    cout << c << endl;
  }
}

Measured memory_bytes: 10500
l = [[[0] * 10 for _ in range(3)] for _ in range(4)]
for _ in range(int(input())):
    b, f, r, v = map(int, input().split())
    l[b - 1][f - 1][r - 1] += v
 
for i in range(4):
    for j in range(3):
        print(end = " ")
        print(*l[i][j])
    if i != 3:
        print("####################")

Measured memory_bytes: 7724
import numpy as np

N, A = list(map(int, input().split()))
X = list(map(int, input().split()))

dp = [np.array([[0]*(N*A+1) for _ in range(N+1)])]
#dp[0]: [0, 0]～[N, N*A]

for x in X:
  new_dp = dp[-1].copy()
  new_dp[1:, x:] += dp[-1][0:N, 0:N*A+1-x]
  if x<=N*A:
    new_dp[1, x] += 1
  
  dp.append(new_dp)
#print(dp[-1])
  
print(sum([dp[-1][i, i*A] for i in range(1, N+1)]))



Measured memory_bytes: 63688
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	ll N, Z, W;
	cin >> N >> Z >> W;
	ll A = -1, B;
	rep(i, N - 1) cin >> A;
	cin >> B;
	if (A == -1) A = B;
	cout << max(abs(B - W), abs(A - B)) << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    s = []
    t = []
    for i in range(N):
        a,b = map(str, input().split())
        s.append(a)
        t.append(int(b))
    X = input()

    last = s.index(X)

    t = t[last+1:]

    print(sum(t))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  char a[200];
  int n,k,l,i;
  cin>>n;
  while(n--){
    string s1,s2;
    cin>>s1>>s2;
    for(i=0;i<200;i++)a[i]='0';
    for(k=0,i=s2.size()-1;i>=0;i--)a[k++]=s2[i];
    for(l=0,i=s1.size()-1;i>=0;i--,l++){
      a[l]+=s1[i]-'0';
      if(a[l]>'9'){a[l+1]++;a[l]-=10;
        if(!i)l++;
      }
    }
    if(k>80||l>80)cout<<"overflow";
    else if(l<k)for(i=k-1;i>=0;i--)cout<<a[i];
    else for(i=l-1;i>=0;i--)cout<<a[i];
    cout<<endl;
  }
}

Measured memory_bytes: 2984
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N, M;
long long int x[100000];
long long int y[100000];
long long int sum_x[100000];
long long int ulti_x;
long long int sum_y[100000];
long long int ulti_y;
long long int box;

int main(){
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	box = x[0];
	for (int i = 0; i < N; i++) {
		x[i] -= box;
	}
	for (int i = 0; i < M; i++) {
		cin >> y[i];
	}
	box = y[0];
	for (int i = 0; i < M; i++) {
		y[i] -= box;
	}
	for (int i = 1; i < N; i++)sum_x[i] = sum_x[i - 1] + x[i];
	box = sum_x[N - 1];
	ulti_x = box;
	for (int i = 1; i < N; i++) {
		box -= (x[i] - x[i - 1])*(N - i);
		ulti_x += box;
		ulti_x %= MOD;
	}
	for (int i = 1; i < M; i++)sum_y[i] = sum_y[i - 1] + y[i];
	box = sum_y[M - 1];
	ulti_y = box;
	for (int i = 1; i < M; i++) {
		box -= (y[i] - y[i - 1])*(M - i);
		ulti_y += box;
		ulti_y %= MOD;
	}
	cout << (ulti_x*ulti_y) % MOD << endl;
	return 0;
}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    D,X = map(int, lines.pop(0).split(' '))
    NLIST = []
    res = 0
    for i in range(N):
        a = int(lines.pop(0))
        res += (D - 1)// a + 1
    res += X
    print(res)

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3064
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int v0 = a * b;
    int v1 = c * d;
    cout << max(v0, v1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int a,b;
int32_t main()
{
    cin>>a>>b;
    return cout<<lcm(a,b),0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long bipow(long long n, int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

int main(){
    int N;
    cin >> N;
    vector<long long> C(N);
    REP(i, N) cin >> C[i];
    sort(C.begin(), C.end(), greater<long long>());

    long long ans = 0;
    for(int i=0; i<N; i++){
        long long tmp = bipow(2, N-i-1);
        tmp = (tmp * C[i]) % MOD;
        long long tmp2;
        if(i == 0){
            tmp2 = 1;
        }else{
            tmp2 = bipow(2, i-1);
            tmp2 = (tmp2 * (i+2)) % MOD;
        }
        ans += (tmp * tmp2) % MOD;
        ans %= MOD;
    }
    ans = (ans * bipow(2, N)) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
#nCをp(=10**9+7)で割ったときのあまり(モジュラ逆数)
def cmb(n,r,p):
  if r<0 or n<r:
    return 0
  r=min(r,n-r)
  return facto[n]*factoinv[r]*factoinv[n-r]%p
p=10**9+7
n,m=map(int,input().split())
#0,1の時の値をいれたn!のリスト(modp)
facto=[1,1]
#0,1の時の値をいれたn!の逆元のリスト(modp)
factoinv=[1,1]
#0,1の場合を入れたn!の逆元も求めるために使うnの逆元のリスト(modp)
inv=[0,1]
#2からスタート
for i in range(2,m+1):
  facto.append((facto[-1]*i)%p)
  inv.append((-inv[p%i]*(p//i))%p)
  factoinv.append((factoinv[-1]*inv[-1])%p)
if n==m:
  kosuub=0
  for i in range(n+1):
    kosuub+=(facto[(n-i)]*cmb(n,i,p)*((-1)**i))%p
  kosuu=(kosuub*facto[(n)])%p
  print(kosuu)
else:
  kosuub=0
  for i in range(n+1):
    kosuub+=(cmb((m-i),(n-i),p)*facto[(n-i)]*cmb(n,i,p)*((-1)**i))%p
  kosuu=(kosuub*cmb(m,n,p)*facto[n])%p
  print(kosuu)

Measured memory_bytes: 68348
X = 3
bingo = ((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6))
def checkbingo(a):
    for i,j,k in bingo:
        if a[i] + a[j] + a[k] == 0:
            return True 
    return False
    
    

a = []
for i in range(X):
    a += list(map(int,input().split()))
    
N = int(input())
for j in range(N):
    b = int(input())
    if b in a:
        a[a.index(b)] = 0
if checkbingo(a):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9228
n = gets.split.map(&:to_i)
if n[1] == 2
  puts "-1"
  exit
end
friend  = 0
side = []
for i in 2..n[0]
  side.push([1,i])
end
(n[0]-2).downto(1){|i| friend += i}
if friend < n[1]
  puts "-1"
  exit
end
count = 1
check = 2
while friend > n[1]
  if check + count <= n[0]
    friend -= 1
    side.push([check,check+count])
    check += 1
  else
    check = 2
    count += 1
  end
  if count > n[0]
    puts "-1"
    exit
  end
end

puts side.length
(side.length).times{|i| puts side[i].join(" ")}


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

int main(){
	int k, n;
	cin >> k >> n;
	
	//距離配列作成	
	int tmp;
	int dis[n]={0};
	cin >> dis[0];
  int pre=dis[0];
	for(int i=1; i<n; i++){
		cin >> tmp;
		dis[i]=tmp-pre;
              pre = tmp;
     // cout << tmp << " " << dis[i] << endl;
      
	}
  //cout << dis[n] << " " << k << endl;
  
	dis[n]=k-pre;
	
	//for(int i=0; i<n+1; i++) cout << dis[i] << endl;
	
  	//距離計算
	int ans;
	int now=k;
	for(int i=1; i<n; i++){
		ans=k-dis[i];
		if(ans<now) now=ans;
      
     // cout << ans << " " << now << endl;
      
	}
	ans=k-dis[0]-dis[n];
	
	cout << min(ans, now) << endl;

}

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

class Test
{
    static void Main()
    {
        string ss;
        while ( (ss = Console.ReadLine()) != "0 0")
        {
            int H = int.Parse(ss.Split()[0]);
            int W = int.Parse(ss.Split()[1]);

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (i > 0 && i < H - 1 && j > 0 && j < W - 1)
                        Console.Write(".");
                    else
                        Console.Write("#");
                }
                Console.Write("\n");
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 13924
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int dat[100001];
int cnt[100001];
int gen[100001];
int main()
{
	int num,mod;
	scanf("%d%d",&num,&mod);
	for(int i=0;i<num;i++)
	{
		int z;
		scanf("%d",&z);
		cnt[z%mod]++;
		dat[z]++;
	}
	for(int i=0;i<=100000;i++)
	{
		gen[i%mod]+=dat[i]/2;
	}
	int ret=0;
	for(int i=0;i+i<=mod;i++)
	{
		if(i==0||i+i==mod)ret+=cnt[i]/2;
		else
		{
			if(cnt[i]<cnt[mod-i])ret+=cnt[i]+min((cnt[mod-i]-cnt[i])/2,gen[mod-i]);
			else ret+=cnt[mod-i]+min((cnt[i]-cnt[mod-i])/2,gen[i]);
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;

const int INF = 1e18;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n)
    {
        ans += a[i];
    }
    ans -= n;
    cout << ans << endl;
}

signed main()
{
    solve();
    return 0;
}


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

int main(void)
{
	int i,r;
	double n[1000], sum = 0, ave;
	while(1)
	{
		scanf("%d",&r);
		if(r==0)
		{
			break;
		}
		for(i=0;i<r;i++)
		{
			scanf("%lf",&n[i]);
			sum += n[i];
		}
		
		ave = sum / r;
		sum = 0;
		
		for(i=0;i<r;i++)
		{
			sum += (n[i]-ave) * (n[i]-ave);
		}
		
		sum = sum / r;
		printf("%lf\n",sqrt(sum));
		sum = 0;
	}
	return 0;

}

Measured memory_bytes: 660
#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());
  cout << vec.at(N - 1) - vec.at(0) << endl;
}

Measured memory_bytes: 256
//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll

using namespace std;
using namespace __gnu_pbds;

using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
	cout<<w.size()<<en;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<en;
	if (fl) cout<<flush;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a,int base=10)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=base;
		k+=a[i]-'0';
	}
	return k;
}

template<class T>
void eras(vector<T>& a,T b)
{
	a.erase(find(a.begin(),a.end(),b));
}

string its(ll k,int base=10)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%base)+'0');
		k/=base;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

const int N=300010;
int n,m;
int wa[N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
	cin>>n>>m;
	int a=0,w=0;
	while (m--)
	{
		int x;
		string h;
		cin>>x>>h;
		if (h=="AC")
		{
			if (wa[x]<0) continue;
			++a;
			w+=wa[x];
			wa[x]=-MOD;
		}
		else ++wa[x];
	}
	cout<<a<<' '<<w;
}





Measured memory_bytes: 640
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

ll h[maxn];
ll dp[maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n;
    scanf("%d", &n);

    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    dp[1] = 0;
    for(int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    for(int i = 1; i <= n; i++)
    {
        if(i + 1 <= n)  dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        if(i + 2 <= n)  dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    printf("%lld\n", dp[n]);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

int b[1000][1000];

int main(){
  int h,w;
  scanf("%d%d",&h,&w);
  vector<int> r(h,0), c(w,0);

  for(int i=0;i<h;i++)for(int j=0;j<w;j++){
      scanf("%d",&b[i][j]);
      if(!b[i][j])r[i]++, c[j]++;
    }

  for(int i=0;i<h;i++)for(int j=0;j<w;j++){
      printf("%d%c",(r[i]+c[j]+1-b[i][j])&1,j+1==w?'\n':' ');
    }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 212345;
vector<int> g[MAX_N];
int grundy[MAX_N];
int parent[MAX_N];
int deg[MAX_N];

bool check(int v, int parent_grundy, int begin, int begin_grundy) {
  set<int> vis;
  for (int child : g[v]) if (grundy[child] != -1) vis.insert(grundy[child]);
  vis.insert(parent_grundy);
  int x = 0;
  while (vis.count(x) > 0) x++;

  if (v == begin) {
    return x == begin_grundy;
  }
  return check(parent[v], x, begin, begin_grundy);
}

int main2() {
  REP(i, MAX_N) g[i].clear();
  CLR(grundy, -1);
  CLR(deg, 0);

  int N = nextInt();
  REP(i, N) {
    int p = nextInt() - 1;
    g[p].push_back(i);
    parent[i] = p;
  }
  REP(i, N) deg[i] = g[i].size();

  queue<int> q;
  REP(i, N) if (deg[i] == 0) { q.push(i); }

  int done = 0;
  while (q.size() > 0) {
    int v = q.front(); q.pop();

    deg[parent[v]]--;
    if (deg[parent[v]] == 0) { q.push(parent[v]); }

    set<int> vis;
    for (int child : g[v]) vis.insert(grundy[child]);
    int x = 0;
    while (vis.count(x) > 0) x++;
    grundy[v] = x;
    done++;
  }

  bool ans = false;
  REP(i, N) if (grundy[i] == -1) {
    vector<int> cand;
    set<int> vis;
    for (int child : g[i]) if (grundy[child] != -1) vis.insert(grundy[child]);
    for (int x = 0; cand.size() < 2; x++) {
      if (vis.count(x) == 0) cand.push_back(x);
    }
    ans = (check(parent[i], cand[0], i, cand[0]) || check(parent[i], cand[1], i, cand[1]));
    break;
  }

  cout << (ans ? "POSSIBLE":"IMPOSSIBLE") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 42240
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut keys: Vec<(usize, usize)> = vec![];
    for _ in 0..m {
        let a: usize = read();
        let b: usize = read();
        let mut key = 0;
        for _ in 0..b {
            let c: u32 = read();
            key |= (2 as usize).pow(c - 1);
        }
        keys.push((key, a));
    }
    let mut dp = vec![None; (2 as usize).pow(n as u32)];
    dp[0] = Some(0);
    for i in 0..(2 as usize).pow(n as u32) {
        if dp[i].is_none() {
            continue;
        }
        for key in keys.iter() {
            let k = i | key.0;
            dp[k] = match dp[k] {
                None => Some(dp[i].unwrap() + key.1),
                Some(v) => Some(std::cmp::min(v, dp[i].unwrap() + key.1))
            };
        }
    }
    let v = dp.pop().unwrap();
    println!("{}", if v.is_some() {
        v.unwrap() as i32
    } else {
        -1
    });
}


Measured memory_bytes: 4352
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> takoyaki(N);
    REP(i,N) cin >> takoyaki[i];

    int ans=0;
    REP(i,N){
        for(int j=i+1;j<N;j++){
            ans += takoyaki[i] * takoyaki[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define pyn(a) if(a)puts("Yes");else puts("No");
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
ll n,ans;
string s;
map<string,int>m;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        ans+=m[s]++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int x = 0;
    for (int& it : a)
        cin >> it, x ^= it;
    for (int it : a) 
        cout << (x ^ it) << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(i=0;i<N;++i)
 
int main(){
  ll i,now=0,N,K;
  cin>>N>>K;
  vector<ll> g(N),loop;
  rep(i,N){
    cin>>g[i];
    --g[i];
  }
  set<ll> se;
  while(se.insert(now).second&&K--){
    now=g[now];
  }
  if(K<=0){
    cout<<now+1<<endl;
    return 0;
  }
  se.clear();
  while(se.insert(now).second){
    loop.emplace_back(now);
    now=g[now];
  }
  cout<<loop[K%loop.size()]+1<<endl;
}

Measured memory_bytes: 12400
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main(){
  int n;
  cin >> n;
  if(!(n%2))n--;
  cout<<n/2<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,i,j,d=0;
  cin >> a;
  int b[a];
  for(i=0;i<a;i++){
    cin >> b[i];
  }
  for(i=0;i<a;i++){
    for(j=i+1;j<a;j++){
      d=d+b[i]*b[j];
    }
  }
  cout << d << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
  long long N;
  cin>>N;
  long long A[N];
  long long t=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    t+=A[i];
  }
  long long sum=0;
  long long min1=t;
  for(int i=0;i<N;i++){
    sum+=A[i];
    min1=min(min1,abs(sum-(t-sum)));
  }
  
   cout<<min1<<endl;
 return 0; 
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>

using namespace std;
typedef long long ll;


ll ans,mx,mn=1e8,sum,cnt;
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}

	ans = n-k;
	if(ans%(k-1)!=0){
		cout<<ans/(k-1)+2;
	}
	else cout<<ans/(k-1)+1<<endl;
}


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

using namespace std;

int n, a[100010];

int main(){
  cin >> n;
  for (int i=1; i <= n; i++) cin >> a[i];
  int ans = 0; 
  int ted = 0;
  for (int i = 1; i <= n; i++){
      if (a[i] == i) ted++;
    else ans += (ted / 2) + ted % 2, ted = 0;
  }
  ans += (ted / 2) + ted % 2;
  cout << ans;
  
  return 0;
  
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
private static Scanner s = new Scanner(System.in);
static int count = 0;
static int[] A = new int[2000001];
public static void main(String[] args) {
	int k;
	while(true) {
		String com = s.next();
		if(com.equals("insert")) {
			k = s.nextInt();
			insert(k);
		}else if(com.equals("extract")) {
			System.out.println(extract());
		}else {
			return;
		}
	}
}
static void insert(int n) {
	count++;
	A[count] = n;
	int i = count;
	while(i > 1 && A[i/2] < A[i]) {
		int tmp = A[i/2];
		A[i/2] = A[i];
		A[i] = tmp;
		i /= 2;
	}
}

static int extract() {
	if(count < 1) return -1;
	int set = A[1];
	A[1] = A[count];
	count--;
	maxHeapify(1);
	return set;
}

static void maxHeapify(int i) {
	int l = i * 2;
	int r = i * 2 + 1;
	int max;
	if(l <= count && A[l] > A[i]) {
		max = l;
	} else {
		max = i;
	}
	if(r <= count && A[r] > A[max]) {
		max = r;
	}
	if(max != i) {
		int tmp = A[i];
		A[i] = A[max];
		A[max] = tmp;
		maxHeapify(max);
	}
}
}


Measured memory_bytes: 555004
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt() - 1;
        }
        int index = 0;
        Set<Integer> index_memory = new HashSet<>();        
        while (!index_memory.contains(index)) {
            index_memory.add(index);
            index = A[index];
        }
        Set<Integer> loop_memory = new HashSet<>();
        while (!loop_memory.contains(index)) {
            loop_memory.add(index);
            index = A[index];
        }
        int toLoop = index_memory.size() - loop_memory.size();
        long r;
        if (K <= toLoop) {
            r = K;
            index = 0;
        } else {
            r = (K - toLoop) % loop_memory.size();
        }
        for (int i = 0; i < r; i++) {
            index = A[index];
        }
        System.out.println(index + 1);
        sc.close();
    }
}

Measured memory_bytes: 79440
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
	"strings"
)

type pair struct {
	num, val int
}
type byval []pair

func (p byval) Len() int           { return len(p) }
func (p byval) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p byval) Less(i, j int) bool { return p[i].val < p[j].val }

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	pairs := make([]pair, n)
	for i := 0; i < n; i++ {
		a := eGetInt(scanner)
		pairs[i] = pair{i, a}
	}
	sort.Sort(byval(pairs))
	m := make(map[int]int, n)
	for i := 0; i < n; i++ {
		m[pairs[i].num] = i
	}
	for i := 0; i < n; i++ {
		rank := m[i]
		if rank != n-1 {
			fmt.Println(pairs[n-1].val)
		} else {
			fmt.Println(pairs[n-2].val)
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin>>k;
    string s;
    for(int i=0;i<k;i++){
    	s+="ACL";
	}
	cout<<s<<"\n";
}


Measured memory_bytes: 3568
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

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

const int INF = 1111111111;

using namespace std;

const int N = 1111111;
int a[N];
int b[N];
int n;

void init()
{
	cin >> n;
	rep(i, n)
	{
		cin >> a[i] >> b[i];
	}
}

void solve()
{
	sort(a, a + n);
	sort(b, b + n);

	if (n % 2 == 0)
	{
		int p1 = n / 2 - 1;
		int p2 = n / 2;
		int val = (b[p1] + b[p2] - a[p1] - a[p2] + 1);
		cout << val << endl;
	}
	else
	{
		int p = n / 2;
		cout << b[p] - a[p] + 1 << endl;
	}
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 4728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0){
				break ;
		}
		for (int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i + j) % 2 == 0){
					System.out.printf("#");
				}else{
					System.out.printf(".");
				}
			}
			System.out.printf("\n");
		}
		System.out.printf("\n");
 		}
	}
}


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

using i64 = int_fast64_t;
using f64 = double;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1e9 + 7;
using m64 = modint<MOD>;

void solve() {
    i64 n;
    cin >> n;
    
    m64 ans = 1;
    i64 x = 0, y = 0, z = 0;
    for (i64 i = 0; i < n; i++) {
        i64 a;
        cin >> a;
        ans *= (x == a) + (y == a) + (z == a);
        (x == a ? x : (y == a ? y : z))++;
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		String[] str = new BufferedReader(new InputStreamReader(System.in)).readLine().split(" ");
		
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);
		
		int cnt = 0;
		for (int i = a; i <= b; i++) cnt += (c % i) == 0 ? 1 : 0;
				
		System.out.println(cnt);
	}
}

Measured memory_bytes: 24480
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int min, max;
  cin >> min;
  max = min;
  for (int i = 1; i < N; i++) {
    int tmp;
    cin >> tmp;
    if (max < tmp) {
      max = tmp;
    } else if (min > tmp) {
      min = tmp;
    }
  };
  cout << max - min;
}

Measured memory_bytes: 256
open Batteries
let rec sum lst =
  match lst with
  | [] -> 0
  | first :: rest -> first + sum rest
let kn = Scanf.sscanf (read_line()) "%d %d" (fun k n ->
  [|k; n|]
)
let k = kn.(0)
let n = kn.(1)
let a = read_line () |> String.split_on_char ' ' |> List.map int_of_string |> Array.of_list
let rec get_lengths i =
  if i = (Array.length a) - 1 then [(k-a.(i))+a.(0)] else
  a.(i+1) - a.(i) :: get_lengths (i+1)

let lengths = List.sort compare @@ get_lengths 0
let _ = Printf.printf "%d\n" (sum @@ List.tl @@ List.rev lengths)


Measured memory_bytes: 23600