akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;

const int inf = 1e9;
const ll inf64 = 1e18;

const int K = 40;

int main() {

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, T;

    cin >> n >> T;

    vector<int> a(n + 1), b(n + 1), perm(n), bs;

    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        perm[i - 1] = i;
        if (a[i] == 0) {
            bs.push_back(b[i]);
        }
    }

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

    sort(perm.begin(), perm.end(), [&](int i, int j) {
        return 1ll * a[j] * (b[i] + 1) < 1ll * a[i] * (b[j] + 1);
    });

    vector<vector<int>> dp(n + 1, vector<int>(K, T + 1));

    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        int I = perm[i - 1];
        for (int j = 0; j < K; j++) {
            dp[i][j] = dp[i - 1][j];
            if (a[I] > 0 && j > 0) {
                int tmp = (int) min(1ll + T, 1ll * (dp[i - 1][j - 1] + 1) * (a[I] + 1) + b[I]);
                dp[i][j] = min(dp[i][j], tmp);
            }
        }
    }

    int res = 0;

    for (int j = 0; j < K; j++) {
        int tmp = j;
        int cur = dp[n][j];
        for (int bi : bs) {
            if (cur + 1 + bi <= T) {
                cur += 1 + bi;
                tmp++;
            }
        }
        if (cur <= T)
            res = max(res, tmp);
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 42616
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;



int main() {
    double r;
    double PI =3.141592653589;
  cin >>r;
  
   printf("%lf %lf \n" ,PI*r*r,PI*2*r);
}


Measured memory_bytes: 3296
program abc049c
    use,intrinsic :: iso_fortran_env
    implicit none
    character(100000):: s
    character(:),allocatable:: dream, dreamer, erase, eraser
    integer(int32):: i

    read*, s
    dream = 'dream'
    dreamer = 'dreamer'
    erase = 'erase'
    eraser = 'eraser'

    if (dfs(s)) then
        print'(a)', 'YES'
    else
        print'(a)', 'NO'
    end if
contains
    recursive function dfs(s) result(ret)
        character(*):: s
        logical:: ret
        ret = .false.
        if (trim(s) == '') then
            ret = .true.
            return
        end if

        if (s(1:5) == dream) ret = ret .or. dfs(s(6:))
        if (s(1:7) == dreamer) ret = ret .or. dfs(s(8:))
        if (s(1:5) == erase) ret = ret .or. dfs(s(6:))
        if (s(1:6) == eraser) ret = ret .or. dfs(s(7:))
    end function
end program abc049c

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807

//演算の定義
auto query = [](ll x, ll y) { return x+y; };
//単位元
const ll unit = 0;
struct SegTree
{
private:
  ll n;
  vector<ll> node;

public:
  SegTree(vector<ll> v)
  {
    node.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, unit); //最小値なので残りはINFで埋める
    n = 1LL << 64 - __builtin_clzll(v.size());
    for (ll i = 0; i < v.size(); i++)
      node[i + n - 1] = v[i]; //最下段から構築
    for (ll i = n - 2; i >= 0; i--)
      node[i] = query(node[2 * i + 1], node[2 * i + 2]);
  }

  void update(ll x, ll val)
  {
    x += (n - 1);  // 最下段index
    node[x] += val; //valを加算などするときは+=
    while (x > 0)
    {
      x = (x - 1) / 2;
      node[x] = query(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  // 要求区間 [a, b) 中の要素の最小値を答える k := 自分がいるノードのインデックス 対象区間は [l, r) にあたる
  ll getmin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1)
  {
    // 最初に呼び出されたときの対象区間は [0, n)
    if (r < 0)
      r = n;
    // 要求区間と対象区間が交わらない -> 適当に返す
    if (r <= a || b <= l)
      return unit;
    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    if (a <= l && r <= b)
      return node[k];
    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    ll vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    return query(vl, vr);
  }
};

int main()
{
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
ll n , q ;
cin >> n >> q ;

vector<ll> t(n);
SegTree s(t);
rep(i,q){
  ll a , b , c ;
  cin >> a >> b >> c ;
  if(a==0)s.update(b, c);
  else cout << s.getmin(b, c+1) << endl;
}
return 0;
}



Measured memory_bytes: 6552
#include <iostream>
#include <cassert>
using namespace std;
#define N (8)
#define FREE (-1)
#define NOT_FREE (1)

int row[N],col[N],drops[2*N-1],dneg[2*N-1];

bool X[N][N];

void initialize(){
    for(int i=0;i<N;i++){
        row[i]=FREE;col[i]=FREE;
    }
    for(int i=0;i<2*N-1;i++){
        drops[i]=FREE;dneg[i]=FREE;
    }
}

void printBoard(){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(X[i][j]){
                if(row[i]!=j)return;
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cout<<((row[i]==j)?"Q":".");
        }
        cout<<endl;
    }
}

void recursive(int i){
    if(i==N){
        printBoard();return;
    }
    
    for(int j=0;j<N;j++){
        if(NOT_FREE==col[j]||NOT_FREE==drops[i+j]||NOT_FREE==dneg[i-j+N-1])continue;
        row[i]=j;col[j]=drops[i+j]=dneg[i-j+N-1]=NOT_FREE;
        recursive(i+1);
        row[i]=col[j]=drops[i+j]=dneg[i-j+N-1]=FREE;
        
    }
}

int main(void){
    initialize();
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            X[i][j]=false;
        }
    }
    
    int k;cin>>k;
    for(int i=0;i<k;i++){
        int r,c;cin>>r>>c;
        X[r][c]=true;
    }
    recursive(0);
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10000;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0,  0 };
static const int dy[] = { 0,  0, 1, -1 };

