akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

using namespace std;

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int n,x,a=0,b=0,c=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        if(x%4==0) a++;
        else if(x%2==0) b++;
        else c++;
    }
    for(int i=1;i<=n;i++)
    {
        if(i%2==1) {if(c==0) break;c--;}
        else
        {
            if(a==0) {printf("No");return 0;}
            a--;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
int main(){
	cin>>n>>s;
	for (int i=0;i<min(n,(int)s.size());i++) cout<<s[i];
	if (n<s.size()) cout<<"...";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3624
while(1):
    l = input().split()
    a = int(l[0])
    b = int(l[2])
    op = l[1]
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    else:
        break;


Measured memory_bytes: 5592
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int W = in.nextInt(), H = in.nextInt(),
            x = in.nextInt(), y = in.nextInt(), r = in.nextInt();
        
        if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
            System.out.println("Yes");
        }
        else  System.out.println("No");
    }
}


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

using ll = long long;
using namespace std;
vector<int> a;
int cnt = 0;
int n;


void dfs(int depth, ll cur)
{
    if(depth == n){
        cnt += (cur % 2 == 0);
        return;
    }

    dfs(depth + 1, cur * (a[depth] + 1));
    dfs(depth + 1, cur * (a[depth]));
    dfs(depth + 1, cur * (a[depth] - 1));
}




int main()
{
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    dfs(0,1);
    cout << cnt << endl;

}

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

int main(){
int H,W;
  cin>>H>>W;
  char S[H][W];
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){ 
   cin>>S[i][j]; }}
  
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
     if(S[i][j]=='#'){cout<<'#';}
     else{
      int count=0;
        for(int k=-1; k<=1; k++){ // 探索の可動範囲の指定
         for(int p=-1; p<=1; p++){
          int tx=i+k, ty=j+p;
           if(0<=tx && tx<H && 0<=ty && ty<W && S[tx][ty]=='#'){
            count++;}
         }}
     cout<<count;} 
   }
    cout<<endl;
  }   
  
}

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

#define getNum(i) scanf("%d", &(i))
#define MODULO 1000000007l
#define INF 100000000
#define FOR(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;

