akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

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

void process(){
    int K;
    int N;
    int *A;
    int max = 0;
    int temp;
    int i;
    cin >> K >> N;
    A = new int[N];
    for(i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    for(i=1;i<N;i++){
        if( i + 1 >= N){
            temp = K - A[i] + A[0];
        }else{
            temp = A[i+1] - A[i];
        }
        if(temp > max){
            max = temp;
        }
        temp = A[i]-A[i-1];
        if(temp > max){
            max = temp;
        }
    }
    cout << K - max << endl;
}

Measured memory_bytes: 1024
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

//main.cpp----------------------------


void solve();

ll a[3], b[3];
ll c[5] = {};

int main() {
  rep(i, 3) cin >> a[i] >> b[i];

  solve();

  return 0;
}

void solve() {
  bool flag = true;

  rep(i, 3) {
    c[a[i]] += 1;
    c[b[i]] += 1;
  }

  if(c[1]!=1) flag = false;
  if(c[2]!=2) flag = false;
  if(c[3]!=2) flag = false;
  if(c[4]!=1) flag = false;

  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
string s;
int p;

ll expr();

ll num()
{
	ll res;
	if (isdigit(s[p]))
	{
		res = 0;
		while (isdigit(s[p]))
		{
			res *= 10;
			res += s[p] - '0';
			p++;
		}
	}
	else res = expr();
	return res % MOD;
}

ll term()
{
	ll lhs = num();
	while (s[p] == '#')
	{
		p++;
		ll rhs = num();
		if (rhs > 32) lhs = 0;
		else lhs >>= rhs;
	}
	return lhs;
}

ll expr()
{
	ll res;
	if (s[p] == 'S')
	{
		p += 2;
		ll tmp = term();
		p++;
		res = tmp * tmp % MOD;
	}
	else res = term();
	return res;
}

ll parse()
{
	p = 0;
	ll res = term();
	return res;
}

void convert(string &t)
{
	s.clear();
	REP(i, t.size())
	{
		if (t[i] != ' ') s += t[i];
	}
	bool update = true;
	while (update)
	{
		update = false;
		REP(i, s.size() - 2)
		{
			if (s[i] == '>'&&s[i + 1] == '>' && (s[i + 2] == 'S' || isdigit(s[i + 2])))
			{
				s.erase(i, 1);
				s[i] = '#';
				update = true;
				break;
			}
		}
	}
}

int main()
{
	string t;
	while (getline(cin, t))
	{
		if (t == "#") break;
		convert(t);
		cout << parse() << endl;
	}
	return 0;
}

Measured memory_bytes: 5928
#include<iostream>
#include <cstddef>
#include<set>
#include<stack>
#include <deque>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<cmath>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#define  ll  long long
#define ull unsigned long long
#define  sl(a)  scanf("%lld",&a)
#define  si(a)  scanf("%d",&a)
#define mem(n,m) memset(n,m,sizeof(n))
#define PI acos(-1)
#define pb    push_back
#define pf    push_front
#define vll   vector<ll>
#define pll   pair<ll,ll>
#define mp  make_pair
#define vpll vector< pair <ll,ll> >
#define vplpll vector<pair<ll,pair<ll,ll> > >
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S(X) ( (X) * (X) )
#define forab(i, a, b) for(i = a; i <= b; i++)
#define forn(i, n) for(i = 0; i < n; i++)
#define print(a,b) printf("Case %lld: %lld\n",a,b)
using namespace std;
ll powd(ll a,ll b){if(b==1){return a;}if(b%2==1){return powd(a,b-1)*a;}else{ll x=powd(a,b/2); return x*x;}}
ll powm(ll a,ll b,ll m){if(b==0){return 1;}if(b==1){return a%m;}if(b%2==1){return ((powm(a,b-1,m)%m)*(a%m))%m;}else{ll x=powm(a,b/2,m); return ((x%m)*(x%m))%m;}}
ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b,a%b);}
typedef multiset<ll> mlset;
typedef set<ll> mset;
typedef struct node* pnode;
int main()
{
    ll x,k,d;
    sl(x);
    sl(k);
    sl(d);
    ll mi=1e9;
    ll di=abs(0-x);
    ll m=di/d;
    //cout<<m<<endl;
    m=min(m,k);
    mi=min(abs(x+m*d),abs(x-m*d));
    if(k-m>0)
    {
        if((k-m)%2==1)
        {
            if(mi>0)
            {
                mi=abs(mi-d);
            }
            else
            {
                mi=abs(mi+d);
            }
        }
    }
    cout<<mi<<endl;
    return 0;
}

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i.ft<<" "<<i.sd<<endl;cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)	A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

const ll N = 1005;

ll A[N][N];
ll B[N];

