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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = true;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

int main(int argc, char const* argv[])
{
	LL a,b;
	cin >> a >> b;
	map<LL ,LL> mp;
	LL lmax = sqrt(max(a,b)) + 1;
	for (LL i = 1; i <= lmax; i++) {
		if (a%i == 0) {
			if (b%i == 0 and isPrime(i)) {
				mp[i]++;
			}
			if (b%(a/i) == 0 and isPrime(a/i)) {
				mp[a/i]++;
			}
		}
		if (b%i == 0) {
			if (a%(b/i) == 0 and isPrime(b/i)) {
				mp[b/i]++;
			}
		}
	}
	cout << mp.size() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  long long n;
  std::cin >> n;

  long long x = 1;
  long long res1, res2;
  while (x * x <= n) {
    if (n % x == 0) {
      res1 = x;
      res2 = n / x;
    }
    x += 1;
  }

  std::cout << res1 + res2 - 2 << std::endl;

  return 0;
}


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

int main(){
  int n,p=0,w=0,g=0,y=0;
  string s;
  
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> s;
    if(s=="P" && p==0){
      p++;
    }else if(s=="W" && w==0){
      w++;
    }else if(s=="G" && g==0){
      g++;
    }else if(s=="Y" && y==0){
      y++;
    }
  }
  int t=p+w+g+y;
  
  if(t==4){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 10**9
while r - l > 1:
  m = (l + r) // 2
  s = 0
  for x in a:
    s += (x - 1) // m
  if s <= k:
    r = m
  else:
    l = m
print(r)


Measured memory_bytes: 30840
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	cout<<(n * n * n)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans = INF;
    ll now = 0;
    for(int i=0;i<=2*max(x,y);i++){
        if(i%2!=0) continue;
        now = 0;
        now += i*c;
        ll aa = x - i/2, bb = y-i/2;
        if(aa<0) aa = 0;
        if(bb<0) bb = 0;
        now+=a*aa+b*bb;
        ans = min(ans,now);
    }
        cout<<ans<<endl;
    

    return 0;
}

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

int main() {
 int n;
 cin>>n;
 vector<int> x(n);
 rep(i,n){
   cin>>x[i];
 }
 int min_h=100000000;
 rep(i,100){
   int h=0;
   rep(j,n){
     h+=(x[j]-i)*(x[j]-i);
   }
   min_h=min(min_h,h);
 }
 cout<<min_h<<endl;
}

Measured memory_bytes: 256
N,M,C = map(int, input().split())

B=list(input().split())
count = 0
result = C
for _ in range(N):
	A = list(input().split())
	for i in range(M):
		result += int(A[i]) * int(B[i])
	if result > 0:
		count+=1
	result = C

print(count)

Measured memory_bytes: 3064
#include <stdio.h>

#define  MID  500000
#define   N   1000000
#define INFTY 2000000000

void mergeSort(int*,int,int);
void merge(int*,int,int,int);

int count=0;

int main(){
  int i;
  int n;
  int A[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);  
  }

  mergeSort(A,0,n);

  for(i=0;i<n-1;i++){
  printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",count);
  
  return 0;
}

void mergeSort(int *A,int left,int right){
  int mid;
  
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

void merge(int *A,int left,int mid,int right){

  int i;
  int j;
  int k;
  int n1 = mid - left;
  int n2 = right - mid;
  int L[MID];
  int R[MID];
  
  for(i=0;i<n1;i++){
    L[i] = A[left+i];
  }
  
  for(j=0;j<n2;j++){
    R[j] = A[mid+j];
  }
    L[n1] = INFTY;
    R[n2] = INFTY;
    
    i = 0;
    j = 0;
    
  for(k=left;k<right;k++){
    if(L[i] <= R[j]){
      A[k]=L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
    }
    count++;
  }
}

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

using namespace std;

double dp[3010][3010];

int main() {
	int n;
	cin >> n;
	vector<double> p(n);
	for(int i = 0; i <= n; i++) {
		if(i!=n) cin >> p[i];
		for(int j = 0; j <= n; j++) {
			dp[i][j] = 0;
			if(i == 0 and j == 0) dp[i][j] = 1;
		}
	}
	// dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
	for(int i = 1; i <= n; i++) {
		dp[i][0] = dp[i-1][0]*(1-p[i-1]);
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			dp[i+1][j+1] = dp[i][j+1]*(1-p[i]) + dp[i][j]*p[i];
		}
	}
	
	double proba = 0;
	for(int i = 1; i <= n; i++)
		if(i > n/2) proba += dp[n][i];

	printf("%.10f\n", proba);
}


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