int main() {

#ifdef CONTEST
    freopen("input.in", "r", stdin);
#endif
    IOS
    int n;
    cin >> n;
    vector<int> a(n);
    FOR(i,0,n-1) cin >> a[i];
    int ans = 0;
    FOR(i,0,n-1) {
        if (a[i] == i+1) {
            int len = 0;
            while (i+len < n && a[i+len] == i+len+1) len++;
            ans += (len+1)/2;
            i += len-1;
        }
    }
    cout << ans << endl;


}

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

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

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

	int minCost = INT_MAX;
	for (int i = -100; i < 101; ++i) {
		int cost = 0;
		for (size_t t = 0; t < vec.size(); ++t) {
			cost += pow(vec[t] - i, 2);
		}

		minCost = min(cost, minCost);
	}

	cout << minCost << endl;
	return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int x, y;
            ReadInt(out x, out y);

            int answer = Score(x) + Score(y) + (x == 1 && y == 1 ? 400000 : 0);
            Console.WriteLine(answer);
        }

        static int Score(int value)
        {
            switch (value)
            {
                case 1:
                    return 300000;
                case 2:
                    return 200000;
                case 3:
                    return 100000;
                default:
                    return 0;
            }
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

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

int main() {
  int r,g,b; cin >> r >> g >> b;
  
  if ((g * 10 + b) % 4 ==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
	int n;cin>>n;
	int t,a;cin>>t>>a;
	vector<int> h(n);
	int ansnum=-1;;
	int ansd=-1;
	for(int i=0;i<n;i++){
		cin>>h[i];
		int d=1000*a-(1000*t-h[i]*6);
		if(d<0)d*=-1;
		if(ansd>d){
			ansnum=i;
			ansd=d;
		}
		if(ansnum==-1){
			ansnum=i;
			ansd=d;
		}

	}
	cout<<ansnum+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
const int N=1e5 + 5;
 
mi mp;
int n;
int k;
 
int check(int x)
{
	while(x>0)
	{
		int f= x%10;
		if(mp[f]>=1)
		{
			return 0;
		}
		x=x/10;
	}
	return 1;
}
 
int32_t main()
{
	IOS;
	cin >> n >> k;
	rep(i,1,k)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	int cur=n;
	while(1)
	{
		if(check(cur)==1)
		{
			cout << cur << endl;
			break;
		}
		cur++;
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)

using namespace std;

int main(){
    long long int x,ans=1;
    cin>>x;
    ans+=(x/11)*2-1;
    if((x-11*(x/11))>6){
        ans+=2;
    }
    else{
        if((x-11*(x/11))!=0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int sy[4] = { 0,1,0,-1 };

#define atcoder (int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

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

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

ll dp[100010] = { 0 };

int main(){
	
	int n;
	ll y;
	cin >> n >> y;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (n - i - j < 0)continue;
			if (i * 10000 + j * 5000 == y - (n - i - j) * 1000) {
				cout << i << ' ' << j << ' ' << n-i-j << endl;

				//system("pause");
				return 0;
			}
		}
	}

	cout << -1 << ' ' << -1 << ' ' << -1 << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.nextLine();

			int result = 0;
			for (char c : s.toCharArray()) {
				if (c == '+') {
					result++;
				} else {
					result--;
				}
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] s = new int[n];
        Arrays.fill(s , 0);
        for(int i = 0 ; i < k ; i++){
            int d = sc.nextInt();
            int[] a = new int[d];
            for(int j = 0 ; j < d ; j++){
                a[j] = sc.nextInt() - 1;
                s[a[j]]++;
            } 
        }
        sc.close();
        Arrays.sort(s);
        int yono = 0;
        while(s[yono] == 0){
            yono++;
        }
        System.out.println(yono);
    }
}

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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int maximum = 0, minus = 0;
    for (int i = 1; i <= n; i++) {
        sum += i;
        
        if (sum >= n) {
            maximum = i;
            minus = sum - n;
            break;
        }
    }
    
    for (int i = 1; i <= maximum; i++) {
        if (i == minus) continue;
        cout << i << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int a[3];

int main(void)
{
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	
	if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES";
	else cout << "NO";
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int w,h,x,y,r;
    int rx,ry,jx,jy;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if (x < 0 || y < 0)  printf("No\n");
    else if ((float)x >= (float)w/2 && (float)y >= (float)h/2){
        rx = w - x;
        jx = (rx >= r);
        ry = h - y;
        jy = (ry >= r);
        if (jx == 1 && jy == 1) printf("Yes\n");
        else printf("No\n");
    }
    else if ((float)x >= (float)w/2){
         rx = w - x;
        jx = (rx >= r);
        ry = y;
        jy = (ry >= r);
        if (jx == 1 && jy == 1) printf("Yes\n");
        else printf("No\n");
    }
    else if ((float)y >= (float)h/2){
        rx = x;
        jx = (rx >= r);
        ry = h - y;
        jy = (ry >= r);
        if (jx == 1 && jy == 1) printf("Yes\n");
        else printf("No\n");
    }
    else {
        rx = x;
        jx = (rx >= r);
        ry = y;
        jy = (ry >= r);
        if (jx == 1 && jy == 1) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;
using P = pair<ll, ll>;

int main(){
  ll n, m;
  cin >> n >> m;
  vector<P> ab(n);
  rep(i, n){
    ll a, b;
    cin >> a >> b;
    ab[i] = P(a, b);
  }
  sort(ab.begin(), ab.end());
  ll num = 0;
  ll ans = 0;
  ll x = 0;
  while(1){
    if (num + ab[x].second >= m){
      ans += ab[x].first * (m - num);
      break;
    }
    else{
      num += ab[x].second;
      ans += ab[x].first * ab[x].second;
      x++;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4844
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	string s;	
	cin >> s;

	if(s[0] == 'S')
		cout << "Cloudy";
	else if(s[0] == 'C')
		cout << "Rainy";
	else
		cout << "Sunny";

}	

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c,x,jshq=0,ybzzh;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                ybzzh=i*500+j*100+k*50;
                if(ybzzh==x)
                    jshq++;
                if(ybzzh>x)
                    break;
            }
        }
    }
    cout<<jshq<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const ll MOD = (ll)1e9 + 7LL;
const int MAX_N = (int)1e5 + 5;

ll cnt[26];

int main()
{
	memset(cnt, 0LL, sizeof(cnt));

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll N; cin >> N;
	string S; cin >> S;

	rep (i, N){
		++cnt[(int)(S[i] - 'a')];
	} // end rep

	ll res = 1LL;
	rep (i, 26){
		res = res * (cnt[i] + 1LL);
		res %= MOD;
	} // end rep

	res = (res + MOD - 1LL) % MOD;
	cout << res << endl;
 
	return 0;
}

Measured memory_bytes: 512
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define s(x) x.size()

using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e5+2;
const ll mod = 1e9+7;

bool cmp(pair<string,int> a, pair<string,int> b){
	if(a.first < b.first)
	return true;
	else if(a.first == b.first){
		return a.second > b.second;
	}else{
		return false;
	}
}


void solve(){
	int n; cin >> n;
	vector<pair<string,int>> v;
	map<pair<string,int>,int> mapp;;
	for(int i = 1; i <= n; i++){
		string s; cin >> s;
		int a; cin >> a;
		v.push_back(mp(s,a));
		mapp[v[i-1]] = i;
	}
	sort(all(v),cmp);
	for(int i = 0; i < s(v); i++){
		cout << mapp[v[i]] << endl;
	}
}

int main(){ 
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}


Measured memory_bytes: 256
// B - 81
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	rp(i, 1, 10){
		rp(j, 1, 10){
			if(i*j == N){
				cout<< "Yes" <<endl;
				return 0;
			}
		}
	}
	cout<< "No" <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  int X;
  cin >> X;
  LL ret = X / 500 * 1000;
  X %= 500;
  ret += X / 5 * 5;
  cout << ret << endl;
}

Measured memory_bytes: 256
d=int(input())
c=list(map(int,input().split()))
c_days=[0]*26
c_days_2=[0]*26
fir_ans=0
sec_ans=0
for i in range(d):
    s=list(map(int,input().split()))
    #最大満足度を選択
    n=s.index(max(s))
    c_days_2[n]=i+1
    if i==0:
        nn=s.index(max(s))
    else:
        #最小不満を選択
        c_low=[c[x]*(i+1-c_days[x]) for x in range(26)]
        #print(*c_low)
        nn=c_low.index(max(c_low))
        sec_ans+=s[nn]
        c_days[nn]=i+1

    for l in range(26):
        los=c[l]*(i+1-c_days[l])
        sec_ans-=los

        los=c[l]*(i+1-c_days_2[l])
        fir_ans-=los

    if fir_ans>=sec_ans:
        print(n+1)
        sec_ans=fir_ans
        c_days_2=c_days
    else:
        print(nn+1)
        fir_ans=sec_ans
        c_days=c_days_2


Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <queue>
using namespace std;

int N, M;
int DP[100000][11];
vector<vector<int>>E;
void ColorChange(int v, int d, int  c) {
	if (DP[v][d] == 0) {
		DP[v][d] = c;
	}
	else return;
	if (d == 0)return;

	for (int i = d - 1; i >= 0;i--) {
		ColorChange(v, i, c);
	}

	for (int i = 0; i < E[v].size(); i++) {
		if (DP[E[v][i]][d - 1] == 0)ColorChange(E[v][i], d - 1, c);
	}
}

int main()
{
	cin >> N >> M;
	E.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	int q; cin >> q;
	vector<tuple<int, int, int>>query;
	for (int i = 0; i < q; i++) {
		int v, d, c; cin >> v >> d >> c;
		v--;
		query.push_back(make_tuple(v, d, c));
	}

	for (int i = q - 1; i >= 0; i--) {
		int v, d, c;
		tie(v, d, c) = query[i];

		ColorChange(v, d, c);
	}

	for (int i = 0; i < N; i++) {
		cout << DP[i][0] << endl;
	}

	return 0;
}

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

int main(){

  long long int ans,a,b,c,d,e,n;
  ans = 0;
  cin >> n >> a >> b >> c >> d >> e;

  ans = (n + min({a,b,c,d,e})-1)/min({a,b,c,d,e}) + 4;

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

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
broken = set(A)
mod = 1000000007

unreachable = False
for i in range(M-1):
    if A[i+1] - A[i] == 1:
        unreachable = True
        break

pat = [0]*(N+2)
pat[0] = 1
if unreachable:
    print(0)
else:
    for i in range(N):
        if i in broken:
            continue
        pat[i+1] = (pat[i+1] + pat[i]) % mod
        pat[i+2] = (pat[i+2] + pat[i]) % mod
    print(pat[N])


Measured memory_bytes: 13216
import bisect

n=int(input())
l=list(map(int, input().split())) 
l.sort()
count=0

for i in range(n-1):
    for j in range(i+1,n):
        index=bisect.bisect_left(l,l[i]+l[j])
        count+=index-j-1
print(count)


Measured memory_bytes: 42972
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    xs = list()
    ys = list()
    hs = list()

    # See:
    # https://beta.atcoder.jp/contests/abc112/submissions/3360331
    # https://img.atcoder.jp/abc112/editorial.pdf
    # https://www.youtube.com/watch?v=CURWJ1Dr44A
    for i in range(n):
        xi, yi, hi = map(int, input().split())
        xs.append(xi)
        ys.append(yi)
        hs.append(hi)

        # Record a position satisfying the task conditions.
        if hi > 0:
            pos = i

    for cx in range(100 + 1):
        for cy in range(100 + 1):
            is_consistent = True
            candidate_height = abs(xs[pos] - cx) + abs(ys[pos] - cy) + hs[pos]

            for i in range(n):
                each_height = max(candidate_height - abs(xs[i] - cx) - abs(ys[i] - cy), 0)

                if hs[i] != each_height:
                    is_consistent = False
                    break

            if is_consistent:
                print(cx, cy, candidate_height)
                exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

struct P3
{
    double x, y, z;
    P3() : x(0), y(0), z(0){}
    P3(double x, double y, double z) : x(x), y(y), z(z) {}
    P3 operator-(const P3 &p) const
	{
		return P3(x-p.x, y-p.y, z-p.z);
    }
};

double norm(const P3 &p)
{
    return(p.x * p.x + p.y * p.y + p.z * p.z);
}

void solve()
{
	double nt1, nt2, et1, et2;
	const double R = 6378.1;
    while(cin >> nt1 >> et1 >> nt2 >> et2)
	{
		if(nt1 == -1 && nt2 == -1 && et1 == -1 && et2 == -1) 
		{
			break;
		}
		nt1 = nt1 / 360 * 2 * M_PI;
		et1 = et1 / 360 * 2 * M_PI;
		nt2 = nt2 / 360 * 2 * M_PI;
		et2 = et2 / 360 * 2 * M_PI;
		
		P3 p1 = P3(cos(nt1) * cos(et1), cos(nt1) * sin(et1), sin(nt1));
		P3 p2 = P3(cos(nt2) * cos(et2), cos(nt2) * sin(et2), sin(nt2));
		double d = norm(p1 - p2);
		double th = acos((2 - d) / 2);
		cout << (int)(R * th + 0.5) << endl;
    }
}

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

Measured memory_bytes: 1272
using System;

namespace ABC178B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = long.Parse(input[0]);
            var b = long.Parse(input[1]);
            var c = long.Parse(input[2]);
            var d = long.Parse(input[3]);

            var answer = a * c;
            answer = Math.Max(answer, b * c);
            answer = Math.Max(answer, a * d);
            answer = Math.Max(answer, b * d);
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27520
#include<iostream>

using namespace std;

int par[40000];
int bit[40000];
int xx[100001],yy[100001];
bool bx[100001],by[100001];

int find(int x){
  return (x==par[x])?x:par[x]=find(par[x]);
}

void unite(int a,int b){
  int r=find(a);
  bit[r]|=bit[find(b)];
  par[find(b)]=r;
}

int main(){
  int N,W,H;
  cin>>N>>W>>H;
  for(int i=0;i<N;i++){
    par[i]=i;
    int x,y;
    cin>>x>>y;
    bit[i]=(x==1)|(x==W)<<1|(y==1)<<2|(y==H)<<3;
    if(!bx[x]++){
      xx[x]=i;
    }else{
      unite(xx[x],i);
    }
    if(!by[y]++){
      yy[y]=i;
    }else{
      unite(yy[y],i);
    }
  }
  int ans=N*2;
  for(int i=0;i<4;i++){
    int p=0,c=0;
    for(int j=0;j<N;j++){
      if(find(j)==j){
	p++;
	c+=bit[j]>>i&1^1;
      }
    }
    ans=min(ans,(p==1)?N-1:c+N-1);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2448
n,m=map(int,input().split())

# input順,県P,Y年,P内通し番号
city_list=[]
for i in range(m):
    p,y=map(int,input().split())
    city_list.append([i,p,y])

city_list=sorted(city_list,key=lambda x:(x[1],x[2]))

city=city_list[0][1]
count=0
for i in range(m):
    if city == city_list[i][1]:
        count+=1
    else:
        city = city_list[i][1]
        count=1
    city_list[i].append(count)

city_list=sorted(city_list,key=lambda x:(x[0]))

for id in city_list:
    print(str(id[1]).zfill(6) + str(id[3]).zfill(6))

Measured memory_bytes: 36248
//abc109_a.cpp
//Sat Sep  8 20:56:44 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a,b;
	cin >> a >> b;

	int flag = 0;
	for (int i=1;i<=3;i++){
		if ((a*b*i)%2==1){
			flag = 1;
		}
	}
	if (flag == 1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
//	printf("%.4f\n",ans);
}

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

class Program
{
    static void Main(string[] args)
    {
        char[] input = Console.ReadLine().ToCharArray();
        bool flag = true;
        for(int i = 0; i < input.Length-1; i++)
        {
            if (input[i] == input[i + 1]) { flag = false; }
        }
        if (flag) { Console.WriteLine("Good"); }
        else { Console.WriteLine("Bad"); }
    }
   
}


Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define cq(i,s,n) for(int i=s;i<=n;i++)
using namespace std;
const double eps=1e-12;
struct Point{
    double x,y;
}a[500005];
Point o;
int n; 
double ri;
double dis(Point a,Point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 
}

void tt(Point p1,Point p2,Point p3){
    double a,b,c,d,e,f;
    a=p2.y-p1.y;
    b=p3.y-p1.y;
    c=p2.x-p1.x;
    d=p3.x-p1.x;
    f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
    e=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
    o.x=(a*f-b*e)/(2*a*d-2*b*c);
    o.y=(d*e-c*f)/(2*a*d-2*b*c);
    ri=dis(o,p1);
}

int main(){
    scanf("%d",&n);
    cq(i,1,n){
        scanf("%lf%lf",&a[i].x,&a[i].y);
    }
    random_shuffle(a+1,a+n+1);
    o=a[1];ri=0;
    cq(i,2,n){
        if(dis(a[i],o)>ri+eps){
            o=a[i];ri=0;
            cq(j,1,i-1){
                if(dis(o,a[j])>ri+eps){
                    o.x=(a[i].x+a[j].x)/2;
                    o.y=(a[i].y+a[j].y)/2;
                    ri=dis(o,a[j]);
                    cq(k,1,j-1){
                        if(dis(o,a[k])>ri+eps){
                            tt(a[i],a[j],a[k]);
                        }
                    }
                }
            }
        }
    }
    printf("%.10lf",ri);
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a > b)swap (a,b);
    if(b > c)swap (c,b);
    if(a > b)swap (a,b);
    
    
    if(a == b && b != c || b == c && b != a) cout << "Yes" << endl; 
    
    else cout << "No" << endl; 
    
    return 0;
}


Measured memory_bytes: 3572
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from collections import deque

class SegTree():
    def __init__(self, n):
        self.value = [0 for i in range(n*2)]

MOD = 10 ** 9 + 7

def getinvmod(n):
    return [pow(i, MOD-2, MOD) for i in range(n+1)]


def main():
    n = getN()
    nums = getList()
    index = [-1 for i in range(n)]

    for i, num in enumerate(nums):
        if index[num - 1] == -1:
            index[num - 1] = i
        else:
            ida = i
            idb = index[num - 1]
            break

    side = n - (ida - idb)

    invmod = getinvmod(n+1)

    # print(invmod)
    #
    # print([(i * iv) % MOD for i, iv in enumerate(invmod)])
    ans = n + 1
    minus = 1
    print((ans - minus)%MOD)
    # print(side, ida, idb,"side")
    for i in range(1, n + 1):
        ans *= (n - i + 1)
        ans *= invmod[i + 1]
        ans %= MOD
        if i <= side:
            minus *= side - i + 1
            minus *= invmod[i]
            minus %= MOD

        else:
            minus = 0

        print((ans - minus) % MOD)
        # print(ans, minus)



if __name__ == "__main__":
    main()

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[202020],Y[202020];
vector<int> Ys;
pair<int,int> P[202020];

template<class V,int NV> class SegTree_1 {
public:
	vector<V> val;
	static V const def=1LL<<60;
	V comp(V l,V r){ return min(l,r);};
	
	SegTree_1(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=comp(v,val[entry]); //上書きかチェック
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_1<ll,1<<20> stp,stm;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		P[i]={X[i],i};
		Ys.push_back(Y[i]);
	}
	sort(ALL(Ys));
	sort(P,P+N);
	ll ret=0;
	FOR(i,N) {
		x=P[i].second;
		y=lower_bound(ALL(Ys),Y[x])-Ys.begin();
		
		ll a=stp.getval(0,y+1);
		ret=max(ret,X[x]+Y[x]-a);
		a=stm.getval(y,N+1);
		ret=max(ret,X[x]-Y[x]-a);
		stp.update(y,X[x]+Y[x]);
		stm.update(y,X[x]-Y[x]);
	}
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 40184
n = gets.to_i
as = gets.split.map(&:to_i)
evens = []
odds  = []
as.map.with_index { |e, i| i.even? ? evens << e : odds << e }
if n.odd?
  puts (evens.reverse + odds).join(" ")
else
  puts (odds.reverse + evens).join(" ")
end


Measured memory_bytes: 27640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include <string.h>
#include <math.h>

using namespace std;

int n;
int f[100][10] = {}, p[100][11] = {};
long long res = -10000000000;

void cal(int *_st) {
	int st[10], c=0;
	for (int i = 0; i < 10; i++) {
		st[i] = _st[i];
		if (st[i] == 1)c++;
	}
	if (c == 0)return;


	long ret = 0;
	for (int i = 0; i < n; i++) {
		int tmp = 0;
		for (int j = 0; j < 10; j++) 
			if (st[j] == 1 && f[i][j] == 1)tmp++;
		ret += p[i][tmp];
	}
	if (ret > res)res = ret;
}


void d(int *_st, int no) {
	int st1[10], st2[10];
	for (int i = 0; i < 10; i++) {
		st1[i] = _st[i];
		st2[i] = _st[i];
	}

	if (no > 9) {
		cal(st1);
		return;
	}
	d(st1, no+1);
	st2[no] = 1;
	d(st2, no+1);
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> f[i][j];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 10; j++)
			cin >> p[i][j];
	}

	int st[10] = {};
	d(st, 0);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 1e3 + 10;
int arr[MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    int sum = 0;
    for(int i = 0; i  <n; i ++) {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    for(int i = 0; i < k; i ++) {
        sum += arr[i];
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3640
#include <stdio.h>
int main(void){
  int A,B;
  int C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  int i;
  while(A>0){
    C=C-B;
    if(C<=0){
      printf("Yes\n");
      return 0;
    }
    else{
      A=A-D;
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1632
#include <bits/stdc++.h>
using namespace std;
using XY = array<int, 2>;

int getMaxLength(XY start, const vector<string>& S){
    int H = S.size();
    int W = S.front().size();
    using XYZ = array<int,3>;
    queue<XYZ> q;
    q.push(XYZ{start[0], start[1], 0});
    set<XY> used;
    used.insert(start);
    int vmax = 0;
    while(!q.empty()){
        auto v = q.front(); q.pop();
        vmax = max(vmax, v[2]);

        vector<XY> candidates = {
            XY{v[0], v[1]+1},
            XY{v[0], v[1]-1},
            XY{v[0]+1, v[1]},
            XY{v[0]-1, v[1]},
        };
        for(auto cand : candidates){
            if(cand[0] <  0) continue;
            if(cand[0] >= H) continue;
            if(cand[1] <  0) continue;
            if(cand[1] >= W) continue;
            if(used.count(cand) > 0) continue;
            if(S[cand[0]][cand[1]] == '#') continue;
            q.push(XYZ{cand[0], cand[1], v[2]+1});
            used.insert(XY{cand[0], cand[1]});
        }
    }
    return vmax;
}

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin >> S[i];
    }
    int res=0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') continue;
            res = max(res, getMaxLength(XY{i, j}, S));
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;
ll a[51];

bool Check_single(ll t){
	ll need = 0;
	for(int i=1; i<=n; ++i){
		ll p = a[i];
		p += t;
		p -= (n-1);
		if(p <= 0) continue;
		need += (p + n) / (n+1);
	}
	return need <= t;
}

bool Check(ll t){
	for(int i=0; i<n; ++i) if(Check_single(t+i)) return 1;
	return 0;
}

int main()
{
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> a[i];
	ll l=-1, r=ll(1e18);
	while(l+1<r){
		ll mid=(l+r)/2;
		(Check(mid)?r:l)=mid;
	}
	for(int i=0; i<n; ++i) if(Check_single(r+i)){
		cout << r+i << endl;
		break;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#include <iostream>
#include <deque>
using namespace std;
#define reg register
#define LL long long
#define INF 0x3f3f3f3f
#define max(a, b) (a > b ? a : b)

template<typename T>
void re (T &x){
    x = 0;
    int f = 1;
    char c = getchar ();
    while (c < '0' || c > '9'){
        if (c == '-') f = -1;
        c = getchar ();
    }
    while (c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + c - 48;
        c = getchar ();
    }
    x *= f;
}

template<typename T>
void pr (T x){
    if (x < 0){
        putchar ('-');
        x = ~x + 1;
    }
    if (x / 10) pr (x / 10);
    putchar (x % 10 + 48);
}

int m, d, tot;

int main (){
    re (m); re (d);
    for (int i = 1; i <= m; i++){
        for (int j = 1; j <= d; j++){
            int d1 = j % 10, d10 = j / 10;
            if (d1 >= 2 && d10 >= 2 && d1 * d10 == i)
                tot ++;
        }
    }
    pr (tot);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = len(str(N))
T = ["7","5","3"]
ans = 0
for s in range(3,S+1):
    for i in range(3**s):
        A = []
        n = i
        for j in range(s):
            A.append(n%3)
            n//=3
        if len(set(A))<3:continue
        k = "".join([T[a] for a in A])
        if int(k)<=N:ans+=1
print(ans)

Measured memory_bytes: 3188
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = InputNumList();
            WriteLine((a[0] - 1) * (a[1] - 1));
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



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

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

LL A[51];
vector<pii> ans;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    for(int i = 1; i <= n; ++i)
        cin>>A[i];
    int mi = 0, ma = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(A[mi]>A[i])
            mi = i;
        if(A[ma]<A[i])
            ma = i;
    }
    if(ma && abs(A[ma])>=abs(A[mi]))
    {
        for(int i = 2; i <= n; ++i)
        {
            while(A[i]<A[i-1])
            {
                A[i] += A[ma];
                ans.emplace_back(ma, i);
                if(A[i]>A[ma])
                    ma = i;
            }
        }
    }
    else if(abs(A[mi])>A[ma])
    {
        for(int i = n-1; i >= 1; --i)
        {
            while(A[i]>A[i+1])
            {
                A[i] += A[mi];
                ans.emplace_back(mi, i);
                if(A[i]<A[mi])
                    mi = i;
            }
        }
    }
    cout<<ans.size()<<endl;
    for(pii i:ans)
        cout<<i.first<<' '<<i.second<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

AC=0
WA=0
TLE=0
RE=0

for i in range(N):
  judge=input()
  
  if judge == "AC":
    AC = AC + 1
  if judge == "WA":
    WA = WA + 1
  if judge == "TLE":
    TLE = TLE + 1
  if judge == "RE":
    RE = RE + 1

    
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))


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

using ll = long long;

const int N = 200005;

int n;
ll a[N], b[N], r;

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%lld", a + i);
        b[n + 1 - i] = a[i];
    }
    partial_sum(a + 1, a + n + 1, a + 1);
    partial_sum(b + 1, b + n + 1, b + 1);
    r = a[n];
    for(int i = 2; i <= n - 2; i++){
        int x = int(lower_bound(a + 1, a + i + 1, (a[i] + 1) / 2) - a);
        int y = int(lower_bound(b + 1, b + (n - i) + 1,
            (b[n - i] + 1) / 2) - b);
        for(int j = 0; j < 2; j++) for(int k = 0; k < 2; k++){
            auto t = minmax({a[x - j], a[i] - a[x - j],
                b[y - k], b[n - i] - b[y - k]});
            r = min(r, t.second - t.first);
        }
    }
    printf("%lld\n", r);
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>                          
using namespace std;    
long long ans,n,a,x,c,e,g;
int main(){
	cin>>n;
	if(n>777777753) n=777777753;
	for(int i=357;i<=n;i+=2)
	{
		a=i;
		int f=0;
		c=0;
		e=0;
		g=0;
		while(a>0)
		{
			x=a%10;
			if(x!=3&&x!=5&&x!=7) {f=1;break;}
			else 
			{
				if(x==3) c++;
				if(x==5) e++;
				if(x==7) g++;
			}
			a/=10;
		}
		if(f==0&&c>0&&e>0&&g>0) ans++;
	}
	cout<<ans;
	return 0;
}

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

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    int cnt1 = 0,cnt0 = 0;
    int tonari = 0;
    for(int i = 0; i < n; i++){
        int g;
        cin >> g;
        if(g == 0) cnt0++;
        else cnt1++;
        if(cnt0 <= w-2 && cnt0 == cnt1) tonari++;
        else if(cnt0 >= w && cnt0 <= w+h-2 && cnt0 == cnt1+2) tonari++;
        else if(cnt0 >= w+h-1 && cnt0 <= 2*w+h-3 && cnt0 == cnt1+4) tonari++;
    }
    cout << tonari << '\n';
    return 0;
}


Measured memory_bytes: 3112
H,W,K=map(int, input().split())
m=[[0] * W for i in range(H)]
for i in range(H):
	row = str(input())
	m[i]=list(row)

ans=0

for i in range(2 ** H):
	mpart = []
	for j in range(H):
		if ((i >> j) & 1):
			mpart.append(m[j])
	
	for k in range(2 ** W):
		m2=[]
		for l in range(W):
			if ((k >> l) & 1):
				for _ in range(len(mpart)):
					m2.append(mpart[_][l])
		
		
		if m2.count("#")==K:
			ans+=1


print(ans)



# 2darray 

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;


void solve()
{
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	cout << ceil(double(N - 1) / (K - 1)) << endl;
}

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

Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define ll long long

const unsigned long long MAXN = int(1e5) + 5;
const ll INF = (1e18);

vector< vector<int> > g(MAXN, vector<int>());
int in_degree[MAXN], dp[MAXN];
bool was[MAXN];

void dfs(int v) {
    assert(!was[v]);
    was[v] = 1;
    for (int to : g[v]) {
        dp[to] = max(dp[to], dp[v] + 1);
        in_degree[to] --;
        if (in_degree[to] == 0)
            dfs(to);
    }
}

int main(){
    int n,m;cin >> n >> m;
    while (m --) {
        int u,w;cin >> u >> w;
        g[u].push_back(w);
        in_degree[w] ++;
    }
    for (int i = 1;i <= n;i ++) {
        if (!was[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }
    int ans = 0;
    for (int i = 1;i <= n;i ++) {
        ans = max(ans, dp[i]);
    }
    cout << ans;
    return 0;
}

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

int a[100010];

int main() {
	int n;
	scanf("%d",&n);
	for (int i = 0; i < n; i++) scanf("%d",&a[i]);
	sort(a,a+n);
	printf("%d ",a[n-1]);
	int min2 = a[n-1]+1, ans2 = -1;
	for (int i = 0; i < n-1; i++)	
		if (abs(a[i]*2-a[n-1]) < min2) {
			ans2 = a[i];
			min2 = abs(a[i]*2-a[n-1]);
		}
	printf("%d\n",ans2);
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
	final int MOD = 1000000007;
	final int INF = 1000000000;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int cnt = 0;
		for(int i = 0; i < n; ++i){
			int a = Integer.parseInt(sc.next());
			if(isPrime(a)) ++cnt;
		}
		sc.close();
		System.out.println(cnt);
	}
	
	public static boolean isPrime(int x){
		if(x < 2) return false;
	    if(x == 2) return true;
	    if(x % 2 == 0) return false;
	    for(int i = 3; i * i <= x; i += 2)
	        if(x % i == 0) return false;
	    return true;
	}
	
}



Measured memory_bytes: 41756
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let ans = v.iter().sum::<i64>() - v.iter().max().unwrap();
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2156
import java.util.*;
public class Main {

	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		int dp[]=new int[n+1];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
		}
		dp[1]=Math.abs(arr[0]-arr[1]);
		for(int i=2;i<n;i++)
		{
			int opt1=dp[i-2]+Math.abs(arr[i-2]-arr[i]);
			int opt2=dp[i-1]+Math.abs(arr[i]-arr[i-1]);
		//	System.out.println(opt1+" "+opt2);
			dp[i]=Math.min(opt1, opt2);
		}
		System.out.println(dp[n-1]);
	}
}


Measured memory_bytes: 60196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

vector<int> g[200005];
int ans[200005];
bool visited[200005];

void dfs(int from, int to) {
    if (visited[to]) return;
    visited[to] = true;
    if (from != -1) ans[to] += ans[from];
    for (int i : g[to]) {
        dfs(to, i);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    rep(i, 0, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(-1, 0);
    rep(i, 0, n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 20608
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const ll N = 1e16 + 10;

bool check(ll a, ll b);
int digit_sum(ll x);

int main() {
	fast_cin();
	int k; cin >> k;
	ll inc = 1, i = 1;
	while (k--) {
		cout << i << '\n';
		while (!check(i + inc, i + inc * 10)) {
			inc *= 10;
		}
		i += inc;
	}
}

bool check(ll a, ll b) {
	ll sa = digit_sum(a);
	ll sb = digit_sum(b);
	return (a * sb <= b * sa);
}

int digit_sum(ll x) {
	int ans = 0;
	while (x) {
		ans += x % 10;
		x /= 10;
	}
	return ans;
}

Measured memory_bytes: 256
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    
    for h in range(H) :
        if h == 0 or h == H-1 :
            print("#" * W)
        else :
            print("#", "." * (W-2), "#", sep="", end="")
            print()
    print()


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  string s1=s.substr(0,2);
  string s2=s.substr(2,2);
  int a=stoi(s1);
  int b=stoi(s2);
  if (a < 13 && b < 13 && 0 < a && 0 < b) cout << "AMBIGUOUS" << endl;
  else if ( a < 13 && 0 < a) cout << "MMYY" << endl;
  else if (b < 13 && 0 < b) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  return 0;
}
  
  

Measured memory_bytes: 256