set<pll> s,t;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    rep(i,1,n+1)	rep(j,1,n)	cin>>A[i][j];
    ll ans=1;
    rep(i,1,n+1)	B[i]=1;
    rep(i,1,n+1){
    	ll j = A[i][B[i]];
    	if(s.find({j,i})!=s.end()){
    		B[i]++;
    		B[j]++;
    		if(B[i]<n){
    			t.insert({i,A[i][B[i]]});
    		}
    		if(B[j]<n){
    			t.insert({j,A[j][B[j]]});
    		}
    		s.erase({j,i});
    	}
    	else{
    		s.insert({i,j});
    	}
    }
    while(!t.empty()){
    	set<pll> temp;
    	ans++;
    	for(auto k:t){
    		ll i = k.ft;
    		ll j = k.sd;
    		if(s.find({j,i})!=s.end()){
    			B[i]++;
	    		B[j]++;
	    		if(B[i]<n){
	    			temp.insert({i,A[i][B[i]]});
	    		}
	    		if(B[j]<n){
	    			temp.insert({j,A[j][B[j]]});
	    		}
	    		s.erase({j,i});
    		}
    		else{
    			s.insert({i,j});
    		}
    	}
    	t.clear();
    	for(auto k:temp)	t.insert(k);
    }
    if(s.empty()){
    	cout<<ans<<endl;
    }
    else{
    	cout<<-1<<endl;
    }
    return 0;
}

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

long long solve(long long h, long long n, long long c) {
  if (h == 0) {
    return c;
  }
  c += n;
  n *= 2;
  h /= 2;
  solve(h, n, c);
}

int main() {
  long long H;
  cin >> H;
  cout << solve(H, 1, 0);
}

Measured memory_bytes: 256
function main(input) {
	const args = input.split('\n');
	const A=parseInt(args[0],10);
	 B=parseInt(args[1],10);
	 C=parseInt(args[2],10);
	 X=parseInt(args[3],10);

	var count = 0;

    for (var a = 0; a <= A; ++a) {
        for (var b = 0; b <= B; ++b) {
            for (var c = 0; c <= C; ++c) {
                var sum = (a * 500) + (b * 100) + (c * 50);
                if (sum === X) count++;
            }
        }
    }
    console.log(count);
}
   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32340
//Name : Rupa Dey
  //Date : 11 September 2020
//joi sri gour hori gobindo...
//gobindo ja hobe vlor jonnoi hobe..
#include<bits/stdc++.h>
#define ll long long
#define d double
#define ld long double
#define vi vector<int>
#define vul vector<ull>
#define vl vector<ll>
#define pb push_back
#define si set<int>
#define sl set<ll>
#define yes cout<<"YES\n"<<endl
#define no cout<<"NO\n"<<endl
#define ys cout<<"Yes\n"<<endl
#define n0 cout<<"No\n"<<endl
#define test cin>>t; while(t--)
#define for(i,a,n) for(i=a;i<n;i++)
#define mp make_pair
#define ft first
#define sc second
#define gp ' ';
#define MAX 9999999
#define MOD 1000000007
#define nd endl
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k,ans;
    cin>>n>>k;
    if((n%k)==0) cout<<"0"<<nd;
    else
    cout<<"1"<<nd;

}
//hare krishna...
//hey gobindo kripa koro......
//only gobindo exists..^..


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;


}

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

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    for(auto& e: w){
        cin >> e;
    }
    vector<int> s_1(n+1), s_2(n+1);
    s_1[0] = 0;
    s_2[n] = 0;
    for(int i = 1;i <= n;i++){
        s_1[i] = s_1[i-1] + w[i-1];
    }
    for(int i = n - 1;i >= 0;i--){
        s_2[i] = s_2[i+1] + w[i];
    }
    int res = abs(s_1[n] - s_2[n]);
    for(int i = 1;i < n;i++){
        res = min(res, abs(s_1[i] - s_2[i]));
    }
    // for(auto e : s_1){
    //     cout << e << endl;
    // }
    // cout << endl;
    // for(auto e : s_2){
    //     cout << e << endl;
    // }
    // cout << endl;
    cout << res << endl;
    return 0;
}

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