bool  kaibunn (string S) {
  int i;
  for (i = 0; i < S.length(); i++ ) {
  if (S[i] == S[S.length() - i - 1]) {
  continue;
  }
  else {
  return false;
  }
  }
  return true;
}

int main () {
string S;
cin >> S;
string substr = S.substr(0,(S.length() - 1) / 2);
if (kaibunn (S) && kaibunn (substr)) {
cout << "Yes" << endl;}
else {
cout << "No" << endl;}
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);

        char[] a = sc.next().toCharArray();
        String res = "Good";
        char prev = '#';
        for (int i =0;i<a.length;i++) {
            if (prev == a[i]) {
                res = "Bad";
                break;
            }
            prev = a[i];
        }

        out.println(res);
        out.flush();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep2(i,1,n+1){
        int num = to_string(i).length();
        if(num%2!=0) ans++;
    }
    
    cout << ans;
    
	return 0;
}

Measured memory_bytes: 3768
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

int *F;

int f(int n){
  if(n == 0 || n == 1){
    return F[n] = 1;
  }

  if(F[n] != 0){
    return F[n];
  }

  return F[n] = f(n - 2) + f(n - 1);
}

int main(){

  int n;

  cin >> n;

  F = new int[n + 1];

  for(int i = 0; i <= n; i++){
    F[i] = 0;
  }

  cout << f(n) << endl;


  return 0;
}



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

int main(){
    int n,max_num = -1000001,min_num = 1000001,temp;
    long long int sum = 0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&temp);
        sum += temp;
        max_num = max(max_num,temp);
        min_num = min(min_num,temp);
    }
    printf("%d %d %lld\n",min_num,max_num,sum);
}


Measured memory_bytes: 2768
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 2e2 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }

