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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vi a(N+1);;
    for(int i=0;i<N-1;i++){
        int temp;
        cin >> temp;
        a[temp]++;
    }
    for(int i=1;i<=N;i++){
        cout << a[i] << endl;
    }
    return 0;
}

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

const ll MAXN = 200000;

ll N, K, ans=0, tmp=0;
vector<ll> A(MAXN, 0);

signed main(){
    cin >> N >> K;
    for(int i=K+1;i<=N;i++) {
        ans += N/i*(i-K)+max(0LL, N%i-max(0LL, (K-1)));
        //cout << i << " " << (i-K)*N/i+max(0LL, N%i-max(0LL, (K-1))) << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

const int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1, 0};

int H, W, N;

inline bool inside(int x, int y) {
    return 1 <= x && x < H - 1 && 1 <= y && y < W - 1;
}


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

    cin >> H >> W >> N;
    vi a(N), b(N);
    rep(i, N) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    map<Pii, int> cnt;
    rep(i, N) {
        rep(k, 9) {
            if (inside(a[i] + dx[k], b[i] + dy[k])) {
                cnt[Pii(a[i] + dx[k], b[i] + dy[k])]++;
            }
        }
    }

    map<int, int> ans;
    int res = (H - 2) * (W - 2);
    for (auto&& p : cnt) {
        ans[p.second]++;
        res--;
    }

    cout << res << endl;
    rep(i, 9) {
        cout << ans[i + 1] << endl;
    }

}


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


int main()
{
	string S;
	int a;
	cin >> S;
	a = 700;
	for (int i = 0; i <= 2; i++)
	{
		if (S[i] == 'o')
		{
			a = a + 100;
		}
	}
	
		cout << a << endl;

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> ans;
  vector<bool> prime(246913,1);
  for(int i = 2;i <= 246912;i++){
    if(prime[i]){
      for(int j = 2 * i;j <= 246912;j += i){
        prime[j] = 0;
      }
    }
  }
  while(cin >> n,n){
    int count = 0;
    for(int i = n + 1;i <= 2*n;i++){
      if(prime[i])count++;
    }
    ans.push_back(count);
  }
  for(int i = 0;i < ans.size();i++)cout << ans[i] << endl;
}


Measured memory_bytes: 3144
#include<stdio.h>
#define PI 3.141592
#include <stdlib.h>

int main(){ 
        int N;
        scanf("%d",&N);

        int a[N-1];

        int i;
        for(i=0;i<N-1;i++){
                scanf("%d",&a[i]);
        }

        int ans[N];
        for(i=0;i<N;i++){
                ans[i] = 0;
        }

        for(i=0;i<N-1;i++){
                ans[ a[i]-1 ] = ans[ a[i]-1 ] +1;
        }

        for(i=0;i<N;i++){
                printf("%d\n",ans[i]);
        }
}  

Measured memory_bytes: 3288
//DP contest at atCoder

#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<n; i++)
#define sz(v) (int)(v).size()
using vi = vector < int >;
using vii = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';


int64 knapsack(vpii &re, int n, int wt, int s) {
	vector < int64 > ans(s + 1, biGinf);
	ans[0] = 0;
	for0(i, n) {
		for (int j = s; j >= re[i].S; j--) {
			ans[j] = min(ans[j], (int64)re[i].F + ans[j - re[i].S]);
		}
		// otpv2(ans);
		// cout << nwl;
	}
	int k = -1;
	for0(i, s + 1) if (ans[i] <= (int64)wt) k = i;
	return k;
}