int main(){
  const int Max=(1<<30);
  const int Min=(1<<31);
  const int NAN=Max+1;
  int N;
  while(cin>>N,N){
    int max=Min;
    int min=Max;
    vector<string> vec(N);
    for(int i=0;i<N;i++){
      cin>>vec[i];
    }
    bool flag=true;
    for(int i=0;i<N;i++){
      if(vec[i]=="x"){
	if((i>=1 && vec[i-1]=="x") || (i+1<N && vec[i+1]=="x")){
	  flag=false;
	}else{
	  int b=NAN;
	  int a=NAN;
	  if(i>=1) b=atoi(vec[i-1].c_str());
	  if(i+1<N) a=atoi(vec[i+1].c_str());
	  if(i&1){
	    if(b==NAN) b=Min;
	    if(a==NAN) a=Min;
	    if(max<b) max=b;
	    if(max<a) max=a;
	  }else{
	    if(b==NAN) b=Max;
	    if(a==NAN) a=Max;
	    if(min>b) min=b;
	    if(min>a) min=a;
	  }
	}
      }else{
	int b=NAN;
	int c=atoi(vec[i].c_str());
	int a=NAN;
	if(i>=1 && vec[i-1]!="x")
	  b=atoi(vec[i-1].c_str());
	if(i+1<N && vec[i+1]!="x")
	  a=atoi(vec[i+1].c_str());
	if(i&1){
	  if(b==NAN) b=Min;
	  if(a==NAN) a=Min;
	  if(b>=c || a>=c) flag=false;	  
	}else{
	  if(b==NAN) b=Max;
	  if(a==NAN) a=Max;
	  if(b<=c || a<=c) flag=false;	  
	}
      }
    }
    int ch=(min-max-1)*flag;
    if(ch==0 || max>=min){
      cout<<"none"<<endl;
    }else if(ch==1){
      cout<<min-1<<endl;
    }else{
      cout<<"ambiguous"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1288
import sys
N = int(input())
X = [[0,0,0]] + [list(map(int, input().split())) for _ in range(N)]
A = [[0]*3 for _ in range(N+1)]
for i in range(1,N+1):
  A[i][0] = max(A[i-1][1],A[i-1][2]) + X[i][0]
  A[i][1] = max(A[i-1][0],A[i-1][2]) + X[i][1]
  A[i][2] = max(A[i-1][0],A[i-1][1]) + X[i][2]

print(max(A[N]))

Measured memory_bytes: 103004
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	vector<map<int, int> > cnt(31, map<int, int>());
	int ans = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		int tmpcnt = 0;
		while(a % 2 == 0){
			tmpcnt++;
			a /= 2;
		}
		if(cnt[tmpcnt].find(a) == cnt[tmpcnt].end()) cnt[tmpcnt][a] = 1;
		else cnt[tmpcnt][a]++;
	}
	for(int i = 0; i <= 30; i++){
		for(int j = 30; j > 1; j--){
			for(auto k = cnt[i].begin(); k != cnt[i].end(); k++){
				int tmp = (1 << j) - (*k).first;
				if(cnt[i].find(tmp) == cnt[i].end()) continue;
				int res = min((*k).second, cnt[i][tmp]);
				ans += res;
				(*k).second -= res;
				cnt[i][tmp] -= res;
			}
		}
		if(cnt[i].find(1) != cnt[i].end()) ans += cnt[i][1] / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector<P> vec;

namespace std{
  bool operator < (const P &a,const P &b){
    return (a.imag()==b.imag()?
            a.real()<b.real():
            a.imag()<b.imag());
  }
};

double eps=1e-8;
double PI=acos(-1);

bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
bool eq(P a,P b){return (abs(a-b)<eps);}

double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}
P project(P a,P b,P c){b-=a;c-=a;return a+b*real(c/b);}
P reflect(P a,P b,P c){b-=a;c-=a;return a+conj(c/b)*b;}
int ccw(P a,P b,P c){
  b-=a,c-=a,a=c*conj(b);
  if(a.imag()>eps)return 1;//ccw
  if(a.imag()<-eps)return -1;//cw
  if(a.real()<-eps)return 2;//ob
  if(abs(b)+eps<abs(c))return -2;//of
  return 0;//os
}

//segment ab , point c
double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

bool isintersect(P a,P b,P c,P d){
  return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
}

//segment ab , segment cd
P intersect(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

double dist(P a,P b,P c,P d){
  if(isintersect(a,b,c,d))return 0;
  double ab=min(dist(a,b,c),dist(a,b,d));
  double cd=min(dist(c,d,a),dist(c,d,b));
  return min(ab,cd);
}

double calcArea(vec &t){
  double res=0;
  int n=t.size();
  for(int i=0;i<n;i++)res+=cross(t[i],t[(i+1==n?0:i+1)]);
  return abs(res/2.0);
}

double Arg(P a,P b,P c){
  b-=a,c-=a;
  return arg(c*conj(b));
}

int inPolygon(vec &t,P p){
  int n=t.size();
  double sum=0;  
  for(int i=0;i<n;i++){
    P a=t[i],b=t[(i+1==n?0:i+1)];
    if( ccw(a,b,p) == 0 )return 1;// on
    sum+= Arg(p,a,b);
  }
  if( abs(sum) < eps )return 0;//out
  else  return 2;//in
}

typedef pair<double,P> Pair;
vec ConvexHull(vec t){
  vector<Pair> u;
  vec R;
  int N=t.size(),K=0,C=0;
  for(int i=1;i<N;i++)if(t[i]<t[K])K=i;
  for(int i=0;i<N;i++)u.push_back(Pair(arg(t[i]-t[K]),t[i]));
  R.push_back(t[K]),C++;
  sort(u.begin(),u.end());
  for(int i=0;i<N;i++){
    P p=u[i].second;
    if(2<=C&&ccw(R[C-2],R[C-1],p)==0)continue;
    if(2<=C&&ccw(R[C-2],R[C-1],p)==2)continue;
    while(2<=C&&ccw(R[C-2],R[C-1],p)!=1)R.pop_back(),C--;
    R.push_back(p),C++;    
  }
  return R;
}

vec cutConvex(vec &t,P a,P b){
  int N=t.size();
  vec res;
  for(int i=0;i<N;i++){
    P c=t[i],d=t[(i+1)%N];
    int C=ccw(a,b,c),D=ccw(a,b,d);
    if(C!=-1)res.push_back(c);
    if(C+D==0&&max(C,D)==1)res.push_back(intersect(a,b,c,d));
  }
  return res;
}

double maxDist(vec &t){
  vec u=t;//ConvexHull(t);
  int N=u.size(),K=0;
  double res=0;
  for(int i=0;i<N;i++){
    while(abs(u[i]-u[K])<abs(u[i]-u[(K+1)%N]))K=(K+1)%N;
    res=max(res,abs(u[i]-u[K]));
  }
  return res;
}


int main(){
  int n;
  cin>>n;
  vec t;
  double x,y;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    t.push_back(P(x,y));
  }
  printf("%.8f\n",maxDist(t));
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <tuple>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <unordered_map>

using namespace std;
using str = string;

#define rep(a,l,r) for(int a=(l);a<(r);a++)
#define get cin>>
#define put cout<<

void run() {

	int n; get n;

	if (n < 105){
		put 0;
		return;
	}

	int ans{0};
	for (int i = 105; i <= n; i+=2){
		int count{0};
		rep(j,1,n+1){
			if(i%j==0){
				count++;
			}
		}

		if(count==8){
			ans++;
		}
	}

	put ans;
}
int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);run();return 0;}


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


int32_t main()
{
	int n,m; cin>>n>>m;
	double s =0.0;
	double arr[n];
	for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        s+=arr[i];
    }
    sort(arr,arr+n,[](int a,int b){
         if(a>b)return 1;
         return 0;
         });
    int ct=0;
    double minn = s/(4.0*m);
    for(int i=0;i<n;i++)
    {
        if(arr[i]>=minn){
            ct++;
        }

    }
    if(ct>=m)cout<<"Yes";
    else cout<<"No";
}


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