int dp[ 101 ][ 4 ][ 3 ];
int n, m, a, ans;
int ar[ 101 ] = {};
int solve( int now, int b, int d ) {
	if ( d == 3 ) {
		return 0;
	}
	if ( now == n ) {
		return 1;
	}
	if ( dp[ now ][ b ][ d ] >= 0 ) {
		return dp[ now ][ b ][ d ];
	}
	int res = 0;
	if ( ar[ now ] != 0 ) {
		if ( b == ar[ now ] ) {
			res = solve( now + 1, ar[ now ], d + 1 );
			res %= mod;
		}
		else {
			res = solve( now + 1, ar[ now ], 1 );
			res %= mod;
		}
	}
	else {
		for ( int i = 1; i <= 3; i++ ) {
			if ( b == i ) {
				res += solve( now + 1, i, d + 1 );
				res %= mod;
			}
			else {
				res += solve( now + 1, i, 1 );
				res %= mod;
			}
		}
	}
	return dp[ now ][ b ][ d ] = res;
}

int main() {
	scanf( "%d %d", &n, &m );
	memset( dp, -1, sizeof( dp ) );
	for ( int i = 0; i < m; i++ ) {
		scanf( "%d", &a );
		scanf( "%d", &ar[ a - 1 ] );
	}
	ans = solve( 0, 0, 0 );
	printf( "%d\n", ans );
	return 0;
}

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

int main()
{
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = K; i < N; i++)
  {
    if (A.at(i) > A.at(i - K))
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 4840
N, A, B, C, D = [int(i) for i in input().split(" ")]

set1, set2 = 0, 0
set1_v, set2_v = 0, 0

while set1 < N:
    set1 += A
    set1_v += B

while set2 < N:
    set2 += C
    set2_v += D

print(min(set1_v, set2_v))


Measured memory_bytes: 5604
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        int ans = 0;

        for (int i = 0; i < n; i++)
           p[i]=sc.nextInt();

        Arrays.sort(p);
        for (int i = 0; i < k; i++) ans+=p[i];

        System.out.println(ans);
    }
}


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

int main(){
	string s; cin >> s;
	if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3628
n = gets.chomp.to_i
hash = {}
n.times do
    tmp = gets.chomp.split("").sort.join("")
    if hash.has_key?(tmp)
        hash[tmp] += 1
    else
        hash[tmp] = 1
    end
end
ans = 0
hash.each do |k,v|
    ans += v * (v-1) / 2
end
puts ans

Measured memory_bytes: 18428
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

    N,K=map(int,input().split())
    L=sorted(list(map(int,input().split())),reverse=True)

    print(sum([L[i] for i in range(K)]))


resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int sievesize;
int exp(int a, int x){
    if (x == 0) return 1;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x & 1){
        p *= a;
        p %= mod;
    }
    return p;
}
bitset<1010> bs;
vector<int> primes;
void sieve(int upperbound){
    sievesize = upperbound+1;
    bs.set();
    bs[0] =bs[1] = 0;
    for (int i = 2; i < sievesize; i++) if (bs[i]){
        for (int j = i*i; j < sievesize; j += i) bs[j] = 0;
        primes.push_back(i);
    }
}
map<int,int> total;
map<int,int> ct[10005];
int a[10005];
int main(){
    int n;
    scanf("%d",&n);
    sieve(1005);
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
        int K = a[i];
        for (auto x : primes){
            if (x*x > a[i]) break;
            int cur = 0;
            while (K%x == 0){
                K/=x;
                cur++;
            }
            ct[i][x] = cur;
            total[x] = max(total[x],cur);
        }
        if (K != 1){
            ct[i][K] = 1;
            total[K] = max(total[K],1);
        }
    }
    ll cur = 1;
    for (auto x : total){
        //printf("%d %d\n",x.first,x.second);
        cur *= exp(x.first,x.second);
        cur %= mod;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++){
        ll k = cur;
        for (auto x : ct[i]){
            k *= exp(exp(x.first,x.second),mod-2);
            k %= mod;
        }
        ans += k;
        ans %= mod;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 79872
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int d[2010][2010];
int ans[2010];
int main()
{
	int N, X, Y;
	cin >> N >> X >> Y;
	X--; Y--;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int num = mod;
			num = min(j - i, abs(X - i) + 1 + abs(j - Y));
			ans[num]++;
		}
	}
	for (int i = 1; i < N; i++) {
		cout << ans[i] << endl;
	}
}

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