int main() {
// #ifndef ONLINE_JUDGE
// 	if (fopen("input.txt", "r")) {
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	}
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code
	int n, wt;
	cin >> n >> wt;
	vpii re;
	int s = 0;
	for0(i, n) {
		int x, y;
		cin >> x >> y;
		s += y;
		re.pb({x, y});
	}

	cout << knapsack(re, n, wt, s);
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
using namespace std;
const int MAXN=100005;
const int MOD=20040301;
char a[MAXN];
int b[MAXN];
int ans[MAXN];
int d[MAXN];
int stack[MAXN];
int top;
bool tag;
int lef[MAXN],righ[MAXN];
int ou[MAXN];
int main()
{
	scanf("%s",a);
	int N=strlen(a);
	for(int i=1;i<=N;i++)
	{
		if(a[i-1]=='R')
		{
			b[i]=1;
		}
		else
		{
			b[i]=0;
		}
	}
	for(int i=1;i<=N;i++)
	{
		if(b[i]==b[stack[top]]&&top)
		{
			top--;
		}
		if(!b[i])
		{
			righ[i]=stack[top];
		}
		top++;
		stack[top]=i;
	}
	top=0;
	for(int i=N;i>=1;i--)
	{
		if(b[i]==b[stack[top]]&&top)
		{
			top--;
		}
		if(b[i])
		{
			lef[i]=stack[top];
		}
		top++;
		stack[top]=i;
	}
/*	for(int i=1;i<=N;i++)
	{
		if(b[i])
		{
			printf("%d ",lef[i]);
		}
		else
		{
			printf("%d ",righ[i]);
		}
	}*/
	for(int i=1;i<=N;i++)
	{
		if(b[i])
		{
			if((lef[i]-i)%2==1)
			{
				ou[lef[i]-1]++;
			}
			else
			{
				ou[lef[i]]++;
			}
		}
		else
		{
			if((i-righ[i])%2==1)
			{
				ou[righ[i]+1]++;
			}
			else
			{
				ou[righ[i]]++;
			}
		}
	}
	for(int i=1;i<=N;i++)
	{
		printf("%d ",ou[i]);
	}
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long ll;

int main() {
  //string s; cin >> s; int n = s.size()-1, m; cin >> m;
  int n, m; cin >> n >> m;
  string s; cin >> s;
  if (m >= n) {
    cout << n << endl;
    return 0;
  }
  int lf[n+1]; fill(lf, lf+n+1, 1e9);
  for(int i=n-1; i>=n-m; i--) {
    //cout << i << " " << s[i] << endl;
    if (s[i] == '0') lf[n] = i;
    //for(int x:lf) cout << x << " "; cout << endl;
  }
  for(int i=n-m-1; i>=0; i--) {
    //cout << i << " " << i+m << " " << i+m+1 << endl;
    if (s[i] == '0') lf[i+m] = i;
    else lf[i+m] = lf[i+m+1];
    //for(int x:lf) cout << x << " "; cout << endl;
  }
  for(int i=m; i>0; i--) {
    lf[i-1] = lf[i];
  }
  
  //for(int x:lf) cout << x << " "; cout << endl;
  
  int t = n; string res;
  stack<int> st; int jjj = 0;
  while(t>0 && jjj <= 1e6) {
    jjj++;
    st.push(t - lf[t]);
    t = lf[t];
    if (t == 1e9) return puts("-1") * 0;
  }
  if (jjj >= 1e6) return puts("-1") * 0;
  while(!st.empty()) {
    cout << st.top() << " "; st.pop();
  }
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
map<char,int> d;
int n=s.size();
string ans="yes";
rep(i,n){
    if(d.count(s[i])){
        ans="no";
    }
    d[s[i]]++;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  ll h,m,s;
  h=n/3600;
  n-=h*3600;
  m=n/60;
  n-=m*60;
  s=n;
  cout<<h<<":"<<m<<":"<<s<<endl;
}


Measured memory_bytes: 3096
/*#include<iostream>
using namespace std;
int main()
{
	int i,k,n,x,sum;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&x);
		for(i=1;i<=x;i++)
		{
			sum=i;
			k=i;
			while(k)
			{
				sum+=(k%10);
				k/=10;
			}
			if(sum==x)
			{
				printf("%d\n",i);
				break;
			}
		}
		if(i>x)
			printf("%d\n",0);
	}
	return 0;
}*/
#include<iostream>
using namespace std;
long long s(long long a,long long b,long long c)
{
	if(c>b)
		return 0;
	long long sum=1;
	if(a%c==0)
	{
		b-=(b%c);
		sum+=(b-a)/c;
	}
	else
	{
		a+=(c-(a%c));
		b-=(b%c);
		sum+=(b-a)/c;
	}
	return sum;
}
long long gcd(long long c,long long d)
{
	long long t;
	if(d>c)
	{
		t=c;
		c=d;
		d=t;
	}
	while(c%d)
	{
		t=c%d;
		c=d;
		d=t;
	}
	return d;
}
int main()
{
	long long a,b,c,d,x1,x2,x3;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	x1=s(a,b,c);
	x2=s(a,b,d);
	x3=s(a,b,c*d/gcd(c,d));
	printf("%lld",b-a+1-x1-x2+x3);
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
    input! {
      x: [i32; 5],
    }
    for i in 0..5 {
        if x[i] == 0 {
            println!("{}", i + 1);
        }
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int H, W;
  cin >> H >> W;
  VEC<string> s(H);
  REP(i, 0, H) { cin >> s[i]; }
  MAT<int> a=MATINIT(int, H, W, 0);
  REP(h, 0, H) {
    REP(w, 0, W) {
      if (s[h][w] == '#') {
        REP(i, 0, 3) {
          REP(j, 0, 3) {
            int ni = h + i - 1;
            int nj = w + j - 1;
            if(0<=ni && ni<H && 0<= nj && nj<W){
              ++a[ni][nj];
            }
          }
        }
      }
    }
  }

  REP(h, 0, H) {
    REP(w,0,W){
      if(s[h][w]=='.'){
        char c = '0' + a[h][w];
      cout << c;
      }
      else cout << '#';
    }
    cout << endl;
  }

  return 0;
  }


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000

int main(void){
	int i, n;
	scanf("%d", &n);
	double p[n];
	
	for(i = 0; i < n; i++){
		scanf("%lf",&p[i]);
	}
	
	double q[n+1];
	for(i = 0; i<= n; i++){
		scanf("%lf",&q[i]);
	}
	
	double Et[n+1][n+1];
	double d[n+1];
	Et[0][0]=q[0];
	d[0]=p[0]+q[0];
	
	for(i = 1; i <= n; i++){
		Et[i][i] = q[i];
		Et[i-1][i] = p[i-1]+(q[i-1]+q[i])*2;
		d[i] = d[i-1]+p[i]+q[i];
	}
	
	int j, k;
	double x,y;
	for(i = 1; i < n; i++){
		for(j = 0; j < n-i; j++){
			x = Et[j][j] + Et[j+1][i+j+1];
			for(k = j; k < i+j; k++){
				y = Et[j][k+1]+Et[k+2][i+j+1];
				if(x>y) x = y;
			}
			Et[j][i+j+1] = x + d[i+j] - d[j-1] + q[i+j+1];
		}
	}
	printf("%lf\n",Et[0][n]);
	return 0;
}


Measured memory_bytes: 3756
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())
 
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]
n=int(input())

print(A[n-1])


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

int main(){
  int i, j;
  char S[27];
  vector<bool> C(26, false);
  scanf("%s", S);
  for(i = 0; S[i] != '\0'; i++){
    C.at(S[i]-'a') = true;
  }
  if(i != 26){
    for(j = 0; j < 26; j++) if(C.at(j) == false) break;
    S[i] = 'a' + j;
    S[i+1] = '\0';
  }else if(strcmp(S, "zyxwvutsrqponmlkjihgfedcba") == 0){
    cout << -1 << endl;
    return 0;
  }else{
    vector<bool> C2(26, false);
    for(j = 25; j > 0; j--){
      C2.at(S[j]-'a') = true;
      if(S[j-1] < S[j]) break;
    }
    int k;
    for(k = S[j-1] - 'a'; k < 26; k++) if(C2.at(k) == true) break;
    S[j-1] = k + 'a';
    S[j] = '\0';
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for i in range(1, N):
    if a[i - 1] + a[i] > x:
        if a[i - 1] + a[i] - x <= a[i]:
            c += a[i - 1] + a[i] - x
            a[i] -= a[i - 1] + a[i] - x
        else:
            c += a[i - 1] + a[i] - x
            a[i] = 0
print(c)


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

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){
  ll N;
  cin >> N;
  string S;
  cin >> S;

  string res = "No";

  if(N % 2 == 0)
  {
    bool flg = true;
    for(int i = 0; i < N/2; ++i)
    {
      if(S[i] != S[i + N/2])flg = false;
    }
    if(flg)
    {
      res = "Yes";
    }

  }

  cout << res << endl;

  return 0;    
}



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

#define S 102 * 2
#define P 102

int main(){
	
	char s[S];
	char p[P];
	char temp[S] = "";
	int sLength;
	int pLength;
	int i, k;
	int pos;
	int flag = 0;
	
	fgets(s, sizeof(s), stdin);
	fgets(p, sizeof(p), stdin);
	s[strlen(s) - 1] = '\0';
	p[strlen(p) - 1] = '\0';
	strcat(temp, s);
	strcat(s, temp);
	
	sLength = strlen(s);
	pLength = strlen(p);
	
//	printf("s = %s\n", s);
//	printf("p = %s\n", p);
	
	for(i = 0; i <= sLength - pLength; i++){
		pos = 0;
		
		if(p[pos] == s[i]){
//			printf("searchStart@%d\n", i);
			for(k = 1; k < pLength; k++){
				if(p[pos + k] != s[i + k]){
					break;
				}
			}
		}
		
		if(k == pLength){
			flag = 1;
			break;
		}
		
	}
	
	if(flag){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 524
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
//USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN THE RESPECTIVE DATA STRUCTURE
//NOTE THAT MEMSET CANT FILL THE DOUBLE VALUES;
//ACCUMULATE DOES NOT WORK PROPERLY IF VALUES START SUMMING BEYOND 1E9...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!
 
// NUMERIC DEFINITIONS :
    #define INF 100000000000000005
    #define inf 1000000000
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500003;
   
void solve()
{
    ll n,k;cin>>n>>k;string s;cin>>s;
    char a = s[0];
    for(ll i=1;i<n && k;i++)
    {
        if(a!=s[i])
        {
            while(a!=s[i] && i<n)
            {
                s[i] = a;
                i++;
            }
               k--;
        }
     
    }
    ll ans =0;
    for(ll i=1;i<n;i++)
    {
        if(s[i]^s[i-1])continue;
        ans++;
    }
    cout<<ans<<endl;

}
 
signed main()
{
   Need_for_speed(activated);
//
//satisy
//    {
//  solve();
//   }
 
    solve();
    
    return 0;
}
 


Measured memory_bytes: 3780
def main():
    N = int(input())
    W = [input() for _ in range(N)]
     
    # まだ発話していない
    w = set(W)
    if len(W) != len(w):
        print('No')
        return

    # 先頭は直前の単語の末尾と一致
    for i in range(len(W)-1):
        be = W[i][-1]
        af = W[i+1][0]
        if be != af:
            print('No')
            return
    print('Yes')
    return



main()

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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

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


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

def case1(h, w):
    MIN = float('inf')
    for i in range(1, h):
        sa = i * w
        sb = (h - i) * (w//2)
        sc = (h - i) * (w - w//2)
        if max([sa,sb,sc]) - min([sa,sb,sc]) < MIN:
            MIN = max([sa,sb,sc]) - min([sa,sb,sc]) 
    return MIN

def case2(h, w):
    MIN = float('inf')
    for i in range(1, h):
        sa = i * w
        sb = (h - i)//2 * w
        sc = (h - i -(h - i)//2) * w
        if max([sa,sb,sc]) - min([sa,sb,sc]) < MIN:
            MIN = max([sa,sb,sc]) - min([sa,sb,sc]) 
    return MIN
print(min([case1(H,W) , case1(W,H), case2(H,W), case2(W,H)]))

Measured memory_bytes: 3064
from itertools import permutations
from math import sqrt

N = int(input())
x, y = [], []
dist = []

for n in range(N):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)

for i in permutations(range(N)):
    d = 0
    for j in range(len(i) - 1):
        d += sqrt((x[i[j]] - x[i[j + 1]])**2 + (y[i[j]] - y[i[j + 1]])**2)
    dist.append(d)

print(sum(dist) / len(dist))

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
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();}


int main(){
  string  s;
  cin >> s;
  rep(i,s.size()-2){
    if(s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]){
      cout << i+1 << ' ' << i+3 << endl;
      return 0;
    }
  }
  rep(i,s.size()-1){
    if(s[i] == s[i+1]){
      cout << i+1 << ' ' << i+2 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int res = 0;
  res += min(a, k);
  k = max(k - a, 0);
  k = max(k - b, 0);
  res -= min(c, k);
  cout << res << endl;
}


Measured memory_bytes: 3628
from collections import Counter
N, K =  map(int, (input().split(' ')))
sushi = [tuple(map(int, input().split(' '))) for _ in range(N)]
all_sushi = sorted(sushi, key=lambda x: -x[1])
default_sushi = all_sushi[:K]
amari = all_sushi[K:]
len_amari = len(amari)
counter = Counter([i[0] for i in default_sushi])
result = []
def calc_value(sushi):
    return sum([i[1] for i in sushi]) + len(counter)**2

fs = []
def change_sushi(sushi):
    oishisa = sum([i[1] for i in sushi])
    fs.append(oishisa + len(counter)**2)
    amari_index = 0
    for s in sushi[::-1]:
        if counter[s[0]] >= 2:
            while amari_index < len_amari:
                a = amari[amari_index]
                amari_index += 1
                if a[0] not in counter:
                    counter[s[0]] -= 1
                    counter[a[0]] += 1
                    oishisa = oishisa - s[1] + a[1]
                    fs.append(oishisa + len(counter)**2)
                    break
    print(max(fs))
    exit()
            
    
def get_sushi(sushi):
    #result.append(calc_value(sushi))
    changed_sushi = change_sushi(sushi)
    #if not changed_sushi:
        #print(max(result))
        #return
    #get_sushi(changed_sushi)

get_sushi(default_sushi)


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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b){
		if(a!=c) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else if(b==c) cout << "Yes" << endl;
	else if(a==c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()

  def divi(n):
    res = []
    for i in range(1, int(n**0.5)+1):
      if n % i == 0:
        res.append(i)
        if i != n // i:
          res.append(n // i)
    return res

  def digitlen(n):
    return len(str(n))
  
  def f(a, b):
    x = digitlen(a)
    y = digitlen(b)
    if x >= y:
      return x
    else:
      return y

  if n == 1:
    print(1)
    return 

  ans = int(1e9+7)
  for e in divi(n):
    b = n // e
    ans = min(ans, f(e, b))
  print(ans)
  
main()

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;

namespace agc037_a
{
  class Program
  {
    static void Main(string[] args)
    {
      var s = CIn.Read().ToCharArray();

      var ans = 0;
      var last = "";
      var now = "";

      for (var i = 0; i < s.Length; i++)
      {
        now = "";

        for (var j = i; j < s.Length; j++)
        {
          now += s[j];

          if (last != now)
          {
            i = j;
            last = now;
            ans++;
            break;
          }
        }
      }

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 17120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll d,t,s;
  cin >> d >> t >> s;
  if(t*s>=d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3644
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        boolean[][] f = new boolean[n][10];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 10; j++) {
                f[i][j] = in.ni()==1;
            }
        }
        int[][] p = new int[n][11];
        for (int i = 0; i < n; i++) p[i] = in.ni(11);
        int ans = Integer.MIN_VALUE, sum = 0, count = 0;
        String format = "%".concat(String.valueOf(10)).concat("s"), s;
        for (int i = 1; i < (1 << 10); i++) {
            s = String.format(format, Integer.toString(i,2)).replace(' ', '0');
            sum = 0;
            for (int j = 0; j < n; j++) {
                count = 0;
                for (int k = 0; k < 10; k++) {
                    if(s.charAt(k)=='1'&&f[j][k]) count++;
                }
                sum += p[j][count];
            }
            ans = Math.max(ans, sum);
        }
        out.println(ans);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

const int MAX = 100;
bool dictionary(string l, string r) {
	for (int i = 0;i < min(l.length(), r.length());i ++) {
		if (l[i] > r[i]) return false;
		else if (l[i] < r[i]) return true;
	}
	return l.length() < r.length();
}
int main() {
	int N, L;
	cin >> N >> L;
	string S[MAX];
	for (int i = 0;i < N;i ++) cin >> S[i];
	sort(S, S+N, dictionary);
	for (int i = 0;i < N;i ++) cout << S[i];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

stringをこの規則で実装してくれるソートアルゴリズムはないはずなので自力実装が不可欠だね
幸い、条件はあるし、O(N^2)は許されるのでバブルソートが手頃なんじゃないかな
上コードのように、algorithmのソートに比較関数だけ渡すのも手だね
オーダーはO(NLlogN)、かな
*/

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<string> vs;
typedef vector<Def> vi;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
vs in,bl;
int n,m,out;
void f(int a,int b,vs NOW){
//	rep(i,3)cout<<in[i]<<endl;
//	cout<<endl;
	if(a==m){
		out=max(out,b);
		return;
	}
	for(int x=-1;x<2;x++){
		for(int y=-1;y<2;y++){
			vs now=NOW;
			bool h=true;
			rep(i,2)rep(j,2)rep(k,2){
				int dx=x+j;
				int dy=y+k;
				if(dx<0||dy<0||dx>=2||dy>=2);
				else continue;
				if(bl[a][i*4+j*2+k]=='#')h=false;
			}
			if(h){
				int pos=0;
				for(int w=30;w>=0;w--){
					bool h=true;
					rep(i,2)rep(j,2)rep(k,2){
						int dx=x+j,dy=y+k;
						if(dx<0||dy<0||dx>=2||dy>=2)continue;
						if(bl[a][i*4+j*2+k]=='#'&&now[w+i][dx*2+dy]=='#')
							h=false;
					}
					
					if(!h){
						pos=w+1;
						break;
					}
				}
				rep(i,2)rep(j,2)rep(k,2){
					int dx=x+j,dy=y+k;
					if(dx<0||dy<0||dx>=2||dy>=2)continue;
					if(bl[a][i*4+j*2+k]=='#'){
						now[pos+i][dx*2+dy]='#';
					}
				}
				int co=0;
				loop(i,1,now.size()){
					if(now[i]=="####"){
						co++;
						now.erase(now.begin()+i);
						i--;
					}
				}
				f(a+1,b+co,now);
			}
		}
	}
}
int main(){
	while(cin>>n>>m,n){
		in=vs(40,"....");
		in[0]="####";
		rep(i,n){
			string a,b;cin>>a>>b;
			in[i+1]=a+b;
		}
		bl=vs(m);
		rep(i,m){
			string a,b,c,d;cin>>a>>b>>c>>d;
			bl[i]=a+b+c+d;
		}
		out=0;
		f(0,0,in);
		cout<<out<<endl;
	}
}


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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; ++i) cin >> a[i], a[i]--;
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 1; i < n; ++i) cin >> c[i];
	int ans = b[a[0]];
	for (int i = 1; i < n; ++i) {
		ans += b[a[i]];
		if (a[i] - a[i - 1] == 1) ans += c[a[i]];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int              //cout<<fixed<<setprecision(9)<<double value; 
#define INF 1000000000000000007
#define pb emplace_back 
#define md 1000000007
#define all(s) s.begin(),s.end()
typedef vector<int> vi;
int gh[100005];
int d=13;
ll dp[100005][14];
ll getsum(int idx,int n,int sum){
	if(idx>n)return (sum==5);
	if(dp[idx][sum]!=-1)return dp[idx][sum];
	ll res=0;
	if(gh[idx]!=-1){
		res+=getsum(idx+1,n,(sum*10+gh[idx])%d);
	}
	else{
		for(int i=0;i<=9;i++){
			res+=getsum(idx+1,n,(sum*10+i)%d);
		}
	}
	/*for(int i=0;i<=limit;i++){
		if(i<limit||flag){
			res+=getsum(idx+1,n,(sum+i)%d,true);
		}
		else{
			res+=getsum(idx+1,n,(sum+i)%d,false);
		}
	}*/
	return dp[idx][sum]=res%md;
}
void solve(){
	string b;
	cin>>b;
	//cin>>d;
	for(int i=0;i<b.size();i++){
		if(b[i]=='?')
		gh[i+1]=-1;
		else
		gh[i+1]=b[i]-'0';
	}
	memset(dp,-1,sizeof dp);
    ll r=getsum(1,b.size(),0);
   cout<<(r)%md<<"\n";
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
   int t=1;
  // cin>>t;
     while(t--){
     	solve();
	 }
     return 0;
}

Measured memory_bytes: 22872
#include <iostream>
using namespace std;
int n, m, k;
int main()
{
	cin >> n >> m >> k;
	for (int x = 0; x <= m; x++)
		for (int y = 0; y <= n; y++)
			if (y * m + x * n - 2 * x * y == k)
				return cout<<"Yes", 0;
	cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll N,M;
Graph G(100010);

ll D[3][100010];
bool done[100010];
priority_queue<pair<ll,ll>> Q;

ll stop = 0;

void dijkstra(ll s){
    rep(i,3) fill(D[i],D[i] + 100010,INF);
    fill(done,done+100010,false);
    D[0][s] = 0;
    Q.emplace(0,s);
    while(Q.size()){
        stop++;
        ll x = Q.top().second;
        ll n = G[x].size();
        Q.pop();
        if(D[0][x] != INF && D[1][x] != INF && D[2][x] != INF) done[x] = true;
        rep(i,n){
            ll y = G[x][i];
            if(D[0][y] != INF && D[1][y] != INF && D[2][y] != INF) continue;
            rep(j,3){
                if(D[j][x] == INF) continue;
                else{
                    if(D[(j+1) % 3][y] > D[j][x] + 1){
                        D[(j+1) % 3][y] = min(D[(j+1) % 3][y],D[j][x] + 1);
                        Q.emplace(-D[(j+1) % 3][y],y);
                    }
                }
            } 
        }
    }
}

int main(){
    cin >> N >> M;
    rep(i,M){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    ll S,T;
    cin >> S >> T;
    S--;T--;
    dijkstra(S);
    /*rep(i,N){
        rep(j,3) cout << D[j][i] << ' ';
        cout << endl;
    }*/
    if(D[0][T] == INF){
        cout << -1 << endl;
    }else{
        cout << D[0][T] / 3 << endl;
    }
}


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

int main(){
  int a,b,x;
  cin>>a>>b>>x;
  if(x>=a&&x<=a+b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	vector<bool> sunuke(n, true);
	for (int i = 0; i < k; i++) {
		int okashi; cin >> okashi;

		for (int j = 0; j < okashi; j++) {
			int x; cin >> x;
			sunuke.at(x - 1) = false;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (sunuke.at(i)) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3640
A,B,C,X,Y = map(int,input().split())
if C >= A/2 + B/2:
  print(A*X+B*Y)
else:
  if X < Y:
#    add_cost_half = 2*(Y-X)*C
#    add_cost = (Y-X)*B
    ness_cost = 2*X*C
    add_cost_min = (Y-X)*min(2*C,B)
    total_cost = ness_cost + add_cost_min
    print(total_cost)
  elif X >= Y:
    ness_cost = 2*Y*C
    add_cost_min = (X-Y)*min(2*C,A)
    total_cost = ness_cost + add_cost_min
    print(total_cost)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  //in
  cin >> n;
  pair<int,int> b;
  vector<pair<char,int> >a(n,pair<char,int>(0,0));
  vector<pair<int,int> >y;
  vector<bool> del(n,0);
  int c=0;
  for(int i=0;i<n;i++){
    cin >> a[i].first >> a[i].second;
    if(a[i].first=='y'){
      b.first=a[i].second;
      b.second=i;
      y.push_back(b);
    }
  }
  //syori
  sort(y.begin(),y.end());
  for(int i=0;i<y.size();i++){
    if(del[y[i].second]==1)continue;
    c++;
    for(int j=y[i].second;j<a.size();j++){
      if(a[j].first=='n'&&a[j].second>=y[i].first)break;
      else{
	del[j]=1;
      }
    }
    for(int j=y[i].second;j>=0;j--){
      if(a[j].first=='n'&&a[j].second>=y[i].first)break;
      else{
	del[j]=1;
      }
    }
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3132
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;

int main(void){
    std::string s;
    int ans=0;
    cin >> s;

    for(int i=0;i<5;i++){
        if(s[i]=='A' && s[i+1]=='C'){ans++;}
        else{;}
    }

    if(ans>=1){printf("Yes");}
    else{printf("No");}
}

Measured memory_bytes: 256
# coding:utf-8
from functools import lru_cache


@lru_cache(maxsize=None)
def lucas(num):
    if num == 0:
        return 2
    elif num == 1:
        return 1
    else:
        return lucas(num - 1) + lucas(num - 2)


def main():
    n = int(input())
    print(lucas(n))


if __name__ == "__main__":
    main()


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

int main()
{
    int a,b,c,k,n=0;
    cin >>a>>b>>c>> k;
    if(k<=a)
    n+=k;
    else if(k<=(a+b))
    n=a;
    else
    n+=2*a-(k-b);
    cout << n;

    return 0;
}

Measured memory_bytes: 3636
def main():
    x = int(input())
    if x <= 6:
        ans = 1
    else:
        p, q = divmod(x, 11)
        r, s = divmod(q, 6)
        ans = 2 * p + r + int(s != 0)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] a = null;
		try(Scanner sc = new Scanner(System.in)){
			// N入力 aスペース区切り入力
			a = new int[sc.nextInt()];
			for(int i = 0; i < a.length; i ++) {
				a[i] = sc.nextInt();
			}
		}
		
		// a要素の4の倍数カウント
		int cnt4 = 0;
		// a要素の2の倍数カウント
		int cnt2 = 0;
		for(int i = 0; i < a.length; i++) {
			
			// 要素が4の倍数
			if(a[i] % 4 == 0) {
				cnt4++;
			}
			// 要素が2の倍数
			else if(a[i] % 2 == 0){
				cnt2++;
			}
		}
		// 2の倍数の数を要素数から排除
		int n = a.length - cnt2;
		
		// 2の倍数が存在した
		if(cnt2 != 0){
			// 偶数
			if(n % 2 == 0) {
				// 4の倍数が要素の半分以上
				if((n /2) <= cnt4) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}				
			} else {
				// 4の倍数が要素の半分より上
				if((n /2) < cnt4) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}				
			}
		} else {
			// 4の倍数が要素の半分以上
			if((n /2) <= cnt4) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 50392
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

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

    map<string, ll> mp;
    rep(i,n){
        string tmp;
        cin >> tmp;
        sort(tmp.begin(), tmp.end());
        mp[tmp]+=1;
    }
    damp(mp)
    ll ans=0LL;
    for(auto p : mp){
        ans+= (p.second-1LL)*(p.second)/2;
    }
    cout << ans << endl;
    return 0;
}

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

M = [[0]*10 for _ in range(10)]
for i in range(1, N+1):
    s = str(i)
    M[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += M[i][j] * M[j][i]
print(ans)

Measured memory_bytes: 41580
#include <bits/stdc++.h>    //vectorを使う
#include <string>
using namespace std;


int main(void){
    string s;
    cin >> s ;
    int cnt=0;
    for(int i=0; i < s.size(); ++i){
        if(s.at(i)-'0'==i%2){
            cnt=cnt+1;
        }
    }
    if(s.size()/2>=cnt){
        cout << cnt << endl;
    }else{
        cout << s.size()-cnt << endl;
    }
}

Measured memory_bytes: 512
INF = 10 ** 10
MOD = 10 ** 9 + 7

def solve(N):
    HP = [int(input()) for _ in range(N)]
    M = int(input())
    all_magic = []
    single_magic = []
    zero = False
    for _ in range(M):
        a = input().split()
        if zero:
            continue
        if a[2] == 'Single':
            mp = int(a[1])
            dam = int(a[3])
            if mp == 0 and dam > 0:
                zero = True
                continue
            single_magic.append((mp,dam))
        else:
            mp = int(a[1])
            dam = int(a[3])
            if mp == 0 and dam > 0:
                zero = True
                continue
            all_magic.append((mp,dam))
    if zero:
        print(0)
        return

    MAXHP = max(HP) + 5
    dp_single = [INF] * MAXHP
    dp_single[0] = 0
    for p,damage in single_magic:
        for i in range(min(damage,MAXHP)):
            dp_single[i] = min(dp_single[i],p)
        for i in range(damage,MAXHP):
            dp_single[i] = min(dp_single[i],dp_single[i - damage] + p)
    for i in range(MAXHP - 2,-1,-1):
        dp_single[i] = min(dp_single[i],dp_single[i + 1])

    dp_all = [INF] * MAXHP
    dp_all[0] = 0
    for p,damage in all_magic:
        for i in range(min(damage,MAXHP)):
            dp_all[i] = min(dp_all[i],p)
        for i in range(damage,MAXHP):
            dp_all[i] = min(dp_all[i],dp_all[i - damage] + p)
    
    ans = INF
    for all_dam in range(MAXHP):
        ret = dp_all[all_dam]
        if ret == INF:
            continue
        for h in HP:
            h -= all_dam
            if h > 0:
                ret += dp_single[h]
        ans = min(ans,ret)
    print(ans)

def main():
    while True:
        N = int(input())
        if N == 0:
            return
        solve(N)
if __name__ == '__main__':
    main()



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

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    char b[h][w];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
            cin >> b[i][j];
    }
    int ans = 0;
    for (int t = 0; t < (1 << (h + w)); t++)
    {
        bitset<12> s(t);
        int count = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (!s[i] && !s[h + j])
                    count += (b[i][j] == '#');
            }
        }
        ans += (count == k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int dp[1001][1001];
int map[1001][1001];
int MOD = 1000000007;

int main(void){
	int H, W; cin >> H >> W;
	for(int i=0; i<H; i++){
		string str; cin >> str;
		for(int j=0; j<W; j++){
			if(str[j] == '.') map[i][j] = 1;
			else map[i][j] = -1;
		}
	}

	dp[0][0] = 1;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(map[i][j] == -1) continue;
			if(i!=0) dp[i][j] += dp[i-1][j];
			if(j!=0) dp[i][j] += dp[i][j-1];
			dp[i][j] %= MOD;
		}
	}

	cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 8064
import numpy as np
h,w=map(int,input().split())
field=[list(input()) for i in range(h)]
field=[[0 if field[j][i]=='#' else h+w for i in range(w)]for j in range(h)]
field=np.array(field)
for i in range(1,h):
  field[i,:]=np.minimum(field[i,:],field[i-1,:]+1)
for i in range(h-1,0,-1):
  field[i-1,:]=np.minimum(field[i,:]+1,field[i-1,:])
for i in range(1,w):
  field[:,i]=np.minimum(field[:,i],field[:,i-1]+1)
for i in range(w-1,0,-1):
  field[:,i-1]=np.minimum(field[:,i]+1,field[:,i-1])
print(np.max(field))

Measured memory_bytes: 69264
#include<bits/stdc++.h>
using namespace std;
int n,s[100000],q,t,c,l,m,r,i,j;
main(){  
  for(cin>>n;i<n;cin>>s[i++]);
  for(cin>>q;j++<q;){
    l=0,r=n,cin>>t;
    while(m=(l+r)/2,l<r){
      if(t==s[m]){c++;break;}
      if(t<s[m])r=m;
      else if(t>s[m])l=m+1;
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  string s;
  cin>>a>>s;
  for(int i=0;i<a/2+1;i++){
    if(s[i]!=s[i+a/2]||a%2==1){
    cout<<"No"<<endl;
    break;
    }
    if(s[i]==s[i+a])
      continue;
    if(i==a/2-1&&s[i]==s[i+a/2]){
      cout<<"Yes"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

previous_dish = -100
satisfaction_level = 0

for index in range(n):
    satisfaction_level += b[a[index] - 1]
    if previous_dish + 1 == a[index]:
        satisfaction_level += c[previous_dish - 1]

    previous_dish = a[index]

print(satisfaction_level)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main(int argc, const char * argv[]) {
    vector<string> v(3);
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    int cnt[3] = {0, 0, 0}, num = 0;
    while (1) {
        if (cnt[num] >= v[num].length()) {
            if (num == 0) {
                cout << 'A' << endl;
            } else if (num == 1) {
                cout << 'B' << endl;
            } else {
                cout << 'C' << endl;
            }
            return 0;
        }

        int tmp = num;
        if (v[num][cnt[num]] == 'a') {
            num = 0;
        }else if(v[num][cnt[num]] == 'b'){
            num = 1;
        }else{
            num = 2;
        }
        cnt[tmp]++;
    }
}

Measured memory_bytes: 256