int main(){
	int c,n,m;
	cin >> c >> n >> m;
	vector<int> s(n), p(n);
	for(int i=0; i<n; i++){
		cin >> s[i] >> p[i];
	}
	vector<int> dp(c+1, 0);
	for(int i=0; i<n; i++){
		for(int j=c-s[i]; j>=0; j--){
			dp[j+s[i]] = max(dp[j+s[i]], dp[j] +p[i]);
		}
	}
	for(int i=1; i<=m; i++){
		cout << dp[c/i] *i << endl;
	}
    return 0;
}


Measured memory_bytes: 3216
<?php
fscanf(STDIN, "%d %d", $n, $k);
$s = trim(fgets(STDIN));
$arrayS = str_split($s);
$h = 0;
for($i=0; $i<$n-1; $i++) {
    if($arrayS[$i] == $arrayS[$i+1]) {
        $h++;
    }
}
$h = $h + 2*$k;
echo min($h,$n-1);


Measured memory_bytes: 10744
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin>>c;
  if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
    cout<<"vowel"<<endl;
  }
  else{
    cout<<"consonant"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    char a;
    cin>>n;
    for(int i=0;i<n;i++) {
    	cin>>a;
    	if(a=='Y'){
    		cout << "Four" <<endl;
    		return 0;
    	}
    }
    cout <<"Three" <<endl;
    return 0;
}


Measured memory_bytes: 256
/*
                    Author: Ankit Kaul
    **********************Code Belongs to Respective Author Only************************************
    */
    /*#pragma GCC optimize("O3")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
    #include <bits/stdc++.h>
    #define endl       '\n'
    #define PI          3.141592653589
    #define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #define M           1000000007
    #define int         long long int
    #define inf         INT_MAX
    #define pb          emplace_back
    #define pf          emplace_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    using namespace std;
    int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
    int power(int x,int n){
        int result=1;
        while(n>0)
        {   if(n % 2 ==1)
            result=(result * x) % M;
            x=(x*x)% M;
            n=n/2;
        }
    return result % M;
    }      
    bool isPrime(int n) 
    { 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
    } 
int inv(int a)
{   return power(a,M-2);
}
int ncr(int n,int r)
{   int ret=1;
    int z=1;
    for(int i=0;i<r;i++)
    ret=(ret*(n-i))%M;
    for(int i=1;i<=r;i++)
    z=(z*i)%M;
    return (ret*inv(z))%M;
}
signed main()
    {   jaldi
        int n,a,b;
        cin>>n>>a>>b;
        int sum=power(2,n)-1;
        int s=ncr(n,a);
        int q=ncr(n,b);
        sum=(sum-s-q)%M;
        sum=(sum+M)%M;
        cout<<sum;
    }   


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  ll n,m;
  cin>>n>>m;
  if(2*n>=m) cout<<m/2<<endl;
  else cout<<n+(m-2*n)/4<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics; 

class _Class
{
  void _Do()
  {
    var A_B = Split.ints();
    if (A_B[0] >8 || A_B[1] > 8)
    {
      Console.Write(":(");
    }
    else 
    {
      Console.Write("Yay!");
    }

  }


  //
  static void Main(string[] args)
  {
    _(args);
    new _Class()._Do();
  }

  [Conditional("DEBUG")]
  static void _(string[] args)
  {
    if (args.Length != 0 && File.Exists(args[0]))
      Console.SetIn(new StreamReader(args[0]));
    else
      Console.Error.WriteLine("in");
  }
}

static class Split
{


  // 1
  public static string[] strings()
  {
    return Console.ReadLine().Split();
  }


  // [2.1] -2,147,483,648 ~ +2,147,483,647
  public static int[] ints()
  {
    var _s = Console.ReadLine().Split();

    var x = new int[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = int.Parse(_s[i]);

    return x;
  }

  // [2.2] 
  // -9,223,372,036,854,775,808 ~ 
  // +9,223,372,036,854,775,807
  public static long[] longs()
  {
    var _s = Console.ReadLine().Split();

    var x = new long[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = long.Parse(_s[i]);

    return x;
  }

  public static double[] doubles()
  {
    var _s = Console.ReadLine().Split();

    var x = new double[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = double.Parse(_s[i]);

    return x;
  }

  public static BigInteger[] bigs()
  {
    var _s = Console.ReadLine().Split();

    var x = new BigInteger[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = BigInteger.Parse(_s[i]);

    return x;
  }
}




Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define inf 10000000
using namespace std;
typedef long long int ll;

int main(){

    int K,i,j=0,ans;
    cin >> K;

    for(i=0 ; i<K ; i++){
        if((i+1)%2 == 0){
            j++;
        }
    }

    ans = j * (K-j);

    cout << ans << endl;

}


Measured memory_bytes: 256
import numpy as np

N = int(input())
p = [int(i) for i in input().split()]
q = [i for i in range(1, N+1)]
p = np.array(p)
q = np.array(q)
r = np.array(p-q)
num =  len(np.where(r==0)[0])
print("YES" if N - num == 2 or N == num else "NO")


Measured memory_bytes: 14456
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}
const int N = 3005;
double a[N];
double dp[N][N];


signed main(){
	IOS
	int n,m;	cin >> n >> m;
	rep(i,n)	cin >> a[i+1];
	dp[0][0] = 1;
	for(int i=0;i<=n;i++){
		for(int j=0;j <= (n-i);j++){
			if(i+j != 0){
				if(i == 0)		dp[i][j] = dp[i][j-1] * a[i+j];
				else if(j == 0)	dp[i][j] = dp[i-1][j] * (1 - a[i+j]);
				else			dp[i][j] = dp[i-1][j] * (1 - a[i+j]) + dp[i][j-1] * a[i+j];
			}
		}
	}
	/*
	rep(i,n+1){
		rep(j,n+1)	cout << dp[i][j] << ' ';
		cout << endl;
	}
	*/
	double ans = 0;
	for(int i=0;i < n/2+1;i++){
		ans += dp[i][n-i];
	}
	cout << setprecision(15) << ans << endl;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll a,b;
