akhauriyash/Code-Regression huggingface dataset:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    R, S, P = il()
    T = list(iss())

    ret = 0
    bk = ['n']*N
    for n in range(N):
        t = T[n]
        tmp = 0
        if t == 'r' and bk[n-K] != 'p':
            tmp = P
            bk[n] = 'p'
        elif t == 's' and bk[n-K] != 'r':
            tmp = R
            bk[n] = 'r'
        elif t == 'p' and bk[n-K] != 's':
            tmp = S
            bk[n] = 's'

        ret += tmp

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4780
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	long long x;
	cin >> x;
	if(x%10==x){
		cout << x << endl;
		return 0;
	}
	long long x_temp=x;
	bool all_9=true;
	int keta=0,now,now_sum=0;
	while(x_temp){
		keta++;
		now=x_temp%10;
		now_sum+=now;
		if(now!=9)all_9=false;
		x_temp/=10;
	}
	if(all_9==true){
		cout << 9*keta << endl;
		return 0;
	}
	long long ans=max(now_sum,9*(keta-1)+(now-1));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int N, A[100001], B[100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, A);
    copy_n(A, N, B), sort(B, B + N);
    for_each(A, A + N, [](int &v) { v = lower_bound(B, B + N, v) - B; });
    fill_n(B, N + 1, 0);
    int ans = 0;
    for (int i = 0; i < N; i++) ans += (A[i] - i) & 1;
    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 4440
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws Exception
	{
		int n=nextInt();
		int cnt[]=new int[n+1];
		for(int x=1;x*x<=n;x++)
			for(int y=1;y*y<=n;y++)
				for(int z=1;z*z<=n;z++)
				{
					int curr=x*x+y*y+z*z+x*y+y*z+z*x;
					if(curr<=n)
						cnt[curr]++;
				}
		for(int i=1;i<=n;i++)
			out.println(cnt[i]);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 33984
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stdio.h>

using namespace std;
int main(void)
{
    long long a;
    long long b;
    long long x;
    
    cin >> a >> b >> x;

    long long ans = 0;

    if (a == 0) {
        ans = b / x + 1;
    }
    else {
        ans = (b / x) - ((a-1) / x);
    }

    cout << ans << endl;



    return 0;
}

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int64_t> A;
    A.reserve(N);
    std::cin.ignore();
    int64_t total = 0;
    int64_t other = 0;
    int n = N;
    while(n > 0) {
        int v;
        std::cin >> v;
        total += v;
        v *= 2;
        if(n%2 == 0) other += v;
        A.push_back(v);
        --n;
    }
    
    int64_t x = total-other;
    for(int i = 0; i < N -1; ++i) {
        std::cout << x <<" ";
        x = A[i] - x;
    }
    std::cout<< x <<std::flush;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
main(){
  int n=5;
  int a[n];
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=1;i<=n;i++)
    if(a[i]==0){
      cout<<i<<endl;
  break;}}
  