int main(){
    ll x, k, d;
    scanf("%lld%lld%lld",&x,&k,&d);
    x=abs(x);
    if(x/d>=k){
        printf("%lld\n",x-k*d);
        return 0;
    }
    k-=x/d;
    x%=d;
    ll y=abs(x-d);
    if(k&1) printf("%lld\n",y);
    else printf("%lld\n",x);
    return 0;
}
/*
*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


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

using namespace std;

int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if (2 * a < b) b = 2 * a;
  if (2 * b < c) c = 2 * b;
  if (2 * c < d) d = 2 * c;
  int n;
  scanf("%d", &n);
  long long ans = 1LL * (n / 2) * d;
  if (n % 2 == 1) {
    ans += c;
  }
  printf("%lld\n", ans);
}

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

const int N = 2e5 + 10, M = N;
int w[N];

bool vis[N];

int h[N], e[M], ne[M], idx;
void add(int a, int b) {
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
} 
int n, m;
int cnt;
void dfs(int u, int fa) {
	vis[u] = 1;
	int flag = 0;
	for(int i = h[u]; i != -1; i = ne[i]) {
		int v = e[i];
		if(w[v] >= w[u]) flag = 1;
		if(v == fa) continue;
		if(!vis[v]) dfs(v, u);
	}
	if(!flag) cnt++;
}


int main()
{
	idx = 0;
	memset(h, -1, sizeof h);
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d", &w[i]);
	for(int i = 1; i <= m; i++) {
		int a, b; scanf("%d%d", &a, &b);
		add(a, b), add(b, a);
	}
		
	for(int i = 1; i <= n; i++) {
		if(!vis[i]) dfs(i, 0);
	}

	printf("%d\n", cnt);
}

Measured memory_bytes: 8236
n = int(input())
v = [[0]+[]*(n+1) for i in range(n+1)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    v[a].append([b,c])
    v[b].append([a,c])

q,k = map(int,input().split())
l = [k]
while l:
    now = l.pop()
    for i in v[now][1:]:
        if v[i[0]][0] == 0:
            v[i[0]][0] = i[1]+v[now][0]
            l.append(i[0])
            
for i in range(q):
    x,y = map(int,input().split())
    print(v[x][0]+v[y][0])

Measured memory_bytes: 101988
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n = 0;
	int day = 0;
	int x = 0; 
	int i = 0;
	int dayscho[150];
	int thing = 0;
	for(i=0;i<=100;i++)
	{
		dayscho[i] = 0;
	}
	cin>>n>>day>>x;
	for(i=1;i<=n;i++)
	{
		cin>>thing;
		for(int j=0;j<=100;j++)
		{
			int add = (j*thing)+1;
			if(add>100)
			{
				break;
			}
			else
			{
			dayscho[add] += 1;
			}

		}
	}
		
	for(int h=0;h<=day;h++)
	{
		x = x + dayscho[h];
	}
	cout<<x;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#define int long long
#define N 1002
#define M 5002
using namespace std;
int head[N],ver[N],nxt[N],l;
int n,i,v[N],f[M],g[N];
int read()
{
	char c=getchar();
	int w=0;
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0'){
		w=w*10+c-'0';
		c=getchar();
	}
	return w;
}
void insert(int x,int y)
{
	l++;
	ver[l]=y;
	nxt[l]=head[x];
	head[x]=l;
}
void dp(int x)
{
	for(int i=head[x];i;i=nxt[i]){
		int y=ver[i];
		dp(y);
	}
	memset(f,0,sizeof(f));
	for(int i=head[x];i;i=nxt[i]){
		int y=ver[i];
		for(int j=v[x];j>=0;j--){
			int tmp=1<<30;
			if(j>=v[y]) tmp=min(tmp,f[j-v[y]]+g[y]);
			if(j>=g[y]) tmp=min(tmp,f[j-g[y]]+v[y]);
			f[j]=tmp;
		}
	}
	g[x]=1<<30;
	for(int i=0;i<=v[x];i++) g[x]=min(g[x],f[i]);
}
signed main()
{
	n=read();
	for(i=2;i<=n;i++){
		int fa=read();
		insert(fa,i);
	}
	for(i=1;i<=n;i++) v[i]=read();
	dp(1);
	if(g[1]!=1<<30) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	int mx=-1000000000,b=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mx=max(mx,a[i]);
		if(mx==a[i]){
			b=i;
		}
	}
	int sum=0;
	for(int i=0;i<n;i++){
		if(i!=b){
			sum=sum+a[i];
		}
	}
	if(a[b]>=sum){
		cout<<"No";
	}
	else{
		cout<<"Yes";
	}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
count = 0
only_even = True
while only_even:
  for i in range(n):
    if a[i] % 2 != 0:
      only_even = False
    
  if only_even == False:
    break

  for i in range(n):
    a[i] /= 2   
  count += 1

print(count)

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

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

  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == "AC")
      ac++;
    else if (s[i] == "WA")
      wa++;
    else if (s[i] == "TLE")
      tle++;
    else if (s[i] == "RE")
      re++;
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


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

int main(){
  int N;
  cin>>N;
  vector<int>a(N+1);
  vector<int>b(N+1,0);
  vector<int>c(N+1,0);
  
  for(int i=1;i<N+1;i++){
    cin>>a[i];
  }
  for(int i=N;i>=1;i--){
    if(a[i]==1 && b[i]%2==0){
      c[i]=1;
    }
    else if(a[i]==1 && b[i]%2==1){
      c[i]=0;
    }
    else if(a[i]==0 && b[i]%2==0){
      c[i]=0;
    }
    else if(a[i]==0 && b[i]%2==1){
      c[i]=1;
    }
    if(c[i]==1){
      for(int j=1;j*j<=i;j++){
        if(i%j==0){
          b[j]++;
          if(j*j!=i){
            b[i/j]++;
          }
        }
      }
    }
  }
  
  int ans=0;
  for(int i=1;i<=N;i++){
    if(c[i]==1){
      ans++;
    }
  }
  cout<<ans<<endl;  
  if(ans==0) return 0;
  int temp=ans;
  for(int i=1;i<=N;i++){
    if(c[i]==1 && temp!=1){
      cout<<i<<" ";
      temp--;
    }
    else if(c[i]==1 && temp==1){
      cout<<i<<endl;
    }
  }
  return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

ll N, K;
string s;
ll ans = 0;

void solve() {
    cin >> N >> K;
    int A[N];
    int idx = 0;
    rep(i,N) {
        cin >> A[i];
        if (A[i] == 1) idx = i;
    }
    ans = (idx + (K-1) - 1) / (K-1);
    //cout << ans << endl;
    if (idx+1 < K) idx = K-1;
    if (idx < N-1)
        ans += (N - idx - 1 + (K-1) - 1) / (K-1);
    cout << (N-1 + K-1 - 1) / (K-1) << endl;
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  string x;
  cin >> x;

  int ans = 0;
  stack<char> stk;

  for (int i = 0; i < x.size(); i++) {
    if (x[i] == 'S') {
      stk.push('S');

    } else if (x[i] == 'T') {
      if (!stk.empty()) {
        stk.pop();
      } else {
        ans++;
      }
    }
  }

  cout << ans + stk.size() << endl;
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  long long sum = 0;
  for(int i = 0; i < s.size(); i++){
    sum += s.at(i) - '0';
  }
  if(sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3748
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    int X;
    cin >> X;

    vector<int> m(N);
    for(int i = 0; i < N; i++) cin >> m.at(i);
    int sum = 0;
    for(int i = 0; i < N; i++) sum += m.at(i);

    int tmp = 1000;
    for(int i = 0; i < N; i++) tmp = min(tmp, m.at(i));

    while(X >= sum){
        sum += tmp;
        N++;
    }
    N--;
    cout << N << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const long long INF=(long long)0x3f3f3f3f3f3f3f3f;
const int MOD=(int)1e9+7;

int main()
{
    /*ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    //freopen("output.txt","w+",stdout);
    //freopen("input.txt","r+",stdin);
    int n,m;
    cin>>n>>m;
    cout<<(n<=8&&m<=8?"Yay! ":":( ");
    return 0;
}


Measured memory_bytes: 3600
n, k = map(int,input().split())
b = [False]*n
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        if b[a[j]-1]:
            continue
        b[a[j]-1] = True
print(b.count(False))

Measured memory_bytes: 9204
import math
a,b,h,m = str(input()).split()
_a = int(a)
_b = int(b)
arc_m = int(m)/60.0
arc_h = int(h)/12.0 + arc_m/12
_cos = math.cos(abs(arc_m - arc_h)*2*math.pi)
print(math.sqrt(_a**2 + _b**2 - 2*_a*_b*_cos))

Measured memory_bytes: 9472
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  
int l;
int k = 1;
while(cin>>l){
  
  if(l!=0){
  cout << "Case" << " "<<k <<":"<< " "<< l << endl;
  }
  k++;
}
  
  return 0;
}


Measured memory_bytes: 2984
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int BIG_INT = 1000000000;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int k;
	cin >> k;
	vector<int> a{ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	cout << a[k-1] << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    ll H,W,K;cin>>H>>W>>K;
    ll a[H][W];
    rep(i,H)rep(j,W){
        char c;cin>>c;
        a[i][j]=c-'0';
    }
    int ans=inf;
    rep(bit,1<<(H-1)){
        int p=__builtin_popcount(bit);
        int now=p;
        vvl cnt(p+1,vl(W));
        rep(j,W){
            int g=0;
            if(a[0][j])cnt[0][j]++;
            rep(i,H-1){
                if(bit>>i&1)g++;
                if(a[i+1][j])cnt[g][j]++;
            }
        }
        bool ch=0;
        rep(i,p+1)rep(j,W)if(cnt[i][j]>K)ch=1;
        if(ch)continue;
        vl num(p+1);
        rep(j,W){
            rep(i,p+1) num[i]+=cnt[i][j];
            bool f=0;
            rep(i,p+1) if(num[i]>K)f=1;
            if(f){
                now++;
                num=vl(p+1);
                rep(i,p+1) num[i]+=cnt[i][j];
            }
        }
        ans=min(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if (s[0] == s[1]) cout << "Bad";
    else if (s[1] == s[2]) cout << "Bad";
    else if (s[2] == s[3]) cout << "Bad";
    else cout << "Good";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



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

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;
int gcd(int a,int b)
{
  if(a>b)swap(a,b);
  if(a==0){return b;}
  else return gcd(b%a,a);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  cout<<a/gcd(a,b)*b<<endl;
  return 0;

}


Measured memory_bytes: 256
#!python3

# input
s = input()
K = int(input())


def main():
    n = len(s)
    alpha = [chr(i) for i in range(97, 97+26)]
    d = {x: [] for x in alpha}
    for i in range(n):
        d[s[i]].append(i)

    st = set()
    for i in range(n):
        for j in range(1, 6):
            if i + j > n:
                break
            st.add(s[i:(i + j)])
    
    ans = sorted(st)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()


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

parent = [i + 1 for i in range(n)]
rank = [0 for i in range(n)]

def find(x):
    if parent[x - 1] == x:
        return x
    else:
        parent[x - 1] = find(parent[x - 1])
        return parent[x - 1]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x - 1] < rank[y - 1]:
        parent[x - 1] = y
    else:
        parent[y - 1] = x
        if rank[x - 1] == rank[y - 1]:
            rank[x - 1] += 1

for i in range(m):
    x, y, z = map(int, input().split())
    unite(x, y)
ans = n
for i in range(n):
    if find(i + 1) != i + 1:
        ans -= 1
print(ans)

Measured memory_bytes: 13684
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    int n; cin >> n;
    string s; cin >> s;

    vector<int> w(n+1,0);
    vector<int> b(n+1,0);

    int ind = 0, wc = 0, bc = 0;
    while (ind < n) {
        if(s[ind] == '.') {
            wc += 1;
        } else {
            bc += 1;
        } 
        w[ind+1] = wc;
        b[ind+1] = bc;
        ind += 1;
    }

    int res = 1000000000;
    res = min(res, w[n]);
    res = min(res, b[n]);
    for (int i = 1; i < n; i++) {
        res = min(res, b[i] + w[n] - w[i]);
    }
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2180
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;

bool ch(string s)
{
    for(int i = 1; i < s.size(); i++)
        if(s[0] != s[i]) return false;
    return true;
}
int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    
    while(true)
    {
        if(ch(s))
        {
            cout << s << endl;
            return 0;
        }
        s = to_string(stoi(s) + 1);
    }
    return 0;
}


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

#define MAX 1000002
typedef unsigned char byte;
byte mask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

int Lv[MAX];
int n, k;

bool cmp_Lv(const int i, const int j){ return Lv[i] < Lv[j]; }

bool cmp(const int i, const int j){
    if(Lv[i] != Lv[j]){ return Lv[i] < Lv[j]; }
    int L_i = (i + k >= n ? -1 : Lv[i + k]);
    int L_j = (j + k >= n ? -1 : Lv[j + k]);

    return L_i < L_j;
}

int main()
{
    int A[MAX];
    char c[MAX];
    scanf("%s", c);
    std::string T = std::string(c);
    n = T.size();
    byte *t;
    t = new byte [(n >> 3) + 1];

    int i;
    for(i = 0; i < n; i++){ A[i] = i; }
    for(i = 0; i < n; i++){ Lv[i] = T[i]; }
    std::sort(A, A + n, cmp_Lv);

    for(i = 1; i < n; i++){
        t[i >> 3] = (Lv[A[i]] != Lv[A[i - 1]] ? t[i >> 3] | mask[i & 7] : t[i >> 3] & ~mask[i & 7]);
    }

    Lv[A[0]] = 0;
    for(i = 1; i < n; i++){
        Lv[A[i]] = Lv[A[i - 1]] + !!(mask[i & 7] & t[i >> 3]); 
    }

    k = 1;
    while(1){
        if(k > n) break;

        std::sort(A, A + n, cmp);
 
        for(i = 1; i < n; i++){
            t[i >> 3] = (cmp(A[i - 1], A[i]) ? t[i >> 3] | mask[i & 7] : t[i >> 3] & ~mask[i & 7]);
        }
        Lv[A[0]] = 0;
        for(i = 1; i < n; i++){
            Lv[A[i]] = Lv[A[i - 1]] + !!(mask[i & 7] & t[i >> 3]);
        }

        if(Lv[A[n - 1]] == n - 1) break;
        k <<= 1;
    };

    char p[1000];
    int q, left, right, mid, crit;
    bool exist;
    scanf("%d", &q);

    A[n] = n;

    while(q){
        scanf("%s", p);
        std::string P = std::string(p);
        left = 0, right = n, exist = false;
        while(left < right){

            if(n < P.size()){ exist = false; break; }

            mid = (left + right) / 2;
            crit = T.compare(A[mid], P.size(), P);

            if(crit > 0){ right = mid; }
            else if(crit < 0){ left = mid + 1; }
            else{ exist = true; break; }
        };
        if(T.compare(A[right], P.size(), P) == 0) exist = true;
        if(exist){ printf("1\n"); }else{ printf("0\n"); }
        q--;
    }
    return 0;
}

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

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

    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
struct Graph {
    std::vector<std::vector<Edge<Cost>>> graph;

    Graph(int n = 0) : graph(n) {}

    void span(bool direct, int src, int dst, Cost cost = 1) {
        graph[src].emplace_back(src, dst, cost);
        if (!direct) graph[dst].emplace_back(dst, src, cost);
    }

    int size() const { return graph.size(); }
    void clear() { graph.clear(); }
    void resize(int n) { graph.resize(n); }

    std::vector<Edge<Cost>>& operator[](int v) { return graph[v]; }
    std::vector<Edge<Cost>> operator[](int v) const { return graph[v]; }
};

template <class Cost>
std::vector<int> bfs(const Graph<Cost>& graph, int s) {
    std::vector<Cost> dist(graph.size(), -1);
    dist[s] = 0;
    std::queue<int> que;
    que.push(s);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (const auto& e : graph[v]) {
            if (dist[e.dst] != -1) continue;
            dist[e.dst] = dist[v] + e.cost;
            que.push(e.dst);
        }
    }

    return dist;
}

void solve() {
    int n, m;
    std::cin >> n >> m;
    Graph<> graph(n);

    while (m--) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        graph.span(false, u, v);
    }

    std::vector<int> ans(n, 0);

    std::vector<int> dist(graph.size(), -1);
    dist[0] = 0;
    std::queue<int> que;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (const auto& e : graph[v]) {
            if (dist[e.dst] != -1) continue;
            ans[e.dst] = v;
            dist[e.dst] = dist[v] + e.cost;
            que.push(e.dst);
        }
    }

    std::cout << "Yes\n";
    for (int i = 1; i < n; ++i) {
        std::cout << ans[i] + 1 << "\n";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 14288
def solve(string):
    k = int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    n = 7
    ans = 1
    while n % k:
        n = (10 * n + 7) % k
        ans += 1
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int sum  =0;
	int arr[m];
	for(int i=0; i<m; i++){
		cin>>arr[i];
	}
	for(int i=0; i<m; i++){
		sum += arr[i];
	}
	if(sum > n){
		cout<<"-1"<<endl;
	}
	else{
		cout<<(n-sum)<<endl;
	}
	




	return 0;
}


Measured memory_bytes: 3644
h, w = gets.split.map(&:to_i)
c = 10.times.map {gets.split.map(&:to_i)}
c << [0, 0]

10.times do |k|
    10.times do |i|
        10.times do |j|
            c[i][j] = c[i][k] + c[k][j] if c[i][j] > c[i][k] + c[k][j]
        end
    end
end

ans = 0
h.times {gets.split.each {|e| ans += c[e.to_i][1]}}
puts ans

Measured memory_bytes: 2172
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int train[30];

int main() {
	int n=in();
	while(n--){
		string str;
		cin>>str;
		int i;
		for(i=0;i<30;i++)train[i]=-1000;
		int m=0;
		int k=0;
		for(i=0;i<str.size();i++){
			if(i%3==0){
				train[str[i]-'a']=k;
			}
			if(i%3==2){
				if(str[i]=='>')k++;
				else k--;
				chmin(m,k);
			}
		}
		while(1){
			for(i=0;i<30;i++){
				if(train[i]==m){
					cout<<(char)(i+'a');
					m++;
					break;
				}
			}
			if(i==30)break;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

string s;

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

    int N, K;
    cin >> N >> K >> s;

    priority_queue<int> pq;

    int l = 0;
    int r = 0;
    int num = 0;
    queue<int> nextl;
    int ans = 0;
    while (r < N)
    {
        if ((r > 0 && s[r - 1] == '0' && s[r] == '1'))
        {
            nextl.push(r);
            ++num;
        }

        if (num == K && (r > 1 && s[r - 1] == '1' && s[r] == '0'))
        {
            ans = MAX(ans, r - l);
            --num;
            l = nextl.front();
            nextl.pop();;
        }
        ++r;
    }

    cout << MAX(ans, r - l) << "\n";
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int gcd(int a,int b){
   if(a%b==0) return b;
   return gcd(b,a%b);
}
int digit(int num){
   int cnt=0;
   while(num!=0){
      cnt+=num%10;
      num=num/10;
   }
   return cnt;
}
int main(void){
   int N;
   cin>>N;
   vector<int> A(N);
   for(int i=0;i<N;i++){
      cin>>A[i];
   }
   int ans=0;
   int now=0;
   while(now<N){
      ans++;
      int end=now;
      bool up=false;
      bool down=false;
      while(end+1<N){
         if(A[end+1]>A[end]){
            if(down){
               break;
            }else{
               up=true;
            }
         }
         if(A[end+1]<A[end]){
            if(up){
               break;
            }else{
               down=true;
            }
         }
         end++;
      }
      now=end+1;
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvl;
const int mod = 1000000007;
const int N = 3e5;
vi g[N];
int a[N];
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,k,j;
	set<int> x;
	fo(i, 3){
		cin>>n;
		x.insert(n);
	}
	cout<<(int)x.size()<<endl;
	return 0;
} 

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
for(int v:g[u]){
	if (v == par) continue;
	dfs(v, u);
}
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)

const int maxn = 1e5 + 5;

int n, k, a[maxn];

int main() {
  cin >> n >> k;

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

  int found = -1;
  rep(i, 0, n) {
    if (a[i] == 1) {
      found = i;
      break;
    }
  }

  int pre = max(0, found - k + 1);

  int ans = 1e9;
  rep(i, pre, found + 1) {
    int nxt = min(n - 1, i + k - 1);
    int trai = (i + k - 2) / (k - 1);
    int phai = (n - 1 - nxt + k - 2) / (k - 1);
    ans = min(ans, phai + trai + 1);
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 640
import sys
import collections
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, Q = map(int, input().split())
graph = collections.defaultdict(list)
for _ in xrange(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

values = [0] * (1+N)
for _ in xrange(Q):
    a, b = map(int, input().split())
    values[a] += b
q = [(0, 1)]
while q:
    parent, child = q.pop()
    values[child] += values[parent]
    for i in graph[child]:
        if i == parent: continue
        q.append((child, i))
ans = ' '.join(map(str, values[1:]))
print(ans)
   

Measured memory_bytes: 70184
package main

import "fmt"

func main() {
	var w, h, x, y float64
	fmt.Scan(&w, &h, &x, &y)

	fmt.Println(w * h / 2)

	if w/2 == x && h/2 == y {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
  int n,k;
  int i;
  int h;
  int count=0;
  
  scanf("%d %d",&n,&k);
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&h);
    if(h>=k)
    {
      count++;
    }
  }
  
    
    printf("%d",count);
    
    return 0;
}
  


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  const long mod=1000000007;
  long int N,M;
  cin>>N>>M;
  vector <long int> den (M);
  vector <long int> vec (N+1,true);
  for (long int i=0;i<M;i++){
    cin>>den.at(i);
    vec.at(den.at(i))=false;
  }
  
  vec.at(0)=1;
  if(vec.at(1))
    vec.at(1)=1;
  
  long ans;
  if (N==1)
    ans=vec.at(N);
  
  else{
     for(long int i=0;i<N-1;i++){
       if(vec.at(i+2)){
         
         vec.at(i+2)=vec.at(i+1)+vec.at(i);
         vec.at(i+2)%=mod;
       }
       
       else
         vec.at(i+2)=0;
       
       ans=vec.at(i+2)%mod;
     }
  }
    
  cout<<ans<<endl;
}
    

Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int main(){
  int n;
  string u[11];
  double x[11];
  double jpy=0,btc=0,sum=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>x[i]>>u[i];
  }
  for(int i=1;i<=n;i++){
    if(u[i]=="JPY"){
      jpy+=x[i];
    }
    else{
      btc+=x[i];
    }
  }
  btc*=380000.0;
  sum=jpy+btc;
  printf("%.8f",sum);
  return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	ll a,b,c,d;	cin >>a>>b>>c>>d;
	
	if(abs(c-b)+abs(b-a)==abs(c-a)){
		if(abs(c-b)<=d&&abs(b-a)<=d) cout << "Yes" <<endl;
		else cout <<"No" <<endl;
	}
	else{
		if(abs(c-a)<=d) cout << "Yes" <<endl;
		else cout <<"No" <<endl;
	}
	
	
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


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

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,x,y;

	cin >> a >> b >> c >> x >>y;

	int ans = a*x + b * y;

	rep(i,0,max(x,y)+1) {

		int money = 2 * c * i + max(0, x - i) * a + max(0, y - i) * b;

		ans = min(ans, money);
	}

	
	
	cout << ans << endl;
	


}
	

Measured memory_bytes: 256