ll x[125252];

int main(){
  scanf("%d%lld%lld",&n,&a,&b);
  REP(i,n)scanf("%lld",x+i);
  ll ans = 0;
  REP(i,n-1){
    int to = i+1;
    ll dst = x[to]-x[i];
    ans += min(dst*a,b);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, pair<int, vector<int>>>;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph(n, vector<int>());
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    graph.at(y).push_back(x);
    graph.at(x).push_back(y);
  }
  P p = make_pair(0, make_pair(0, vector<int>(n, 0)));
  p.second.second.at(0) = 1;
  queue<P> que;  
  que.push(p);
  // cout << "graph:start" << endl;
  // rep(i,n){
  //   cout << i << ", ";
  //   cout << "[ ";
  //   for(auto &v: graph.at(i)) cout << v << ": ";
  //   cout << " ]" << endl;
  // }
  // cout << "graph:end" << endl;
  int ans = 0;
  while(!que.empty()) {
    P v = que.front();
    que.pop();
    if (v.second.first == n - 1) {
      int tmp = count(ALL(v.second.second), 1);  
      if (tmp == n) ans++;
      continue;
    } 
    for(auto &nv : graph.at(v.first)) {      
      if (v.second.second.at(nv) >= 1) continue;  
      vector<int> tvec(n, 0);
      rep(i, n) tvec.at(i) = v.second.second.at(i);
      tvec.at(nv)++;
      que.push(make_pair(nv, make_pair(v.second.first+1, tvec)));
    }
  }
  cout << ans << endl;

  
  
  return 0;
}

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

using namespace std;

int main(){
	int n;
  cin >> n;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    int a; cin >> a;
  	mp[a]++;
  }
  long long cnt=0;
  long long ans=0;
  for(auto x:mp){
    // cout << x.first <<":" << x.second << '\n';
  	if((x.second)%2==0){
      cnt++;
       if(x.second > 2)
      ans += x.second-2;
    }
    else {if(x.second>1)ans += x.second-1;}
  }
  long long final=0;
  if(cnt%2==0){
    final = n-cnt-ans;
  }
  else{
     final = n - cnt - ans - 1;
  }
  cout << final;

}


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