Measured memory_bytes: 3636
using System;
using System.Linq;
public class B{
        public static void Main(){
        long[] nk = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        long ans = nk[1];
        for (long i = 0;i<nk[0]-1;i++){
            ans *= (nk[1]-1);
        }
        
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Mod=1000000007;
int n,K;
#define Maxn 100010
int fact[Maxn],inv[Maxn];
int head[Maxn],v[Maxn<<1],nxt[Maxn<<1],tot=0;
int siz[Maxn],dp[Maxn],mul[Maxn],son[Maxn];
inline void add_edge(int s,int e){
	tot++;v[tot]=e;nxt[tot]=head[s];head[s]=tot;
	tot++;v[tot]=s;nxt[tot]=head[e];head[e]=tot;
}
inline int A(int a,int b){
//	cout<<"a b "<<a<<"  "<<b<<endl; 
	if(a<b)return 0;
//	cout<<fact[a]<<" "<<inv[a-b]<<endl;
	return 1ll*fact[a]*inv[a-b]%Mod;
	}

int Ans;
void dfs(int u,int f){
	son[u]=0;
	for(int i=head[u];i;i=nxt[i])
	    if(v[i]^f){
			son[u]++;
			dfs(v[i],u);
	    }
	if(son[u]){
		if(u==1)Ans=1ll*Ans*A(K-1,son[u])%Mod;
		else Ans=1ll*Ans*A(K-2,son[u])%Mod;
	//	cout<<"u "<<son[u]<<" "<<Ans<<endl;
	}
}

int main(){
	scanf("%d%d",&n,&K);
	Ans=K;
	fact[0]=1;
	for(register int i=1;i<=K;++i)fact[i]=1ll*fact[i-1]*i%Mod;
	inv[0]=inv[1]=1;
	for(register int i=2;i<=K;++i)inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for(register int i=2;i<=K;++i)inv[i]=1ll*inv[i]*inv[i-1]%Mod;
	int s,e;
	for(register int i=1;i<n;++i){
		scanf("%d%d",&s,&e);
		add_edge(s,e);
	}
	dfs(1,0);
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int i, j, k, n, x;
	cin >> n;
	vector<int> ans(n + 1, 0);
	for (i = 1; i * i <= n; i++) {
		for (j = 1; j * j <= n; j++) 
			for (k = 1; k * k <= n; k++) {
				x = i * i + j * j + k * k + i * j + j * k + k * i;
				if (x <= n) ans[x]++;
			}
	}

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


Measured memory_bytes: 3252
#include<bits/stdc++.h>
#define ull unsigned long long
#define lowbit(x) ((x)&(-x))
#define dis(p,q) sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y))

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
typedef long long ll;
typedef double db;
using namespace std;

namespace _{
    bool rEOF = 1;//为0表示文件结尾
    inline char nc(){
        static char buf[100000], *p1 = buf, *p2 = buf;
        return p1 == p2&&rEOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (rEOF = 0, EOF) : *p1++;
    }
    template<class _T>
    inline bool read(_T &num){
        char c = nc(), f = 1; num = 0;
        while (c<'0' || c>'9')c == '-' && (f = -1), c = nc();
        while (c >= '0'&&c <= '9')num = num * 10 + c - '0', c = nc();
        return (bool)(num *= f);
    }
    inline bool need(char &c){ return c >= 'a'&&c <= 'z' || c >= 'A'&&c <= 'Z'; }//读入的字符范围
    inline bool read_str(char *a){
        while ((*a = nc()) && need(*a) && rEOF)++a;
        *a = '\0'; return rEOF;
    }
}using namespace _;
int a[100005];
struct node
{
    int b,c,k;
    bool friend operator <(node x,node y)
    {
        if(x.c==y.c)
            return x.b<y.b;
        return x.c>y.c;
    }
}q[100005];
priority_queue<int,vector<int >,greater<int > >que;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),que.push(a[i]);
    for(int i=1;i<=m;i++)
        scanf("%d%d",&q[i].b,&q[i].c);
    sort(q+1,q+1+m);
    for(int i=1;i<=m;i++)
    {
        while(q[i].b--)
        {
            int k=que.top();
            if(k<q[i].c)
            {
                que.pop();
                que.push(q[i].c);
            }
            else break;
        }
    }
    ll ans=0;
    while(que.size())
    {
        int k=que.top();
        que.pop();
        ans+=k;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2296
#include<iostream>
#include<cstring>
#include<cctype>
using namespace std;

int main(){
    char swap;
    string str;
    int length,i;

    getline(cin,str);
    length = str.size();
    for(i=0;i<length;i++){
        if(isalpha(str[i])){
            if(islower(str[i])){
                swap = str[i];
                str[i] = toupper(swap);
            }else if(isupper(str[i])){
                swap = str[i];
                str[i] = tolower(swap);
            }
        }
    }
    cout << str << endl;
    return 0;
}



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

using namespace std;

double dp[3005][3005];//dp[i][j] -> we get j heads from first i coins 

int main(){
  int n;
  cin>>n;
  dp[0][0]=1.0;
  for(int i=1;i<=n;i++){
    double p;
    cin>>p;
    for(int j=0;j<=i;++j){
    	dp[i][j] = (j>0?(p*dp[i-1][j-1]):0.0) + (1.0-p)*dp[i-1][j];
    }
  }
  double ans = 0;
  for(int i=0;i<=n;i++){
  	if(i>n-i){
      ans+=dp[n][i];
    }
  }
  cout<<fixed<<setprecision(10)<<ans;
  return 0;
}

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

#define fi first
#define se second
typedef pair<int,int> PII;

int n;
vector <int> g[1<<17];

int dive(int u) {
    int ret = 0;
    vector <int> dp;
    for (auto v : g[u])
        dp.push_back(dive(v));
    sort(dp.begin(),dp.end());
    for (auto x : dp) {
        if (x <= ret) ret++;
        else ret = x + 1;
    }
    return ret;
};

int main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u;
        cin >> u;
        u--;
        g[u].push_back(i);
    }
    cout << dive(0);
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
int a[100005];
LL f[100005], r[100005];
LL inv(LL a){
    LL res = 1, b = mod-2;
    while(b){
        if(b%2 == 1) res = res*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return res;
}
void prec(int n){
    f[0] = 1;
    for(int i=1;i<=n;i++) f[i] = f[i-1]*i%mod;
    for(int i=0;i<=n;i++) r[i] = inv(f[i]);
}
LL C(int a, int b){
    return f[a]*r[b]%mod*r[a-b]%mod;
}
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    prec(n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    sort(a+1, a+1+n);
    for(int i=1;i<=n;i++) a[i] = (a[i] + mod)%mod;
    if(k == 1) printf("0\n");
    else{
        LL ans = 0;
        for(int i=k;i<=n;i++) ans = (ans + C(i-1, k-1)*a[i]%mod)%mod;
        for(int i=n-k+1;i>=1;i--) ans = (ans - C(n-i, k-1)*a[i]%mod + mod)%mod;
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vull = vector<ull>;
#define rep(i, n) for (ull i = 0; i < n; ++i)
#define rep1(i, n) for (ull i = 1; i < n; ++i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define pb push_back
#define fi first
#define se second
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}
template <typename T> void arrout(const T arr, int n) {
  for (int i = 0; i < n; ++i, cout << (i != n ? " " : "\n")) {
    cout << arr[i];
  }
}

vull divisors(ull n){
  vull v0,v1;
  ull MAX=(int)sqrt(n)+1;
  rep1(i,MAX) if(n%i==0) {
    v0.pb(i); v1.pb(n/i);
  }
  reverse(v1.begin(),v1.end());
  auto it=v1.begin();
  if(v0.back()==v1.front()) it++;
  copy(it,v1.end(),back_inserter(v0));
  return v0;
}

void solve() {
  // main coding
  ll a,b,k; cin>>a>>b>>k;
  ll g=gcd(a,b);
  vull v=divisors(g);
  reverse(v.begin(),v.end());
  cout<<v[k-1]<<endl;
}

int main() {
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
b = 2 ** N
minima = int(1e18)
flg = False
for i in range(b):
  S = 0
  L = [0 for _ in range(N)]
  SS = [0 for _ in range(M)]
  tmp = i
  for j in range(N):
    if tmp % 2 == 1:
      L[j] = 1
    tmp //= 2
  for k in range(N):
    if L[k] == 1:
      S += A[k][0]
      for l in range(M):
        SS[l] += A[k][l+1]
  if min(SS) >= X:
    flg = True
    if minima > S:
      minima = S
if flg:
  print(minima)
else:
  print(-1)

Measured memory_bytes: 9248
#include <iostream>
#include <cstdio>
//#define ll long long
#define ll long long
using namespace std;
ll cnm(ll n,ll m)
{
	if(m>n/2)
	m=n-m;
	ll a=1,b=1;
	for(int i=1;i<=m;i++)
	{
		a*=n+1-i;
		b*=i;
		if(a%b==0)
		{
			a/=b;
			b=1;
		}
	}
	return a/b;
}
const int N=1e5*2+2;
int a[N];
int num[N];
ll c[N];
int main(){
	int k;
	scanf("%d",&k);
	int maxn=0;
	for (int i=1;i<=k;i++){
		scanf("%d",&a[i]);
		maxn=max(maxn,a[i]);
		num[a[i]]++;
	}
	for (int i=2;i<=k;i++){
		c[i]=cnm(i,2);
	}
	ll ans=0;
	for (int i=1;i<=maxn;i++){
//		cout<<i<<" "<<num[i]<<endl;
		if (num[i])ans+=c[num[i]];
	}
	for (int i=1;i<=k;i++){
		ll ansn=ans;
		ansn-=c[num[a[i]]];
		ansn+=c[num[a[i]]-1];
		printf("%lld\n",ansn);
	}
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >>s;
  string t[4];
  t[0]="SS";t[1]="SW";t[2]="WS";t[3]="WW";
  int flag=0;
  rep(i,4){  
    string ans;
    ans=t[i];
    rep1(i,n-2){
      if((ans[i]=='S' && s[i]=='o') || (ans[i]=='W' && s[i]=='x')){
	ans.pb(ans[i-1]);
      }
      else{
	if(ans[i-1]=='S') ans.pb('W');
	else ans.pb('S');
      }
    }
    if((ans[n-1]=='S' && s[n-1]=='o') || (ans[n-1]=='W' && s[n-1]=='x')){
      if(ans[0]==ans[n-2]) flag=1;
    }
    else{
      if(ans[n-2]!=ans[0]) flag=1;
    }
    if(flag){
      if((ans[0]=='S' && s[0]=='o') || (ans[0]=='W' && s[0]=='x')){
	if(ans[1]==ans[n-1]) flag=2;
      }
      else{
	if(ans[n-1]!=ans[1]) flag=2;
      }
    }
    if(flag==2){
      rep(i,n)cout << ans[i];
      cout << "" << endl;
      break;
    }
    flag=0;
  }
  if(flag!=2) cout << -1 << endl;
  
  return 0;
  

}


Measured memory_bytes: 712
using System;
using System.Linq;
class Program
{

    static void Main(string[] args)
    {
        var num = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var d = 1;
        while (num[0] >= num[1])
        {
            num[0] /= num[1];
            d++;
        }
        Console.WriteLine(d);
    }
}


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

int main() {
    int h, w;
    cin >> h >> w;
    string s[60];
    for(int i = 0; i < h; ++ i) cin >> s[i];
    
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
    
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(s[i][j] == '#') continue;
            
            int counter = 0;
            for(int d = 0; d < 8; ++d) {
                const int ni = i + dx[d];
                const int nj = j + dy[d];
                
                if(ni < 0 || h <= ni) continue;
                if(nj < 0 || w <= nj) continue;
                if(s[ni][nj] == '#') ++counter;
            }
            
            s[i][j] = '0' + counter;
        }
    }
    
    for(int i = 0; i < h; ++i) cout << s[i] << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main{    Main(){
	Scanner sc =new Scanner(System.in);
	while(true){
	    int a=sc.nextInt();
	    int b;
	    int c=0;
	    int d=1;
	    int m=100000;
	    boolean x=true;
	    if(a==0)break;
	    for(int i=0;i<a;i++){
		b=sc.nextInt();
		if(b>=2){
		    x=false;
		    c++;
		}
		if(b>0)d++;
	    }  
	    if(x){
		System.out.println("NA");
	    }else if(c==1){
		System.out.println(2);
	    }else{
		System.out.println(d);
	    }
	}
    }
    public static void main (String[]arg){
	new Main();
    }
}

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

int main() 
{
    long long X, Y;
    cin >> X >> Y;
    
    long long sum = X;
    long long ans = 1;
    for (long long i = X+X; i <= Y; i+=X) {
        if (sum < i && i % sum == 0) {
            X += sum;
            sum = i;
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector <long long> h(n);
    for (int tsumugi = 0; tsumugi < n; tsumugi++){
        cin >> h[tsumugi];
    }
    
    long long ans = 0;
    long long temp = 0;

    for (int matsuri = 0; matsuri < n -1; matsuri++){
        if (h[matsuri] >= h[matsuri + 1]){
            temp++;
            // cout << "Done 1" << endl;
        }
        else{
            ans = max(ans, temp);
            temp = 0;
        }
    }
    ans = max(ans, temp);

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

Measured memory_bytes: 1024
#include <iostream>
#include <map>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define mp(a, b) make_pair(a, b)

int main(){
    multimap<pair<int, int>, pair<int, int> > m;
    rep(i, 150)rep(j, i){
        if(i == 0 || j == 0)continue;
        // m.emplace(mp(i*i + j*j, i*j), mp(j, i));
        m.insert(mp(mp(i*i + j*j, i*j), mp(j, i)));
    }
    int h, w;
    while(cin >> h >> w, h|w){
        pair<int, int> ans = m.upper_bound(mp(h*h + w*w, h*w))->second;
        cout << ans.first << ' ' << ans.second << '\n';
    }
    return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

pi Sub(vi x,vi t,int l){
	int n=x.size();
	int sum=0,cnt=0;
	REP(i,n){
		int w=(t[i]-1)/(l*2);
		sum+=w*(l*2);
		if(t[i]<=w*(l*2)+(l-x[i])*2){
			if(t[i]<=w*(l*2)+x[i]*2){
				cnt++;
			}else{
				if(cnt){
					sum+=l*2;
					cnt--;
				}else{
					sum+=l*2;
				}
			}
		}else{
			sum+=l*2;
		}
	}
	return pi(sum,cnt);
}

signed main(){
	int n=read(),l=read();
	vi x(n),t(n);
	REP(i,n)
		x[i]=read();
	REP(i,n)
		t[i]=read();
	if((l-x[n-1])*2>=t[n-1]){
		x.pop_back();
		t.pop_back();
		n--;
	}
	int mid=upper_bound(ALL(x),l/2)-x.begin();
	int ans=l*2;
	vi x1,x2,t1,t2;
	REP(i,mid){
		x1.PB(x[i]);
		t1.PB(t[i]);
	}
	for(int i=n-1;i>=mid;i--){
		x2.PB(l-x[i]);
		t2.PB(t[i]);
	}
	pi s1=Sub(x1,t1,l);
	pi s2=Sub(x2,t2,l);
	ans+=s1.first;
	ans+=s2.first;
	ans+=(s1.second+s2.second+1)/2*l*2;
	print(ans);
}


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

int main()
{
	int N, K;
	cin >> N >> K;

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

		if (h >= K) {
			count++;
		}
	}

	cout << count << endl;
}





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

int main(void)
{
  int n,max=0,tmp,i;
  scanf("%d",&n);
  int l[n],ans=0;
  for(i=0;i<n;i++)
    {
      scanf("%d",&l[i]);
      if(l[i] > max)
	{
	  max = l[i];
	  tmp = i;
	}
    }
  for(i=0;i<n;i++)
    {
      if(i != tmp)
	{
	  ans += l[i];
	}
    }
  if(ans > max)
    {
      printf("Yes\n");
    }
  else
    {
      printf("No\n");
    }
  
  return 0;
}


Measured memory_bytes: 128
N = int(input())
cnt = 0
ans = 0
for i in range(1,N+1):
    if i%2 == 1:
        for j in range(1,i+1):
            if i%j == 0:
                cnt += 1
    if cnt == 8:
        ans += 1
    cnt = 0
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
multiset<int>  card[1080];
char col[1080];
int num[1080];
int n, m, edge[10800];

bool dfs(int x){
	if(card[x].size() == 0)return true;
	int tmp = *card[x].begin();
	if(card[x].count(tmp) >= 3){
		card[x].erase(card[x].find(tmp));
		card[x].erase(card[x].find(tmp));
		card[x].erase(card[x].find(tmp));
		if(dfs(x))return true;
		card[x].insert(tmp);
		card[x].insert(tmp);
		card[x].insert(tmp);
	}
	if(card[x].count(tmp) && card[x].count(tmp+1) && card[x].count(tmp+2)){
		card[x].erase(card[x].find(tmp));
		card[x].erase(card[x].find(tmp+1));
		card[x].erase(card[x].find(tmp+2));
		if(dfs(x))return true;
	}
	return false;
}

bool ok(int c){
	bool res = dfs(c);
	while(!card[c].empty())card[c].erase(card[c].begin());
	return res;
}

void solve(){
	for(int i = 0;i < 9;i++)cin >> num[i];
	for(int i = 0;i < 9;i++){
		cin >> col[i];
		card[col[i]].insert(num[i]);
	}
	if(ok('R') & ok('G') & ok('B')){
		cout << 1 << endl;
	}
	else cout << 0 << endl;
	return;	
}

int main(){
	int t;
	cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 1256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>
#include <iomanip>

using namespace std;


int main(){
	int a,b,c,d;
	
	cin >> a >> b >> c >> d;
	
	if((b+c-1)/b > (a+d-1)/d)cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}

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

int main(void){
	int A,B;
	scanf("%d %d",&A,&B);
	for(int k=1;k<=1250;k++){
		if((int)(k*0.08)==A){
			if((int)(k*0.1)==B){
				printf("%d",k);
				return 0;
			}
		}
	}
	printf("-1");
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int a,s;
	char op;
	scanf("%d",&a);
	cin>>op;
	while(op!='='){
		if(op=='+'){
			scanf("%d",&s);
			a=a+s;
		}
		else if(op=='-'){
			scanf("%d",&s);
			a=a-s;
		}
		else if(op=='*'){
			scanf("%d",&s);
			a=a*s;
		}
		else if(op=='/'){
			scanf("%d",&s);
			a=a/s;
		}
//		scanf("%d",&a);
		cin>>op;
	}
	printf("%d\n",a);

	return 0;
}

Measured memory_bytes: 1208
#include <cstdio>

#define M 2000010
int A[M], B[M], C[M];

int main()
{
	#ifdef LOCAL
		freopen("E:\\Temp\\input.txt", "r", stdin);
		freopen("E:\\Temp\\output.txt", "w", stdout);
	#endif

	int i, n;
	scanf("%d", &n);
	for(i=0; i<n; ++i) {
		scanf("%d", &A[i]);
		++B[A[i]];
	}
	for(i=0; i<M; ++i) {
		if(B[i]) {
			printf("%d", i);
			--B[i]; break;
		}
	}
	for(i=0; i<M; ++i) {
		if(B[i]) 
			while(B[i]--) printf(" %d", i);
	}
	printf("\n");

	return 0;
}

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

int main() {
  string n;
  cin >> n;
  long long sm = 0;
  for ( int i = 0; i < n.size(); i++ ) {
    sm += (n[i]-'0');
  }
  string ans = ( sm%9 == 0 ) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define PII pair <int, int>
#define x first
#define y second

using namespace std;

int n, m;

char ch[1010][1010];

vector <PII> V(0);

int Dis[1010][1010];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%s", ch[i] + 1);
	memset(Dis, -1, sizeof Dis);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(ch[i][j] == '#') V.push_back(PII(i, j)), Dis[i][j] = 0;
	int ans = 0;
	for(int i = 0; i < V.size(); i++) {
		PII S = V[i];
		for(int j = -1; j <= 1; j++)
			for(int k = -!j; k <= 1; k += 2) {
				PII K = PII(S.x + j, S.y + k);
				if(K.x >= 1 && K.x <= n && K.y >= 1 && K.y <= m && Dis[K.x][K.y] == -1) {
					ans = (Dis[K.x][K.y] = Dis[S.x][S.y] + 1);
					V.push_back(K);
				}
			}
	}
	printf("%d\n", ans);
	return 0;
}

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

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

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

int main(void) {
	
	ll m; cin >>m;
	cout << 24+24-m <<endl;
	
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
char m[105][105];
int W,H;
void dfs(int a,int b,char ch){
	m[a][b]='.';
	int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
	for(int i=0;i<4;i++){
		int nx=dx[i]+a,ny=dy[i]+b;
		if(nx>=0&&nx<W&&ny>=0&&ny<H&&m[nx][ny]==ch)dfs(nx,ny,ch);
	}
}
int main(void){
	while(scanf("%d%d",&W,&H)&&W+H){
		for(int i=0;i<W;i++)
		for(int j=0;j<H;j++)
		cin>>m[i][j];//input;
		int res=0;
		for(int i=0;i<W;i++)
		for(int j=0;j<H;j++){
			if(m[i][j]!='.'){
				dfs(i,j,m[i][j]);
				res++;
			}
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	ll r,D,x;
	cin>>r>>D>>x;
	rep(i,10){
		x = r*x-D;
		cout<<x<<endl;
	}
}

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

using ll = long long int;

const int MAX_N = (int)(1e5 + 5);

int n;
ll m;
ll a[MAX_N];

ll acc_a[MAX_N];

unordered_map<ll, ll> mp;

ll ans;

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &(a[i]));
  }

  acc_a[0] = 0;
  for (int i = 1; i <= n; ++i) {
    acc_a[i] = a[i] + acc_a[i - 1];
  }

  ll whole = 0;
  for (int i = 0; i <= n; ++i) {
    // cout << i << ":" << (acc_a[i]) << "_" << (acc_a[i] % m) << endl;
    whole += ((acc_a[i] % m) == 0) ? 1 : 0;
    mp[(acc_a[i] % m)] += 1;
  }

  // cout << whole << endl;

  /*
  for (auto e: mp) {
    cout << e.first << "_" << e.second << endl;
  }
  */

  unordered_map<ll, ll> cur_mp;
  for (int i = 1; i <= n; ++i) {
    ll target = (acc_a[i] % m);

    cur_mp[target] += 1;

    ans += mp[target] - cur_mp[target];
  }

  printf("%lld\n",ans);

  /*
  ll tmp = 0;
  for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) {
    if (i > j) continue;
    ll sum = acc_a[j] - acc_a[i - 1];

    if (sum % m == 0) {
      cout << i << "_" << j << endl;
    }
  }
  */

  return 0;
}

Measured memory_bytes: 8228
import heapq

a, b, c, d = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = list(map(int, input().split()))
B = sorted(B, reverse=True)
C = list(map(int, input().split()))
C = sorted(C, reverse=True)
ans = []
q_list = []
n_q = []
heapq.heappush(n_q, [-(A[0] + B[0] + C[0]), 0, 0, 0])
for i in range(d):
    x, y, z, v = map(int, heapq.heappop(n_q))
    ans.append(-x)

    if y + 1 < a and [y + 1, z, v] not in q_list:
        heapq.heappush(n_q, [-(A[y + 1] + B[z] + C[v]), y + 1, z, v])
        q_list.append([y + 1, z, v])
    if z + 1 < b and [y, z + 1, v] not in q_list:
        heapq.heappush(n_q, [-(A[y] + B[z + 1] + C[v]), y, z + 1, v])
        q_list.append([y, z + 1, v])
    if v + 1 < c and [y, z, v + 1] not in q_list:
        heapq.heappush(n_q, [-(A[y] + B[z] + C[v + 1]), y, z, v + 1])
        q_list.append([y, z, v + 1])

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


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

vector<int> inv, fac, finv;

inline ll binomial(int a, int b) {
    return ((ll)fac[a] * finv[b] % MOD) * finv[a - b] % MOD;
}

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

    int N, M;
    cin >> N >> M;
    vector<vector<bool>> A(N, vector<bool>(N)), B(M, vector<bool>(M));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            char c;
            cin >> c;
            A[i][j] = (c == '#');
        }
    }

    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < M; ++j) {
            char c;
            cin >> c;
            B[i][j] = (c == '#');
        }
    }

    for (int i = 0; i <= N - M; ++i) {
        for (int j = 0; j <= N - M; ++j) {
            bool isok = true;
            for (int k = 0; k < M; ++k) {
                for (int l = 0; l < M; ++l) {
                    if (A[i + k][j + l] != B[k][l]) {
                        isok = false;
                        break;
                    }
                }
                if (!isok)
                    break;
            }
            if (isok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio> 
int main(){
	int N,d[100]={},ans=0;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int x;
		scanf("%d",&x);
		d[x-1]=1;
	}
	for(int i=0;i<100;i++)ans+=d[i];
	printf("%d",ans);
}

Measured memory_bytes: 128
n = int(input())

slist = [0]*4
for i in range(n):
    result = input()

    if result == "AC":
        slist[0]+=1
    if result == "WA":
        slist[1]+=1
    if result == "TLE":
        slist[2]+=1
    if result == "RE":
        slist[3]+=1

print("AC x ",slist[0])
print("WA x ",slist[1])
print("TLE x ",slist[2])
print("RE x ",slist[3])


Measured memory_bytes: 9204
#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
ll n,m,Q,F[1010101],sz[1010101]; 
struct node{
	int id,x,y;
}q[1010101];
inline bool cmp(node a,node b){
	return a.id<b.id;
}
int find(int u){
	if (F[u]!=u) F[u]=find(F[u]);
	return F[u];
}
inline void fail(){
	puts("No");exit(0);
}
signed main(){
	n=read(),m=read(),Q=read();
	for (int i=1;i<=n;i++) F[i]=i,sz[i]=1;
	for (int i=1;i<=Q;i++){
		q[i].x=read()+1,q[i].y=read()+1,q[i].id=read();
	}
	sort(q+1,q+1+Q,cmp);
	register int i;
	ll tot=0,_min=0,_max=0,tot1=0;
	for (i=1;i<=Q;i++){
		if (q[i].id==1) break;
		int xx=find(q[i].x),yy=find(q[i].y);
		if (xx==yy) continue;
		F[xx]=yy,tot1++;
		sz[yy]+=sz[xx];
	}
	bool flag=0;
	if (i==Q+1) flag=1;
	for (;i<=Q;i++){
		if (find(q[i].x)==find(q[i].y)) fail();
	}
	for (int i=1;i<=n;i++){
		if (sz[find(i)]==1) tot++;
	}
	ll xx=(n-tot-tot1);
	if (xx==1&&tot==1&&!flag) fail();
	_min=(flag==1?n-1:n);
	_max=tot1+(xx+tot)*(xx+tot-1)/2;
	if (m>=_min&&m<=_max){
		puts("Yes");
		return 0;
	}
	fail();
	return 0;
}



Measured memory_bytes: 6336
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  std::vector< ll > vb(N, 0LL);
  std::vector< ll > vsuma(N, 0LL);
  std::vector< ll > vsumb(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];

  }
  for (ll i = 0; i < N; i++) {
    std::cin >> vb[i];
  }

  vsuma[0] = va[0];
  vsumb[0] = vb[0];
  for (ll i = 1; i < N; i++) {
    vsuma[i] = vsuma[i-1] + va[i];
    vsumb[i] = vsumb[i-1] + vb[i];
  }

  ll ans = 0LL;
  for (ll i = 0; i < N; i++) {
    ll sum = 0LL;
    if (i == 0) {
      sum = vsuma[i] + vsumb[N-1];
    } else {
      sum = vsuma[i] + vsumb[N-1] - vsumb[i-1];
    }
    ans = std::max(ans, sum);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s; cin>>s;
    int n=s.size();
    if(n%2==0){
        int ans=n/2;
        char che=s[n/2];
        rep(i,n/2){
            if(s[n/2-i-1]==che && s[n/2+i]==che){
                ans++;
            }else break;
        }
        cout<<ans<<endl;
        return 0;
    }else{
        int ans=(n+1)/2;
        char che=s[n/2];
        rep(i,n/2){
            if(s[n/2-1-i]==che && s[n/2+1+i]==che){
                ans++;
            }else break;
        }
        cout<<ans<<endl;
        return 0;
    }
}

Measured memory_bytes: 3748
<?php
fscanf(STDIN, '%d %d', $n, $m);
$numbers = fgets(STDIN);
$exploded_numbers = explode(' ', trim($numbers));
rsort($exploded_numbers);

$array_sum = array_sum($exploded_numbers);
$wall = (int)ceil($array_sum / (4 * $m));

for ($i=0; $i<$m; $i++) {
  if ($exploded_numbers[$i] < $wall) {
    echo 'No';
    exit;
  }
}

echo 'Yes';

Measured memory_bytes: 4728
def main():
    N = int(input())
    friendly = list(map(int, input().split()))

    friendly.sort()

    ans = friendly[-1]
    
    FLAG = True
    index = N - 2
    
    
    for i in range(N - 2):
        if (FLAG):
            ans += friendly[index]
            FLAG = False
        else:
            ans += friendly[index]
            FLAG = True
            index -= 1
    
        
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31436
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

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

    vector<int> cnt;
    for(int i=0; i<n; i++){
        int num=1;
        while(i + 1 < n && s[i] == s[i+1]){
            num++;
            i++;
        }

        cnt.eb(num);
    }

    int m=cnt.size();
    vector<int> sum(m+10, 0);
    for(int i=0; i<m; i++){
        sum[i+1] = sum[i] + cnt[i];
    }

    int ans=0;
    for(int i=(s[0]=='0'?1:0); i<=m; i+=2){
        int ub = sum[min(i+k*2-1, m)];
        int lb = sum[max(i-2, 0)];

        chmax(ans, ub - lb);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1272
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,r=0;
	cin>>N;
	for(int k=1;k<=N;k+=2)
	{
		int t=0;
		for(int i=1;i<=k;i++)
			if(k%i==0)t++;
		if(t==8)r++;
	}
	cout<<r<<endl;
}


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

ll keta(ll t){
  ll k = 0; 
  while(t > 0){
    t >>= 1;
    k++;
  }
  return k;
}

int main(){
  ll N;  cin >> N;
  multiset<ll> a;
  for(ll i = 0; i < N; i++){
    ll tmp; cin >> tmp;
    a.emplace(tmp);
  }
  ll ans = 0;
  
  while(a.size() > 1){
    auto it = a.end();
    it--;
    a.erase(it);
    ll pr = (1 << keta(*it)) - *it;
    auto pit = a.find(pr);
    if(pit != a.end()){
      ans++;
      a.erase(pit);
    }
  }
  cout << ans;
}

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


void solve(std::string C){
    const string x = "abcdefghijklmnopqrstuvwxyz";
    cout << x.at(C.at(0) - 'a' + 1) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::string C;
    std::cin >> C;
    solve(C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int h,w,d,q,n;
int a[303][303];
int l[100010],r[100010];
pii p[100010];

int main(){
	cin>>h>>w>>d;
	n=h*w;
	REP(i,h){
		REP(j,w){
			cin>>a[i][j];
			a[i][j]--;
			p[a[i][j]]=pii(i,j);
		}
	}
	cin>>q;
	REP(i,q){
		cin>>l[i]>>r[i];
		l[i]--; r[i]--;
	}
	int cost[d][n/d+1];
	REP(i,d)REP(j,n/d+1)cost[i][j]=0;

	REP(i,d){
		int ny=p[i].first;
		int nx=p[i].second;
		for(int j=1;j<n/d+1;j++){
			if(i+d*j>=n)break;
			int ty=p[i+d*j].first;
			int tx=p[i+d*j].second;
			int c=abs(ny-ty)+abs(nx-tx);
			//cout<<ny<<" "<<nx<<" "<<ty<<" "<<tx<<endl;
			//show(c);
			cost[i][j]=cost[i][j-1]+c;
			ny=ty;
			nx=tx;
		}
	}
	/*
	REP(i,d){
		REP(j,n/d+1){
			cout<<cost[i][j]<<" ";
		}
		cout<<endl;
	}
	//*/
	
	REP(time,q){
		ll ans=0;
		int i=l[time]%d;
		ans+=cost[i][(r[time]-i)/d]-cost[i][(l[time]-i)/d];
		cout<<ans<<endl;
	}
	return 0;
}


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

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

int N;
int L[101010];
int R[101010];

int SL[202020];
int SR[202020];
const int G=101000;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	SR[G]++;
	SL[G]++;
	FOR(i,N) {
		cin>>L[i]>>R[i];
		SR[G+L[i]]++;
		SL[G+R[i]]++;
	}
	for(i=G+G;i>=0;i--) SR[i]+=SR[i+1];
	FOR(i,2*G) if(i) SL[i]+=SL[i-1];
	
	ll ret=0;
	for(i=10;i<2*G-10;i++) {
		x = SL[i];
		y = SR[i+1];
		ret += min(x,y)*2;
		
	}
	cout<<ret<<endl;
}


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


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

typedef pair<int,string> P;
int n;

void Print(vector<queue<P> > &qs, int dot, int target) {
    while(qs[target].size()) {
        for(int i = 0; i < dot; i++) cout << ".";
        P p  = qs[target].front(); qs[target].pop();
        cout << p.second << endl;
        if(p.first < n)
            Print(qs, dot + 1, p.first);
    }
}

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

    vector<queue<P> > ques(n);
    for(int i = 0; i < n; i++) {
        ques[k[i]].push(P(i + 1, m[i]));
    }

    Print(ques, 0, 0);

    return 0;
}

Measured memory_bytes: 1868
#include "bits/stdc++.h"
using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int X;
    cin >> X;

    int ans = 0;

    for (int i = 0; i <= A; i++){
        for (int j = 0; j <= B; j++){
            for (int k = 0; k <= C; k++){
                if (i * 500 + j * 100 + k * 50 == X) ans++;
            }
        }
    }
    cout << ans << endl;
}

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


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

    string f;
    cin >> f;

    if(f==s){
        cout << n-1 << " " << m << endl;
    }
    else cout << n << " " << m-1 << endl;
    return 0;
}


Measured memory_bytes: 256
if let s = readLine() {
  let ss = s.split(separator: " ")
  let a = Int(ss[0])!
  let b = Int(ss[1])!
  let c = Int(ss[2])!
  let k = Int(ss[3])!
  switch k {
  case 1...a:      print(k)
  case a...a+b:    print(a)
  case a+b...a+b+c:print(a-(k-a-b))
  default: break
  }
}

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

int main(){
	int a,b;
  	string c = "";
  	string d = "";
  cin>>a>>b;
  
	for(int i = 0; i < a; i++) {
  		c += (char) b + '0';
  	}
	for(int i = 0; i < b; i++) {
      	d += (char) a + '0';
    }
  if(a<b){
    cout<<d;
  }
  else{ 
    cout<<c;
  }
}

Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
/*using vi = vector <int>;
using vs = vector <string>;
using vc = vector <char>;*/
//vector<vector<char> > hyou(N, vector<char>(N));
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
//グローバル変数宣言
int b=0,c=0,d=0,n,k;

signed main(){
   cin>>k>>n;
   vector<int>a(n);
   rep(i,n)cin>>a[i];
   rep(i,n){
       if(i==0)b=a[i]+k-a[n-1];
       else b=max(a[i]-a[i-1],b);
       }
       print(k-b);
}


Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < 25; i++) {
        for(int j = 0; j < 15; j++) {
            if(4 * i + 7 * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int main(){
    int num[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    int x,y;
    cin>>x>>y;
    if(num[x]==num[y])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
void main() {
	((N, arr) => ((S, T) => zip(S, T).map!(p => format("%s%s", p[0], p[1])).join)(arr[0], arr[1]))(ri, readAs!(string[])).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

int main(void){
  int a, b;
  scanf("%d %d",&a ,&b);
  if((a+b)%2==0) printf("%d\n",(a+b)/2);
  else printf("%d\n",(a+b)/2+1);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int N;cin>>N;
    vector<double> A(N);
    
    priority_queue<double,vector<double>,greater<double>> PQ;
    
    for(int i=0;i<N;i++){
        int a;cin>>a;
        PQ.push(a);
    }
    
    while(PQ.size()>=2){
        double a=PQ.top();PQ.pop();
        double b=PQ.top();PQ.pop();
        PQ.push((a+b)/2.0);
    }
    
    cout<<setprecision(25)<<PQ.top()<<endl;
}




Measured memory_bytes: 256