int main(void){
  char s[10];
  int i;
  scanf("%s",s);
  for(i=0;i<strlen(s)-1;i++) if(s[i]=='A' && s[i+1]=='C') break;
  if(i==strlen(s)-1) printf("No\n");
  else printf("Yes\n");
  return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const ll mod=1000000007;
int d[100010];

int main(void){
	int n,t;
	cin >> n >> t;
	rep(i,n) cin >> d[i];
	sort(d,d+n);

	ll sum=1;
	for(int i=1;i<n;++i){
		ll cur=lower_bound(d,d+n,d[i]-t)-d;
		sum=(sum*(i-cur+1))%mod;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1560
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = 998244353;

int N;

signed main()
{
	cin >> N;
	vi a(N);
	rep(i, N) cin >> a[i];

	int mx = 0;

	int sum = 0;
	
	rep(i, N) {
		sum += a[i] - 1;
	}

	cout << sum << endl;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int count = 0;
        for(int i = 0; i < N; i++){
            int s = Integer.parseInt(sc.next());
            while(s % 2 == 0){
                s = s/2;
                count++;
            }
        }
       
        System.out.println(count);
    
    }
}

Measured memory_bytes: 31940
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A_num = len(A)
B_num = len(B)
Ali = [0]
Bli = [0]
sumA = 0
sumB = 0
for a in range(A_num):
  sumA += A[a]
  Ali.append(sumA)
for b in range(B_num):
  sumB += B[b]
  Bli.append(sumB)
b_start = 0
time = 0
ans = 0
Bli.reverse()
for i in range(A_num+1):
  for j in range(b_start,B_num+1):
    time = Ali[i] + Bli[j]
    if time <= K:
      #print("i:",i,"j:",(B_num - j),"time:",time)
      b_start = j
      ans = max(ans,i+(B_num - j))
      break
print(ans)

Measured memory_bytes: 49044
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;

int main() {
    
    string S;
    cin >> S;
    
    int ans = S.size();
    
    for ( int i = 0; i < 2; i++){
        
        int cnt = 0;
        
        for (int j = 0; j < S.size(); j++){
            // (char)(0 + ' 0') -> '0';
            // (char)(1 + ' 0') -> '1';
            
            if( j % 2 == 0 && S[j] != (char)(i + '0')) cnt++;
            if( j % 2 == 1 && S[j] == (char)(i + '0')) cnt++;
        }
        
        ans = min(ans, cnt);
    }
    cout <<ans << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007
ll dp[3001][3001];
int main()
{
	int N, T;
	cin >> N >> T;
	pairs(K);
	fx(N) {
		pairsp(K);
	}
sorts(K)
	fx(N+1) {
		fy(T+1){
			dp[x][y] = -1;
		}
	}
	dp[0][0] = 0;
	fx(N) {
		dp[x + 1][T] = max(dp[x][T], dp[x + 1][T]);
		fy(T) {
			dp[x + 1][y] = max(dp[x][y], dp[x + 1][y]);
			if (dp[x][y]>=0) {
				if (y+K[x].first<T) {
					dp[x + 1][y + K[x].first] =max( dp[x][y] + K[x].second, dp[x + 1][y + K[x].first]);
				}
				else {
					dp[x + 1][T] =max( dp[x][y] + K[x].second, dp[x + 1][T]);
				}
			}
		}
	}

	ll ans = 0;
	fx(T+1) {
		ans = max(ans, dp[N][x]);
	}
	ce(ans)

    return 0;
}



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

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

int main()
{
    int h, w; cin>>h>>w;
    vector<string> s(h);
    for(auto& e: s) cin>>e;

#define rep(i, n) for(int i=0; i<n; ++i)
    int res=0;
    rep(sr, h) rep(sc, w) if (s[sr][sc]=='.')
    rep(gr, h) rep(gc, w) if (s[gr][gc]=='.') {
        queue<pair<int, int>> q;
        vector<vector<int>> v(h, vector<int>(w, -1));
        q.emplace(sr, sc);
        v[sr][sc]=0;
        while (!q.empty()) {
            auto p=q.front(); q.pop();
            int r=p.first;
            int c=p.second;
            int d=v[r][c];
            if (r==gr and c==gc) {
                res=max(res, d);
                break;
            }
            for(int i=0; i<4; ++i) {
                int nr=r+dr[i];
                int nc=c+dc[i];
                if (nr<0 or nr>=h or nc<0 or nc>=w) continue;
                if (s[nr][nc]=='#' or ~v[nr][nc]) continue;
                q.emplace(nr, nc);
                v[nr][nc]=d+1;
            }
        }
    }
    cout<<res<<endl;
}


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

int a[110];
multiset<int> s;

int main() {
	ios_base::sync_with_stdio(0);
  	int n, m; cin >> n;
  	for (int i=0;i<n;i++) {
    	int x; cin >> x;
      	s.insert(x);
    }
  	cin >> m;
  	for (int i=0;i<m;i++) {
    	int x; cin >> x;
      	auto t = s.find(x);
      	if (t==s.end()||*t!=x) {
        	cout << "NO\n";
            return 0;
        }
      	s.erase(t);
    }
  	cout << "YES\n";
}

Measured memory_bytes: 13028
#include<stdio.h>

void swap(int *x, int *y){
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    if((a < c && c < b) || (a == c && b > a)){
        swap(&b, &c);
    }
    else if((b < a && a < c) || (a == c && b < a)){
        swap(&a, &b);
    }
    else if(c < a && a < b){
        swap(&b, &c);
        swap(&a, &b);
    }
    else if(b < c && c < a){
        swap(&a, &b);
        swap(&b, &c);
    }
    else if((c < b && b < a) || (a == b && c < a) || (b == c && c < a)){
        swap(&a, &c);
    }

    printf("%d %d %d\n", a, b, c);
    
    return 0;
}


Measured memory_bytes: 2060
N=int(input())
travel=[[0,0,0]]+[ list(map(int,input().split(' '))) for i in range(N) ]
ans='Yes'
for i in range(N):
  dt = travel[i+1][0]-travel[i][0]
  dx = abs(travel[i+1][1]-travel[i][1])
  dy = abs(travel[i+1][2]-travel[i][2])
  if dx+dy<=dt and (dx+dy)%2==dt%2:
    continue
  else:
    ans='No'
    break
print(ans)

Measured memory_bytes: 28092
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) {
	try {
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
			String input;
			input = buf.readLine();
			
			String[] strAry = input.split(" ");
		       int W = Integer.parseInt(strAry[0]);
		       int H = Integer.parseInt(strAry[1]);
		       int x = Integer.parseInt(strAry[2]);
		       int y = Integer.parseInt(strAry[3]);
		       int r = Integer.parseInt(strAry[4]);
		       
		     if(0 > (x - r) || (x + r) > W){
		    	 	System.out.println("No");    	 	
		     }
		     else if(0 > (y - r) || (y +r) > H){
		    	 	System.out.println("No");
		     }
		     else{
		    	 System.out.println("Yes");
		     }
		     
	} catch (Exception e) {
		// TODO: handle exception
	}
}
}

Measured memory_bytes: 24404
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.numeric;
import std.math;
import std.typecons;
import std.functional;

const MOD = 1000000000 + 7;

class FermatCombination {
	long factrial[]; //階乗を保持
	long inverse[];  //逆元を保持
	
	this(int size) {
		factrial = new long[size + 1];
		inverse = new long[size + 1];
		factrial[0] = 1;
		inverse[0] = 1;
		
		for (int i = 1; i <= size; i++) {
			factrial[i] = (factrial[i - 1] * i) % MOD;  //階乗を求める
			inverse[i] = pow(factrial[i], MOD - 2) % MOD; // フェルマーの小定理で逆元を求める
		}
	}
	
	long combine(int n, int k) {
		return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
	}
	
	long pow(long x, int n) { //x^n 計算量O(logn)
		long ans = 1;
		while (n > 0) {
			if ((n & 1) == 1) {
				ans = ans * x % MOD;
			}
			x = x * x % MOD; //一周する度にx, x^2, x^4, x^8となる
			n >>= 1; //桁をずらす n = n >> 1
		}
		return ans;
	}
}

alias Vector = Tuple!(int, "x", int, "y");

void main() {
  int X, Y; readf("%d %d\n", &X, &Y);
  if (min(X, Y) * 2 < max(X, Y)) {
    writeln(0);
    exit(0);
  }

  int stepSize = 0;
  auto destination = Vector(X, Y);
  foreach(n; 1..666667) {
    auto base = Vector(2*n, n);
    auto diff = Vector(destination.x - base.x, destination.y - base.y);
    if (diff.x == -diff.y) {
      stepSize = n;
      break;
    }
  }

  if (stepSize == 0) {
    writeln(0);
    exit(0);
  }

  auto position = X - stepSize;
  writeln(new FermatCombination(stepSize).combine(stepSize, position));
}


Measured memory_bytes: 15100
// In The Name Of God
#include<bits/stdc++.h>
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define err(i) cerr << #i << " : " << i << "\n"
#define pb push_back
#define ll long long
using namespace std;

const int MAXN = 1e5+22 ;

ll x,y;

int main()
{
	cin>>x>>y;
	if(abs(x-y)>1) cout<<"Alice";
	else cout<<"Brown";
	
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

lli gcd(lli x, lli y)
{
       if(x<y)swap(x,y);
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	vector<lli> lg(n),rg(n);

	lg[0]=a[0],rg[n-1]=a[n-1];
	REP(i,1,n)lg[i] = gcd(lg[i-1],a[i]);
	for(lli i=n-2;i>=0;i--)rg[i]=gcd(rg[i+1],a[i]);

	if(DEBUG){
		REP(i,0,n){
			cout<<"lg="<<lg[i]<<" rg="<<rg[i]<<endl;
		}
	}

	lli ans = max(lg[n-2],rg[1]);

	REP(i,1,n-1){
		ans = max(ans,gcd(lg[i-1],rg[i+1]));
	}
	cout<<ans<<endl;

	return 0;
}

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

int main() {
  int n,m;
  cin >> m >> n;
  string s[n];
  int x=0,y=0;
  for(int i=0; i<n; i++) {
    cin >> s[i];
    for(int j=0; j<m; j++) {
      if(s[i][j]=='W') y++;
    }
  }
  int a=0,b=1,M=y;
  for(int j=0; j<m; j++) {
    for(int i=0; i<n; i++) {
      if(s[i][j]=='W') y--;
      else x++;
    }
    if(x+y<M) {
      M=x+y;
      a=j+1;
      b=j+2;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 2700
#include<stdio.h>
int i, s, t;
char b[200010];
int main(){
    scanf("%s",b);
    for(i=0;b[i]!='\0';i++){
        if(b[i]=='S'){
            t++;
        }else{
            if(t==0){
                s++;
            }else{
                t--;
            }
        }
    }
    printf("%d",s+t);
}

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

int main() {
  int N;
  string color;
  cin >> N;
  
  for(int i=0; i<N; i++){
    cin >> color;
    
    if(color=="Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i==N-1 && color != "Y"){
      cout << "Three" << endl;
    }

  }
  cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define LEN 7

struct node{
  int key;
  struct node *parent, *left, *right;
};

typedef struct node node;
typedef struct node * nodepointer;

void insert(int);
void inorder(nodepointer);
void preorder(nodepointer);
nodepointer find(int);
void delete(nodepointer);
nodepointer getSuccessor(nodepointer);
nodepointer getMinimum(nodepointer);

nodepointer root;

int main(){
  int n, k;
  int i;
  char com[LEN];

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf(" %s", com);
    if(com[0] == 'i'){
      scanf("%d", &k);
      insert(k);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0] == 'f'){
      scanf("%d", &k);
      if(find(k) == NULL) printf("no\n");
      else printf("yes\n");
    }
    else{
      scanf("%d", &k);
      if(find(k) != NULL) delete(find(k));
    }
  }

  return 0;
}

void insert(int k){
  nodepointer x, y, z; //zが新しく挿入するノード

  z = (nodepointer)malloc(sizeof(node));
  //zの設定　zは葉だからleft,rightはnullでok
  z -> key = k;
  z -> left = NULL;
  z -> right = NULL;

  x = root; //たどる際のスタートは根
  y = NULL; //yはxの親
  //xがnullになるまでたどる。このときyはxの直前のノード、つまりxの親であり葉ノードである。
  while(x != NULL){
    y = x;
    if(z -> key < x -> key) x = x -> left;
    else x = x -> right;
  }
  z -> parent = y;

  //rootがnullのときwhile回らずにyはnullのまま
  //つまり、木が空っぽのときyはnull
  if(y == NULL) root = z;
  else if(z -> key < y -> key) y -> left = z;
  else y -> right = z;
}

void inorder(nodepointer n){
  if(n == NULL) return;
  inorder(n -> left);
  printf(" %d", n -> key);
  inorder(n -> right);
}

void preorder(nodepointer n){
  if(n == NULL) return;
  printf(" %d", n -> key);
  preorder(n -> left);
  preorder(n -> right);
}

nodepointer find(int k){
  nodepointer n;
  n = root;
  while(n != NULL && n -> key != k){
    if(k < n -> key) n = n -> left; //nのkeyの方が大きければ探したいkeyは左にある
    else n = n -> right; //nのkeyの方が小さければ探したいkeyは右にある
  }
  return n;
}

void delete(nodepointer z){
  nodepointer x, y; //yを削除するノードとする
  if(z -> left != NULL && z -> right != NULL) y = getSuccessor(z); //zの子2つ
  else y = z; //zの子1or0

  //yの子xを決める
  //子がいないときはxにNULLが入る
  if(y -> left != NULL) x = y -> left; //yに左の子がいればxを左の子に
  else x = y -> right; //yに右の子がいればxを右の子に

  //xの親を設定
  if(x != NULL) x -> parent = y -> parent;

  //yが根のときxを根に設定
  if(y -> parent == NULL) root = x;

  //yが左の子ならxも左の子に
  else if(y == y -> parent -> left) y -> parent -> left = x;

  //yが右の子ならxも右の子に
  else y -> parent -> right = x;

  //zの次節点が削除されたらyのkeyをzにコピー
  if(y != z) z -> key = y -> key;

  free(y);
}

nodepointer getSuccessor(nodepointer n){
  nodepointer y; //yはnの親

  //右の子がいるとき、右の部分木でキーが最小の節点が次節点
  if(n -> right != NULL) return getMinimum(n -> right);

  //親を辿っていき、『「最初に出てきた左の子である節点」の親』が次節点
  y = n -> parent;
  while(y != NULL && n == y -> right){
    n = y;
    y = y -> parent;
  }

  return y;
}

//ひたすら左の子を辿れば、nを根とする部分木のなかで最小のキーを持つ節点を見つけられる
nodepointer getMinimum(nodepointer n){
  while(n -> left != NULL) n = n -> left;
  return n;
}



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



int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
    int kind,a,b;
    while(cin >> kind){
        if(kind == 1){
            cout << "Hello World" << endl;
        } else {
            cin >> a >> b;
            cout << (a+b) << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    map<LL,LL> L;
    LL tmp;
    int N;cin >> N;
    rep(i,N){
        cin >> tmp;
        L[tmp]++;
    }  
    LL ans = 0;
    for(auto itr = L.begin();itr != L.end();itr++){ 
        LL key = itr -> first;
        LL value = itr -> second;
        if(key > value)ans += value;
        else ans += value - key;
    }
    cout << ans << endl;
}


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

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

	for(int i=0;i<=s.size()-1;i++)
	{
		if(s[i]!=t[i])
		{
			cout << "No";
			return 0;
		} 
	} 
	
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3528
#include<stdio.h>
int main()
{
	int a[10][10],i,j,s,N,flag=0;
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			s=i*j;
			a[i][j]=s;
		}
	}
	scanf("%d",&N);
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			if(a[i][j]==N)
			flag=1;
		}
	}
	if (flag==1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
f = False
for i in range(N-M+1):
  if f:
    break
  for j in range(N-M+1):
    if f:
      break
    match = True
    for k in range(M):
      if not match:
        break
      for l in range(M):
        if not match:
          break
        if A[i+k][j+l] != B[k][l]:
          match = False
    if match:
      f = True

if f:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<array>
#include<list>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<functional>
#include<memory>
#include<random>
#include<sstream>
#include<iomanip>
#include<thread>

using namespace std;

using ll = unsigned long long;

using vec = vector<int>;
using mat = vector<vec>;


int main()
{
	int N, A, B;
	cin >> N >> A >> B;

	int x=0, y=0, z=0;

	for (int i = 0; i < N; ++i)
	{
		int P; cin >> P;

		if (P <= A)
		{
			x++;
		}
		else if (P <= B)
		{
			y++;
		}
		else
		{
			z++;
		}
	}

	int min = x;
	if (min > y)min = y;
	if (min > z)min = z;

	cout << min << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char s[10000];
int main()
{
    int x, i, r, a;
    scanf("%d", &x);
    scanf("%s", &s);
    int n = strlen(s);
    r = x%26;
    if(r>0)
    {
        x = r;
    }
    for(i=0; i<n; i++)
    {
        a = s[i] + x;
        if(a>90)
            s[i] = (a%90) + 64;
        else
            s[i] = s[i] + x;
        printf("%c", s[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

const int MAX_N=1000000;

typedef long long ll;

using namespace std;

ll n,dat[2*MAX_N-1];

void init(int n_){
	n=1;
	while(n<n_)n*=2;
}

void update(int k,ll a){
	k+=n-1;
	dat[k]=a;
	
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[2*k+1],dat[2*k+2]);
	}
}

ll query(int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	else {
		ll vl=query(a,b,k*2+1,l,(l+r)/2);
		ll vr=query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

int main(void){
	
	ll in,m,ans=0;
	
	cin >> m;
	
	init(m);
	
	for(int i=0;i<m;i++){
		cin >> in;
		update(in,in+query(1,in+1,0,0,n));
		ans=max(ans,dat[in+n-1]);
	}
	//cout << m*(m+1)/2-query(1,m+1,0,0,n) << endl;
	cout << m*(m+1)/2-ans << endl;
	
	return 0;
}

Measured memory_bytes: 2744
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back

using namespace std;
typedef pair<ll,ll> pll;

ll n ,q;
ll s[200005] , t[200005] , x[200005];
ll D[200005];
typedef pair<ll,ll> pll;
vector< pair<pll, ll> > eve;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n >> q;
        eve.clear();
        for(ll i=1;i<=n;i++) {
                cin >> s[i] >> t[i] >> x[i];
                s[i] -= x[i];
                t[i] -= x[i];
                eve.pb(make_pair( make_pair(s[i],t[i])  , x[i]));
        }
        //sort(eve.begin(), eve.end());
        //for(auto &i : eve) cout << " " << i.first.first <<  " " << i.first.second << " " << i.second << endl;
        vector< pair<pll,ll> > ee;
        for(ll i=0;i<eve.size();i++){
                ee.pb(make_pair(make_pair(eve[i].first.first, 1) , eve[i].second));
                ee.pb(make_pair(make_pair(eve[i].first.second, -1), eve[i].second));
        }
        sort(ee.begin() , ee.end());
        //for(auto &i : ee) cout << " " << i.first.first <<  " " << i.first.second << " " << i.second << endl;
        multiset<ll> ans;
        ll ptr = 0;
        for(ll i=1;i<=q;i++) {
                ll x;
                cin >> x;
                while(ptr < ee.size() && ee[ptr].first.first <= x){
                        if(ee[ptr].first.second == 1) ans.insert(ee[ptr].second);
                        else ans.erase(ans.find(ee[ptr].second));

                        ptr++;
                }
                if(ans.size()>0) cout << *ans.begin() << "\n";
                else cout << "-1\n";
        }
        return 0;
}


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

public static class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var max = 0;
        var cur = 0;
        for (int i = 0; i < N; i++)
        {
            var D = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (D[0] == D[1])
            {
                cur++;
                max = Math.Max(cur, max);
            }
            else
            {
                cur = 0;
            }
        }

        Console.WriteLine(max >= 3 ? "Yes" : "No");
    }
}

Measured memory_bytes: 28308
import Data.Array
import Data.List

main = do
    n <- read <$> getLine :: IO Int
    ns <- listArray ((1,1), (2,n)) . map read . words <$> getContents :: IO (Array (Int, Int) Int)
    print $ dp ns

dp :: Array (Int, Int) Int -> Int
dp ns = memo!(1,1)
    where
    (_,(_,xe)) = bounds ns
    memo = array ((1,1),(2,xe)) [((y,x), f y x)|x<-reverse [1..xe],y<-[2,1]]
    f y x
        | y==2 && x==xe = ns!(2,xe)
        | y==2          = memo!(2,x+1) + ns!(2,x)
        | y==1 && x==xe = memo!(2,xe)  + ns!(1,xe)
        | otherwise     = max (memo!(y,x+1)) (memo!(y+1,x)) + ns!(y,x)

    

Measured memory_bytes: 1020
#include<stdio.h>
#include<stdlib.h>

int main(){

int s;
scanf("%d",&s);
int a[200];
a[0] = s;

for (int i = 1; i <= 200; i++)
{
  if (a[i-1]%2==0)
  {
    a[i] = a[i-1]/2;
  }else
  {
    a[i] = a[i-1]*3+1;
  }
  
  if (i%100==0)
  {
    for (int j = i-100; j < i-1; j++)
    {
      for (int k = j+1; k <= j+100; k++)
      {
        if(a[k] == a[j]){
          printf("%d",k+1);
          exit(0);
        }
      }
    }
  }
}

return 0;

}


Measured memory_bytes: 1736
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int n;
    cin >> n;
    vi cook(n), sufficient(n, 0), additional_sufficient(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> cook[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> sufficient[i];
    }
    for (int i = 0; i < n - 1; ++i) {
        cin >> additional_sufficient[i];

    }
    int ans = 0;

    for (int i = 0; i < n; ++i) {
        ans += sufficient[cook[i] - 1];
        if (i < n - 1 && cook[i] + 1 == cook[i + 1]) {
            ans += additional_sufficient[cook[i] - 1];
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
H,W=map(int, input().split())

S=[input() for _ in range(H)]

ans =[]

for i in range(H):
    s = ''
    for j in range(W):
        if S[i][j] != '#':
            cnt = 0
            for k in range(-1, 2):
                for m in range(-1, 2):
                    col = i + k
                    row = j + m
                    if (col < 0 or row < 0 or col > H-1 or row > W-1) or (k == 0 and m == 0):
                        continue
                    else:
                        if S[col][row] == '#':
                            cnt += 1
            s += str(cnt)
        else:
            s += '#'
    ans.append(s)

for i in range(H):
    print(ans[i])



Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int n = in.nextInt();
            int s = in.nextInt();
            int[] data = in.na(n);
            for (int l = 1; l <= n; l++) {
                int m = l * (s - 1) + 1;
                if (m >= n) {
                    out.println(l);
                    return;
                }


            }


        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = nextInt();
            }
            return k;
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21588
#include <iostream>
using namespace std;
int main(void){
    int n,x;
     
    while(true){
        cin>>n>>x;
        if(n==0&&x==0)  break;
        else{
            int sum=0;
            int i,j,k,A;
            for(i=1;i<=n-2;i++){
                for(j=i+1;j<=n-1;j++){
                    for(k=j+1;k<=n;k++){
                      A=i+k+j;
                      if(A==x)   sum=sum+1;
                       
                    }
                }
            }
            cout<<sum;
            cout<<endl;
        }
    }
}


Measured memory_bytes: 3116
using System;

class Problem {
    public static void Call(int n) {
        for (var i = 1; i <= n; i++) {
            var x = i;
            if (x % 3 == 0) {
                Console.Write(" " + i);
                continue;
            }
            while (x != 0) {
                if (x % 10 == 3) {
                    Console.Write(" " + i);
                    break;
                }
                x /= 10;
            }
        }
        Console.WriteLine();
    }
    
    public static void Main() {
        var n = int.Parse(Console.ReadLine());
        Call(n);
    }
}


Measured memory_bytes: 9332
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, K;
  cin >> N >> K;
  vector<long> data(N), memo(N, -1);
  for(int i = 0; i < N; i++)cin >> data.at(i);
  long pl = 0, count = 0;
  while(memo.at(pl) == -1){
    memo.at(pl) = count;
    count++;
    pl = data.at(pl) - 1;
    if(count == K){
      cout << pl + 1 << endl;
      return 0;
    }
  }
  K -= memo.at(pl);
  K %= count - memo.at(pl);
  for(long i = 0; i < K; i++){
    pl = data.at(pl) - 1;
  }
  cout << pl + 1 << endl;
  return 0;
}


Measured memory_bytes: 6428
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

def mod_inv(a):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, M
  while z1 != 1:
    d, m = divmod(z2, z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1%M

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  return g

def sum_grundy(grundy):
  sum_g = [defaultdict(int, {0:B_sum}) for i in range(3)]
  W, prev = B, 1
  for i in range(1, N+1):
    for s, g in zip(sum_g, grundy):
      if i in g:
        if prev != i:
          W, prev = W * pow(B, i-prev, M) % M, i
        s[g[i]] =  (s[g[i]] + W) % M
        s[0] =  (s[0] - W) % M
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

N = int(input())
M = 998244353
B = pow(10, 18, M)
B_sum = (pow(B, N+1, M) - B) * mod_inv(B-1) % M

edge = [read_edge() for i in range(3)]
grundy = list(map(calc_grundy, edge))
sum_g = sum_grundy(grundy)
ans = 0
for gx, sx in sum_g[0].items():
  for gy, sy in sum_g[1].items():
    gz = gx^gy
    if gz in sum_g[2]:
      ans = (ans + sx*sy*sum_g[2][gz]) % M
print(ans)


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	map<string,int> M;
	REP(i,N){
		M[in<string>()]++;
	}
	int K=0;
	for(auto& x:M){
		K = max(K,x.second);
	}
	map<string,int> L;
	for(auto& x:M){
		if(x.second==K) L.emplace(x);
	}
	for(auto& x:L){
		out(x.first);
	}
	return 0;
}


Measured memory_bytes: 36352
from collections import Counter
def f(n):
    if n<2:
        return 0
    return n*(n-1)//2
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = 0
for c in cnt.values():
    ans += f(c)

for a in A:
    print(ans-cnt[a]+1)

Measured memory_bytes: 34060
#include<iostream>
#include<algorithm>
using namespace std;
long long int dp[3000][3000];
long long int game(int b,int e,int chance,long long int a[]){
	if(e==b){
		if(chance%2)
		return 0;
		return a[e];
	}
	if(chance%2){
		long long int f=game(b+1,e,chance+1,a);
		long long int s=game(b,e-1,chance+1,a);
		if(f<s)
		return f;
		return s;
	}
	if(dp[b][e]==-1)
	dp[b][e]=max(game(b+1,e,chance+1,a)+a[b],game(b,e-1,chance+1,a)+a[e]);
	return dp[b][e];
}
int main(){
	int n;cin>>n;
	long long int sum=0,a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];sum=sum+a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
		dp[i][j]=-1;
	}
	cout<<2*game(0,n-1,0,a)-sum;
}

Measured memory_bytes: 70784
#include<iostream>
#include<cstdio>

using namespace std;

int x, ans, a, b;

int main() {
	cin >> x;
	a = x / 500;
	b = (x - a * 500) / 5;
	ans = a * 1000 + b * 5;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

char s[100005];

int main()
{
    scanf("%s", s);
    int len = strlen(s);
    for(int i = 0; i < len; i += 2)
    {
        printf("%c", s[i]);
    }
    return 0;
}


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

using namespace std;

const int MOD = 1e9 + 7;

int cnt[30];

int main() {
	int n; string s; cin >> n >> s;
	for (int i = 0; i < n; ++i) cnt[s[i] - 'a']++;
	int answer = 1;
	for (int i = 0; i < 26; ++i) {
		answer = 1ll * answer * (cnt[i] + 1) % MOD;
	}
	cout << (answer - 1 + MOD) % MOD << "\n";
	return 0;
}


Measured memory_bytes: 1020