int main() {
    int n;
    cin >> n;
    vector<ll> d(n);
    rep(i, 0, n) cin >> d[i];
    if (d[0] >= 1) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, 1, n) {
        if (d[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    sort(all(d));
    rep(i, 1, n) {
        if (d[i] - d[i - 1] >= 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    d.push_back(10000000);
    ll cnt = 1;
    vector<ll> v;
    rep(i, 2, n + 1) {
        if (d[i] != d[i - 1]) {
            v.push_back(cnt);
            cnt = 1;
        } else cnt++;
    }
    ll ans = 1;
    rep(i, 0, v.size() - 1) {
        rep(j, 0, v[i + 1]) {
            ans *= v[i] % MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2800
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

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

int main(void)
{
	int m;
	cin >> m;
	rep(t, m) {
		int budget, year, n;
		cin >> budget >> year >> n;
		int ans = 0;
		rep(i, n) {
			int type, cost;
			double rate;
			cin >> type >> rate >> cost;

			if (type == 1) {
				int A = budget;
				rep(j, year) {
					int B  = A * rate;
					int zandaka = A+B - cost;
					A = zandaka;
				}
				ans = max(ans, A);
			} else {
				int A = budget;
				int risi = 0;
				rep(j, year) {
					int B  = A * rate;
					int zandaka = A - cost;
					A = zandaka;
					risi += B;
				}
				A += risi;
				ans = max(ans, A);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#!/usr/bin/env python3
import os
from sys import stdin, stdout


def solve(tc):
    n = int(stdin.readline().strip())
    seq = list(map(int, stdin.readline().split()))

    seq = sorted(seq, reverse=True)

    ans = seq[0]
    cur = 1
    shared = 0
    for i in range(2, n):
        ans += seq[cur]
        shared += 1
        if shared==2:
            cur += 1
            shared = 0
    print(ans)



tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1


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

int main() {
  int n,k,ans = 0;
  cin >> n >> k;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data.at(i);
  }
  for(int i = 0;i < n;i++){
    if(k - data.at(i) < data.at(i)){
      ans += 2*(k-data.at(i));
    }
    else{
      ans += 2*data.at(i);
    }
  }
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;

const int MAX_V = 100000;
const int MAX_LOG_V = 17;

vector<int> G[MAX_V];
int root = 0;

int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

void dfs(int v, int p, int d) {
    parent[0][v] = p;
    depth[v] = d;
    for (int i = 0; i < G[v].size(); i++) {
        if (G[v][i] != p) dfs(G[v][i], v, d + 1);
    }
}

void init(int V) {
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
        for (int v = 0; v < V; v++) {
            if (parent[k][v] < 0) parent[k + 1][v] = -1;
            else parent[k + 1][v] = parent[k][parent[k][v]];
        }
    }
}

int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_V; k++) {
        if ((depth[v] - depth[u]) >> k & 1) {
            v = parent[k][v];
        }
    }
    if (u == v) return u;
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
        if (parent[k][u] != parent[k][v]) {
            u = parent[k][u];
            v = parent[k][v];
        }
    }
    return parent[0][u];
}

using P = pair<int, int>;
using T = tuple<int, int, int>;

vector< vector<T> > g;
vector<int> xs, ys;
vector<int> ans;
vector< vector<P> > memo;

vector<int> cnt, dist, color_dist;

void dfs2(int cur, int par) {
    for (P& p : memo[cur]) {
        int i = p.first;
        ans[i] += (dist[cur] + cnt[xs[i]] * ys[i] - color_dist[xs[i]]) * p.second;
    }

    for (T& t : g[cur]) {
        int nex, c, d;
        tie(nex, c, d) = t;
        if (nex == par) continue;
        dist[nex] = dist[cur] + d;
        color_dist[c] += d;
        cnt[c]++;
        dfs2(nex, cur);
        color_dist[c] -= d;
        cnt[c]--;        
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--;
        G[a].push_back(b);
        G[b].push_back(a);
        g[a].emplace_back(b, c, d);
        g[b].emplace_back(a, c, d);
    }

    xs.resize(q);
    ys.resize(q);
    memo.resize(n);
    init(n);
    for (int i = 0; i < q; i++) {
        int u, v;
        cin >> xs[i] >> ys[i] >> u >> v;
        xs[i]--;
        u--;
        v--;
        memo[u].emplace_back(i, 1);
        memo[v].emplace_back(i, 1);
        int l = lca(u, v);
        memo[l].emplace_back(i, -2);
    }

    ans.resize(q, 0);
    cnt.resize(n - 1, 0);
    color_dist.resize(n - 1, 0);
    dist.resize(n, 0);
    dfs2(0, -1);

    for (int i = 0; i < q; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 33656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string s, t; cin >> s >> t;
  int a, b; cin >> a >> b;

  string u; cin >> u;
  if (u == s) a--;
  else b--;

  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
using namespace std;
#define MOD 1000000007


long long kaijo[5000001];
long long inv[5000001];



long long mul(long long x,long long y){
    return (x*y)%MOD;
}

long long bekijo(long long x,long long n){
    if(n==0)return 1;
    if(n%2==1)return mul(x,bekijo(x,n-1));
    return mul(bekijo(x,n/2),bekijo(x,n/2));
}

long long nCk(int n,int k){
    if(k==-1)return n==k?1:0;
    return mul(kaijo[n],mul(inv[k],inv[n-k]));
}

int main(void){
    kaijo[0]=1;
    for(long long i=1;i<=5000000;i++){
        kaijo[i]=mul(kaijo[i-1],i);
    }
    
    inv[5000000]=bekijo(kaijo[5000000],MOD-2);
    for(long long i=5000000-1;i>=0;i--){
        inv[i]=mul(inv[i+1],i+1);
    }
    
    while(1){
        long long int A,B,C,Sx,Sy;
        scanf("%lld%lld%lld%lld%lld",&A,&B,&C,&Sx,&Sy);
        if(A+B+C==0)break;
        
        /*引き分けた総得点をi点とするとチームXがA回の試合で合計Sx-i点勝ってYがB回の試合でSy-i点勝った*/
        /*Sx-i>=AかつSy-i>=Bのときのみ考える、つまりiの範囲は0からmin(Sx-A,Sy-B)*/
        /*勝ち点の振り分け方はSx-i点をA個の箱に全部最低1個ずつ振り分ける方法なので(Sx-i-1)C(A-1)*/
        /*同様に負け点の振り分けは(Sy-i-1)C(B-1)*/
        /*引き分け点の振り分けはA+B+C個の箱に(0個も許して)分ける方法なので(i+1)H(A+B+C-1)=(i+A+B+C-1)C(A+B+C-1)*/
        /*さらに勝った試合AをA+B+C個のどこに置き、BをB+Cのどこに置くかで(A+B+C)CA * (B+C)CB通り*/
        
        long long ans=0;
        for(int i=0;i<=min(Sx-A,Sy-B);i++){
            long long po=1;
            po=mul(po,nCk(Sx-i-1,A-1));
            po=mul(po,nCk(Sy-i-1,B-1));
            po=mul(po,nCk(i+A+B+C-1,A+B+C-1));
            po=mul(po,nCk(A+B+C,A));
            po=mul(po,nCk(B+C,B));
            ans+=po;
            ans%=MOD;
        }
        printf("%lld\n",ans);
        
    }
    
    
    return 0;
}



Measured memory_bytes: 81324
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

const MOD: isize = 1_000_000_007;

fn main() {
    input! {
        n: isize,
        m: isize
    };
    let diff = (n - m).abs();
    if diff == 0 {
        println!("{}", product(n) * product(m) * 2 % MOD);
    } else if diff == 1 {
        println!("{}", product(n) * product(m) % MOD);
    } else {
        println!("0");
    }
}

fn product(num: isize) -> isize {
    (1..=num).fold(1, |acc, x| acc * x % MOD)
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int h, w, k;
  cin >> h >> w >> k;
  vvi m(h, vi(w));
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) m[i][j] = s[j] == '1';
  }

  int mn = inf;
  rep(r, 1 << h - 1) {
    int c = __builtin_popcount(r);
    vi cur(c + 1);

    int cnt = c;
    bool ok = true;
    rep(j, w) {
      vi d(sz(cur));
      bool cut = false;
      int idx = 0;

      if (m[0][j]) cur[idx]++, d[idx]++;
      if (cur[idx] > k) cut = true;
      rep(i, h - 1) {
        if (r >> i & 1) idx++;
        if (m[i + 1][j]) cur[idx]++, d[idx]++;
        if (cur[idx] > k) cut = true;
        if (d[idx] > k) ok = false;
      }

      if (!ok) {
        cnt = inf;
        break;
      }

      if (cut) {
        cnt++;
        copy(all(d), cur.begin());
      }
    }

    mn = min(mn, cnt);
  }

  cout << mn;

  return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const ll MAXN=1e6+5;
ll n,m,t;
ll v[MAXN];
char s[MAXN];
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll tmp=c-a-b;
    if(tmp<0){cout<<"No";return 0;}
    ll tmpp=4*a*b;
    if(tmpp<tmp*tmp)cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

int main(void)
{
	int A, B, C, N, sum=0;
	cin >> N;
	vector<int> vec(N);
	for (auto& a : vec)
	{
		cin >> a;
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			sum += (vec[i] * vec[j]);
		}
	}

	cout << sum << endl;

}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

x, y = map(int, readline().split())

flg = 0

for i in range(x+1):
    if y == ((i*2) + ((x-i)*4)):
        flg = 1

if flg == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9236
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
 int main(){
     int q,w; 
     cin >> q >> w;
     char a[q][w]={};
     int v[q]={};
     int h[w]={};
     for(int i=0;i<q;i++){
         for(int j=0;j<w;j++){
             cin >> a[i][j];
             if(a[i][j]=='#'){ v[i]=1; h[j]=1; }
         }
     }
    for(int i=0;i<q;i++){
        for(int j=0;j<w;j++){
            if(v[i]==1&&h[j]==1) cout << a[i][j];
        }
        if(v[i]==1) cout << endl;
    }
    return 0;
     

 }

Measured memory_bytes: 256
#include<cstdio>
#include<cassert>
int n,licz;
long double start;
long double tab[3003][3003];
long double res;

long double chance(int t, long double x, long double y){
	if(t==0)return (1.0-x)*(1.0-y);
	if(t==1)return 1.0-(1.0-x)*(1.0-y)-x*y;
	else return x*y;
}

//0 -> -n/2
//1 -> -n/2+1
//n/2 -> -1
//n/2+1 -> 1...

int main(){

	scanf("%d", &n);
	scanf("%Lf", &start);
	tab[0][n/2]		=1.0-start;
	tab[0][n/2+1]	=start;

	for(int i=0;i<n/2;i++){
		++licz;
		long double x,y;
		scanf("%Lf %Lf", &x, &y);

		tab[licz][0] = tab[licz-1][0]*chance(1,x,y) + tab[licz-1][1]*chance(0,x,y);
		for(int j=1;j<=n;j++){
			tab[licz][j] = tab[licz-1][j-1]*chance(2,x,y) + tab[licz-1][j]*chance(1,x,y) + tab[licz-1][j+1]*chance(0,x,y);
		}
	}
	for(int i=n/2+1;i<=n;i++){
		res+=tab[licz][i];
	}
	//assert(res<=1);
	printf("%.10Lf\n", res);

}


Measured memory_bytes: 71936
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var s string
	fmt.Scan(&s)

	r := regexp.MustCompile(`^A?KIHA?BA?RA?$`)
	if r.MatchString(s) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vi V(N); REP(i, N) cin >> V[i];
    vi C(N); REP(i, N) cin >> C[i];

    int ans = 0;
    REP(i,N) {
        if (V[i] > C[i]) ans += V[i] - C[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
for k in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j]==b:
                a[i][j]=-1
for i in range(3):
    ans=True
    for j in range(3):
        if a[i][j]!=-1:
            ans=False
            break
    if ans:
        print("Yes")
        exit()
for i in range(3):
    ans=True
    for j in range(3):
        if a[j][i]!=-1:
            ans=False
            break
    if ans:
        print("Yes")
        exit()
ans=True
for i in range(3):
    if a[i][i]!=-1:
        ans=False
        break
if ans:
    print("Yes")
    exit()
ans=True
for i in range(3):
    if a[i][2-i]!=-1:
        ans=False
        break
if ans:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
	ll ch[62][2];
int main() {
	ll n;cin>>n;
	for(ll i=0;i<62;i++){
		ch[i][0]=n;
	}
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		ll now=0;
		while(x!=0){
			if(x%2==1){
				ch[now][1]++;
				ch[now][0]--;
			}
			now++;
			x/=2;
		}
	}
	ll now=1;
	ll ans=0;
	for(ll i=0;i<62;i++){
		ll cn=ch[i][0]*ch[i][1];
		cn%=inf;
		cn*=now;
		cn%=inf;
		ans+=cn;
		ans%=inf;
		now*=2;
		now%=inf;
	}
	cout <<ans;
	return 0;
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int count = 0;
  for(int i=0;i<s.size();i++){
    if(s[i] == 'x')count++;
  }
  if(count < 8)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
from itertools import product


def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
        return ANS
    return 10 ** 5


tgt = list(map(int, input().split()))
l = [int(input()) for _ in range(tgt[0])]

ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 77652
N=int(input())
p=[float(i) for i in input().split()]
dp=[[0 for j in range(i+2)] for i in range(N)]
dp[0][0]=1-p[0]
dp[0][1]=p[0]
for i in range(1,N):
    for j in range(i+2):
        if j==0:
            dp[i][j]=dp[i-1][j]*(1-p[i])
        elif j==i+1:
            dp[i][j]=dp[i-1][j-1]*p[i]
        else:
            dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i]
ans=0
for j in range(N+1):
    if j>N-j:
        ans+=dp[N-1][j]
print(ans)


Measured memory_bytes: 149384
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int ComputeCost(int stage[20][20],int dst,int visited,int N){
  int res = stage[dst][0];
  for(int i=0;i<N;i++){
    if(visited & (1<<i)){
      res = min(stage[dst][i+1],res);
    }
  }
  return res;
}
int main(){
  int N;
  while(~scanf("%d",&N)){
    if(N==0) break;
    int stage[20][20];//[N][N+1]
    for(int y=0;y<N;y++){
      for(int x=0;x<N+1;x++){
	int num;
	scanf("%d",&num);
	stage[y][x] = num;
      }
    }

    int dp[16][1<<16];
    memset(dp,0x3f,sizeof(dp));
    //init dp
    for(int i=0;i<N;i++){
      int got = (1 << i);
      dp[i][got] = stage[i][0];
    }

    for(int visited = 1;visited <= (1<<N) -1; visited++){
      for(int from = 0; from < N; from++){
	for(int to = 0; to < N; to++){
	  if(!(visited & (1<<from))) continue;
	  if(visited & (1<<to)) continue;
	  int cost = ComputeCost(stage,to,visited,N);
	  // printf("cost:%d\n",cost);
	  dp[to][visited | (1<<to)] 
	    = min(dp[to][visited | (1<<to)],dp[from][visited] + cost);
	}
      }
    }

    int res = INF;
    for(int i=0;i<N;i++){
      res = min(dp[i][(1<<N)-1],res);
    }
    printf("%d\n",res);
  }
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int cnt = 0, ans = 0;
  for(int i=0;i<3;i++){
    if (s[i] == 'R'){
      cnt ++;
      ans = max(ans, cnt);
    }else{
      cnt = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
/* 
************COPIED*************
*/
#include <bits/stdc++.h>
using namespace std;
 
#define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define lli long long int
#define ld long double
#define p_b push_back
#define m_p make_pair
#define fs first
#define sc second
#define all(x) x.begin(),x.end()
#define fr(i,a,n) for(lli i=a; i<n; i++)
#define rep(i,a,n) for(lli i=a; i>=n; i--)
const lli mod = 1e9 + 7;
/*****************************************************/
long double arr[3000][3000];
int main()
{
    fastIO
    int n;
	long double x,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(i==1){
			arr[i][0]=1-x;
			arr[i][1]=x;
		}
		else 
		for(int j=0;j<=i;j++){
			if(j==0){
				arr[i][j]=(1-x)*arr[i-1][j];
			}else {
				arr[i][j]=(1-x)*arr[i-1][j]+x*arr[i-1][j-1];
			}
		}
	}
	for(int i=(n+1)/2;i<=n;i++){
		ans+=arr[n][i];
	}
	
	printf("%0.10Lf",ans);
	

   // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 139008